Create a custom distro: Create your first image (USB)


I’ve just received two messages with the same question related to my previous article Create your first ISO image: “Is there a way to create an USB stick with it ?“. Short answer is: “Yes, there’s  script to do it” but if you’re still reading you may want more information. Here’s what you might do if you want to create a bootable USB stick from your virtual slax build machine.

I’m still referring to my previous article: “Create a custom distro: Create your first ISO image“, path and directories are still the same

Take a look at the source !

The creation of a bootable USB stick is not a mess, it’s quite simple, if you take a closer look to “” script located into the /boot directory you might understand what you can do with it but if you’re lazy or you want to have more automation you may use the script listed below, I’ve created it for personal purposes but it’s basically a wrapper of 

Let’s keep the same virtual machine, same paths and locations, just place a script in the same dir where you’ve placed the script for creating the ISO image for CDs (/root/target/).

# This script builds an ISO file from the image created

echo "Mounting and formatting the USB Stick"
mkdir -p $MOUNTPOINT
umount $TARGET 2>/dev/null
mkfs.ext2 $TARGET -m 0
# Device not found or not mounted
if [[ $? -ne 0 [[; then
echo -e "Generating `du -kLs image` size"
echo "Copying contents into the USB Stick..."
echo -e "Target disk size"
umount $TARGET
echo -e  "Installation Completed"

This script is very simple but just to be clear here’s what it does:

  1. Create the mount point for your usb stick
  2. Format the usb stick (ext2 is sufficient but you may use something else)
  3. Mount your usb drive
  4. Copy the contents with your new image in it
  5. Add lilo to make it bootable

In my virtual environment /dev/sda is my primary virtual hard disk, take a look at previous article for path usage, /dev/sdb is what VMWare uses when I connect an USB stick to the virtual machine. Before running this script make some checks in your current system, as you can see it’s a batch script to format and wipe sdb internal contents, so you’ve been warned !

If you’re inside my virtual environment you don’t need to worry about it script is smart enough to understand where it resides and it applies lilo in the MBR of the mounted drive.

There’s a lot of space for improvements so if you modify it or automate the script a little bit more just drop me few notes or send me your version and I’ll modify and republish it for the community

As usual feel free to contribute with your comments


Previous step:

Create a custom distro: Create your first ISO image (CD)

Next step:

Create a bare bone machine with minimal footprint and requirements