How to extend a VMWare disk and have the partition and file system size extended on Linux

Task: To resize one of the virtual disk in my Linux VM from 40GB to 150GB
Assume the disk concern is not a system disk
Assume the mount point is /mydata and disk is /dev/sdc1 in this example
We need to expand the below objects in sequence:

  • VMDisk
  • Partition
  • File System

  1. Unmount the disk:
    umount /mydata
  2. Use fsck to make sure no partition data error:
    fsck -n /dev/sdc1
  3. Go to vSphere client, resize the size of the "Provisioned Size" directly.  Click OK to save.
  4. Reboot
  5. The Linux kernel might not aware the change of the disk size.  We need to use the below command to force a refresh:
    sudo partprobe
  6. use fdisk to check the disk size again
    fdisk -l /dev/sdc
  7. Use tune2fs to downgrade the partition to Ext2
    [root@myserver /]# tune2fs -O ^has_journal /dev/sdc1
    tune2fs 1.41.12 (17-May-2010)
  8. fdisk /dev/sdc
    1. print out the partition table by command p:
      Command (m for help): p

      Disk /dev/sdc: 161.1 GB, 161061273600 bytes
      255 heads, 63 sectors/track, 19581 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        5221    41937651   83  Linux
    2. delete partition 1
      Command (m for help): d
      Selected partition 1

      (Since I have only one partition, I am not prompted to enter a partition number.)
    3. create a new partition again
      Command (m for help): n
      Command action
         e   extended
         p   primary partition (1-4)
      p
      Partition number (1-4): 1
      First cylinder (1-19581, default 1):
      Using default value 1
      Last cylinder, +cylinders or +size{K,M,G} (1-19581, default 19581):
      Using default value 19581


      Command (m for help):
    4. Print the partition table again, we will find the partition has been extended:
      Command (m for help): p

      Disk /dev/sdc: 161.1 GB, 161061273600 bytes
      255 heads, 63 sectors/track, 19581 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

      Command (m for help):
    5. Press w to save the partition setting:
      Command (m for help): w
      The partition table has been altered!

      Calling ioctl() to re-read partition table.
      Syncing disks.
    6. reboot again
  9. Use tune2fs to resize the file system to maximum size:
    [root@myserver ~]# resize2fs /dev/sdc1
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/sdc1 to 39321087 (4k) blocks.
    The filesystem on /dev/sdc1 is now 39321087 blocks long.
  10. Check disk again:
     fsck -n /dev/sdc1
  11. Create the journal and turn the file system to ext3 again:
    [root@myserver ~]# tune2fs -j /dev/sdc1
    tune2fs 1.41.12 (17-May-2010)
    Creating journal inode: done
    This filesystem will be automatically checked every 26 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
  12. Reboot the system or mount the disk:
    mount /mydata
  13. use df -h command to verify the file system has been expanded.
Reference: How to Forge

Comments

Popular Posts