A Bash script to report partitions, types, file systems, and disk space usage
showmydisks [-L] [-u] ["dev1 ... devN"]
showmydisks
tries to list all "disks", partitions, their types, and if available file systems, disk space usage, and mount points. Option -u
also prints the number of unallocated sectors as reported by fdisk
. -L
returns only the list of devices.
The script has not been tested much but was known to run well on Debian 4 and 5 and Ubuntu 9 and 10. v0.12 has been tested on Debian 7.9 and Lubuntu 14.04.3.
root@ubuntu:~# ./showmydisks > sda: ATA FUJITSU MHZ2160B (149 GB) |-- 1: type 7 (NTFS?) 9 GB on /windows as fuseblk (5 GB free) |-- 2: 188 MB on /boot as ext3 (142 MB free) |-- 3: extended partition |-- 5: Linux swap partition, 956 MB |-- 6: 956 MB on /tmp as ext3 (876 MB free) |-- 7: 1 GB on /var as ext3 (1 GB free) |-- 8: 760 MB on / (430 MB free) |-- 9: 4 GB on /usr as ext3 (1 GB free) |-- 10: type 7 (NTFS?) 116 GB on /data as fuseblk (86 GB free) > sdb: Kingston DataTraveler II (983 MB) |-- 1: partition type e > sdc: WD 10EAVS External (931 GB) |-- 1: type 7 (NTFS?) 931 GB vfat|msdos > sdd: WD 10EAVS External (931 GB) |-- 1: type 7 (NTFS?) 931 GB on /import/KRAM as fuseblk (649 GB free)
Show also number of unallocated sectors (-u
), list only a specific disk:
root@ubuntu:~# ./showmydisks -u sdb > sdb: WD 10EAVS External (931 GB) |-- 1: type 7 (NTFS?) 931 GB vfat|msdos (5165 unallocated sectors)
Run as unprivileged user (non-root):
user@debian:~$ ./showmydisks showmydisks: warning: you probably want to be root > hda: IBM-DTTA-351680 (15 GB) |-- 1: type unknown 15 GB on /backups as ext2 (2 GB free) > sda: ICP Host Drive #00 (34 GB) |-- 1: type unknown 250 MB on / as ext2 (170 MB free) |-- 2: type unknown 23 MB on /boot as ext2 (13 MB free) |-- 3: type unknown 321 MB fs unknown |-- 4: type unknown 1 KB fs unknown |-- 5: type unknown 305 MB on /tmp as ext2 (275 MB free) [...]
The above example shows that as non-root user partition types are not read. Hence, here sda4
is also not detected as extended partition.
Since version 0.07 showmydisks
also includes Software RAID devices (automatically or upon request as shown here):
user@debian:~$ ./showmydisks md showmydisks: warning: you probably want to be root > md: Software RAID (185 GB) |-- 0: raid1 on / as ext3 (88 MB free) |-- 1: raid1 fs unknown |-- 2: raid1 on /usr as ext3 (3 GB free) |-- 3: raid1 on /var as ext3 (732 MB free) |-- 4: raid1 on /home_u1 as ext3 (26 GB free) |-- 5: raid1 on /srv/backups as ext3 (16 GB free)
There are many. Some bigger ones are (we could call them "feature requests", too)
0.02 * 2004-12-23 first buggy "punish me" alpha release 0.03 * 2005-01-19 added code to read /sys/block/sd?/device/... 0.04 * 2009-09-13 cosmetic changes and testing if it still works 0.05 * 2009-09-14 print warning if not /root but go on; added --help; 0.05 * 2009-09-14 removed sfdisk requirement; some cosmetics 0.06 * 2009-09-15 added -u (unallocated sectors); removed bc requirement 0.07 * 2009-09-15 added support for /dev/md (Software RAID) 0.08 * 2010-03-07 added support for -L (only list devices) 0.09 * 2011-02-20 added ext4 + LUKS, more info about fd partitions (mdstat) 0.10 * 2012-08-25 skipping disks with no /sys/block/$MYDEV/size, + cosmetics 0.11 * 2015-03-27 added note about lsblk from util-linux 0.12 * 2015-09-12 fixed detection of rootfs device
Please accept my sincere apology for the horrible coding style of this script. I am not a programmer, and when I started to write this script some 15 years ago my style was indeed worse than today.
Andreas Schamanek, 2009-09-15 13:20
See also my blog posting Listing disks, partitions, and more.
Andreas Schamanek, 2009-09-23 09:47, 2009-09-23 09:48
If on a system GNU parted is available one might want to use parted -l
to list disks, partitions, sizes and file systems. It features nicely formatted output (see below) and detects NTFS file systems. It does not show mount points and free disk spaces, though.
debian:~# parted -l Model: SAMSUNG HM120JC (ide) Disk /dev/hda: 120GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32.3kB 41.1MB 41.1MB primary ext3 boot 2 41.1MB 543MB 502MB primary ext3 3 543MB 120GB 119GB extended 5 543MB 1546MB 1003MB logical ext3 6 1546MB 1744MB 197MB logical linux-swap 7 1744MB 2040MB 296MB logical ext3 8 2040MB 3537MB 1497MB logical ext3 9 3537MB 120GB 116GB logical ext3 Model: WDC WD5000AAKB-00H8A (scsi) Disk /dev/sda: 500GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 512B 500GB 500GB primary ext3
Andreas Schamanek, 2015-09-12 22:43
Only recently I found the wonderful lsblk
from the util-linux collection. This is a great alternative providing more details and a beautiful output with several options to configure it. lsblk
should be available on all major Linux distributions by default.
Example output:
# lsblk --ascii -o "NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT" NAME TYPE SIZE FSTYPE MOUNTPOINT sda disk 465.3G `-sda1 part 465.3G ext4 /home.nobak sdb disk 223.1G |-sdb1 part 3.7G ext4 / |-sdb2 part 5.6G swap \[SWAP\] |-sdb3 part 1K |-sdb5 part 9.3G ext4 /usr |-sdb6 part 4.7G ext4 /tmp |-sdb7 part 4.7G ext4 /var |-sdb8 part 4.7G ext4 /var/lib/mysql |-sdb9 part 4.7G ext4 /var/mail |-sdb10 part 97.8G ext4 /home `-sdb11 part 88G ext4