3

I'm trying to create software to restore backups that I already create with scripts. I haven't needed to restore any, fortunately, but now I want to move the contents of one of my backups to a SSD drive, and it turns out it's harder than I expected.

Right now I'm trying to recreate the partition table. I'd like to use parted because it seems the easiest of the available tools to use in a script. I see two things that are puzzling me.

First, a command like

parted /dev/sdh mklabel gpt mkpart primary fat32 2048 4096 print

makes a gpt partition table and a partition, but it shows a name "primary" and that is what blkid calls a "PARTLABEL". Reading the info and man pages seems to indicate it should be the filesystem type, not name. On experimentation, it appears no fs type is accepted any more, and that is the name instead.

The second problem is: I do not want a name on the partition at all, but I've tried "" and " " with no luck.

So: how do I create a partition without a PARTLABEL? I can certainly do it in gparted, but I cannot script that.

Eliah Kagan
  • 119,640
ForDummies
  • 555
  • 5
  • 16

2 Answers2

3

I found the way, and boy is it odd. If I want parted to accept a blank string (at least for this purpose) I have to quote it three times. That's right, three.

It looks like this:

parted -s $destination mkpart "'\ '" ntfs  1874585600s  1876559871s

So it's a backslash-space inside single quotes inside double quotes. That works, and I've been unable to find anything simpler. For instance if I just leave it out, parted still accepts the command, but uses 'ntfs' both as a filesystem type and a partition name.

Grrrrr.

Eliah Kagan
  • 119,640
ForDummies
  • 555
  • 5
  • 16
0

I tried various methods to get an actual blank name (also this) but no method worked for a non-interactive script. However using a pipe to automatically "type" in the commands worked:

printf "\nfat32\n1048576B\n537919487B\n" | parted /dev/sda mkpart
Output:
Partition name?  []?
File system type?  [ext2]? fat32
Start? 1048576B
End? 537919487B
Information: You may need to update /etc/fstab.

For some reason the File system was blank:

parted /dev/sda u b p
Number  Start     End         Size        File system  Name  Flags
 1      1048576B  537919487B  536870912B                     msftdata

Had to format it with this as final step:

mkfs -t fat -F 32 /dev/sda1