Getting information about which partition is used for the boot partition is very easy. The command below will show the current partition on the selected drive that is flagged as bootable.
(base) jason@jason-Lenovo-H50-55:~$ sudo fdisk -l /dev/sdb Disk /dev/sdb: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: ST1000DM003-1ER1 Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: dos Disk identifier: 0x2db152e2 Device Boot Start End Sectors Size Id Type /dev/sdb1 * 2048 1953523711 1953521664 931.5G 83 Linux |
This works perfectly.
However, there are two hard disks in this computer, and they both have bootable partitions. This is how to list all bootable partitions on all hard drives.
(base) jason@jason-Lenovo-H50-55:~$ sudo fdisk -l | grep '* ' | awk '{print $1 " " $2 " " $3 " " $4}' /dev/sda1 * 2048 1953521663 /dev/sdb1 * 2048 1953523711 |
This a very useful one-liner.
And an even better version. This prints more information and a useful header to tell the user which column is which.
(base) jason@jason-Lenovo-H50-55:~$ sudo fdisk -l | grep '* ' | awk 'BEGIN { printf("%-10s %-15s %-10s %s\n", "Device", "Boot", "Start", "End"); } { printf("%-10s %-15s %-10s %d\n", $1, $2, $3, $4) }' Device Boot Start End /dev/sda1 * 2048 1953521663 /dev/sdb1 * 2048 1953523711 |
The lsblk utility may also be used to get this information in a readable manner.
(base) jason@jason-Lenovo-H50-55:~$ lsblk -e 7 -o model,name,fstype,size,fsused,label,partlabel,mountpoint,uuid MODEL NAME FSTYPE SIZE FSUSED LABEL PARTLABEL MOUNTPOINT UUID WDC_WD10EZEX-00WN4A0 sda 931.5G └─sda1 ntfs 931.5G 4C1E66AD1E66902E ST1000DM003-1ER162 sdb 931.5G └─sdb1 ext4 931.5G 108.5G / a4f0c3ac-d565-4385-98c5-a40bbedbd52e |
A nice and readable tree view of all bootable partitions.
The Linux user may also list all filesystems with a certain filesystem. For example, list all partitions formatted using ext4.
(base) jason@jason-Lenovo-H50-55:~$ df -Hla --type=ext4 Filesystem Size Used Avail Use% Mounted on /dev/sdb1 984G 117G 817G 13% / |
It is also possible to view information about the boot drive the system was booted from.
(base) jason@jason-Lenovo-H50-55:~$ mount | grep -E '(/|/boot) ' | awk '{print $1,$2,$3}' /dev/sdb1 on / |
A very good one-liner.