23

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
  1. Is it the correct way to create partition in the script ? Is there any better way ?
  2. 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
2
  • It may be (at least didactically) worth to mention that parted /dev/mmcblk0 --script mklabel gpt deletes all existing partitions. For me it was parted /dev/mmcblk0 --script mklabel msdos
    – grenix
    Jan 28, 2022 at 11:28
  • Why is there a gap between 132MB and 233MB? Mar 28 at 18:55

2 Answers 2

31

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.

5
  • Thank you for reply, Let me test it. I will update the result.
    – ART
    May 5, 2015 at 16:13
  • I don't get that warning now, Thank you :)
    – ART
    May 5, 2015 at 16:27
  • any suggestions for this unix.stackexchange.com/questions/248939/…
    – ART
    Dec 12, 2015 at 13:03
  • I 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/…
    – CodeMed
    Mar 7, 2017 at 20:05
  • 2
    I'd add '--' between the device and the commands - this way you can use '-1' for max size.
    – niry
    Jun 15, 2018 at 23:37
5

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.

6
  • At 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
    Mar 16, 2019 at 14:39
  • 1
    Ok, 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.
    – plugwash
    Mar 16, 2019 at 14:46
  • FWIW, 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 the primary here to an arbitrary partition name.
    – Asmadeus
    Oct 7, 2019 at 4:56
  • 2
    @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.
    – Khrystoph
    Oct 30, 2019 at 19:01
  • Negative arguments and unit "MiB" (I don't know about "-s") do not go well together. The result will be in most cases be "Warning: The resulting partition is not properly aligned for best performance" if the total device size is not exactly divisible by 1 MiB (I have yet to see an example where it is). - Mar 28 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .