Table of Contents

showmydisks

A Bash script to report partitions, types, file systems, and disk space usage

Synopsis

showmydisks [-L] [-u] ["dev1 ... devN"]

Description

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.

Examples

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)

Limitations

There are many. Some bigger ones are (we could call them "feature requests", too)

  1. Does not support disks with GUID Partition Table (GTP).
  2. Detection of filesystems of non-Linux partitions is not implemented.
  3. Detection of filesystems requires root privileges.
  4. Support for UUIDs is not implemented.
  5. LVMs are not detected.
  6. The script is not luser proof.

History

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

Download

showmydisks.sh

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.