Correctly finding disk size on hosts on mixed setup of hosts

417 views Asked by At

I am trying to find size on a large no. of different linux machines with various kind of FS arrangements. 1. plain JBOD setup (I can parse sfdisk -s) 2. Hardware raid setup ( again parse fdisk -s) 3. Software raid setup ( it seems like fdisk gives an error in total size, it adds up the logical devices and the raid devices )

other ways of segregating sw-raid with real logical drives is via 'blkid': but getting the correct disk size is getting complex ie. get the 'linux_raid_member' omit that from sfdisk list and adding them togethjer separately

Basically I have the following on a host and want an easier solution if it exists and I am not knowing about it.

[root@blg90083 ~]# blkid
/dev/sdb1: UUID="7f729082-186f-f46d-8fe8-84d260bef9d4" UUID_SUB="6fa3dc8a-31ad-fcf2-d0b2-81c18952d4d5" LABEL="blg90083.rain.yvm.yahoo.com:0" TYPE="linux_raid_member" 
/dev/sdb2: UUID="7b14fafb-5312-12a2-54e9-eedb578bac65" UUID_SUB="93826b2c-eaf3-b75f-b239-a179f87d0964" LABEL="blg90083.rain.yvm.yahoo.com:1" TYPE="linux_raid_member" 
/dev/sdb3: UUID="1dd82b73-ee85-6887-6f2f-9eba7cd6bdf4" UUID_SUB="78bae867-ae23-62fa-fb2b-7d32c66418d3" LABEL="blg90083.rain.yvm.yahoo.com:2" TYPE="linux_raid_member" 
/dev/sdb4: LABEL="vm1" UUID="6f04ae19-0359-44f5-9772-a3d166d47ff2" TYPE="ext4" 
/dev/sdc1: UUID="fac06467-eb52-53e7-c1a8-7620cfe729c2" UUID_SUB="62e39030-5031-c022-    ffff-942b43e40fc5" LABEL="blg90083.rain.yvm.yahoo.com:3" TYPE="linux_raid_member" 
/dev/sdc2: LABEL="vm2" UUID="ca99d725-88e9-44db-ba32-232b59901719" TYPE="ext4" 
/dev/sdd1: UUID="fac06467-eb52-53e7-c1a8-7620cfe729c2" UUID_SUB="b202e3dc-d3d4-5789-f636-cb72f9ea7438" LABEL="blg90083.rain.yvm.yahoo.com:3" TYPE="linux_raid_member" 
/dev/sdd2: LABEL="vm3" UUID="ee4e29f0-6128-4bbd-a896-536b42831e7c" TYPE="ext4" 
/dev/sda1: UUID="7f729082-186f-f46d-8fe8-84d260bef9d4" UUID_SUB="3c84576a-21a0-6202-514a-a9a525bf96a7" LABEL="blg90083.rain.yvm.yahoo.com:0" TYPE="linux_raid_member" 
/dev/sda2: UUID="7b14fafb-5312-12a2-54e9-eedb578bac65" UUID_SUB="50a6c707-2ddb-45ec-aa35-009bbb2b2e8c" LABEL="blg90083.rain.yvm.yahoo.com:1" TYPE="linux_raid_member" 
/dev/sda3: UUID="1dd82b73-ee85-6887-6f2f-9eba7cd6bdf4" UUID_SUB="2b3a23f7-52cc-ed4f-4a74-3ec6202e15b8" LABEL="blg90083.rain.yvm.yahoo.com:2" TYPE="linux_raid_member" 
/dev/sda4: LABEL="vm0" UUID="cfd97d8a-b970-431b-851d-0b9bbd192906" TYPE="ext4" 
/dev/md0: UUID="1b9ebdab-069c-4a05-938c-6e789e896fc4" TYPE="ext3" 
/dev/md1: UUID="856064eb-e631-42be-a6c3-454cbe968534" TYPE="ext4" 
/dev/md2: UUID="2cd6b9b2-e043-4337-af14-1166ec770021" TYPE="ext4" 
/dev/md3: UUID="b9fc9734-baf5-4f05-8bcc-8c4bbf70e0f2" TYPE="swap" 

[root@blg90083 ~]# sfdisk -s | egrep 'md[0123]'
/dev/sdb: 1953514584
/dev/sdc: 1953514584
/dev/sdd: 1953514584
/dev/sde: 1953514584
/dev/sdf: 1953514584
/dev/sda: 1953514584
/dev/md0:    124988
/dev/md1:   7998452
/dev/md2:  63998904
/dev/md3:  15998904
total: 11809208752 blocks

[root@blg90083 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/md1              7.6G  3.6G  3.9G  49% /
tmpfs                  12G     0   12G   0% /dev/shm
/dev/md0              119M   55M   63M  47% /boot
/dev/sda4             1.8T  204M  1.8T   1% /vm/0
/dev/sdb4             1.8T  196M  1.8T   1% /vm/1
/dev/sdc2             1.9T  196M  1.8T   1% /vm/2
/dev/sdd2             1.9T  196M  1.8T   1% /vm/3
/dev/md2               61G  182M   60G   1% /home
1

There are 1 answers

1
jørgensen On BEST ANSWER

Obtain size:

blockdev --getsize64 /dev/sda

Tree overview (requires util-linux 2.19):

lsblk

lsblk also has a handful of options to customize its output (e.g. -b).