VMware ext3 partition re-sizing without loosing data ...

One my Virtual appliances in a VMware vSphere environment [VMware Studio to be precise] was clogged up and utilizing 100% of my data partition, by the way this partition was added manually and linked to the VMware Studio build directory, but 20 appliance builds later you are still out of space ... :(

Disclaimer:

This worked for me and if in doubt (which I always have) backup the disk (if you can spare the room ... :), in my case I just duplicated the /dev/sdb HD and I now have the same partition mounted twice so I will perform the following steps (resizing) on /dev/sdc and once I happy with my changes I will remove the old partition, so I mounted /dev/sdb1 as /backup and /dev/sdc1 (cloned HD) as /data.

 

  1. Extend the partition:
    From within the vSphere client select the VM, Edit Settings and resize the Virtual Hard disk size in VMware considering you are using Thin Provisioning feel free to give it as much as you think you will use, I increased it from 100GB to 300GB.
  2. Unmount the active partition [ the one you want to resize ]
    umount /dev/sdc1
  3. Remove the ext3 journal from the file system [basically degrade it to ext2 ...]
    tune2fs -O ^has_journal /dev/sdc1
    note the -O ^has_journal option which removes the journal from the partition, if this doesn’t work for some reason add the -f for we will be running fsck after the expansion in any case.
  4. Re-Partition - step #1 remove existing sdc1 partition
    root@vStudio:~# fdisk /dev/sdc
    The number of cylinders for this disk is set to 39162. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): d
    Selected partition 1
    "P" will show the existing partition table on /dev/sdc (this may differ for you of course with /dev/sd<partition#>
    You should have nothing now (don’t worry fsck will recover it in a sec …)
    Command (m for help): p
    Disk /dev/sdc: 322.1 GB, 322122547200 bytes
    255 heads, 63 sectors/track, 39162 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0xd88b5add
  5. Re-Partition - step #2 create new sdc1 partition (still in fdisk)
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-39162, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-39162, default 39162):
    Using default value 39162
    Accepting all defaults will create a partition which will span on the entire disk.
    P option will now return the 300GB partition … like so:
    Command (m for help): p
    Disk /dev/sdc: 322.1 GB, 322122547200 bytes
    255 heads, 63 sectors/track, 39162 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0xd88b5add
    Device Boot Start End Blocks Id System
    /dev/sdc1 1 39162 314568733+ 83 Linux
  6. Commit changes to partition table:
    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.
  7. Declare new partition
    Some recommend rebooting the machine, but what I found is that fcsk will scan and recover the partition during reboot, thus I used partptrobe.
    So quit fdisk (with “q”) and type partprobe
    root@vStudio:~# partprobe
  8. Resize file system:
    Command (m for help): w
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.

    root@vStudio:~# e2fsck -f /dev/sdc1
    e2fsck 1.40.8 (13-Mar-2008)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    data: 4193/6553600 files (8.6% non-contiguous), 23476426/26214055 blocks
    root@vStudio:~# resize2fs /dev/sdc1
    resize2fs 1.40.8 (13-Mar-2008)
    Resizing the filesystem on /dev/sdc1 to 78642183 (4k) blocks.
    The filesystem on /dev/sdc1 is now 78642183 blocks long.
  9. Regenerate journal [ext3]
    root@vStudio:~# tune2fs -j /dev/sdc1
    tune2fs 1.40.8 (13-Mar-2008)
    Creating journal inode: done
    This filesystem will be automatically checked every 28 mounts or
    180 days, whichever comes first. Use tune2fs -c or -i to override.

 

So that’s about it run mount –a & df –h to check your results:
root@vStudio:~# mount -a
root@vStudio:~# df -h
Filesystem                Size Used Avail Use% Mounted on
/dev/sda5               50G 16G 31G 35% /
varrun                    252M 184K 252M 1% /var/run
varlock                   252M 0 252M 0% /var/lock
udev                      252M 52K 252M 1% /dev
devshm                  252M 0 252M 0% /dev/shm

lrm                          252M 40M 213M 16% /lib/modules/2.6.24-26-generic/volatile

/dev/sda1               122M 23M 93M 20% /boot

/dev/sdb1               100G 89G 5.4G 95% /backup

/dev/sdc1                298G 89G 197G 32% /data  

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com