#1270 Issue closed: old parted does not supprt IEC binary units like MiB GiB so that 300_format_usb_disk needs to be fixed

Labels: enhancement, cleanup, fixed / solved / done, minor bug

jsmeix opened issue at 2017-03-29 13:46:

Current 300_format_usb_disk.sh calls parted like

parted -s /dev/sdb mkpart primary 8Mib 208Mib

but old parted (e.g. GNU Parted 1.6.25.1 on SLE10)
only supports those units

# parted -s /dev/hdc help unit        
  unit UNIT                     set the default unit to UNIT
        UNIT is one of: s, B, kB, MB, GB, TB, compact, cyl, chs, %

and with 'MiB' it silently uses something else as unit which ressults
false partitioning ((e.g. GNU Parted 1.6.25.1 on SLE10):

# parted /dev/hdc mkpart primary 8Mib 108Mib

# parted /dev/hdc unit B print
Disk geometry for /dev/hdc: 0B - 2147483136B
Disk label type: msdos
Number  Start   End     Size    Type      File system  Flags
1       8000000B 107999744B 100000256B primary                type=83

but using 'B' as unit works:

# echo '8*1024*1024' | bc -l
8388608

# echo '108*1024*1024 - 1' | bc -l
113246207

# parted /dev/hdc mkpart primary 8388608B 113246207B

# parted /dev/hdc unit B print
Disk geometry for /dev/hdc: 0B - 2147483136B
Disk label type: msdos
Number  Start   End     Size    Type      File system  Flags
1       8388608B 113245696B 104857600B primary                type=83

# echo '100*1024*1024' | bc -l
104857600

Note that the end byte is the last byte that belongs
to that partition so that one must be careful not to use
113246208 = 108 * 1024 * 1024 as end byte
but 113246207 = 108 * 1024 * 1024 - 1

I will adapt 300_format_usb_disk.sh
to let parted therein work with bytes
to be fully backward compatible.

jsmeix commented at 2017-03-30 11:36:

Even with GNU bash, version 3.1.17 on SLES10
bash arithmetic evaluation works up to 2^63 - 1
cf.
https://github.com/rear/rear/issues/1269#issuecomment-290344953
and
https://github.com/rear/rear/issues/1269#issuecomment-291116581
so that we can use bytes 'B' as unit for parted
up to disk sizes of 9223372036854775807 bytes
i.e. up to 8 EiB minus one byte.

jsmeix commented at 2017-03-31 07:14:

With https://github.com/rear/rear/pull/1273 merged
this issue is fixed.


[Export of Github issue for rear/rear.]