3

I created a backup from /dev/sda1 and /dev/sda4 partitions using dd. but i did not create a backup from /dev/sda2 and /dev/sda3. How can I convert these 2 backup files from /dev/sda1 and /dev/sda4 namely sda1.img and sda4.img to virtualbox disk and boot the system?

Rembo
  • 162
  • If you still have the source disk it may be easier to just create an VDI image from the partitions as described here. – Robert Feb 09 '20 at 12:09
  • @Robert No I only have these 2 files – Rembo Feb 09 '20 at 12:26
  • @MichaelHarvey I am missing /dev/sda2 and /dev/sda3 – Rembo Feb 09 '20 at 12:32
  • @MichaelHarvey I dont have access to original disk to make a dd images of them. I have only /dev/sda1 which contain grub boot loader and /dev/sda4 which has home folder. sda2 and sda3 had just some files in them and 200GB of free space so i didn't use dd on them. – Rembo Feb 09 '20 at 13:03
  • @MichaelHarvey create a virtualbox image that can boot the system without having sda2 and sda3 – Rembo Feb 09 '20 at 13:09
  • 1
    Have you successfully managed to mount the files to a directory on your system? (sudo mount -oloop <FN> <mountpoint>) if you can do this, you can set the mountpoint up as a virtualbox disc location – moo Feb 09 '20 at 13:21
  • I dont need sda2 and sda3. that is why i didn't create a dd image from them. – Rembo Feb 09 '20 at 13:22
  • @Mark Yes I can mount it and see the files. but I want to boot the OS. – Rembo Feb 10 '20 at 13:01
  • @Rembo you need to have a look at the VBoxManage CLI command to create the disk. Something like: VBoxManage internalcommands createrawvmdk -filename "</path/to/file>.vmdk" -rawdisk <diskimg.img> https://mobile.serverwatch.com/server-tutorials/using-a-physical-hard-drive-with-a-virtualbox-vm.html – moo Feb 10 '20 at 14:27

1 Answers1

1

1. Test the disc image mounts sucessfully

mount -t loop <disc image.img> <mountpoint>
cd <mountpoint>
ls # should show disc image contents as expected

2. Create a VMDK image referencing your disc image

VBoxManage internalcommands  createrawvmdk -filename <vmdk filename>.vmdk -rawdisk <disc image.img>

3. Create a VirtualBox machine

Select the VMDK file, created in the previous step, as your disc image.

Alternatives

Other virtualisation technologies are available. For example, you could also use qemu for this task: https://unix.stackexchange.com/questions/276480/booting-a-raw-disk-image-in-qemu

moo
  • 331
  • It is converting but the system is not booting. I got this message: no bootable medium found. system halted! – Rembo Feb 15 '20 at 09:36
  • Depending on how your disc was set up originally (GPT or MBR), it is likely you are missing the boot data from /dev/sda. Make sure you keep backups of the partition before attempting repair http://www.aboutlinux.info/2005/11/how-to-repair-corrupt-mbr-and-boot.html?m=1 – moo Feb 15 '20 at 11:50
  • The issue here is that dd image conversion takes a partition image, not a disk image, and creates a disk with the content of a partition, so /dev/sda1 from source ends up on /dev/sda on the target. I wonder how could this be made to restore /dev/sda1 to /dev/sda1 VDI partition. – mike Nov 16 '20 at 20:45