Scripteable GPT partitions using parted
Solution 1
It's correct in principle but you might consider reducing it to a single parted
call.
parted --script /device \
mklabel gpt \
mkpart primary 1MiB 100MiB \
mkpart primary 100MiB 200MiB \
...
Your alignment issue is probably because you use MB
instead of MiB
. You should not need an actual align-check
command when creating partitions on MiB
boundaries / on a known device.
Solution 2
I know this is old and a pretty good answer in that you can use MiB, but I'd like to throw another option out there for other folks.
Within the script call (--script or -s for the short version), you can add the -a option, which tells it to align and pass the option "optimal" when creating the partitions. Something like this:
sudo parted -s -a optimal -- /dev/sdX mkpart primary 1MiB -2048s
this is just an example of starting at the 1st Mebibyte and ending at the end of the disk minus the last Mebibyte to leave the GPT table in place.
Related videos on Youtube
ART
Updated on September 18, 2022Comments
-
ART over 1 year
I am partitioning eMMC using following commands in the script,
parted /dev/mmcblk0 --script mklabel gpt parted /dev/mmcblk0 --script mkpart primary ext4 32MB 132MB parted /dev/mmcblk0 --script mkpart primary ext4 233MB 433MB parted /dev/mmcblk0 --script mkpart primary ext4 433MB 533MB parted /dev/mmcblk0 --script mkpart primary ext4 533MB 593MB parted /dev/mmcblk0 --script mkpart primary ext4 593MB 793MB parted /dev/mmcblk0 --script mkpart primary ext4 793MB 3800MB parted /dev/mmcblk0 --script align-check min 1
- Is it the correct way to create partition in the script ? Is there any better way ?
-
After creating first partition i am getting following warning
Warning: The resulting partition is not properly aligned for best performance.
Do i need to worry about it ? I tried
parted /dev/mmcblk0 --script align-check min 1
but not sure that's the solution. Any pointers for that?
I am going through this link meanwhile any other suggestions ?Edit: Just a quick reference for frostschutz reply,
MiB = Mebibyte = 1024 KiB KiB = Kibibyte = 1024 Bytes MB = Megabyte = 1,000 KB KB = Kilobyte = 1,000 Bytes
-
grenix about 2 yearsIt may be (at least didactically) worth to mention that
parted /dev/mmcblk0 --script mklabel gpt
deletes all existing partitions. For me it wasparted /dev/mmcblk0 --script mklabel msdos
-
ART almost 9 yearsThank you for reply, Let me test it. I will update the result.
-
ART almost 9 yearsI don't get that warning now, Thank you :)
-
ART over 8 yearsany suggestions for this unix.stackexchange.com/questions/248939/…
-
RabT about 7 yearsI have tried to modify your code for use in a different context. Are you willing to advise? Here is the link: unix.stackexchange.com/questions/349833/…
-
niry almost 6 yearsI'd add '--' between the device and the commands - this way you can use '-1' for max size.
-
plugwash about 5 yearsAt least on my system the "-2048s" doesn't seem to be accepted as a notation for the "end" parameter, it seems to be intepreted as an option.
-
plugwash about 5 yearsOk, after trying many different google searches it seems the lone dash in the middle of the OPs command needs to be a double dash. I would edit the answer to correct these issues but I am running into stack exchanges minimum edit size rule.
-
Asmadeus over 4 yearsFWIW, parted is smart enough to not cobbler the GPT backup label if you end the partition with
-0
(now checked), thus saving one MiB. One might also want to change theprimary
here to an arbitrary partition name. -
Khrystoph over 4 years@plugwash, you have to have the "--" in the command, otherwise it complains about the "-" in the "-2048s" as the minus indicates how far to go back from the end. If the "--" is not present, bash interprets it as a cli arg, and there is no -2 arg in parted. this was likely an error in copy to M$ word or something, then into the response box. iirc, older versions of parted didn't like or don't accept setting the second parameter to -1MiB, which is why I used sector count, because that WAS allowed. asmadeus: I'm not sure parted has always behaved this way, so it's better safe than sorry.