Iso-Hybrid Debian Live on USB with persistence: 2017 version

0. Note up front

This is an updated version (October 2017) of the following page: and draws heavily on that text. Thank you for making that page!

1. Introduction

You may find it convenient to boot your system from a USB key or disk and enjoy your favorite programs instantly. However, Debian's Live iso-hybrid images do not provide persistence by default. Not having this persistence means that any changes made during the session (like the installation of new software) is lost when the session finishes. Adding persistence is therefore a good thing, as the system will then remember all changes made. The older method of simply dd-ing the iso image onto the USB stick wreaks havoc on the stick with respect to the partitions as a result of the change to UEFI style boot that was made not so long ago. When using the older direct dd method, the resulting partitions are just plain wrong after writing, although the stick seems to be able to boot.

In this tutorial we shall explain how to add persistence to your iso-hybrid installation on a USB device. Please take into account that we need a USB device with a storage capacity bigger than 4GB (Iso-Hybrid images are around 2.5GB). It is actually better to have a USB unit with a capacity of at least 8 GB in order to be able to apply Debian's updates on the system later on.

2. Getting ready

First of all we will need an Iso-Hybrid image. We will use the XFCE desktop in this tutorial so we download the live CD file debian-live-X.x.x-amd64-xfce-desktop.iso from the Debian site. You could also opt to choose the unofficial live CD version that includes all non-free firmware in order to make the stick useable on many types of PC's. Before we can continue, we will first need to install some helper programs, so please open a terminal and install the following:

sudo apt-get install gparted mbr dosfstools p7zip syslinux

and wait a bit for the installation of those programs.

3. Preparing the USB device

Plug the USB device. Make sure it is empty or contains nothing important. All the files will be erased in this step!. Please make a copy of any important files you may have on the device. Start gparted. In the right upper side you may access the USB device. Usually it is identified as /dev/sdb if you have a single hard disk in your system. We shall assume from now on /dev/sdb is our USB device. If in your system it is /dev/sdc or whatever, please take it into account from now on. Make sure you work with the intended USB device if you have several units working at the same time. Right click on the partition (usually indicated with a long rectangle with green color indicating a fat32 partition) and make sure it is unmounted. We now write a new partition table by going to Device -> Create Partition table (Choose MS-DOS style). After writing the new partion table there are no partitions yet on the USB device. We will need to make at least two partitions, one for the iso-hybrid image and a second one for persistence. Our Iso-hybrid needs at least 2.2GB, so we prepare a FAT32 partition with a size around 3GB, (so we have no trouble if we update the kernel later on), with label "XFCE" and with the boot flag set. Please do not forget to set this boot flag (Set this after making the partition, by using the menu option 'Manage Flags'). The choice for a FAT32 partition type is made because this type of partition is normally a readable partition type by the PC when starting up from USB, also this makes the partion read/write as we are planning on changing around some files (.iso images are normally ISO9660 CD-Rom parititions, and these are read-only).
The rest of the USB stick will become our persistence partition. So, using gparted again, we prepare in the remaining space an ext4 partition with label "persistence". The label "persistence" is mandatory here, as this label is looked for at startup. After applying all the changes make sure all partitions are unmounted. Close gparted and unplug the USB device.

4. Copy the necessary files

Plug the USB device again and mount your FAT32 /dev/sdb1 partition. Usually it is mounted on /media/yourusername (you can check that by using df or checking in gparted). In a terminal, we move to the folder /media/yourusername/partitionname:

cd /media/yourusername/XFCE

and then we decompress in there the iso-hybrid:

7z x ~/Desktop/debian-live-X.x.x-amd64-xfce-desktop.iso

This may take long depending on the system and the USB device.

The syslinux bootloader configuration folder and files within it are named isolinux when installed on an ISO. You will need to rename the directory and two files changing isolinux to syslinux so the bootloader will find them on your FAT32 live image partition:

mv isolinux syslinux
mv syslinux/isolinux.cfg syslinux/syslinux.cfg
mv syslinux/isolinux.bin syslinux/syslinux.bin

now, we append persistence to the live boot parameters: This is done by editing the file menu.cfg in the syslinux directory with your favorite editor, like nano for example. find the line at the top of the menu that has the boot parameters and add 'persistence' to it. This way persistence will be automatically activated during boot, and you do not have to edit the menu line each startup.

Next, mount your /dev/sdb2 partition (persistence). We will need writing permission to make changes in the partition persistence. Since we used gparted (as root) to create the permissions we have to change the owner:

sudo chown yourusername /media/yourusername/persistence

where yourusername is ... your user name!

Now we turn on full persistence by making a file called 'persistence.conf' in the root of the persistence partition. Using the nano editor, we will put the following text in the file: "/ union" (without the quotes, on one line, ended by cr-lf):

cd /media/yourusername/persistence
sudo nano persistence.conf

then type:

/ union


And save with Ctrl-X (and responding y (yes) to save the file)

5. Make the USB device bootable

Unmount the partitions (you can use gparted). Then we use install-mbr to install a MBR (Master Boot Record) on the USB device and syslinux to install the bootloader to boot into the live image partition (XFCE partition with boot flag).

sudo install-mbr --force /dev/sdb

sudo syslinux -i /dev/sdb1

Finished!!! Now you stop the computer and boot from the USB device. After booting you may apply updates to the system and install your favorite programs in your customized Debian Live image.

6. User name, password and autologin

When you use your Iso-Hybrid, you work with:

Username: user
Password: live

When the system boots, it does not ask you for a user name and password and you are automatically logged in. If you do not like this feature, you have to make changes in the configuration file of the display manager. For XFCE, the display manager is LightDM, so changes are easy to do. Edit the configuration file /etc/lightdm/lightdm.conf and make sure that after [SeatDefaults] you have this:


Next time you boot you can use your user name and password to log in. If you need to add yourself as a user, you can use the Debian 'adduser' tool in the terminal. The other existing tool, with the name 'useradd' is much harder to use, so using 'adduser' will make your life easier.