Results 1 to 5 of 5

Thread: Disk space error

  1. #1
    Join Date
    Dec 2010
    Beans
    6

    Disk space error

    Hello,

    I am trying to find out available disk space in my Desktop. Here are the commands that I tried and their outputs :

    $ df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/sda2 74G 57G 14G 81% /
    none 2.0G 688K 2.0G 1% /dev
    none 2.0G 1.6M 2.0G 1% /dev/shm
    none 2.0G 260K 2.0G 1% /var/run
    none 2.0G 0 2.0G 0% /var/lock
    /dev/sda1 184M 31M 145M 18% /boot
    /dev/sda6 66G 19G 45G 30% /home

    $ sudo du -hs /
    47G /

    First command 'df' shows that 57G is used in '/' partition. Second command 'du' shows 47G is used in '/' folder. I could not understand why '/' partition is using more disk space than '/' folder ?

    Any help in understanding how disk space is measured will be much appreciated.

    Thanks in advance,
    Chak

    Update : modified second command as suggested by mmehboobhan

    $ cd /
    $ sudo du --si -s
    50G .

    Still there seems to be a difference between 'du' and 'df' values.

    Also, does 'du' command on '/' folder consider the space occupied by '/home' folder that resides within '/' folder ? If so, then 'du --si -s' must give larger value than 'df' of '/' partition.

    Any help is appreciated.
    Last edited by chakri1; July 19th, 2012 at 08:22 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    UK
    Beans
    562

    Re: Disk space error

    du shows the USED space by ALL mounted file systems. Disk usage summary shows as 123G on my system, when broken down with df shows what is mounted and where. Hope that helps.

    [root@orac ~]# du -sh /
    123G /

    [root@orac ~]# df
    Filesystem Size Used Avail Use% Mounted on
    /dev/sdb1 19G 6.0G 12G 34% /
    /dev/sdb2 24G 11G 13G 46% /home
    /dev/sda12 36G 23G 12G 67% /media/share
    /dev/sda1 128G 12G 117G 9% /media/xp
    /dev/sda2 196G 74G 122G 38% /media/win7

  3. #3
    Join Date
    Jan 2005
    Location
    South Africa
    Beans
    2,098
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Disk space error

    There are a few things that I'm aware of that can give the difference
    1)
    Deleted files might still be in use by an application; du will not see them but df (the filesystem) will still see them as in use. If you open a huge file in vi, vi will create an equally huge swp file. If you keep vi open and delete the swp file, du will immediately reflect the change but df will not as vi still has it 'open'. If you close vi after that, df will reflect it.
    The command lsof can be of help here. A reboot should mostly get rid of this discrepancy.
    2)
    du traverses directories that it can see. If you mount a partition over a directory (like /dev/sda6 on /home), du will not count the original /home directory but what is mounted on it. If your /home directory (before mounting /dev/sda6 over it) contains a few gigs of data, df will reflect this in the reporting of /dev/sda2 and du will not (as it can't see it).
    Last edited by Wim Sturkenboom; July 19th, 2012 at 09:19 AM.
    If you don't make backups of your important data, your data is obviously not important to you.

  4. #4
    Join Date
    Dec 2010
    Beans
    6

    Re: Disk space error

    Thanks for your reply.

    If 'du' shows COMBINED space used by all mounted file-systems, then it should be higher than 'df' of one single partition. But in my case, du shows 50G while df of '/' partition shows 57G.

    Quote Originally Posted by hal8000 View Post
    du shows the USED space by ALL mounted file systems. Disk usage summary shows as 123G on my system, when broken down with df shows what is mounted and where. Hope that helps.

    [root@orac ~]# du -sh /
    123G /

    [root@orac ~]# df
    Filesystem Size Used Avail Use% Mounted on
    /dev/sdb1 19G 6.0G 12G 34% /
    /dev/sdb2 24G 11G 13G 46% /home
    /dev/sda12 36G 23G 12G 67% /media/share
    /dev/sda1 128G 12G 117G 9% /media/xp
    /dev/sda2 196G 74G 122G 38% /media/win7

  5. #5
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,089
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Disk space error

    Quote Originally Posted by chakri1 View Post
    If 'du' shows COMBINED space used by all mounted file-systems, then it should be higher than 'df' of one single partition. But in my case, du shows 50G while df of '/' partition shows 57G.
    True, but the command
    Code:
    du -sh /
    does indeed calculate the sum used by all mounted partitions. So your discrepancy is larger than it currently appears. You need -x if you only want to analyze the / partition itself, i.e.
    Code:
    du -shx /
    The possible reasons offered by Wim Sturkenboom are very good explanations of what you are seeing. I'd add to this that it is possible for there to be a problem that an fsck of / could sort it out. Here's how to force fsck at reboot http://linux.aldeby.org/post/linux-u...at-reboot.html

    You could also run fsck of /dev/sda2 by booting from a LiveCD.

    If your problem is that /home or /boot have been mounted onto a directory that contains files (the second point mentioned by Wim Sturkenboom), then you would really need to boot from a LiveCD to sort that out. e.g. (from a LiveCD)
    Code:
    sudo mkdir /media/root
    sudo mount /dev/sda2 /media/root
    sudo ls -a /media/root/home /media/root/boot
    If these directories contain files, then they are taking up space but are hidden from du when you boot normally.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •