How to display all the partitions in a tree-like format (primary, extended and logical)?
blkid
You can use the command blkid
to show something along those lines:
$ blkid
/dev/sda1: LABEL="SYSTEM_DRV" UUID="XXXXXX" TYPE="ntfs"
/dev/sda2: LABEL="Windows7_OS" UUID="XXXXX" TYPE="ntfs"
/dev/sda3: LABEL="Lenovo_Recovery" UUID="XXXX" TYPE="ntfs"
/dev/sda5: UUID="XXXX" TYPE="ext4"
/dev/sda6: UUID="XXXX" TYPE="LVM2_member"
/dev/mapper/vg_grinchy-lv_root: UUID="XXXX" TYPE="ext4"
/dev/mapper/vg_grinchy-lv_swap: UUID="XXXX" TYPE="swap"
/dev/mapper/vg_grinchy-lv_home: UUID="XXXX" TYPE="ext4"
I've removed the UUIDs from above and replaced them with X's. The command blkid
also can take arguments if you want different output.
For example:
$ blkid -o list
device fs_type label mount point UUID
----------------------------------------------------------------------------------------------------------------------------------
/dev/sda1 ntfs SYSTEM_DRV (not mounted) XXXX
/dev/sda2 ntfs Windows7_OS (not mounted) XXXX
lsblk
An alternative tool to blkid
is lsblk
. You could use the following options to list all the block devices:
$ lsblk -a
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 0 loop
loop1 7:1 0 0 loop
loop2 7:2 0 0 loop
loop3 7:3 0 0 loop
loop4 7:4 0 0 loop
loop5 7:5 0 0 loop
loop6 7:6 0 0 loop
loop7 7:7 0 0 loop
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 465.3G 0 part
├─vg_totoro-lv_root (dm-0) 253:0 0 431.5G 0 lvm /
├─vg_totoro-lv_swap (dm-1) 253:1 0 13.8G 0 lvm [SWAP]
└─vg_totoro-lv_home (dm-2) 253:2 0 20G 0 lvm /home
sr0 11:0 1 1024M 0 rom
Check out it's usage, it takes additional options.
If all you want is an lsblk
that shows you primary/logical partitions, you should be able to do this with a combination of fdisk
and parsing. fdisk -l
if run as root will list all partitions and will mark extended ones with Ext'd
:
# fdisk -l | grep dev
Disk /dev/sda: 500.1 GB, 500107862016 bytes
/dev/sda1 63 80324 40131 de Dell Utility
/dev/sda2 * 81920 30801919 15360000 7 HPFS/NTFS/exFAT
/dev/sda3 30801920 194643539 81920810 7 HPFS/NTFS/exFAT
/dev/sda4 194643601 976773119 391064759+ f W95 Ext'd (LBA)
/dev/sda5 194643603 198836504 2096451 c W95 FAT32 (LBA)
/dev/sda6 342951936 960387071 308717568 83 Linux
/dev/sda7 198840320 342949887 72054784 83 Linux
/dev/sda8 960389120 976773119 8192000 82 Linux swap / Solaris
You could then combine that with a little parsing to get the output you want:
$ lsblk -a | perl -lpe 'BEGIN{open(A,"sudo fdisk -l |");
while(<A>){next unless /Ext/;
$k{$1}++ if /^.*?(...\d)\s/; }}
@a=split(/\s+/);
$a[0]=~s/\W+//;
s/$a[5]/Extended/ if defined($k{$a[0]});'
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 39.2M 0 part
├─sda2 8:2 0 14.7G 0 part
├─sda3 8:3 0 78.1G 0 part /winblows
├─sda4 8:4 0 1K 0 Extended
├─sda5 8:5 0 2G 0 part
├─sda6 8:6 0 294.4G 0 part /home
├─sda7 8:7 0 68.7G 0 part /
└─sda8 8:8 0 7.8G 0 part [SWAP]
I think that's the best you can do since findmnt
won't show extended partitions since they will never be mounted. Otherwise, you could parse it in the same way.
You can list types of partitions with parted
:
$ sudo parted /dev/sda print
Model: ATA ST3320613AS (scsi)
Dysk /dev/sda: 320GB
Rozmiar sektora (logiczny/fizyczny): 512B/512B
Tablica partycji: msdos
Numer Początek Koniec Rozmiar Typ System plików Flaga
1 1049kB 318GB 318GB primary ext4 ładowalna
2 318GB 320GB 2145MB extended
5 318GB 319GB 1074MB logical linux-swap(v1)
6 319GB 320GB 1071MB logical ext2
There is no tree but it may help, since as you stated it would be a good to at least know the relationship. If you want to use GUI you can try with GParted
: