0

We are using a Python script for running sfdisk creating partitions on our Linux. The code is as below:

        stdin,stdout=\
        (lambda x:(x.stdin,x.stdout))\
        (subprocess.Popen(
            ["/sbin/sfdisk","-uM","--no-reread",device],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT))

#<start>;<size>;<id>;<bootable>;
    t="""0;95;83;
;160;b;*
;;E;
;0;;
;20;b;
;95;b;
;;b;
"""
    print "Writing\n%s"%(t,)
    stdin.write(t)
    stdin.close()

"""Explanation:
/ 100MB (hda1)
/mnt/system 175MB (hda2)
/mnt/configuration 25MB (hda5)
/mnt/logs 100MB (hda6)
/mnt/user 88MB (hda7)
"""

After running this command I am seeing that the explanation is correct and for example systm has 175 MB. What I don't understand is how the size 95 is mapped to 100 Megabyte, 160 to 175, 20 to 25 and so on.

The other question is if I want to increase the size of system to 210 megabyte then what is correct number to write in the command?

1

Note, you have a slightly out-of-date sfdisk command, as since 2015 version 2.26 it no longer accepts -uM, which is used to set the default "unit".

The difference you are seeing is due to whether numbers are given in MB i.e. Megabytes (1000*1000) or MiB i.e. Mebibytes (1024*1024). 100MB is approximately 95MiB.

If you want to future proof your code against a newer sfdisk you should remove the -uM and assume sizes are in sectors of 512 bytes. The newer version allows you to give numbers with a suffix like MiB.

210MB can be calculated as:

echo '210*1000*1000/1024/1024' | bc

about 200MiB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.