2

On my computer, I had multiple partitions and operating systems.

/dev/sda1 -> recovery
/dev/sda2 -> linux
/dev/sda3 -> swap
/dev/sda4 -> windows

I made an image backup of the linux partition:

pv < /dev/sda2 > linux-backup.img

Then, I formatted everything from the laptop.

How can I use this image in a new VirtualBox machine?

I am only interested in the linux partition and want to use it inside a virtual machine for some time. I tried converting the image:

VBoxManage convertfromraw --format VDI linux-backup.img linux.vdi

... but this gives me a whole disk containing the data (/dev/sda inside the VM), not a partition (I guess I would need the data inside a /dev/sda1). And the other problem is, that this is not bootable.

Does anyone have an idea?

UPDATE: updated the question to point out, that I will not use the partition simultaneously from the computer and from the VM! I just want to use it for some time in the VM.

2 Answers 2

0

The command VBoxManage convertfromraw is meant for disk images, not partitions images.

You need to create a new disk containing a partition from your image.

Disclaimer

The following instructions are adapted from my another answer and I haven’t tested them for an image yet.

Instructions

  1. Create a new VM with a new virtual hard drive with a sufficient capacity. Boot a live distro.

  2. Format the blank hard drive, create (at least) a single partition with equal or higher size than your image.

  3. Restore your image to the newly created partition, e.g.

    dd if=/media/shared/partition.img of=/dev/sdb1
    
  4. Optionally extend the restored filesystem to match the current partition size, e.g.

    resize2fs /dev/sdb1
    
  5. Restore GRUB using the chroot method.

  6. Edit configuration files if necessary (especially /etc/fstab, /etc/network/interfaces).

  7. Shut down the VM, detach the live distro media and boot your server clone.

References

1
  • That's basically what worked for me, I used different tools - pv instead of dd, grub-repair instead of chroot, but basically the same idea. Apr 14, 2018 at 11:45
0

I don't know how to do it using your .img file, but your goal is readily do-able using Clonezilla. Just take a Clonezilla backup of the partition, then boot your virtual machine using Clonezilla and restore the backup into it.

I actually just did this yesterday to test an 18.04 upgrade in a vm before doing it on the real machine.

You must log in to answer this question.

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