(as)  [sysadmin] [blog]

 

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 is known to run well on Debian 4 and 5 and Ubuntu 9 and 10.

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. Detection of filesystems of non-Linux partitions is not implemented.
  2. Detection of filesystems requires root privileges.
  3. Support for UUIDs is not implemented.
  4. LVMs are not detected.
  5. 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

Download

Discussion

Andreas Schamanek, 2009/09/15 13:20

See also my blog posting Listing disks, partitions, and more.

Andreas Schamanek, 2009/09/23 09:47

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
Enter your comment. Wiki syntax is allowed:
HALEM
 
 
showmydisks.txt · Last modified: 2012/08/28 19:50 by andreas