User:Tsu2/Guest write to device
Guest Write to Device
From time to time, you may need to write directly to a hardware device.
A common scenario is creating bootable removable media.
Although the steps described describe VMware methods, the steps are virtualization-agnostic and similar steps should be followed to do the same in Virtualbox, KVM, Xen or any other type of virtualization.
These steps assume that the target removable media is already partitioned (single partition) and is formatted FAT32, all which is fairly standard. If not, then you will have to perform actions to prepare your removable media for writing.
Two main steps
1. Configure hardware pass through to the Guest
2. Configure Guest to access, and write to the new device
Configuring Hardware Pass Through to the Removable Storage Media
It is important to know that the following grants the designated Guest monopolistic access to the removable media (eg USB thumb drive, SDcard, etc), so all other Guests and the HostOS will not be able to access when the Guest has access.
1. Open Guest "Virtual Machine Settings"
2. Add a new hard drive, using IDE (not SCSI) settings
3. Select the option to "Use a physical disk"
4. Select the PhysicalDrive.
More than likely the removable drive will be the last item listed.
5. Provide a backing file name.
I do not recommend using the default name because it's likely based on the primary virtual disk file name, so can cause later confusion whether the file can be removed safely when no longer required or is a snapshot file or other still important file. The name you choose can be anything, so long as the file name doesn't already exist in that location.
6. Click the "Finish" button to save your settings and enable your new disk for your Guest.
Configure the Guest
Boot the Guest
Verify you have a new hard drive, if you only have one configured virtual disk file (/dev/sda), verify you now have a new second disk (/dev/sdb). If you see this, then you have successfully passed the device through to your Guest which can now write to the only partition in the device (sdb1)
Write to disk
If your image is in .xz compressed format, then you can write your image using the following
xzcat [image].raw.xz | dd bs=4M of=/dev/sdb1 iflag=fullblock oflag=direct; sync
xzcat [image].raw.xz > /dev/sdb1
If you have a raw file (no compression, a backing file which contains an entire file system), you can simply use "dd" as described in the second half of the above example or use "cat" instead of "xzcat" in the example immediately above which reads and re-directs imput to the device.