LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   fdisk and df giving different hard disk size (https://www.linuxquestions.org/questions/linux-newbie-8/fdisk-and-df-giving-different-hard-disk-size-923168/)

sysmicuser 01-10-2012 10:58 PM

fdisk and df giving different hard disk size
 
Hi Guys.

I am using host operating system as windows xp and guest as centos 6 with virtualization software as Virtual Box.

I had issue with hard disk size of guest so increased it successfully with VirtualBox command line argument.
VBoxmanage modifyhd "path\to\vdi image file\centos60-full.vdi" --resize 40960

all good but now, if we have look df -h still shows old size :(:(:(

fdsik does gives information about 40Gb hard disk size.


[user01@centos60-full ~]$ su -
Password:
[root@centos60-full ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos60full-lv_root
16G 12G 2.8G 82% /
tmpfs 1012M 112K 1012M 1% /dev/shm
/dev/sda1 485M 48M 412M 11% /boot
C_DRIVE 233G 137G 97G 59% /media/sf_C_DRIVE
/dev/sr0 44M 44M 0 100% /media/VBOXADDITIONS_4.1.8_75467
[root@centos60-full ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e134f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/mapper/vg_centos60full-lv_root: 16.7 GB, 16684941312 bytes
255 heads, 63 sectors/track, 2028 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_centos60full-lv_root doesn't contain a valid partition table

Disk /dev/mapper/vg_centos60full-lv_swap: 4261 MB, 4261412864 bytes
255 heads, 63 sectors/track, 518 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_centos60full-lv_swap doesn't contain a valid partition table
[root@centos60-full ~]#


Please assit.

Many thanks in advance.

suicidaleggroll 01-10-2012 11:04 PM

You increased the disk size (what fdisk measures), but not the partition or filesystem size (what df measures).

You'll need to expand the partition to fill the empty space that was created when you expanded the disk. Same thing that happens when you have two partitions on a disk and delete one of them, you end up with a bunch of free space on the disk. The second partition won't automatically expand to fill it, you have to do that by hand.

Dark_Helmet 01-10-2012 11:09 PM

What suicidaleggroll said.

One utility to resize partitions (and the filesystems they contain): gparted

You will need to download an ISO of a Live CD that has gparted on it, boot your virtual machine off the Live CD image, run gparted to resize the partition and filesystem, and then reboot your virtual machine. You cannot run gparted on a mounted, active filesystem--which is why you need an ISO of a Live CD.

sysmicuser 01-10-2012 11:43 PM

Thanks gys, is there not there any better way to do it online?

I really want that 40GB available ASAP.

Any magical command to do?

suicidaleggroll 01-10-2012 11:52 PM

Nope, you can't modify the root partition and filesystem while it's mounted and running. You have to jump through these same hoops with Windows or any other OS too.
Your only option if you want the space without shutting down and running parted on a live cd is to add a second partition to use up the free space, and mount it in a new directory. "/" won't be expanded to the new size, but the additional space will be available in your new filesystem mounted at say "/mnt/extra/".

wpeckham 01-11-2012 11:15 AM

Correction
 
You do not have to jump through that particular hoop with EVERY OS, you can expand (but not shrink) some filesystem while they are mounted when running some operating systems. I am familiar with AIX from IBM. Those capabilities are ON THE WAY for several file system under Linux, but I cannot tell you that they are production ready today.

BTW: If you want to research a few interesting things: AIX uses JFS or JFS2 as the native FS. Linux capability will likely be based upon EXT4 on LVM volumes: that was closest when last I checked.

Alas, none of that helps the OP RIGHT NOW, but may be something to keep in mind for that next system build.

gdejonge 01-11-2012 06:48 PM

Hi Sysmicuser.

Yes you can enlarge your mounted ext[234] filesystem while mounted. Checkout the tool resize2fs.

But remember as with all actions that make changes to your filesytem. Make sure you got a valid backup.

Dark_Helmet 01-11-2012 07:08 PM

Quote:

Originally Posted by gdejonge
Yes you can enlarge your mounted ext[234] filesystem while mounted. Checkout the tool resize2fs.

That is not what the man page says.
Code:

RESIZE2FS(8)                                                                      RESIZE2FS(8)

NAME
      resize2fs - ext2/ext3/ext4 file system resizer

SYNOPSIS
      resize2fs [ -fFpPM ] [ -d debug-flags ] [ -S RAID-stride ] device [ size ]

DESCRIPTION
      The  resize2fs  program  will  resize ext2, ext3, or ext4 file systems.  It can be used to
      enlarge or shrink an unmounted file system located on device.  If the filesystem is mounted,
      it can be used to expand the size of the mounted filesystem, assuming the kernel supports
      on-line resizing.  (As of this writing, the Linux 2.6 kernel supports on-line resize for
      filesystems mounted using ext3 only.)
.

ext2 and ext4 cannot be expanded while mounted according to the man page. Only ext3 is supported and only with a 2.6 kernel.

While CentOS 6 most certainly uses a 2.6 kernel, we do not know what filesystem the OP is using.

Furthermore, the resize2fs man page goes on to state:
Code:

      The resize2fs program does not manipulate the size of partitions.  If you wish to
      enlarge a filesystem, you must make sure you can expand the size of the underlying
      partition first.
  This can be done using fdisk(8) by deleting  the partition and
      recreating it with a larger size or using lvextend(8), if you're using the logical volume
      manager lvm(8).  When recreating the partition, make sure you create it with the same
      starting disk cylinder as before!  Otherwise, the resize operation will certainly not work,
      and you may lose your entire filesystem.  After running fdisk(8), run resize2fs to resize
      the ext2 filesystem to use all of the space in the  newly  enlarged partition.

The OP must still expand the partition to make use of the newly available space. And I don't know of any utility that allows for mounted partition resizing.

sysmicuser 03-14-2012 08:33 AM

Thanks Guys for all your help.

I am closing this thread as SOLVED.

Cheers.
sysmicuser


All times are GMT -5. The time now is 06:26 PM.