Yesterday I was asked to create a document with detailed steps to clone images of devices using “CloneZilla”. What CloneZilla does is just essentially creating/restoring a snapshot of a hard disk so you can clone as much devices as you want, maybe some of you have used “norton ghost” for such task.

Since I must start CloneZilla from a pendrive in each computer/tablet/device adding pictures of the process to the document could be acomplished by taking pictures with my cellphone in each step. I didn’t like that idea so  I’ve managed to boot the  virtual machine (virtualbox) with a physical pendrive to take screenshots of good quality and, in this process, learn about this process which is really simple.

The main documentation of this process can be found here.

The scenario

  • I have a physical booteable pendrive with CloneZilla on it (I’ve also tested with a Ubuntu Live pendrive) both worked.
    • Be carefull with this, my Clonezilla pendrive had to boot from /dev/sdf1 (partition) while my ubuntu pendrive did it from the whole device /dev/sdf (whole disk)
  • I have a virtual machine created in virtualbox called “fubuntu” with no disks attached on it.

The steps

First I connect the booteable pendrive to my computer with Debian and identifty which device it is using sudo dmesg:

I’ve listed the partitions of my pendrive with sudo fdisk -l /dev/sdf:

I knew for this pendrive that my booteable partition was /dev/sdg1, so that’s what I’ve used.

In other scenarios like preparing a Ubuntu Live pendrive like this: dd if=/home/mortiz/ubuntu-live.iso of=/dev/sdf you should use the whole disk instead the partition.

Now the next step is to create a “disk” which really is a file with properties pointing to the real device. I’m using Debian but this can be acomplished in other distros, Windows and MacOS as well. We’ll do that with this command:

Now we have the file created :

Be careful with ‘sudo’. I had to do that command with sudo because root is the owner of /dev/sdf1. The thing is, the file will be generated for root as well. I’ll point out this in next steps to change permissions when needed.

As you can see, our file pendrive_clone was created with “root” permissions, change it to your user using:

Now it should look like this:

If you want to know what’s inside the file you can add execution permissions to your user and read it, this is what mine had:

Now, we should add that file as an “IDE” disk to our virtual machine, but before doing that we must change the device permissions:

As you can see the pendrive and it’s partitions are owned by root. We must change this to avoid problems with permissions between VirtualBox and the O.S, so I did: sudo chown mortiz:disk /dev/sdf1

The change is temporary and after unplugging the pendrive this change will be lost.

Now we are ready to attach that vdmk file to the virtual machine, which in fact, will be reading and writting directly to the pendrive, you can copy the name of your VM directly from here:

And then this command (with the VM powered off):

Warning: Depending on your O.S/Distribution/VirtualBox version the name of the controller (after –storactl) could vary from “IDE” to “IDE Controller”.

When you go to the properties of the VM you’ll see a new IDE device attached to the VM.

And the result is your VM starting from a pendrive 🙂

The errors

I had to solve some problems before the result, here’s a list of them with their solutions.

Errors attaching the disk to the VM

VBoxManage: error: Could not find a registered machine with UUID {xxxxx}
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: “FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())” at line 325 of file VBoxManageStorageController.cpp

mortiz@alberta:~$ sudo VBoxManage storageattach fubuntu –storagectl “IDE” –port 0 –device 0 –type hdd –medium /home/mortiz/Documents/vms/pendrive_clone.vdmk
VBoxManage: error: Could not find a registered machine named ‘fubuntu’
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: “FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())” at line 325 of file VBoxManageStorageController.cpp

Maybe you are using “sudo”, of course root won’t have VM’s in his list. Instead using sudo the attach command should run with your user.

mortiz@alberta:~$ VBoxManage storageattach fubuntu –storagectl “IDE” –port 0 –device 0 –type hdd –medium /home/mortiz/Documents/vms/pendrive_clone.vdmk
VBoxManage: error: Permission problem accessing the file for the medium ‘/home/mortiz/Documents/vms/pendrive_clone.vdmk’ (VERR_ACCESS_DENIED)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
VBoxManage: error: Context: “OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())” at line 179 of file VBoxManageDisk.cpp
VBoxManage: error: Invalid UUID or filename “/home/mortiz/Documents/vms/pendrive_clone.vdmk”

Remember changing the permissions on the device /dev/sdX or the partition /dev/sdXx to your user as I mentioned above.

mortiz@alberta:~$ VBoxManage storageattach b5745ee0-0bef-4f4c-ab82-0802824300e3 –storagectl “IDE” –port 0 –device 0 –type hdd –medium /home/mortiz/Documents/vms/pendrive_clone.vdmk
VBoxManage: error: Controller ‘IDE’ does not support hotplugging
VBoxManage: error: Details: code VBOX_E_INVALID_VM_STATE (0x80bb0002), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: “AttachDevice(Bstr(pszCtl).raw(), port, device, DeviceType_HardDisk, pMedium2Mount)” at line 766 of file VBoxManageStorageController.cpp

Keep the VM powered off while attaching the disk.

mortiz@alberta:~$ VBoxManage storageattach fubuntu –storagectl “IDE” –port 0 –device 0 –type hdd –medium /home/mortiz/Documents/isos/pendrive_cz.vdmk
VBoxManage: error: Permission problem accessing the file for the medium ‘/home/mortiz/Documents/isos/pendrive_clone.vdmk’ (VERR_ACCESS_DENIED)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
VBoxManage: error: Context: “OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())” at line 179 of file VBoxManageDisk.cpp

Verify you’ve changed the permissions on the device /dev/sdX or the partition /dev/sdXx to your user as I mentioned above and that the permissions on the vdmk file are good for your user, not root.

INT18: BOOT FAILURE

You should verify that the pendrive boot is working. If you have a partitioned pendrive try selecting the specific partition to boot from, otherwise use the whole device.