Shrinking a VirtualBox VDI disk image

Published by Tobias Hofmann on

1 min read

I run an SAP NetWeaver ABAP Dev Edition system in a Virtual Box VM. Unfortunately, the update process for this software is to delete and reinstall after the DB license expires. Installing a new NW ABAP version is not overly complex: the SAP provided installer is easy to use and it takes not even 30 minutes to have a system up and running.

Installing a new Linux every time does takes some time. Therefore, my update process is to wipe NW from the disk and reinstall it in the same Linux VM. This means that the space the virtual disk is using keeps growing.

The space used in the VM is 33 GB, and the VDI file is 45 GB. I want to keep the file size minimal. Disk space has a precious value for MacBook users. How to clean up the disk? The steps are the same as shown in my previous blog on how to optimize a VMDK disk.

Remove files

Delete everything in the VM that is not needed. In my case:

rm -rf /sapmnt
rm -rf /usr/sap
rm -rf /sybase

This cleans up the used disk space to less than 4 GB, almost 29GB

Prepare disk

Fill the disk with zeros. This will later allow the compression of the VDI disk.

dd if=/dev/zero of=/var/dummy bs=8126k

Delete the dummy file and shut down Linux.

Minimize disk

Navigate to the location of your VM and the VDI disk image. Use VBoxManager to minimize the disk size.

VBoxManage modifymedium disk ./NWABAP75101.vdi –compact

After the tool finishes, the disk size will be close to what Linux showed in the df output: 4,19 GB.

Let the world know

Tobias Hofmann

Doing stuff with SAP since 1998. Open, web, UX, cloud. I am not a Basis guy, but very knowledgeable about Basis stuff, as it's the foundation of everything I do (DevOps). Performance is king, and unit tests is something I actually do. Developing HTML5 apps when HTML5 wasn't around. HCP/SCP user since 2012, NetWeaver since 2002, ABAP since 1998.

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.