Thursday, 12 January 2012

Resize virtual disk


There are several methods to re-sizing virtual disks listed below. If you want to shrink the disk in ESX4 then using VMmware Converter is the best way to do this, you can no longer use vmkfstools to shrink a disk in ESX4, you can also try using QpartEd to shrink a disk. With all these methods you should make a backup copy of your original vmdk file in case something goes wrong. Also make sure you shutdown the OS cleanly before restarting the VM (GpartEd will sometimes fail otherwise). Methods 1, 4 & 5 are essentially the same using Linux boot CD’s and either GpartEd or QpartEd.

You can also check out my articles I wrote on this that use the methods below:* Using VMware Converter to resize virtual disk files (Pt. 1)
* Increasing virtual disk partition size using DISKPART or GpartEd (Pt. 2)

Method 1 - Using vmkfstools and GParted to extend a disk


1. Download the GParted Live CD ISO and make it available so it can be mounted by the virtual machine’s CD-ROM
2. Shutdown the virtual machine you want to resize
3. Log into the ESX Server console via Putty
4. Type “vmkfstools -X /vmfs/volumes/<volume name>/<VM directory name>/<virtual disk file name>” ie. /vmfs/volumes/Storage1/my_vm.vmdk. New disk size can be specified in kilo, mega or gigabytes and will be the total size of the new disk. So if you want to increase a virtual disk from 
20GB to 24GB you would specify either 24000m or 24g.
5. Power on the Virtual Machine and make sure it boots properly, load Disk Management and you will see the new unallocated space
6. Now to join the unallocated space to the primary partition, first shutdown the Virtual Machine
7. Connect the Virtual Machine to the GParted ISO file and make sure you enable Connected at Power On
8. Power on the Virtual Machine
9. Press ESC at the Bios screen to get to the Boot Menu
10. Select CD-ROM as the Boot device
11. Gnome Partition Editor will load, press Enter at the boot screen
12. At the Boot option screen select Manual Video Card and then select Done
13. Select US English at the Language screen
14. Select qwerty/us.map at the Keyboard screen
15. Select Generic VESA Compatiable at the Video Driver screen
16. Select 8 at the Display Depth screen
17. Select 1024×768 at the Resolution screen
18. Once the partition editor loads, click on /dev/sda1 in the partition list
19. Click the Resize/Move button
20. Click and drag the arrow to extend the size of the partition, make sure you do a resize (double arrow) and not a move (four way arrow) so you should 0 free space preceding and following and then click the Resize/Move button
21. Next click the Apply button and then the operation will start, you can expand Details to see the progress, once completed click the Close button
22. Click the power button in the bottom right corner, then select reboot
23. Edit the VM and remove the ISO from the CD/ROM device (change to Client)
24. When the server restarts it will do a Check Disk, let this complete, Windows will prompt for a reboot after you login
25. Reboot and load Disk Management and your Primary Partion will be the new size without any unallocated space


 
Method 2 - Using VMware Converter to shrink or extend a disk

When you use Converter to copy a VM it will transfer the data to the destination server by one of two ways. If you do not change the disk size or increase the size of your original disks then it does a block level clone of the drive. If you reduce the size of your original disks it instead does a file level clone of the drive.

1. Download Converter and install it on the VM that you want to resize the drives, reboot after the install completes
2. Start Converter application, click the Import Machine button
3. Click Next at the Welcome screen and then Next again at the Source screen
4. Select ‘Physical Computer’ and click Next o Select “This Local Machine” and click Next
5. At the Source Data screen select your volumes and change “Maintain Size” to “Type Size in GB” and enter your new disk size and click Next
6. At the Destination screen click Next
7. Select “Import this machine to a Vmware ESX Server or VirtualCenter virtual machine” and click Next
8. At the Destination login screen, select your ESX/VC server and enter the login information and click Next
9. At the Virtual Machine Name and Folder screen enter a new name for your VM and select a folder and click Next
10. At the Host or Cluster screen select a host for your destination and click Next
11. At the Datastore screen, select a datastore and click Next
12. At the Networks screen, configure your NICs and click Next
13. At the Customization screen, click Next
14. Click Finish and the conversion will begin
15. Once the Conversion is complete, edit the new VM settings and remove any extra hardware that Converter adds (USB/serial/parallel ports, etc.)
16. Shutdown your original source VM and power on your new destination VM
17. Make sure everything is functioning properly on the new VM and you can delete the original VM

Method 3 - Using vmkfstools and another Windows virtual machine to extend a disk 

