-1

Possible Duplicate:
Why can’t Ubuntu see any free space?

I decided to replace the hard drive on my machine running Ubuntu 12.04 LTS . After using the new hard drive for a few days, I noticed that the new hard drive has bad sectors. So I decided to plug my old hard drive back in.

First, I plugged both hard drives in and copied some data files from the new hard drive to the old one. After unplugging the new hard drive, I booted the computer with the old hard drive, and here I got a surprise: I can see 0 bytes available on my /home partition!

The df utility shows that the /home partition has 0 available bytes. I have tried to move some files. But I still has 0 bytes on /home! However, GParted correctly shows that the available size is near 2Gb.

UPDATE 1:

To my surprise, System Monitor shows me that approximately 2 Gb are free and 0 bytes are available on the /home partition. It's slightly shocked me! Are "free" and "available" not the same?

Any help is really appreciated!

Michael Z
  • 101
  • To improve your question, please post the exact output of df, and copy the exact output of System Monitor. Remember, 2Gb, 2GB and 2GiB are different and can mean different things! – Flimm Nov 07 '12 at 17:16

1 Answers1

0

Your question is unclear, but I will attempt to answer as best I can.

When trying to discover the amount of free space you have, you will get different answers from different applications. This is because there are different definitions for the disk space units (KB, KiB, kB, K, k, etc), and there are different definitions of the terms "free space" and "available space". Also, different utilities may approximate differently.

Unit definitions

  • A bit is a zero or a one. A byte is compromised by 8 bits. Nowadays, there is consensus on these definitions.
  • The shorthand for bit is a lowercase b, and the shorthand for a byte is an uppercase B. Many people get this confused, but most applications make this distinction correctly. So if your browser tells you that the download is 8bps, that means eight bits per second, or one byte per second (which is extremely slow). This is not the same as 8Bps!
  • According to the IEC 60027-2 standard, one kilobyte is 1000 bytes, and the unit is denoted as kB. However, in practise, many older applications on Linux and most applications on Windows take one kilobyte to equal 1024 bytes, and use the unit KB. However, newer Linux applications, OS X and hard drive manufacturers use the correct 1000 bytes definitions (known as the SI definition, for its similarities to the metric system).
  • Similarly, according to the standard, one megabyte is 1000000 bytes, and the unit is denoted as MB. However, in practise, many applications take 1MB to mean 1048576 bytes, which is very confusing.
  • According to the standard, one kibibyte is 1024 bytes, and is denoted as KiB. Fortunately, when applications use the KiB unit, there is no confusion. Unfortunately, many applications still don't use that unit, using KB instead, which is ambiguous.

You can read up more on the unit confusion here.

Free space and available space

By default, Linux will reserve 5% of a partition's space for the root user. This is a good idea, because it makes sure the disk will at least be bootable if the hard drive fills up. However, you may find that 5% is too high a figure, and you can adjust it using tune2fs.

Here's how you see how much disk space is reserved:

$ sudo tune2fs -l /dev/sda6 | grep -i -e reserved -e 'block size' -e 'block count'
Block count:              487936
Reserved block count:     24396
Block size:               4096
Reserved GDT blocks:      119
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

The block size in this example is 4096 bytes. That means, we have 4096 * 24396 bytes reserved in this partition.

You can change the percentage like this:

$ sudo tune2fs -m 4 /dev/sda6 # change to 4%

Different applications output

df

Here's what df shows me:

$ df /home
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sda6        1921036 134604   1688848   8% /home

df has an option that uses the SI units:

$ df /home --si
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6       2.0G  138M  1.8G   8% /home

The least confusing is probably just using the number of bytes, like this:

$ df /home --block-size=1
Filesystem      1B-blocks      Used  Available Use% Mounted on
/dev/sda6      1967140864 137834496 1729380352   8% /home

So as you can see, according to df, the size of the partition is 1 967 140 864 bytes, which is 1.967140864GB, or approximately 1.832042694091GiB.

According to df, the size of available space is 1 729 380 352 bytes, which is 1.729380352GB, or approximately 1.61061096GiB. This is the amount of free space that is available to non-root users. The root user can use the additional 5% reserved space.

If you take the total disk space and subtract from it the available and used space, you will get the reserved space:

1967140864B - (1729380352B + 137834496B) = 99926016B

If you do the maths, you will find out that that equals 5% of the total disk space, as we expected.

So, as you can see, by default, df using the unit K meaning 1024 bytes. When passed --si, df uses the unit G meaning 1000000000 bytes, and rounds the results.

System monitor

This is what System Monitor tells me:

Device     Directory Type  Total   Free    Available Used
/dev/sda6  /home     ext4  1.8GiB  1.7GiB  1.6GiB    7%

System Monitor correctly takes the unit GiB to mean 1073741824 bytes. It rounds the result before displaying it to the user.

The "free" space is that which is unallocated on the disk, it includes the disk space reserved for the root user. The "available" space does not include the space reserved for the root user.

GParted

And this is what GParted tells me:

Partition  File System  Mount Point Size     Used       Unused 
/dev/sda6  ext4         /home       1.86GiB  161.44MiB  1.70GiB

GParted correctly takes the unit GiB to mean 1073741824 bytes. It rounds the result before displaying it to the user.

The "unused" space is equivalent to the "free" space displayed by System Monitor: it is the amount of space unallocated, including the space reserved for the root user.

Flimm
  • 41,766