Creating a Debian Linux Installation USB Memory Stick


Monday night, I learned how to use a USB memory stick as bootable install media for Debian Linux. It's a little complicated, mostly because piecing together bootable media is just that way. Once complete, it works great. I can still use the stick for usual file transport purposes, but now if I boot off it then it will offer a Debian Linux installation.

The Preparing Files for USB Memory Stick Booting chapter of the Debian Installation Guide outlines the process.

It describes two ways to do it: an "easy" way and a "flexible" way. The "easy" way makes sense for a one-time deal (and you are willing to reformat the stick afterwards), or if you are willing to dedicate a stick to the installation. I didn't. I've got a 4GB stick that I wanted to make bootable and hold the Debian installation files, but continue to use it for other purposes. That's what the "flexible" method allows.

This note describes the procedure I used.

Get Syslinux

There are a couple things you'll need before you can begin. First, you'll need the syslinux boot loader to make the memory stick a bootable volume. The package is available on many Linux distributions. On my Ubuntu Linux workstation, I added it by saying:

# aptitude install syslinux

Determine the Device

You'll need to determine the device path to your USB memory stick. Linux labels SCSI, SATA, and USB storage devices sequentially: sda, sdb, sdc, and so on. (IDE storage devices are different. They are named starting with hda.)

My workstation has three SATA hard drives. (It also has an IDE DVD burner, but as I noted above, IDE devices doesn't count.) When I inserted the USB memory stick it became the fourth storage device, thus it was assigned device name sdd.

It is absolutely critical that you determine the device path correctly. Otherwise, you could do something bad, like reinitialize a hard disk drive.

One way you can be sure is to insert the memory stick and watch the /var/log/messages log file.

On my system I see this:

Oct 28 09:38:31 chinacat kernel: [196403.470594] usb 2-7: USB disconnect, address 19
Oct 28 09:38:37 chinacat kernel: [196409.729051] usb 2-7: new high speed USB device using ehci_hcd and address 20
Oct 28 09:38:37 chinacat kernel: [196409.878206] usb 2-7: configuration #1 chosen from 1 choice
Oct 28 09:38:37 chinacat kernel: [196409.879142] scsi23 : SCSI emulation for USB Mass Storage devices
Oct 28 09:38:42 chinacat kernel: [196414.883194] scsi 23:0:0:0: Direct-Access  Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 0 CCS
Oct 28 09:38:44 chinacat kernel: [196416.292001] sd 23:0:0:0: [sdd] 7966720 512-byte hardware sectors (4079 MB)
Oct 28 09:38:44 chinacat kernel: [196416.292996] sd 23:0:0:0: [sdd] Write Protect is off
Oct 28 09:38:44 chinacat kernel: [196416.304253] sd 23:0:0:0: [sdd] 7966720 512-byte hardware sectors (4079 MB)
Oct 28 09:38:44 chinacat kernel: [196416.306003] sd 23:0:0:0: [sdd] Write Protect is off
Oct 28 09:38:44 chinacat kernel: [196416.306025]  sdd: sdd1
Oct 28 09:38:44 chinacat kernel: [196416.307091] sd 23:0:0:0: [sdd] Attached SCSI removable disk
Oct 28 09:38:44 chinacat kernel: [196416.307255] sd 23:0:0:0: Attached scsi generic sg4 type 0

Note the mentions of sdd. That confirms that the USB memory stick was assigned device path /dev/sdd.

In this note, I'm going to use /dev/sdx as the memory stick device path.
You'll need to determine the correct device path to your memory stick, and substitute that for sdx.

One more thing: sometimes in this note I refer to /dev/sdx1, with a "1" on the end. That's not a mistake./dev/sdx is the name of the entire device. /dev/sdx1 (with the "1" on the end) refers to the first partition on that device. So take care and be sure to add the "1" where I show it.

Get the Files

We're getting very close. Just one last bit of preparation. You will need to retrieve three files for the install. The first two files are the Linux kernel and root filesystem image that run the install process. The final file is an installation image.

I grabbed the vmlinuz and initrd.gz installer files from this directory:

I downloaded the current netinst installation image (currently called debian-40r5-i386-netinst.iso) from this directory:

The netinst image contains only the most essential packages, and downloads everything else from the net. If you'd prefer to use local copies of packages for the install (i.e. you won't have network access), you could use a CD image instead, such as the debian-40r5-i386-CD-1.iso image.

When complete, I had the following three files in the current directory:

$ ls -l
total 192500
-rw-r--r-- 1 chip chip 169457664 2008-10-27 23:56 debian-40r5-i386-netinst.iso
-rw-r--r-- 1 chip chip    4229504 2008-10-27 23:43 initrd.gz
-rw-r--r-- 1 chip chip    1219068 2008-10-27 22:02 vmlinuz

Format the Memory Stick

Skip this step if your USB memory stick is already partitioned and formatted the way you want. Typically, memory sticks come already partitioned and formatted and you won't need to do this.

Here is the procedure I used to format the device:

# fdisk /dev/sdx

Command (m for help): o (create empty partition table)
Building a new DOS disklabel with disk identifier 0xcaf9c2fb.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n (create a single partition to the full size of the stick)
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-495, default 1): (strike enter)
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-495, default 495): (strike enter)
Using default value 495

Command (m for help): t (set partition type to code "c")
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): a (make the partition bootable)
Partition number (1-4): 1

Command (m for help): w (write out the modified partition table and exit)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

# mkdosfs /dev/sdx1 (build Windows filesystem on newly created partition)
mkdosfs 2.11 (12 Mar 2005)
0+1 records in
0+1 records out

Install Master Boot Record

If you did the above and repartitioned the memory stick then you'll next need to install a Master Boot Record (MBR). That's a small bit of code that fits into the first (512 byte) sector of the device.

If you are using a preformatted stick you probably can skip this step. If you get to the end and find that your system doesn't think the memory stick is bootable, then come back and do this step.

The Ubuntu version of syslinux provides a file mbr.bin that you can use as your MBR. Here is how I installed it to the device.

# dd if=/usr/lib/syslinux/mbr.bin of=/dev/sdx
404 bytes (404 B) copied, 0.0275888 s, 14.6 kB/s

Alternately, your Linux distribution may have a package called mbr that you can use with a command like:

# install-mbr /dev/sdx

Add the Debian Installer

In this step you'll create a syslinux directory on the memory stick, copy all of the installation files there, and install the syslinux boot loader to the stick.

# mkdir -p /tmp/usbstick
# mount /dev/sdx1 /tmp/usbstick
# mkdir -p /tmp/usbstick/syslinux
# cp vmlinuz initrd.gz debian-40r5-i386-netinst.iso /tmp/usbstick/syslinux
# cat >/tmp/usbstick/syslinux/syslinux.cfg
default vmlinuz
append initrd=initrd.gz ramdisk_size=12000 root=/dev/ram rw
(type CTRL-D)

# umount /tmp/usbstick
# syslinux -d /syslinux /dev/sdx1

Boot and Install

That's it. Insert the memory stick into a machine, boot off it, and the Debian installation process should begin.


Comments have been closed for this entry.



Thanks, This was the most

This was the most concise and clear explanation of how to do this I was able to find. It's refreshing to see a how-to that clearly explains every step.

Thanks again,