10

Let's say I have this virtual machine running:

[root@centos ~]# fdisk -ul

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63      417689      208813+  83  Linux
/dev/sda2         2522205    13799834     5638815   83  Linux
/dev/sda3        13799835    16771859     1486012+  8e  Linux LVM
/dev/sda4          417690     2522204     1052257+   5  Extended
/dev/sda5          417753     2522204     1052226   82  Linux swap /     Solaris

How can I know how much free space left for more partitions on the disk?

3
  • With "free space" you mean "not yet allocated to a partition" aka "unpartitioned space", do you? The v command of fdisk verifies the partition table and reports such space as well, e.g. Remaining 239 unallocated 512-byte sectors in my case. Commented Jul 7, 2011 at 16:37
  • that's exactly what I meant. but the -v command means: Print version number of fdisk and exit. Commented Jul 7, 2011 at 17:49
  • 2
    I'm talking about the v command, not the -v command line option, i.e. you need to start fdisk /dev/sda in interactive mode and then type v<ENTER>. Commented Jul 7, 2011 at 18:03

3 Answers 3

11

As root, type in a shell:

# cfdisk /dev/sdX  #Where /dev/sdX is the device 

it will show you something like this:

cfdisk (util-linux-ng 2.18)

                          Disk Drive: /dev/sdb
                    Size: 3926949888 bytes, 3926 MB
          Heads: 255   Sectors per Track: 63   Cylinders: 477

Name        Flags      Part Type  FS Type          [Label]        Size (MB)

sdb1                    Primary   vfat             [ABDEL]          1998.75
sdb2        Boot        Primary   ext3             [linx]           1924.72

if the device has free space it will be shown.

Note: cfdisk in fact is a terminal based partition editor.

1
  • 3
    You could use cfdisk -P s /dev/sdX to print out the partition table to the console without entering the interactive partition editor. If you do enter it as @abdelfatah directs, you can exit by pressing 'q'. Commented Jul 7, 2011 at 12:05
7

You could also use parted in command mode:

parted /dev/sda unit MiB print free

output:

Model: ATA M4-CT128M4SSD2 (scsi)
Disk /dev/sda: 122104MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start     End        Size      Type     File system     Flags
        0.03MiB   1.00MiB    0.97MiB            Free Space
 1      1.00MiB   28672MiB   28671MiB  primary  ext4
        28672MiB  28673MiB   1.00MiB            Free Space
 2      28673MiB  30720MiB   2047MiB   primary  linux-swap(v1)
        30720MiB  30721MiB   1.00MiB            Free Space
 3      30721MiB  92160MiB   61439MiB  primary  ntfs
        92160MiB  122104MiB  29944MiB           Free Space

If you want just the total free space you could run:

parted /dev/sda unit MiB print free | awk '/Free Space/{c++; sum += $3} \
END{if(c == 0) print "No Free Space"; else print sum" MiB"}'
29947 MiB

You can use different units to display the size: B up to TB, KiB up to TiB etc (see man parted for details).

3

To report all drives/partitions and their remaining sizes:

df -h

or:

fdisk -l

For folders use the disk usage command with the -sh options:

du -sh

Note: -h is for showing human readable (i.e. 34 GB instead of 340000000 blocks/bytes)

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.