How to Check Un-allocated Disk Space in Linux

By | September 15, 2023

Un-allocated space is that disk space which is not inside any partition and is lying free. This space cannot be formatted to a file-system without first creating a partition in it.

In order to use the space in unallocated space, you must either create a new partition in that space, or merge the space with some adjacent partition making that particular partition larger.

In this article we shall take a quick look at some commands that can be used to check for unallocated free space on a disk drive like usb flash drive or ssd. If you prefer some gui application then, Gparted, Gnome Disks, KDE Partition Manager are excellent options on linux.

The commands that we shall be using include parted, cfdisk, fdisk.

Parted command

The parted command can be used to check un-allocated disk space. Specify the device path along with "print free" option and note the partition table details.

$ sudo parted /dev/sdd print free
Model: SanDisk Cruzer Blade (scsi)
Disk /dev/sdd: 15.6GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        1024B   88.1kB  87.0kB           Free Space
 2      88.1kB  10.5MB  10.4MB  primary  fat16        esp
        10.5MB  2247MB  2237MB           Free Space
 1      2247MB  15.6GB  13.4GB  primary  fat32

$

Note the table entries marked "Free Space" under the "File system" column. These are the un-allocated areas of the disk that are not inside any partition.

Fdisk command

With Fdisk, its not straight forward to get details about the unallocated space on a drive. Check the output below for the same usb drive:

$ sudo fdisk -l /dev/sdd
Disk /dev/sdd: 14.53 GiB, 15597568000 bytes, 30464000 sectors
Disk model: Cruzer Blade    
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: 0x4953725b

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sdd1       4388864 30463999 26075136 12.4G 83 Linux
/dev/sdd2           172    20455    20284  9.9M ef EFI (FAT-12/16/32)

Partition table entries are not in disk order.
$

Note that the start and end byte-values of partitions are not following each other or in sequence, indicating the presence of free space. However fdisk cannot provide any further details.

Check out the full tutorial on how to use fdisk command over here:
10 Useful fdisk Command Examples on Linux - Manage disk partitions

Cfdisk utility

The cfdisk terminal program is useful in tracking and creating partitions in unallocated space areas of a disk drives. It presents the information in a text user interface style based on curses library.

Cfdisk Check Unallocated Disk Space

Cfdisk Check Unallocated Disk Space

Cfdisk can be used to create and manage partitions in the unallocated area.

Conclusion

When dealing with unallocated space, the best option is usually to use a gui tool like Gparted and manage the partitions more visually. Unallocated areas of disk space are often created during installation of an operating system or when creating a live usb of some linux distro.

In such cases, you can always edit the partitions afterwards and reclaim the space to use it. There is no point letting the space go waste.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *