VMDK(Shrink / Reszie / Rename / Info)

最後更新: 2019-09-23

目錄

  • Resize Disk
  • Shrink a Thin Provisioned Virtual Disk (VMDK)
  • Resize vmdk
  • Rename
  • Lock
  • NAME-00000N.vmdk

 


Snapshot 結構

 

# Disk DescriptorFile
version=1
encoding="windows-1252"
CID=a82738e6
parentCID=c70818c6
isNativeSnapshot="no"
createType="monolithicSparse"
parentFileNameHint="Red Hat Enterprise Linux 6 64-bit-000002.vmdk"
# Extent description
RW 62914560 SPARSE "Red Hat Enterprise Linux 6 64-bit-000003.vmdk"

最頂底層 Image

parentCID=ffffffff

 


Resize Disk

 

Disk Provisioned Size Greyed Out

OR

Failed to reconfigure virtual machine MyServer. Invalid operation for device '2'.

You can't expand with a snapshot. delete the snapshot first

Online resize

只有在 SCSI / SATA mode 才可以 online resize disk

在 IDE mode 係不能 online resize 的 !!

 


Shrink a Thin Provisioned Virtual Disk (VMDK)

 

# In VM

[1]

dd bs=1M count=8192 if=/dev/zero of=zero

# In ESXi Host

[2] Verify disk usage

# display the configured size

ls -lh *.vmdk

-rw-------    1 root     root       50.0G Sep 27 04:22 oods-flat.vmdk
-rw-------    1 root     root         492 Aug 23 04:20 oods.vmdk

# (Disk Usage) command displays the actual size of the virtual disk.

du -h *.vmdk

[3] Run vmkfstools -K [disk]

 * Ensure you have a good backup of the VM before starting

 * Consolidate any lingering snapshots

# -K, --punchzero. punch all the zeroed blocks out of the VMDK file

vmkfstools -K oods.vmdk

vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 1% done.

grep thinProvisioned oods.vmdk

ddb.thinProvisioned = "1"

vmkfstools -i hostname.vmdk -d thin bak-hostname.vmdk

[4] Verify disk usage with du

du -h *.vmdk

19.0G   oods-flat.vmdk
0       oods.vmdk

 


Resize vmdk

 

[1] Backup. Ensure you have a good backup of the VM before starting

Poweroff VM

vmkfstools -i hostname.vmdk -d thin bak-hostname.vmdk

[2] Shrink Partition with GParted

GParted Live ISO

[3] Umount vmdk from VM (without delete it)

[4] Edit VMDK Descriptor

VM-NAME.vmdk              # Descriptor file

VM-NAME.-flat.vmdk       # Data File

vi hostname.vmdk

# Formula: y = size_in_gb * (1024 * 1024 * 1024) / 512

# (N x 2097152)

# The RW value is the number of 512-Byte sectors for the extent or disk file.

i.e.

62914560 x 512B / 1024 / 1024 /1024 = 30Gb

RW y VMFS "hostname-flat.vmdk"

如果想收細  -flat.vmdk 的 Size, 那就要 Step 5, 6, 否則直接跳到 7

[5] Clone Edited VMDK

vmkfstools -i hostname.vmdk -d thin shrunk-hostname.vmdk

P.S.

Cloning it will stop at X % during (New VMDK size)

62914560 -> 31457280

Destination disk format: VMFS thin-provisioned
Cloning disk 'tim.vmdk'...
Clone: 50% done.

[6] Swap VMDK Files & Re-Add to Inventory

# -E, --renamevirtualdisk

vmkfstools -E hostname.vmdk original-hostname.vmdk

vmkfstools -E shrunk-hostname.vmdk hostname.vmdk

[7] mount vmdk to VM again

 


Rename

 

# -E, --renamevirtualdisk

vmkfstools -E "originalname.vmdk" "newname.vmdk"

# clone (copy) a virtual disk

# The vmkfstools command renames both VMDK files and updates the reference within the descriptor.

vmkfstools -i "originalname.vmdk" "newname.vmdk"

 


Lock

 

On Workstation

cannot open the disk '*.vmdk' or one of the snapshot disk is depends on.
Reason: Failed to lock the file.

進到 VMware 的 Guest OS 資料夾, 將所有的 *.lck 資料夾或檔案刪除

 


NAME-00000N.vmdk

 

The 00000x.vmdk file actually is a snapshot.

i.e.

test-00001.vmdk
test-00002.vmdk
test-00003.vmdk

Even if the Snapshot Manager doesn't display a snapshot, never try to delete any files manually.

To get rid of the snapshot, open Snapshot Manager,

create a new snapshot (to enable the "Delete All" button) and then hit "Delete All".