btw: love kvm (used by very large companies) just as virtualbox (oracle)

the task: over the years a windows vm is using up massive amounts of precious server harddisk space (snapshots before everyupdate)

all the snapshots now add up to 500GBytes (was able to shrink it to 150GByte (-70%))

the task is to shrink the vm to “all it needs” usage of disk space (consolidate all snapshots into one harddisk.vhd file)

in order to “delete” all old snapshots, but keep the current state of the vm

it is necessary to:

  • clone the vm into a new vm
  • then delete the old vm
  • then rename the new vm so it matches the old vm
hostnamectl; # tested on
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
      Architecture: x86-64

# with virtualbox
vboxmanage --version
6.0.20r137117

# list all existing vms
VBoxManage list vms

# create new screen session (uninterrupted ssh)
screen -S CloneVeryLargeVM

# now the actual magic
vboxmanage clonevm VMNAME --name="VMNAME_CLONE" --register --mode=machine --options=keepallmacs --options=keepdisknames --options=keephwuuids


# thanks to screen the user can now "sign out" without waiting for the process to finish with
Ctrl+A then D 

# list all running screen sessions
screen -ls
There is a screen on:
	28132.CloneVeryLargeVM	(Detached)
1 Socket in /var/run/screen/S-user.

# resume the session with
screen -R CloneVeryLargeVM

additions:

the option:

 --basefolder=basefolder
#   specifies the name of the folder in which to save the configuration for the new VM. 

could be a usefull option.

Iin VirtualBox the user can not simply “copy & paste” a vm to another harddisk (e.g. external drive for backup)

  • the user will have to change the folder where to save the cloned vm (“base folder”)
  • then clone the vm
  • now the vms is “exported” into basefolder in consistent stress-free-to-import state and user can “copy & paste” it anyhwere the user wants

src: https://docs.oracle.com/en/virtualization/virtualbox/6.0/user/vboxmanage-clonevm.html

admin