1

I have an existing linux system that I'd like to use to create a virtual machine.

I have installed VirtualBox.

I was able to use https://unix.stackexchange.com/questions/16299/using-a-lvm-partition-as-a-virtualbox-drive to create a VMDK from a logical volume.

I am not sure what procedures I should take next to fill that logical volume and make its VMDK a usable system image copied from the existing system.

It would be relatively simple to do mkfs.ext3 /dev/vg1/vm_puppy, mount it, and copy all the files via the network, but I do not know if that would make it a usable virtual machine image.

What are the proper steps to fill that VMDK with a bootable system assuming I already know how to do the file copying step?

2 Answers 2

0

You can use in your virtual machine two hard drives, one is physical one that you want to image and another one is an virtual image of that physical one. To access physical drive make a kinda "pointer" in vmdk as

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
  -rawdisk /dev/vg1/vm_puppy

then in VirtualBox create two additional virtual drives, one for image of physical drive and one for some simple lightweight operation system.

When you finished setup that "simple lightweight operation system" and inside of it, just use dd command to make a full image of physical HDD.

When you finished with imaging and want to use cloned system ( that was from physical harddrive), create a new virtual machine and feed it with cloned virtual image as virtual harddrive.

P.S. If you have a pretty huge hard drive(original system you want to clone) and won't sacrifice space on cloned image, you can do it other way, create a full archive of original with tar command and expand it in virtual machine. This way you can reduce space used by virtual drive. You can move tar's archive to virtual machine over shared VirtualBox folder. the only thing that you would need to do additionally is install grub on virtual drive where you untar archive

(I hope I understand right what you want )

1
  • I suspect using dd to clone the original is not a good idea, since the source system has individual LVM partitions for root, /boot, /usr, /var, and /opt. I'd rather build the VM image in one partition (or maybe two if I need a /boot). Other users might still be able to use your ideas.
    – Mutant Bob
    Commented Jan 1, 2017 at 6:14
0

The solution I eventually used revolved around creating two virtual disks (borrowing and idea from Alex) to attach to the Settings > Storage > SATA Controller.

I used the VirtualBox GUI to create a 128M VMDK to contain the MBR and a /dev/sda1 to be the /boot .

The other VMDK I created earlier from an LVM logical volume became the virtual /dev/sdb (without partitions).

I loaded a gentoo install ISO into the VM's virtual CDROM (Settings > Storage > IDE Controller) and booted from that. Once the gentoo install environment was up and running I was able to partition /dev/sda and create the /dev/sda1 /boot filesystem and copy the kernel and other files from the source host. I did not partition /dev/sdb because it already contained the root filesystem I had constructed before.

I mounted /dev/sdb and the /boot according to Preparing the Disks and rigged some of the virtual filesystems according to Mounting the necessary filesystems. With the filesystems prepared I could chroot and begin to reconfigure the VM to account for the differences between the source machine's disks and the VM's disks.

I had to update /etc/lilo.conf inside the VM to use boot=/dev/sda and root=/dev/sdb.

Likewise /etc/fstab needed alteration since the source host used a lot of individual partitions (a style that has gone out of favor in the intervening decade) and the VM only had /dev/sdb for root and /dev/sda1 for /boot .

I also had to recompile the kernel with support for the ahci sata module, and the e1000 ethernet. The source machine is very old.

One shortcoming of this process is that I had to partition the virtual sda inside a running VM. I do not know if there is a process that would allow me to partition the VMDK and fill its partitions with filesystems and data without booting up the VM that uses it.

I am not sure what problems would have arisen if I had attempted to recompile the guest kernel using the host OS and a chroot instead of recompiling inside of a VM (which would have required the use of the gentoo install ISO anyway).

I could not use a Debian live ISO because at some point in the boot process the screen turned into colored stripes of characters. I assume there's some incompatibility with the virtual video card and it was easier to just get gentoo than shovel through all the related discussions about that bug to test all the suggested solutions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .