Create a persistent Debian Live USB Flash Drive

For a hobby project I have recently build a new computer system. This system is setup only for mining altcoins using three ATI Radeon 7950 graphics cards. I decided to make use of an unused USB Flash Drive for two reasons. Because it is cheap and less power hungry then a conventional hard drive.

Make & model: Kingston DataTraveler Ultimate 3.0 Gen2 32GB Flash Drive

Fast — data transfer rates for USB 3.0 to 100MB/s read and
70MB/s write; USB 2.0 = 30MB/s read and 30MB/s write

Being my favourite Linux distro for hosting 24×7 services I chose to go with the latest release of Debian Live. I picked the standard (text based) flavor, because a desktop is such a waste running a headless system. The standard image does not boot with full persistence, has no auto boot, uses DHCP and cannot shutdown or reboot without user interaction (prompt for USB reject). To allow all this, I modified some parameters and described the steps below.

1. Prerequisites

All steps below I have executed on a system running Debian Wheezy.

Download the standard Debian Live iso-hybrid image debian-live-7.2-amd64-standard.iso.

Install the following packages:

apt-get install p7zip-full gparted mbr dosfstools syslinux

2. Partition the drive

Partition the USB flash drive (in my case /dev/sdd, figure out yours with dmesg)

parted /dev/sdd GNU Parted 2.3 Using /dev/sdd Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mkpart primary fat32 1 1024M (parted) mkpart primary ext4 1024M 12G (parted) set 1 boot on (parted) p Model: Kingston DT Ultimate G2 (scsi) Disk /dev/sdd: 32.0GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 1024MB 1023MB primary boot, lba 2 1024MB 12.0GB 11.0GB primary (parted) quit

3. Create the filesystems

/sbin/mkdosfs -n live /dev/sdd1 mkdosfs 3.0.13 (30 Jun 2012)

/sbin/mkfs.ext4 -L persistence /dev/sdd2

4. Mount both filesystems

mkdir /mnt/live

mount /dev/sdd1 /mnt/live

mkdir /mnt/persistence

mount /dev/sdd2 /mnt/persistence

5. Extract the contents of the ISO to the live partition

cd /mnt/live

7z x ~/download/debian-live-7.2-amd64-standard.iso

6. Modify the boot parameters

Edit the Live-CD menu option:

vi isolinux/live.cfg

Add ‘persistence’ and ‘noeject’ on line 6:

label live-amd64 menu label ^Live (amd64) menu default linux /live/vmlinuz initrd /live/initrd.img append boot=live persistence noeject config quiet splash

If you want to use a static ip (like me), line 6 should be like:

append boot=live persistence noeject config quiet splash ip=eth0:192.168.1.7:255.255.255.0:192.168.1.1:217.149.196.6

Have a look at the live-boot manual page for more options.

Edit the boot menu file:

vi isolinux/isolinux.cfg

Change the timeout value from 0 to 10, so it will autoboot:

include menu.cfg default vesamenu.c32 prompt 0 timeout 10

7. Make the USB Flash drive bootable

/sbin/install-mbr /dev/sdd

syslinux -i /dev/sdd1

8. Modify the bootloader config

mv isolinux syslinux

mv syslinux/isolinux.cfg syslinux/syslinux.cfg

mv syslinux/isolinux.bin syslinux/syslinux.bin

9. Setup persistence on the second partition

cd /media/persistence

echo / union > persistence.conf

10. Unmount the partitions

umount /mnt/live

umount /mnt/persistence

Now you’re ready to rock the USB Flash Drive.

You should be able to ssh into the system using the following credentials:
username: user
password: live

Enjoy!