Chinaunix首页 | 论坛 | 博客
  • 博客访问: 156646
  • 博文数量: 42
  • 博客积分: 852
  • 博客等级: 准尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-10 09:59
文章分类

全部博文(42)

文章存档

2015年(2)

2013年(9)

2012年(21)

2011年(4)

2009年(6)

我的朋友

分类: 系统运维

2013-09-11 11:32:21

.

Shutdown VM and remove from inventory


.

Copy vmx, vmdk, and *-flat.vmdk to Backup

SSH to the correct host, then copy: 
cp /vmfs/volumes/// /backup_destination

.

Determine your desired shrunken file size in blocks (vmdk_shrunken)

Decide your desired shrunken vmdk file size in GB (x) and use the following formula to determine what I will call the "vmdk_shrunken" size:

vmdk_shrunken = [x * (1024*1024*1024)] / 512

I created this equation based on information in the referenced article: "How to Shrink a VMDK file in ESX" see below.

.

Modify RW Block size value in original *.vmdk and save.

vi /path/to/original_vmdk

locate the lines that look like: 
# Extent description 
RW 52428800 VMFS “foo-flat.vmdk”

Change the value beside RW to the value of vmdk_shrunken from above. Save the change.

.

Export the shrunken vmdk file to Backup

You'll need to export a new vmdk file from the edit you just made without overwriting the original:

Use vmfstools -i /path/to/original/original_vmdkfilename.vmdk /path/to/backup/new_vmdkfilename.vmdk (with new filesize)

IMPORTANT: If resizing a VMDK with snapshots, either remove the snapshots OR edit each snapshot using info from Step 4 for each snapshot file, then perform Step 5 on the latest snapshot file in the CID chain. IF YOU HAVE LIVE SNAPSHOTS AND DON'T DO THIS, YOU WILL LOSE DATA!

.

Delete the original *.vmdk and *-flat.vmdk files

Now that you have a backup of the original vmdk's and vmx as well as a newly exported/resized *.vmdk and *-flat.vmdk, you can delete the original files.

rm -rf .vmdk*

.

Copy the new resized files to the correct datastore

Use vmfstools -i /path/to/backup/new_vmdkfile.vmdk /path/to/original/original_vmdkfilenamename.vmdk (with new filesize)

.

Re-add VM to inventory


.

Remove old disk from VM, add new disk to VM

in vSphere, edit settings for the VM and remove the entry for the original HDD.

Add the new vmdk and provide the path to it. Save settings.

.

Remove VM from inventory, Re-re-add VM to inventory

Not sure why, but my VM wouldn't start after performing this step.

.

Turn on VM and enable the disk

For windows VM's, you'll need to get into Disk Management and switch the disk to "Online" status.

.

Reboot the VM

This step will be necessary for VM's (like mine) who run services from the affected disk.

This is a long process (several hours depending on the amount of data and the size of the disk. Not for the faint of heart! Common sense rules apply: always backup before making changes and don't shrink your VMDK smaller than the amount of data on the disk!

This is a good alternative to using the vCenter Converter IF you absolutely must keep the original VM intact, as the Converter will alter the subsequent clone: in my instance: a web server or email server that employs an SSL certificate. In all other cases, use the converter--it works, it's fast, and it's a whole lot easier to use.

Hope this is useful!



from

阅读(2490) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~