diff --git a/content/posts/shrink-vmdk.md b/content/posts/shrink-vmdk.md new file mode 100644 index 0000000..92b08f5 --- /dev/null +++ b/content/posts/shrink-vmdk.md @@ -0,0 +1,81 @@ ++++ +date = '2025-10-12T13:41:47+02:00' +title = 'Shrink VMDK safely' +description = "Thanwer's Blog Post about how to safely resize a VMDK file" +tags = [ + "GNU/Linux", + "Tools", + "ESXi", +] +canonical = "/posts/shrink-vmdk" ++++ + +I recently was tasked to convert a couple physical servers to virtual machines. + +The physical servers basically had 2x 500GB SSDs in a RAID1 configuration, and the total used space was around 40GB. + +To optimize the storage for the virtual machines, I needed to resize the VMDK files accordingly. This process involves several steps to ensure data integrity and minimize downtime. + +Here I document the steps I took to safely resize a VMDK file, without modifying the virtual machine description file (VMX). + +## Step 1: Prepare the physical server + +Before starting, I did the basic preparation on the physical server: + +- As always, create a full backup of the server, just in case something goes wrong +- Clean up unnecessary files to reduce the used space +- Resize the partitions and filesystems to reduce the used space to the smallest possible size (in my case, I resized the partitions to 64GB to have some buffer space) + +![Gparted result](/images/vmdk-gparted-1.jpg) + +## Step 2: Convert the physical server to a virtual machine + +I used Clonezilla to convert the physical server to a virtual machine. +This process was simply: + +- Boot the physical server with the Clonezilla live CD +- Follow the wizard and choose the mode "remote-source" to send the image to a remote server +- On the target virtual machine, boot with the Clonezilla live CD and choose the mode "remote-dest" to receive the image from the physical server +- Inform the IP address of the physical server and start the process + +> Important: In this first step, I created a VMDK file with the same size as the physical disk (in my case, 500GB). + +![ESXi Disks](/images/vmdk-disks.jpg) + +## Step 3: Resize the VMDK file + +Now here is the tricky part, resizing the VMDK file without modifying the VMX file. + +Many tutorials suggest to access the ESXi host via SSH and directly modify the VMX file using a text editor. + +I found it to be very risky, as a small mistake can lead to a non-bootable virtual machine. I lost many attempts this way. + +So instead, I found a method that works without modifying the VMX file: + +Use Clonezilla again, to clone the virtual machine to a new virtual machine with a smaller disk size. + +This time we are going to use local disks, so we need to create a new virtual machine with a smaller disk size (in my case, 64GB). + +![Disks on ESXi](/images/clonezilla-1.jpg) + +![Clonezilla local source](/images/clonezilla-2.jpg) + +When asked about the partition table, choose the option "-k1" to keep the partition table as is. + +![Clonezilla partition table](/images/clonezilla-3.jpg) + +When asked about the mode, choose "Expert" + +![Clonezilla expert mode](/images/clonezilla-4.jpg) + +Then, enable the option "-icds" to ignore the disk size. + +![Clonezilla ignore disk size](/images/clonezilla-5.jpg) + +After following the rest of the wizard, the cloning process will start. + +![Clonezilla cloning](/images/clonezilla-6.jpg) + +After the process is complete, you will have a new virtual machine with a smaller disk size, and the same data as the original virtual machine. + +This will leave you with the original VMDK file, and a smaller one. After verifying that the new virtual machine works correctly, you can delete the original one to free up space. \ No newline at end of file diff --git a/static/images/clonezilla-1.jpg b/static/images/clonezilla-1.jpg new file mode 100644 index 0000000..0b2bc6c Binary files /dev/null and b/static/images/clonezilla-1.jpg differ diff --git a/static/images/clonezilla-2.jpg b/static/images/clonezilla-2.jpg new file mode 100644 index 0000000..6e93a63 Binary files /dev/null and b/static/images/clonezilla-2.jpg differ diff --git a/static/images/clonezilla-3.jpg b/static/images/clonezilla-3.jpg new file mode 100644 index 0000000..d708cf3 Binary files /dev/null and b/static/images/clonezilla-3.jpg differ diff --git a/static/images/clonezilla-4.jpg b/static/images/clonezilla-4.jpg new file mode 100644 index 0000000..51621f4 Binary files /dev/null and b/static/images/clonezilla-4.jpg differ diff --git a/static/images/clonezilla-5.jpg b/static/images/clonezilla-5.jpg new file mode 100644 index 0000000..4aac34d Binary files /dev/null and b/static/images/clonezilla-5.jpg differ diff --git a/static/images/vmdk-disks.jpg b/static/images/vmdk-disks.jpg new file mode 100644 index 0000000..e4e6ce4 Binary files /dev/null and b/static/images/vmdk-disks.jpg differ diff --git a/static/images/vmdk-gparted-1.jpg b/static/images/vmdk-gparted-1.jpg new file mode 100644 index 0000000..3fe4b43 Binary files /dev/null and b/static/images/vmdk-gparted-1.jpg differ