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:
[251461.254219] usb-storage 2-1.3:1.0: USB Mass Storage device detected [251461.254389] scsi host7: usb-storage 2-1.3:1.0 [251462.369665] scsi 7:0:0:0: Direct-Access Kingston DT 100 G2 PMAP PQ: 0 ANSI: 0 CCS [251462.370382] sd 7:0:0:0: Attached scsi generic sg6 type 0 [251462.914888] sd 7:0:0:0: [sdf] 7669824 512-byte logical blocks: (3.93 GB/3.66 GiB) [251462.915522] sd 7:0:0:0: [sdf] Write Protect is off [251462.915525] sd 7:0:0:0: [sdf] Mode Sense: 23 00 00 00
I’ve listed the partitions of my pendrive with sudo fdisk -l /dev/sdf:
Device Boot Start End Sectors Size Id Type /dev/sdg1 2048 489471 487424 238M 83 Linux /dev/sdg2 489472 499711 10240 5M 83 Linux /dev/sdg3 499712 7669823 7170112 3.4G 83 Linux
I knew for this pendrive that my booteable partition was /dev/sdg1, so that’s what I’ve used.
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:
sudo VBoxManage internalcommands createrawvmdk -filename /home/mortiz/Documents/vms/pendrive_clone.vdmk -rawdisk /dev/sdf1
Now we have the file created :
mortiz@alberta:~/Documents/vms$ ls -ltr total 15636288 -rw-r--r-- 1 root root 16011542528 Apr 18 16:03 debian.iso -rwxrwxrwx 1 mortiz mortiz 626 Apr 19 11:00 pendrive_cz.vdmk -rwxrwxrwx 1 mortiz mortiz 629 Apr 19 11:04 pendrive_live.vdmk -rwxrwxrwx 1 root root 533 Apr 19 11:07 pendrive_clone.vdmk
As you can see, our file pendrive_clone was created with «root» permissions, change it to your user using:
sudo chown <your_user>: <pendrive_filename.vdk>
Now it should look like this:
mortiz@alberta:~/Documents/vms$ ls -ltr total 15636288 -rw-r--r-- 1 root root 16011542528 Apr 18 16:03 debian.iso -rwxrwxrwx 1 mortiz mortiz 626 Apr 19 11:00 pendrive_cz.vdmk -rwxrwxrwx 1 mortiz mortiz 629 Apr 19 11:04 pendrive_live.vdmk -rwxrwxrwx 1 mortiz mortiz 533 Apr 19 11:07 pendrive_clone.vdmk
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:
# Disk DescriptorFile version=1 CID=b97fd302 parentCID=ffffffff createType="fullDevice" # Extent description RW 7669824 FLAT "/dev/sdf1" 0 # The disk Data Base #DDB ddb.virtualHWVersion = "4" ddb.adapterType="ide" ddb.geometry.cylinders="7608" ddb.geometry.heads="16" ddb.geometry.sectors="63" ddb.uuid.image="fe2ff6df-9b9d-4442-9456-71eafcc18550" ddb.uuid.parent="00000000-0000-0000-0000-000000000000" ddb.uuid.modification="00000000-0000-0000-0000-000000000000" ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000" ddb.geometry.biosCylinders="951" ddb.geometry.biosHeads="128" ddb.geometry.biosSectors="63"
Now, we should add that file as an «IDE» disk to our virtual machine, but before doing that we must change the device permissions:
mortiz@alberta:~/Documents/vms$ ls -ltr /dev/sdf1 brw-rw---- 1 root disk 8, 97 Apr 19 11:29 /dev/sdf1
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
mortiz@alberta:~/Documents/vms$ ls -ltr /dev/sdf1 brw-rw---- 1 mortiz disk 8, 97 Apr 19 11:29 /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:
mortiz@alberta:~/Documents/vms$ VBoxManage list vms "fubuntu" {b5745ee0-0bef-4f4c-ab82-0802824300e3} "xxxxxx" {e7c1ecea-f608-43cd-8656-39dae2450c10} "ubuntu-xxxxx-1" {54527538-856a-4f48-819d-5cc854697cf1}
And then this command (with the VM powered off):
VBoxManage storageattach fubuntu --storagectl "IDE" --port 0 --device 0 --type hdd --medium /home/mortiz/Documents/vms/pendrive_clone.vdmk
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.