0

I'm looking for a way to clone sector by sector of my physical disk to my VDI virtual disk. As I was reading, some do not recommend the use of dd for this.

If I can not use dd to copy sector by sector and restore the image inside virtualbox, what else is there to do this?

Keep in mind: The image must include the information of each sector (even if it is not assigned) as I want to do information retrieval and forensic tests within VirtualBox.

Operating system: Ubuntu

  • You should detail some more, like your operating system (Linux?) and why dd isn't recommended. If it's because this is the disk you are booting from, then you could do it in two steps, the first in a Live USB making a backup, then reboot to copy to the VDI disk. – harrymc Dec 12 '18 at 18:54
  • @harrymc Honestly I do not know, it has not been clear to me. And since I had asked some other things, they did not explain the reason. Is it because you copy sector by sector? Added the operating system that I use. – MarianoM Dec 12 '18 at 19:18
  • @harrymc Here's the discussion if you want to take a look: forums.virtualbox.org/… – MarianoM Dec 12 '18 at 19:20
0

First off, you can't do this with the system running, or at least, you can't do this safely and expect to get a proper, coherent disk image from doing it with the system running. That's probably the big argument against the dd approach, though it's hard to say without reference to the specific recommendations against it.

Given this, there are a couple of approaches you can take here, but they all require two things:

  • The ability to boot to an alternative OS running from a separate storage device (not just a different partition, but a different disk). For most of the below methods, I would suggest using System Rescue CD for this.
  • Somewhere where you can store the whole disk image. If you're using a Live USB drive, it could be used for this storage if it's big enough, but you'll probably need a big disk to pull this off.

Once you have that, you've got a couple of options:

Partimage

Partimage is disk backup software for Linux that can efficiently store disk images. It does this by only copying sectors that are in-use, and compressing the resultant image file. It's included on most system recovery Live CD's, and even has support for saving and restoring images across the network. The downside is that it has to support the filesystems you have on the disk you're backing up, and it notably does not include support for ext4 or BTRFS. Provided that that's not a limitation, this is what I would suggest using. I'll not go into specifics here of how to use it as there are numerous good tutorials out there.

ddrescue

Using dd for this type of thing isn't as much of an issue if you're doing it from a live system, but it still ahs limitations in that it's a pain to restart a partial copy, it fails if there are any failed reads or writes, and it doesn't give nice progress info. That's where GNU ddrescue comes in. It can do some things similar to dd, but it provides a bunch of features that are extremely useful for copying or cloning disks. The process of using it is essentially the same as for dd, but the command line syntax is different. They have good documentation, so I won't waste space here explaining how to use it, except to comment that you almost always want to use a log file so it can resume partial transfers. Like Partimage, ddrescue is included on most system recovery Live CD's.

qemu-img

qemu-img is a special tool included with the QEMU virtualization software that is used to convert between disk image formats supported by QEMU. QEMU helpfully supports both raw disk images and VDI images, so you can use qemu-img to produce a VDI image from a regular physical disk, which means you can just skip the process of restoring the image inside VirtualBox. The exact command you want looks something like:

qemu-img -O vdi /dev/sda /path/to/image.vdi

Where /dev/sda is whatever disk you're copying from, and /path/to/image.vdi is the intended file name for the disk image. This approach has two downsides though, namely that it can't be resumed if interrupted part way through, and that qemu-img isn't included in most Live CD's (let alone most system recovery focused ones).


If you intend to run the VM on a different system than the one that you're copying the disk from and can establish a network connection between the two systems, you have a lot more flexibility, and can completely remove the need for temporary storage. In this case, you should set up the VM other than copying the disk in, and boot both it and the source system into a Live CD environment. You can then use either NBD or iSCSI between the two systems to directly copy the disk over the network using either dd or ddrescue.

  • Thank you! I did not know all the tools that you have contributed. As for the use of qemu-img, it seems an interesting option. VDI is a native format of VirtualBox, could it present some differences in the format when creating the VDI virtual disk in this way compared to creating it in VirtualBox? Have you tried how this works? Copy sector by sector or only sectors in use? – MarianoM Dec 12 '18 at 21:34
  • As far as I know, qemu-img copys sector by sector unless both the source format and the target format are sparse (which is not the case here). There will be some differences in the structure of the metadata between the two files, but VirtualBox should have no issues with this (it may actually update the file automatically to use the newer metadata format it prefers). – Austin Hemmelgarn Dec 13 '18 at 19:44
0

You are trying to do Physical-to-Virtual, where dd is a possible tool but not the best.

As it isn't recommended to copy the running system from within itself. The process below comes from the article Physical To Virtual (P2V) using VirtualBox and requires:

Here is the procedure. The author describes how to copy one partition, so you will need to modify this slightly to virtualize the whole disk. This is required for including the boot code.

  1. Boot the system with Clonezilla
  2. At the menu, select “Clonezilla Live”
  3. Choose your language when prompted
  4. Select your desired keymap as needed
  5. At the menu, select “Start_Clonezilla”
  6. Specify “device-image” 7 Select “local_dev” to save the image to a local device (NOTE: if you need to save it somewhere else, make the proper selection)
  7. When asked to connect USB devices, do so and then press “Enter”
  8. Choose the desired drive or partition to save the image
  9. A directory structure will be shown for the selected drive or partition. Select the appropriate folder in which to place the backup image
  10. A listing of disk space usage for the selected location will be displayed. Press “Enter”
  11. Choose “Expert” for the backup mode
  12. Select savedisk (when backing up a whole disk), or savepart (when backing up a single partition) - for my example, I am using savepart so some prompts may be a little different
  13. A prompt for the name of the backup is required. Remove the existing information and give it a simple name like “LinuxBack”. The name given is the folder name in which the backup files are placed. Remember the name so you know the location of the backup files
  14. A listing of existing drives and/or partitions will be listed. Highlight the one to backup, press “spacebar” and then “enter”
  15. At the next menu, select -q1 for a dd backup
  16. The next menu shows various parameter options to select. By default, the -c and -j2 are checked. The defaults are fine unless you require others
  17. When prompted for the compression type, select -z0
  18. At the next menu when prompted about splitting the file, make sure the size is larger than the drive or partition being backed up
  19. Select the option to “Skip checking/repairing source file system”, unless you believe it is necessary
  20. At the next menu select to skip checking the saved image file
  21. For the action to perform when the backup is completed, select what you prefer
  22. At this point, the options are set and the command-line should be listed which is being executed to perform the backup. Press “enter”
  23. You are prompted if you want to continue and perform the backup, so press “y” and then “enter”
  24. The backup should begin
  25. Exit Clonezilla when the backup is completed and copy the directory specified in option 14 to the system with VirtualBox, if the virtual system will be run on another system, and be sure to include the directory itself (in my example it would be called LinuxBack)

Once the backup folder and files are moved to the system with VirtualBox installed, perform the following command:

VboxManage convertfromraw --format VDI source.img target.vdi

I have not performed the above procedure myself, and some steps might have changed in some small detail since the above was published, but the general steps should still be the same.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.