6

We are using am335x based custom board, we have eMMC as secondary storage device. Now to list partitions we are using parted utility but parted prints partition sizes in the MB instead of MiB.

Is there any way to ask parted to print partition sizes in MiB unit instead of MB unit?

You can refer to below output which shows the parted is printing sizes in the KB or MB but not in KiB or MiB.

# parted --list
Model: MMC MMC04G (sd/mmc)
Disk /dev/mmcblk0: 3842MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name        Flags
 1      131kB   262kB   131kB                
 2      262kB   393kB   131kB                
 3      393kB   524kB   131kB                
 4      524kB   1573kB  1049kB               
 5      1573kB  2621kB  1049kB               
 6      2621kB  3146kB  524kB                
 7      3146kB  3277kB  131kB                
 8      3277kB  8520kB  5243kB               
 9      8520kB  13.8MB  5243kB               
10      13.8MB  19.0MB  5243kB               
11      19.0MB  19.3MB  262kB                
12      19.3MB  19.5MB  262kB                
13      19.5MB  19.8MB  262kB                
14      21.0MB  32.5MB  11.5MB               
15      33.6MB  243MB   210MB   ext4         
16      243MB   453MB   210MB   ext4         
17      453MB   558MB   105MB   ext4         
18      558MB   621MB   62.9MB  ext4         
19      621MB   830MB   210MB   ext4         
20      830MB   867MB   36.7MB  ext4         
21      867MB   3827MB  2960MB  ext4         
don_crissti
  • 82,805
ART
  • 1,131

3 Answers3

6

Is there any way to ask parted to print partition sizes in MiB unit instead of MB unit?

Yes:

parted <<<'unit MiB print all'

or

printf %s\\n 'unit MiB print list' | parted

or

parted <<\IN                             
unit MiB print list
IN

Same in interactive mode: launch parted and then enter unit MiB print list

don_crissti
  • 82,805
  • parted <<<'unit MiB print all' doesn't work while other two commands works like a charm. Thank you for reply. – ART Jan 15 '16 at 09:05
  • 1
    @AnkurTank - depends whether your shell supports <<< (herestrings) or not. – don_crissti Jan 15 '16 at 09:07
  • shouldn't it be parted <<<'unit MiB print list ? instead of parted <<<'unit MiB print all'. However for me print list also doesn't work but i was just curious. – ART Jan 15 '16 at 09:09
  • On similar lines i found another simple command parted --script /dev/mmcblk0 unit MiB print – ART Jan 15 '16 at 09:20
  • if you don't mind, could you please update parted --script /dev/mmcblk0 unit MiB print also in your answer ? it would be easy for someone to notice that. – ART Jan 15 '16 at 09:36
  • 1
    @AnkurTank - with version 3.2 list or all is the same (with older versions ymmv, see parted --help). Also, what is the point of using the --script option here: parted --script /dev/mmcblk0 unit MiB print when you can simply run parted /dev/mmcblk0 unit MiB print ? – don_crissti Jan 15 '16 at 10:18
  • You are right, parted /dev/mmcblk0 unit MiB print also works :) – ART Jan 15 '16 at 10:22
1

You'd think this would be straightforward with something like

parted unit MiB --list

but this doesn't work. The closest equivalent that I can derive is this, although there's nothing wrong with you replacing the find... with an explicit list of devices if you happen to have them to hand

for dev in $(find /dev/??? /dev/mmcblk* -maxdepth 0 -type b 2>/dev/null); do parted "$dev" unit MiB print; done
Chris Davies
  • 116,213
  • 16
  • 160
  • 287
1

The parted documentation is a bit confusing, but, as the comments point out in the end, the following should work well. Use sudo where appropriate.

Find all disks: fdisk -l or parted -l.

Print all partitions in MiB, where /dev/mmcblk0 is the disk you're interested in:

parted /dev/mmcblk0 unit MiB print

As above, but also print the unpartitioned space:

parted /dev/mmcblk0 unit MiB print free

The synopsis listed by man parted is this:

parted [options] [device [command [options...]...]]

The device is not optional when issuing commands on it.

ovichiro
  • 111