Extend disk in a VMWare client
If you have been allocated more space to your VMWare disk but it doesn’t show up when you run df -h
, this post will tell you how to extend your last partition over your new blocks. The important thing here is that you can only extend your last partition without the risk of losing data.
Lets check my current disk size and usage with df -h
.
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 49G 35G 12G 76% /
udev 1.5G 4.0K 1.5G 1% /dev
tmpfs 603M 236K 602M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.5G 168K 1.5G 1% /run/shm
cgroup 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/sda1 180M 127M 45M 75% /boot
About 54GB in size. Time to open fdisk
.
fdisk /dev/sda
Notice the size of /dev/sda
. A lot more than the 54GB shown before.
Command (m for help): p
Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders, total 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00058d4a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 391167 194560 83 Linux
/dev/sda2 391168 2344959 976896 82 Linux swap / Solaris
/dev/sda3 2344960 104857599 51256320 83 Linux
My last partition is /dev/sda3
so this is where I can add new blocks without losing any data.
Lets delete /dev/sda3
. It’s ok, you don’t delete any data, just the partition from the partition table.
Command (m for help): d
Partition number (1-4): 3
Command (m for help): p
Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders, total 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00058d4a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 391167 194560 83 Linux
/dev/sda2 391168 2344959 976896 82 Linux swap / Solaris
And let’s add a new /dev/sda3
.
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (1-4, default 3): 3
First sector (2344960-167772159, default 2344960):
Using default value 2344960
Last sector, +sectors or +size{K,M,G} (2344960-167772159, default 167772159):
Using default value 167772159
Command (m for help): p
Disk /dev/sda: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders, total 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00058d4a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 391167 194560 83 Linux
/dev/sda2 391168 2344959 976896 82 Linux swap / Solaris
/dev/sda3 2344960 167772159 82713600 83 Linux
And save.
Command (m for help): w
The partition table has been altered!
The new table will be used when we reboot the next time, so let’s do it by invoking reboot
.
Wait, what, you donut see the whole size when running df -h
?
Still 49G.
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 49G 35G 12G 76% /
You have to resize the disk to new the filesystem. That is done by running resize2fs /dev/sda3
.
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/sda3 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 5
The filesystem on /dev/sda3 is now 20678400 blocks long.
Let’s try df -h
now.
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 78G 35G 40G 47% /
And that’s how it’s done.