How to make parted always show the same unit

10,255

Solution 1

According to parted(1), unit can be one of:

  • s sectors
  • B bytes,
  • kB, MB, GB, TB,
  • % percentage of device size,
  • cyl cylinders,
  • chs cylinders, heads, sectors, or
  • compact megabytes for input, and a human-friendly form for output.

e.g:

$ for hdd in /dev/sd? ; do 
      parted -m $hdd unit MB print; done  |\
  column -s: -t
BYT;
/dev/sda  500108MB  scsi      512       512       msdos  ATA WDC WD5002ABYS-0;
2         0.03MB    60003MB   60003MB   reiserfs  ;
3         60003MB   60250MB   247MB     ;
4         60250MB   499858MB  439608MB  ;
5         60250MB   75253MB   15003MB   ext3      ;
6         75253MB   200253MB  125000MB  ext3      ;
7         200253MB  499858MB  299606MB  ;
1         499858MB  500105MB  247MB     ext2      boot;
BYT;
/dev/sdb  500108MB  scsi      512       512       msdos  ATA ST3500418AS;
2         0.03MB    60003MB   60003MB   reiserfs  ;
3         60003MB   60250MB   247MB     ext3      ;
4         60250MB   499858MB  439608MB  ;
5         60250MB   75253MB   15003MB   ;
6         75253MB   200253MB  125000MB  ;
7         200253MB  499858MB  299606MB  ;
1         499858MB  500105MB  247MB     ext2      boot;

Solution 2

I think you should not use the -l argument of parted but the print subcommand:

parted /dev/sda unit MB print

When I do it this way I get all sizes in MB.

Share:
10,255
Alexander Theißen
Author by

Alexander Theißen

Updated on June 20, 2022

Comments

  • Alexander Theißen
    Alexander Theißen almost 2 years

    I use parted in a script. For that reason I need parted to always use the same unit. Otherwise I am not able to do reasonable calculations.

    In this example parted mixes KB and GB:

    pcsyn-038 user # parted -l
    Model: ATA ST9250315AS (scsi)
    Disk /dev/sda: 250GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End     Size    Type     File system     Flags
     1      1049kB  21,5GB  21,5GB  primary  ext4
     3      21,5GB  248GB   226GB   primary  ext4
     2      248GB   250GB   2147MB  primary  linux-swap(v1)
    

    This does not have any effect on the output:

    parted /dev/sda unit MB
    
  • mivk
    mivk almost 12 years
    But the versions of fdisk most commonly installed do not understand GPT partitions. So you cannot rely on fdisk anymore.