Migrating Live System to VM
Quick n’ Dirty Steps¶
modprobe dm-mod
modprobe loop
fallocate -l 40GB -o 1024 /mnt/rex1/backup.img
losetup /dev/loop6 /mnt/rex1/backup.img
Fdisk Steps
fdisk /dev/loop6
- DOS partition table
- create new partition
- type linux
- toggle bootable flag
- write
- exit
Partprobe
partprobe
losetup -d /dev/loop6
Install kpartx
apt-get install kpartx
kpartx -v -a /mnt/rex1/backup.img
> add map loop0p1 (251:0): 0 497664 linear /dev/loop0 2048
ls /dev/mapper/
> control loop0p1
mkfs.ext4 /dev/mapper/loop0p1
mount /dev/mapper/loop0p1 /mnt/virtual
mount | grep /mnt/virtual
> /dev/mapper/loop0p1 on /mnt/virtual type ext4 (rw)
rsync -aAXv /* /mnt/virtual --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs}
kpartx -d -v /dev/loop0
Install virtualbox
apt-get -t wheezy-backports install virtualbox
apt-get install qemu-utils
qemu-img convert -c -f raw -O qcow backup.img backup.qcow2
VBoxManage convertfromraw --format VDI backup.img backup.vdi
VBoxManage convertfromraw --format VMDK backup.img backup.vmdk
Running the VM¶
- Create VM with
backup.vdi
. Virtual Box worked for me flawlessly. - Load-up Super Grub as virtual CD.
- Boot into the virtual machine.
- Install
grub2
if not installed - Generate grub again. (
/usr/sbin/update-grub
) - Fix
/etc/fstab
by executingmount
and adding the right UUID and removing uneeded mounting points. - Set the new
/dev/sda1
as bootable usingcfdisk
. - Umount the Super Grub CD.
- Re-run the VM
It should load up fine.
References¶
https://wiki.archlinux.org/index.php/Moving_an_existing_install_into_%28or_out_of%29_a_virtual_machine
http://stackoverflow.com/questions/1419489/loopback-mounting-individual-partitions-from-within-a-file-that-contains-a-parti
http://wiki.osdev.org/Loopback_Device
http://unix.stackexchange.com/questions/43903/create-file-image-container
http://codeless.fr/?p=25
https://lists.debian.org/debian-user/2011/08/msg01288.html
http://askubuntu.com/questions/197833/recovering-from-grub-rescue-crash
Other Stuff:
http://www.vmware.com/products/converter
http://www.addictivetips.com/windows-tips/convert-use-your-physical-machine-in-vmware-virtualbox-virtual-pc/