Convert Physical Linux Installation into Virtual Machine (Big Partition to Small Partition)

By | March 1, 2020

I wanted to convert to my physical home use Xubuntu machine to virtual machine so that I can have the exactly same environment on another machine.

The physical machine has 512G SSD, 50G used disk space. I want to have a virtual machine with a 80G hard disk.

Tools needed:

  1. 3 USB drivers (one for GParted Live CD, one for CloneZilla Live CD and another one for storing the images), the first two can be small, the third one should be bigger than 80G.
  2. GParted (https://gparted.org/download.php)
  3. CloneZilla (https://clonezilla.org/downloads.php)
  4. Tuxboot (https://tuxboot.org/download/)

So here are the steps:

  1. Create a GParted Live CD using Tuxboot. (https://gparted.org/liveusb.php#linux-method-a)
  2. Create a CloneZilla Live CD using Tuxboot. (https://clonezilla.org/liveusb.php#linux-method-a)
  3. [Important] Boot into GParted Live CD, shrink your physical machine partition to 80G (in my case, 80G, 81920M) because CloneZillar cannot restore bigger image to smaller disk.
  4. Boot into CloneZilla Live CD, backup your partition to your . (https://clonezilla.org/show-live-doc-content.php?topic=clonezilla-live/doc/01_Save_disk_image) Beginner mode is enough, choose partition instead of whole disk.
  5. Create an empty virtual machine with disk size 81G (a little bit bigger thant 80G, just to be safe).
  6. Boot the virtual machine with GParted Live CD and create a partition 80G (should be exactly 80G which is 81920M).
  7. Boot the virtual machine with CloneZilla Live CD and restore the partition from the USB to new created partition in VM. Beginner mode is enough, choose partition instead of whole disk.
  8. At this point, partition data should be all restored in VM. But VM won’t boot because we need to fix the Grub bootloader. (https://www.fosslinux.com/4477/how-to-repair-the-grub-bootloader-using-a-ubuntu-live-usb-drive.htm)
  9. Use a Xubuntu Live CD to boot up the Virtual Machine, follow the steps in #8. Basically the commands are:
    sudo mount /dev/sda1 /mnt
    sudo grub-install --boot-directory=/mnt/boot /dev/sda

     

  10. [If you are using VMWare] At this point, the vm may boot but maybe there’s some graphical issue like black screen because the VM drivers are not installed. In my case, I need to install open-vm-tools-desktop. (https://linuxhint.com/install-vmware-tools-ubuntu/). Just boot into recovery mode of your vm and enable network and:
    sudo apt update
    sudo apt install open-vm-tools-desktop

     

  11. Reboot the VM and everything should work. 🙂