2

A Linux PC currently died due to a motherboard failure. The Harddisk, however,is still working. I transplanted the disk into another Linux machine and found that everything was readable.

Now I want to revive the old PC, but as a VM. Is this possible to do without first having to convert the disk to an image file, i.e. running with the existing disk? I do not know yet if KVM or LXC is a better choice, but would prefer LXC because the host PC is rather slow. Is this possible? My experience with VM deployment is rather limited...

BTW, both computers run Gentoo Linux.

EDITED

Thanks for now for all answers. To clarify matters, the main reason I need the harddisk to run some kind of virtual machine is that the old computer was the main coda server of a small coda cluster. I cannot (easily) get the data out of the "raw" vice partitions, so just running a container might be the easiest way. The host computer is very restricted concerning hardware capabilities, so just cloning the disk via dd will not work - not enough space (!) (don't ask why :-/ - a rather strange setup). Furthermore, the old PC used LVM also. The various partitions and LVM LVs can, however, be mounted on the new host computer quite well - the data are there, and once I even accidentally booted the new host computer with the old disk as "userland" (new kernel, old userland) - worked, so the systems are quite similar.

The charme of an LXC setup would be that it does not need as much resources. The downside is that I have no idea if the CODA servers will run nicely when in a container - so putting them into a full VM may be safer.

1
  • IIt dependends on your linux skills. I was fairly sucessful doing netcated tar.gzs over legacy physical servers to VMs, and then tinkering with grub and fstab Commented Dec 17, 2016 at 11:10

4 Answers 4

3

It is possible to boot from a physical hard drive with VirtualBox. Manual: Using a raw host hard disk from a guest.

Around this I wrote a german howto: Dualboot-Windows virtualisieren. Its focal point is to boot a physical windows, but it works with Linux as well.

The core points for you to do:

  • Install VirtualBox. Make sure to be member of group vboxusers afterwards.
  • find out device file of new hard disk (for example /dev/sdb)
  • Create a VM in VirtualBox without a virtual hard disk (I call it oldsys)
  • as root: create vmdk file pointing to new hard disk

VBoxManage internalcommands createrawvmdk -filename ~/VirtualBox\ VMs/oldsys/oldsys.vmdk -rawdisk /dev/sdb

  • change owner of oldsys.vmdk from root to yours.

  • create udev rule to allow yourself raw disk access, for example

    KERNEL=="sdb", OWNER="myusername", MODE="0600"

  • In VirtualBox, plug in oldsys.vmdk at virtual SATA controller of VM oldsys.

  • If oldsys has been an EFI booted system, change VM settings of oldsys in "system" to "activate EFI"

  • you may need to enable "IO-APIC", too.

  • reboot to enable udev rule

  • run oldsys in VirtualBox. It should boot without any problems.

2
  • By the way, along with this solution you can also setup a dual boot. Then you can run as VM or boot directly as well.
    – mviereck
    Commented Dec 17, 2016 at 13:53
  • Thanks - that was pretty much what I did (except that I ran the VM as root - it is a background server anyways. Commented Feb 17, 2017 at 8:19
2

I would suggest capturing a disk image using ddrescue and then using the image file to back the VM's storage. This way, you don't risk the original copy of your data if anything happens to go wrong with your virtualization plans.

KVM would certainly work, since it would boot the full OS. LXC may work, depending on how similar the systems are. The primary limitation with LXC is that whatever you run inside the container will share the host's kernel. KVM allows you to run a kernel within the guest. As long as you're just operating on a copy of your data, it should be safe to experiment until you find the setup that works best for your situation.

1
  • The systems are not that similar concerning the hardware. The userland is fairly similar - they are both gentoo systems getting updated rather in parallel. Commented Dec 29, 2016 at 18:15
2

It is possible, but it is advisable to create a backup of your disk - if you care about that data.

As long as the CPU of the host PC has virtualization support (on Intel, check via grep vmx /proc/cpuinfo), KVM doesn't slow down the guest much.

Assuming that your old disk is available as /dev/sde you could use a command like this (as normal user):

$ qemu-system-x86_64 -enable-kvm -drive file=/dev/sde,if=virtio,format=raw \
     -m 2048 \
     -net user,hostfwd=tcp::10022-:22 -net nic,model=virtio

This boots a VM with 2 GiB RAM. The -net options are only necessary if you are interested in a port forwarding to the guest sshd and guest net access in general.

If you decide to use an image file instead of real disk you just have to replace /dev/sde with the filename of that image file.

0

I solved this by using VBoxManage. Basically I created a new VirtualBox VM, swapped in the raw disk and went up.

Initially I had a problem with setting up networking correctly (because the host kernel was too old for my VirtualBox helper kernel modules), but after a kernel upgrade I got a bridget network connection, and from then on it was pretty smooth sailing.

You must log in to answer this question.

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