VMWare - expand Linux virtual disk


  1. Backup the concerned VMDK.  For me, I power off the VM and use vSphere to download the .vmdk file.
  2. If you have ESX 3.5 or newer:
    1. Open vSphere client to connect to vCenter the ESX host.
    2. Right-click the virtual machine.
    3. Click Edit Settings.
    4. Select Virtual Disk.
    5. Increase the size of the disk.
      Note: If this option is greyed out then the disk may be running on snapshots or the disk may be at the maximum allowed size depending on the block size of the datastore
    6. Follow the steps in Increasing the size of a disk partition (1004071) so the guest operating system is aware of the change in disk size.
  3. If you have ext3 filesystem in Linux (without using Volumn Group), follow the below steps:




Check the disk usage before the operation

[root@host /]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
(unrelated partition information hided.)
/dev/sdc1             148G  130G   11G  93% /data

In this example, although we have increased the disk size to 250G, the Linux partition will not expand automatically.  It is still 148G.

Print the partition information

[root@host /]# fdisk -l /dev/sdc

Disk /dev/sdc: 268.4 GB, 268435456000 bytes
255 heads, 63 sectors/track, 32635 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: 0x727ae390

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       19581   157284351   83  Linux

My virtual disk has only one partition.  The virtual disk has 32635 cylinders but the Linux partition ends at 19581 cylinder.

Expand the Linux partition by delete and recreate it.


[root@host /]# fdisk /dev/sdc

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

(print the partition information again)

Disk /dev/sdc: 268.4 GB, 268435456000 bytes
255 heads, 63 sectors/track, 32635 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: 0x727ae390

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       19581   157284351   83  Linux

(delete partition by using "d" command.  In this example, fdisk will not ask for partition number since we have only one partition.)

Command (m for help): d
Selected partition 1

(create the partition again by using "n" command.  In this example, I need to use the exactly the same starting cylinder number so that I won't lost my partition table.  What I changed here is the Last cylinder number.)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-32635, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-32635, default 32635):
Using default value 32635

(using "p" command to double check the settings.)

Command (m for help): p

Disk /dev/sdc: 268.4 GB, 268435456000 bytes
255 heads, 63 sectors/track, 32635 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: 0x727ae390

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       32635   262140606   83  Linux

(using "w" command to apply the changes.)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

(reboot!)
[root@host  /]# reboot

(After reboot, use "resize2fs" to expand the file system automatically.)
[root@host  ~]# resize2fs /dev/sdc1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sdc1 is mounted on /data; on-line resizing required
old desc_blocks = 10, new_desc_blocks = 16
Performing an on-line resize of /dev/sdc1 to 65535151 (4k) blocks.
The filesystem on /dev/sdc1 is now 65535151 blocks long.

(Done!  We now use "df" command to check again.  The file system is now expanded to 250G.  Disk usage is now reduced to 56%.)

[root@host  ~]# df -h
/dev/sdc1             247G  130G  104G  56% /data


Reference:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1004047

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1004071

http://www.linuxnepal.com/2011/06/10/extend-the-size-of-ext3-partition-online-in-a-virtual-machine/

Comments

Popular Posts