User Tools

Site Tools


software:multibootusb

Multiboot USB Thumb Drive

I like YUMI as it allows me to build a multiboot USB drive easily. The problem with it is that the main UI runs best under Windows, and I do not have any Windows machines in my office.

However, at our NOC, we have several Windows virtuals, some of which we use internally, so we can use one of those. How to attach a USB Thumbdrive on my workstation to the remote virtual was an interesting problem. I finally came up with one solution: Create a virtual disk image, mount it as a USB Drive on the Windows virtual, do all the work, then use DD to copy the disk image to the the thumbdrive plugged into my physical machine.

Plan your image

  1. Plug in the USB Thumbdrive and get the size of it, in bytes. fdisk will work just fine
    fdisk -l /dev/usbdrive

    On my “32 Gig” drive, this returned 32015679488

  2. Calculate the size of the disk image to work with. This must be smaller or the exact size of the USB drive. For maximum disk space, create block device based on blocks (files) or extents (lvm2).
  3. Decide what the backing device will be. In my case, I'll use lvm2, but you can use a file backed device.
    1. An LVM extent (block) is 4M, or 4194304, so, we need to know the maximum number of extents we can allocate. Just divide the size of the device (in bytes) by the size of the extent (in bytes).
      1. 32015679488 / 4194304 = 7633.1328, round down to 7633
    2. A file will be built in increments of the block size, so find out the block size, the use the systems tools to create a file of the correct size.

On the hypervisor

I'll use saffron as the name of the virtual, and usbthumbdrive as the name of the block device to create. Adjust to your system.

Create block device

lvcreate -l 7633 /dev/vg-md0/usbthumbdrive

In my case, I want to compress the image before copying it to my office over the internet. To facilitate that, I'll fill all the space on the drive with 0's so when I run bzip2 later, the free space will be very compressible. Instead of just sitting and wondering when it will be done, I'll use the pv command to monitor (you can use status=progress on current versions of dd instead) pv will slow the copy a bit, but that is not significant to me in this case.

dd if=/dev/zero | pv -petrs 29G | of=/dev/vg-md0/usbthumbdrive

Mount logical volume on running virtual

Determine an available block name on the virtual by entering the command:

virsh domblklist saffron

On mine, hdb was available. Mount the drive, using the USB bus, to the running virtual.

virsh attach-disk saffron --targetbus usb --source /dev/vg-md0/usbthumbdrive --target hdb --live

On your virtual

Connect to your Windows virtual and format the drive for use

 Control Panel | Administrative Tools | Computer Management | Storage | Disk Management
 Find and format the drive. I use FAT32 normally because YUMI will reformat anyway

Start YUMI and point it to new drive. Do your installs eject thumbdrive

Back on hypervisor

Detach the block device from the virtual.

virsh detach-disk saffron hdb

As previously stated, I want to transfer this, so I'll use pbzip2 to compress it before doing anything. Again, I like to see what is going on, so I'll use pv to monitor the progress

dd if=/dev/vg-md0/usbthumbdrive | pv -petrs 29G | pbzip2 -c > usbthumbdrive.29G.bz2

By blanking the drive before use, and then bzipping it, I turn a 29G empty install into a 2G file. If you have some good installers with compressed images already (Debian, BSD), this is not worth the effort, however.

software/multibootusb.txt · Last modified: 2023/02/26 17:07 by rodolico