The only aim of this article is to save all devices and partitions from damage in a GNU/Linux system when you are performing any formatting action from the command line. This is applicable if you can show all partitions available in your system. There are some command line programs to do it. By using these, you can avoid any false formatting action or any other disaster (incorrect dd command, data loss, incorrectly formatted partition) because you will know exactly what device you want to format. They are fdisk, lsblk, blkid, and df. They are built-in tools in Ubuntu operating system.



sudo fdisk -l
Output example:
Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcd5fd3a8

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048 262148669 262146622   125G 83 Linux
/dev/sda2       262150144 475142143 212992000 101.6G 83 Linux
/dev/sda3       475142144 480245759   5103616   2.4G 82 Linux swap / Solaris
/dev/sda4       480247110 625137344 144890235  69.1G 83 Linux
The argument -l of fdisk shows all partitions available in a table list. By using fdisk -l, we see from the example there are one hard disk drive and four partitions. They are one /dev/sda and then four /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 respectively. By reading the Type column, we know that all partitions are normal Linux-readable partition except /dev/sda3 because it is the only swap partition. We also can see the size of every partition. The largest partition is /dev/sda1 with 125 GB size and the smallest partition is /dev/sda3 with 2.4 GB size.



lsblk -o NAME,LABEL

Output example (first command):
sda       8:0    0 298.1G  0 disk 
├─sda1    8:1    0   125G  0 part 
├─sda2    8:2    0 101.6G  0 part 
├─sda3    8:3    0   2.4G  0 part [SWAP]
└─sda4    8:4    0  69.1G  0 part 
Output example (second command):
├─sda1  Satu
├─sda2  Dua
└─sda4  Cadangan
The command lsblk (list block) shows system partitions in a tree form. The usage of lsblk helps you understand the output of the earlier fdisk -l clearer. From the output example we know that the system has one hard disk (sda) and four partitions (sda1 ... sda4).

The second command example above shows every partition filesystem label. This will help you more to recognize exactly what partition you want to format or any other action. For this purpose, lslbk only is actually good enough.



sudo blkid
Output example:
/dev/sda1: LABEL="Satu" UUID="44f29a01-88ba-470a-a6b5-90473ce2bd7b" TYPE="ext4" PARTUUID="cd5fd3a8-01"
/dev/sda2: LABEL="Dua" UUID="1ced618b-f011-4fe0-b275-5f7bd7c54c51" TYPE="ext4" PARTUUID="cd5fd3a8-02"
/dev/sda3: UUID="4acea42c-ca94-42c6-8af6-620be425eab6" TYPE="swap" PARTUUID="cd5fd3a8-03"
/dev/sda4: LABEL="Cadangan" UUID="b10453df-4fe7-41fd-9161-5bb040b4536d" TYPE="ext4" PARTUUID="cd5fd3a8-04"
The command blkid shows all partitions available in the GNU/Linux system with their label names, filesystems, UUID, and PARTUUID. This command alone is enough to see the partitions labels.



sudo df -h
Output example:
Filesystem      Size  Used Avail Use% Mounted on
udev            943M     0  943M   0% /dev
tmpfs           192M  5.5M  187M   3% /run
/dev/sdb3        20G  9.3G  8.9G  51% /
tmpfs           960M  128K  959M   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           960M     0  960M   0% /sys/fs/cgroup
cgmfs           100K     0  100K   0% /run/cgmanager/fs
tmpfs           192M     0  192M   0% /run/user/117
tmpfs           192M   20K  192M   1% /run/user/1000
/dev/sda1       123G  105G   13G  90% /media/master/Satu
/dev/sda2       100G   84G   12G  89% /media/master/Dua

The df command shows all mounted filesystems available in a GNU/Linux system. The -h argument shows the size in human-readable format such as K, M, and G. From the example, we know at least three partitions: /dev/sdb3 which is the root filesystem, while /dev/sda1 and /dev/sda2 as another mounted partitions. It means the user in the example is running /dev/sdb3 as the operating system, while /dev/sda1 and /dev/sda2 are another partitions available. You may ignore another filesystems available which have no /dev prefix.

Actually, df is not intended for our purpose but imagine when you have no idea what other command available you may use df command there.

, , , , , ,