In this post we are taking a look at some commands that can be used to check up the partitions on your system.
The commands would check what partitions there are on each disk and other details like the total size, used up space and file system etc.
Commands like fdisk, sfdisk and cfdisk are general partitioning tools that can not only display the partition information, but also modify them.
1. fdisk
Fdisk is the most commonly used command to check the partitions on a disk. The fdisk command can display the partitions and details like file system type. However it does not report the size of each partitions.
$ sudo fdisk -l Disk /dev/sda: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 Disk identifier: 0x30093008 Device Boot Start End Blocks Id System /dev/sda1 * 63 146801969 73400953+ 7 HPFS/NTFS/exFAT /dev/sda2 146802031 976771071 414984520+ f W95 Ext'd (LBA) /dev/sda5 146802033 351614654 102406311 7 HPFS/NTFS/exFAT /dev/sda6 351614718 556427339 102406311 83 Linux /dev/sda7 556429312 560427007 1998848 82 Linux swap / Solaris /dev/sda8 560429056 976771071 208171008 83 Linux Disk /dev/sdb: 4048 MB, 4048551936 bytes 54 heads, 9 sectors/track, 16270 cylinders, total 7907328 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 Disk identifier: 0x0001135d Device Boot Start End Blocks Id System /dev/sdb1 * 2048 7907327 3952640 b W95 FAT32
Each device is reported separately with details about size, seconds, id and individual partitions.
2. sfdisk
Sfdisk is another utility with a purpose similar to fdisk, but with more features. It can display the size of each partition in MB.
$ sudo sfdisk -l -uM Disk /dev/sda: 60801 cylinders, 255 heads, 63 sectors/track Warning: extended partition does not start at a cylinder boundary. DOS and Linux will interpret the contents differently. Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End MiB #blocks Id System /dev/sda1 * 0+ 71680- 71681- 73400953+ 7 HPFS/NTFS/exFAT /dev/sda2 71680+ 476938 405259- 414984520+ f W95 Ext'd (LBA) /dev/sda3 0 - 0 0 0 Empty /dev/sda4 0 - 0 0 0 Empty /dev/sda5 71680+ 171686- 100007- 102406311 7 HPFS/NTFS/exFAT /dev/sda6 171686+ 271693- 100007- 102406311 83 Linux /dev/sda7 271694 273645 1952 1998848 82 Linux swap / Solaris /dev/sda8 273647 476938 203292 208171008 83 Linux Disk /dev/sdb: 1020 cylinders, 125 heads, 62 sectors/track Warning: The partition table looks like it was made for C/H/S=*/54/9 (instead of 1020/125/62). For this listing I'll assume that geometry. Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End MiB #blocks Id System /dev/sdb1 * 1 3860 3860 3952640 b W95 FAT32 start: (c,h,s) expected (4,11,6) found (0,32,33) end: (c,h,s) expected (1023,53,9) found (492,53,9) /dev/sdb2 0 - 0 0 0 Empty /dev/sdb3 0 - 0 0 0 Empty /dev/sdb4 0 - 0 0 0 Empty
3. cfdisk
Cfdisk is a linux partition editor with an interactive user interface based on ncurses. It can be used to list out the existing partitions as well as create or modify them.
Here is an example of how to use cfdisk to list the partitions.
Cfdisk works with one partition at a time. So if you need to see the details of a particular disk, then pass the device name to cfdisk.
$ sudo cfdisk /dev/sdb
4. parted
Parted is yet another command line utility to list out partitions and modify them if needed.
Here is an example that lists out the partition details.
$ sudo parted -l Model: ATA ST3500418AS (scsi) Disk /dev/sda: 500GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32.3kB 75.2GB 75.2GB primary ntfs boot 2 75.2GB 500GB 425GB extended lba 5 75.2GB 180GB 105GB logical ntfs 6 180GB 285GB 105GB logical ext4 7 285GB 287GB 2047MB logical linux-swap(v1) 8 287GB 500GB 213GB logical ext4 Model: Sony Storage Media (scsi) Disk /dev/sdb: 4049MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 4049MB 4048MB primary fat32 boot
5. df
Df is not a partitioning utility, but prints out details about only mounted file systems. The list generated by df even includes file systems that are not real disk partitions.
Here is a simple example
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda6 97G 43G 49G 48% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 3.9G 8.0K 3.9G 1% /dev tmpfs 799M 1.7M 797M 1% /run none 5.0M 0 5.0M 0% /run/lock none 3.9G 12M 3.9G 1% /run/shm none 100M 20K 100M 1% /run/user /dev/sda8 196G 154G 33G 83% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 /dev/sda5 98G 37G 62G 38% /media/4668484A68483B47
Only the file systems that start with a /dev are actual devices or partitions.
Use grep to filter out real hard disk partitions/file systems.
$ df -h | grep ^/dev /dev/sda6 97G 43G 49G 48% / /dev/sda8 196G 154G 33G 83% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 /dev/sda5 98G 37G 62G 38% /media/4668484A68483B47
To display only real disk partitions along with partition type, use df like this
$ df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs Filesystem Type Size Used Avail Use% Mounted on /dev/sda6 ext4 97G 43G 49G 48% / /dev/sda8 ext4 196G 154G 33G 83% /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 /dev/sda5 fuseblk 98G 37G 62G 38% /media/4668484A68483B47
Note that df shows only the mounted file systems or partitions and not all.
6. pydf
Improved version of df, written in python. Prints out all the hard disk partitions in a easy to read manner.
$ pydf Filesystem Size Used Avail Use% Mounted on /dev/sda6 96G 43G 48G 44.7 [####.....] / /dev/sda8 195G 153G 32G 78.4 [#######..] /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 /dev/sda5 98G 36G 61G 37.1 [###......] /media/4668484A68483B47
Again, pydf is limited to showing only the mounted file systems.
7. lsblk
Lists out all the storage blocks, which includes disk partitions and optical drives. Details include the total size of the partition/block and the mount point if any.
Does not report the used/free disk space on the partitions.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465.8G 0 disk ├─sda1 8:1 0 70G 0 part ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 97.7G 0 part /media/4668484A68483B47 ├─sda6 8:6 0 97.7G 0 part / ├─sda7 8:7 0 1.9G 0 part [SWAP] └─sda8 8:8 0 198.5G 0 part /media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 sdb 8:16 1 3.8G 0 disk └─sdb1 8:17 1 3.8G 0 part sr0 11:0 1 1024M 0 rom
If there is no MOUNTPOINT, then it means that the file system is not yet mounted. For cd/dvd this means that there is no disk.
Lsblk is capbale of displaying more information about each device like the label and model. Check out the man page for more information
Display UUID and Model of device
The "-o" option can be used to specify the columns to display. The following example shows the UUID and model name column along with other columns.
$ lsblk -o PATH,SIZE,RO,TYPE,MOUNTPOINT,UUID,MODEL PATH SIZE RO TYPE MOUNTPOINT UUID MODEL /dev/loop0 96.5M 1 loop /snap/core/9436 /dev/loop1 229.6M 1 loop /snap/atom/257 /dev/loop2 55M 1 loop /snap/core18/1880 /dev/loop3 54.8M 1 loop /snap/gtk-common-themes/1502 /dev/loop4 156.2M 1 loop /snap/chromium/1213 /dev/loop5 55M 1 loop /snap/core18/1754 /dev/loop6 62.1M 1 loop /snap/gtk-common-themes/1506 /dev/loop7 230.6M 1 loop /snap/atom/258 /dev/loop8 158.4M 1 loop /snap/chromium/1229 /dev/loop9 97M 1 loop /snap/core/9665 /dev/sda 465.8G 0 disk Samsung_Portable_SSD_T5 /dev/sda1 420G 0 part 757dcceb-3e17-4ca8-9ba1-b0cf68fb0134 /dev/sdb 111.8G 0 disk Samsung_SSD_840_EVO_120GB /dev/sdb1 95.4G 0 part / 19d84ceb-8046-4f8d-a85a-cda49515d92c /dev/sdc 111.8G 0 disk Samsung_SSD_850_EVO_120GB /dev/sdc1 95.8G 0 part f41b21a7-e8be-48ac-b10d-cad641bf709b $
The above output has all the necessary information about all the storage devices present on the system or connected via usb. You can see the device name, size, mount point, uuid, model name etc.
This is the best command to see all information about storage devices together in one place.
8. blkid
Prints the block device (partitions and storage media) attributes like uuid and file system type. Does not report the space on the partitions.
$ sudo blkid /dev/sda1: UUID="5E38BE8B38BE6227" TYPE="ntfs" /dev/sda5: UUID="4668484A68483B47" TYPE="ntfs" /dev/sda6: UUID="6fa5a72a-ba26-4588-a103-74bb6b33a763" TYPE="ext4" /dev/sda7: UUID="94443023-34a1-4428-8f65-2fb02e571dae" TYPE="swap" /dev/sda8: UUID="13f35f59-f023-4d98-b06f-9dfaebefd6c1" TYPE="ext4" /dev/sdb1: UUID="08D1-8024" TYPE="vfat"
9. hwinfo
The hwinfo is a general purpose hardware information tool and can be used to print out the disk and partition list.
The output however does not print details about each partition like the above commands.
$ hwinfo --block --short disk: /dev/sda ST3500418AS /dev/sdb Sony Storage Media partition: /dev/sda1 Partition /dev/sda2 Partition /dev/sda5 Partition /dev/sda6 Partition /dev/sda7 Partition /dev/sda8 Partition /dev/sdb1 Partition cdrom: /dev/sr0 SONY DVD RW DRU-190A
To learn more about the Hwinfo command check this post:
Check hardware information on Linux with "hwinfo" command
10. Inxi
Inxi is a very useful command line program that can display information about various hardware components present on the system. To display information about the disk drives and storage devices use the "-D" option with inxi.
$ inxi -D -xx Drives: Local Storage: total: 689.34 GiB used: 106.73 GiB (15.5%) ID-1: /dev/sda vendor: Samsung model: SSD 840 EVO 120GB size: 111.79 GiB speed: 6.0 Gb/s serial: S1D5NSCF471738E ID-2: /dev/sdb vendor: Samsung model: SSD 850 EVO 120GB size: 111.79 GiB speed: 6.0 Gb/s serial: S21SNXAGC12532L ID-3: /dev/sdc type: USB vendor: Samsung model: Portable SSD T5 size: 465.76 GiB serial: S50PNV0M605705E $
The "-x" option prints extra available information.
The output from inxi does not contains details like UUID and mount directory.
To learn more about the inxi command check out this post:
How to use "Inxi" to check Hardware Information on Linux
Summary
The output of parted is concise and complete to get an overview of different partitions, file system on them and the total space. Pydf and df are limited to showing only mounted file systems and the same on them.
Fdisk and Sfdisk show a whole lot of information that can take sometime to interpret whereas, Cfdisk is an interactive partitioning tool that display a single device at a time.
So try them out, and do not forget to comment below.
Nice article and some great info also in the comments. However, there is errata in your description of Fdisk, which I believe comes from your understandable lack of in-depth knowledge, probably through the fact that very few individuals get their noses rubbed in physical-to-virtual conversions these days. Your sentence: However it does not report the size of each partitions. Is inaccurate. Fdisk does report the size of each partition, sda1-sda8 in the example.
In the sda disk overview it states:
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
The confusing part is that in the detail section, Partition sizes are reported in “Blocks” which are refered to as “Sectors in the overview section. In this case, the Sector Size is 512 Bytes, so a disk block is also 512 Bytes.
Device Boot Start End Blocks Id System
/dev/sda1 * 63 146801969 73400953+ 7 HPFS/NTFS/exFAT
/dev/sda2 146802031 976771071 414984520+ f W95 Ext’d (LBA)
/dev/sda5 146802033 351614654 102406311 7 HPFS/NTFS/exFAT
/dev/sda6 351614718 556427339 102406311 83 Linux
/dev/sda7 556429312 560427007 1998848 82 Linux swap / Solaris
/dev/sda8 560429056 976771071 208171008 83 Linux
Thus, sda1 is 73400953 (* 512 byte blocks) = 37,581,287,936 bytes, or (divided by 1,048,576) is 35,840MB. And there is a simpler formula to apply that is “good enough for government work”. Simply imagine comma separators to identify the millions and billions, chopping off hundreds and thousands and divide by 2, which most computer people can still do in their heads. 73400953 -> 73 ,400,953, –> 73 2 = 36 and change. And swap (sda7) is about 1GB.
(I mis-spent a lot of time in my youth recalculating powers of 2 and multiples of 512, usually while waiting for massive disk operations to complete…)
Thank you for this great summary of relevant commands and also showing whether SU privileges are needed or not.
Good article. Thanks for writing this !!.
I’d also suggest including “ncdu” (stands for ncurses du) – https://dev.yorhel.nl/ncdu – in this as it’s quite useful in knowing the disk usage on the terminal in a graphical way
pydf hands down the best alternative if you want a quick glance at disk usage!
Very useful, thank you!
very useful,
How about GUI tools?
Hardinfo is a GUI tool that shows hardware information including disk drives and partitions..
On ubuntu it can be installed with the following command
sudo apt-get install hardinfo
Another tool is gparted.
It is a partition management tool, but can also be used to list the disk drives and partitions
Well done — I learned something!
glad to know that.
thanks for the comment.
Very useful. Thank you for your effort.
Detailed and to the point post. Thanks A Ton!
Very useful
thanks, it was very usefull
Two others: gparted and lshw.
thanks for mentioning.
both are useful tools.
Good one, detailed information.
Spent over an hour reading websites trying to figure out 1 of the many commands you have here….. THANK YOU!!!!!
glad that you found it helpful.
Thx.. some really good info
Thank you for sharing your knowledge. What I learned here there are many paths you can take.
Newbie
tanks gor writing post
very useful,
How about GUI tools?
Thank You very much, It’s very useful.
Thanks,
Very good. Lot of useful commands together.
Here my two cents.
Mostly you also want to know how your system boots.
cat /proc/cmdline
cat /etc/fstab
If system refuse to boot one can use a live system as ‘Parted magic’ Got a lot of tools to get info about your disks
If UUID is not correct for some reason.
Try to mount the boot disk and to edit the files required for boot
Such a useful article in very simple language thanks a lot team.
This article was really helpful for me
Thanks a lot for all the efforts put in
It is very useful commands. Thanks
Awesome article…!!! <3 <3 <3
thank you man , good and perfect collection.
Hi there!
Up to know, this is the most concise and pinpointing article about Linux commands I’ve ever read up to know. Thank you for this invaluable “piece of art”. Even-though, the “pydf” as well as the “hwinfo” commands didn’t work on my centOS7, I’m pretty satisfied about the outcome of your article and I will sleep tonight less ignorant about partitioning /dev.
Thanks!
P.S. Could you explain to me why the aforementioned commands didn’t work?
what output does it show when you try to run pydf and hwinfo ?
Excellent and useful article. I think “lsblk” is useful in understading setup and also “parted -l |grep -i disk” I found handy! :)
Thanks a lot!
one of the best linux articles I have ever red .. thanx
I normally just use cat /proc/partitions
I never stop learning with Linux. Thanks for the tips.
which one would show me partitions as hd0, hd1, etc.?
You could go with “df -h”, the -h flag standing for a “human readable” switch. The df program shows both the /dev entry and it’s mount point.
its very useful for me:),tanks
awesome info, thanks. like “lsblk” to understand the setup.
Good collection of utilities. Thanks and keep up your work.
Example of what I mean:
-a parted with available space column (like pydf or df) or
-a pydf (or a df) that gives you information about unmounted partitions, too
Thanks for your time and sharing your knowledge.
Really nice. It touchs a lot of possibilities.
I’m relatively new to Gnu/Linux, but I’m wondering for a while… why there isn’t out there a single command, util or whatever you want, that gives you all the info in a compact way?
I’m a very newbie and amateur programmer (not a real programmer) and I don’t have the skills to try to do it by myself. But (perhaps because that) I can’t understand why somebody hasn’t done it yet.
It’s a pity.
Nice article! Thx for the info
ncdu is a really nice tool for examining disk usage.
Parted does not seem to be installed on CentOS
Thanks,
I didn’t know many of these tools
Very useful, but, going a bit off-topic (sorry) …..
My system won’t boot (“No such device” etc.) I suspect some UUID conflict in fstab. How can I use the live DVD to see/edit fstab – the suspect one on my Mint partition, not the one the DVD uses?
boot with usb, and edit your fstab in terminal with this command
‘nano /etc/fstab’