1. Shutdown the virtual machine you want to resize
2. Log into the ESX Server console via Putty
3. Type ”vmkfstools -X /vmfs/volumes/<volume name>/<VM directory name>/<virtual disk file name>” ie. /vmfs/volumes/Storage1/my_vm.vmdk. New disk size can be specified in kilo, mega or gigabytes and will be the total size of the new disk. So if you want to increase a virtual disk from 20GB to 24GB you would specify either 24000m or 24g
4. Shutdown the second helper virtual machine
5. Edit the settings of the second VM and add the hard disk from the first VM
6. Power on the second VM and load the Disk Management snap-in and verify that the disk from the first VM has un-allocated space on it
7. Select Start, Run and enter diskpart.exe
8. The command ‘list volume’ will show you all volumes.
9. Select your volume based on the results of the list volume command, ie. ‘select volume 1'
10. Type the command ‘extend’ to extend the volume
11. Check the Disk Management snap-in again and the volume should be extended with a larger capacity
12. Shutdown the second VM and remove (not delete) the disk from it
13. Power on your first VM and the new space should be there and ready to use

Method 4 - Using vmkfstools and System Rescue CD to extend a disk

1. Download the System Rescue ISO and make it available so it can be mounted by the virtual machine’s CD-ROM
2. Shutdown the virtual machine you want to resize
3. Log into the ESX Server console via Putty
4. Type “vmkfstools -X /vmfs/volumes/<volume name>/<VM directory name>/<virtual disk file name>” ie. /vmfs/volumes/Storage1/my_vm.vmdk. New disk size can be specified in kilo, mega or gigabytes and will be the total size of the new disk. So if you want to increase a virtual disk from 20GB to 24GB you would specify either 24000m or 24g
5. Power on the Virtual Machine and make sure it boots properly, load Disk Management and you will see the new unallocated space
6. Now to join the unallocated space to the primary partition, first shutdown the Virtual Machine
7. Connect the Virtual Machine to the System Rescue ISO file and make sure you enable Connected at Power On
8. Power on the Virtual Machine
9. Press ESC at the Bios screen to get to the Boot Menu
10. Select CD-ROM as the Boot device
11. Press Enter at the boot screen
12. Press Enter after boot sequence is complete and then type ‘startx’
13. Once X-windows loads, double-click the GpartEd icon (drive icon, 3rd down on the right hand side)
14. Once the partition editor loads, click on /dev/sda1 in the partition list
15. Click the Resize/Move button
16. Click and drag the arrow to extend the size of the partition, make sure you do a resize (double arrow) and not a move (four way arrow) so you should 0 free space preceding and following and then click the Resize/Move button
17. Next click the Apply button and then the operation will start, you can expand Details to see the progress, once completed click the Close button
18. Click the power button in the bottom right corner, then select reboot
19. Edit the VM and remove the ISO from the CD/ROM device (change to Client)
20. When the server restarts it will do a Check Disk, let this complete, Windows will prompt for a reboot after you login
21. Reboot and load Disk Management and your Primary Partion will be the new size without any unallocated space



Method 5 - Using Knoppix Live CD with QtPartEd to shrink a disk

1. Download the Knoppix Live CD ISO and make it available so it can be mounted by the virtual machine’s CD-ROM
2. Shutdown the virtual machine you want to resize
3. Add a second virtual disk of the new smaller desired size to the VM you want to resize
4. Connect the Virtual Machine to the Knoppix Live CD ISO file and make sure you enable Connected at Power On
5. Power on the Virtual Machine
6. Press ESC at the Bios screen to get to the Boot Menu
7. Select CD-ROM as the Boot device
8. Press Enter at the boot screen
9. Click on the K Menu icon and then select System and then QTPartEd
10. Select your original drive (usually sda) and click on the partition 1
11. Select Operations from the top menu and then Resize, resize the drive so it is just less then the new drives (sdb) capacity
12. Select File from the top menu and then Commit, click Yes at the warning window
13. Once complete, select Cancel if you get a unmounted hard disk window and then OK at the Progress window
14. Open a Konsole window and type “dd if=/dev/sda of=/dev/sdb” This copy will take a long time and will not show a status while it is running. Yyou will get an insufficient space error at the end of the copy, this is normal because the drive you’re copying from is bigger then the destination. But as long as the partition is smaller, everything will work
15. Shutdown the VM and edit the VM settings, remove the original C: drive and change the SCSI ID of the new drive to match the old one (usually 0:0)
16. Power on the VM and it will run a Chkdsk and you will be all set


Method 6 - Use Ghost or another 3rd party imaging product to shrink a disk  

1. Shutdown the virtual machine you want to resize
2. Add a second virtual disk of the new smaller desired size to the VM you want to resize o Use Ghost to clone the first disks partition to your second virtual disk
3. Once complete make sure the second virtual disk is ‘Active’
4. Switch your disks by editing the virtual machine settings and switching the SCSI id’s (0:0 and 0:1)
5. If the virtual machine boots OK and you verify that everything works then shutdown the VM and remove the larger disk and delete it  

No comments:

Post a Comment