How to Build a Debian LiveCD

A live CD or live DVD is a complete bootable Linux operating system loaded from a CD or DVD. Although there are a lots of live Linux CDs, for seemingly every taste and purpose, it might still be useful on occasion to build your own. This guide details the steps to build a bootable live CD/DVD based on Debian “wheezy”.

Step 1 – Installing the necessary software

These are the software packages you need to install on your Debian system:

# apt-get install xorriso live-build syslinux squashfs-tools

Step 2 – Create a basic filesystem

Start by creating a new work directory, and bring in a basic Debian filesystem using debootstrap. Depending on your network connection, it will take some time downloading all the necessary packages:

# mkdir ~/livework && cd ~/livework
# debootstrap --arch=amd64 wheezy chroot

The new filesystem was created in ~/livework/chroot directory. It is time to chroot into the new filesystem and finish the installation.

Step 3 – chroot

# cd ~/livework
# chroot chroot
# mount none -t proc /proc
# mount none -t sysfs /sys
# mount none -t devpts /dev/pts
# export HOME=/root
# export LC_ALL=C
# export PS1="\e[01;31m(live):\W \$ \e[00m"
Debian LiveCD chroot

Debian LiveCD chroot

In chroot you need to bring in a Linux kernel and the necessary livecd packages. You can also set up a root password:

(live):/ $ apt-get install dialog dbus
(live):/ $ dbus-uuidgen > /var/lib/dbus/machine-id
(live):/ $ apt-get install linux-image-amd64 live-boot
(live):/ $ passwd

This is a very basic Debian system. On top of it you can install packages such as vim and ssh (apt-get install vim ssh), a desktop environment (apt-get install lxde), a web browser (apt-get install iceweasel) etc. When you are done, cleanup apt caches and exit chroot.

(live):/ $ apt-get clean
(live):/ $ rm /var/lib/dbus/machine-id && rm -rf /tmp/*
(live):/ $ umount /proc /sys /dev/pts
(live):/ $ exit

Step 4 - ISOLINUX

The CD/DVD image is set up using ISOLINUX. Start by creating a new directory, binary, containing the Linux kernel, a compressed copy of chroot, and isolinux executables:

# cd ~/livework
# mkdir -p binary/live && mkdir -p binary/isolinux
# cp chroot/boot/vmlinuz-3.2.0-4-amd64 binary/live/vmlinuz
# cp chroot/boot/initrd.img-3.2.0-4-amd64 binary/live/initrd
# mksquashfs chroot binary/live/filesystem.squashfs -comp xz -e boot
# cp /usr/lib/syslinux/isolinux.bin binary/isolinux/.
# cp /usr/lib/syslinux/menu.c32 binary/isolinux/.

Next, an isolinux config file is created:

# cat binary/isolinux/isolinux.cfg
ui menu.c32
prompt 0
menu title Boot Menu
timeout 300

label live-amd64
	menu label ^Live (amd64)
	menu default
	linux /live/vmlinuz
 	append initrd=/live/initrd boot=live persistence quiet

label live-amd64-failsafe
	menu label ^Live (amd64 failsafe)
	linux /live/vmlinuz
	append initrd=/live/initrd boot=live persistence config memtest noapic noapm nodma nomce nolapic nomodeset nosmp nosplash vga=normal

endtext

Step 5 - Building the iso image

I use GNU xorriso to build the final iso image. It creates an isohybrid image that can be transferred to a USB stick using dd command.

# cd ~/livework
# xorriso -as mkisofs -r -J -joliet-long -l -cache-inodes \
-isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin -partition_offset 16 \
-A "Debian Live"  -b isolinux/isolinux.bin -c \
isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -o remaster.iso binary

To quickly test the image use qemu (apt-get install qemu).

# qemu-system-x86_64 remaster.iso
LiveCD boot menu in qemu

LiveCD boot menu in qemu

Transferring the iso image to USB stick

As mentioned above, isohybrid images can be transferred to USB using dd command. To find out what device handles your USB stick you can use hwinfo (apt-get install hwinfo):

# hwinfo --disk --short
disk:                                                           
  /dev/sda             HDT722525DLAT80
  /dev/sdb             WDC WD800JB-00FM
  /dev/sdc             Generic USB SD Reader
  /dev/sdd             Generic USB CF Reader
  /dev/sde             Generic USB SM Reader
  /dev/sdf             Generic USB MS Reader
  /dev/sdg             Lexar USB Flash Drive

# dd if=remaster.iso of=/dev/sdg

Reboot your computer from the USB stick and you'll be up and running in no time.

LiveCD running in qemu

LiveCD running in qemu

A few words about persistence

All iso images build using Debian's live-boot package have the capability to autodetect a writable storage data area. This data will persist across multiple boot sessions on the same computer. To enable this feature, create a storage file named live-rw with a valid ext2 filesystem and place it on an existing hard drive partition on the computer you are booting:

# dd if=/dev/zero of=live-rw bs=100MB count=1
# /sbin/mkfs.ext2 -F live-rw
# mv live-rw /.

In my case I've moved live-rw file on my Debian Linux partition. You can also put it on a NTFS partition, at boot time the software will find it and mount it.

Conclusion

The iso image in this example has a size of 92MB. It is a basic Debian system as created by debootstrap, with only the necessary livecd executables. From here it will grow as more packages are added and the image is personalized.

I have decided to document my steps in case anyone might find them useful. Please let me know if you run into problems, or if you have any questions or suggestions. I use these steps to build small network appliances, servers, and rescue disks, nothing important. I've never went as far as to build a full distribution.

If you are considering it for a more serious project, better try live-build. Debian team uses live-build to build the official Debian CDs. The tool is very powerful and highly configurable, and it goes well beyond what I've covered in this example.

About these ads

24 thoughts on “How to Build a Debian LiveCD

  1. Pingback: Hallow Demon

  2. Tal

    Awesome! This will definately come in handy. Thanks!

    Just a few notes though:

    I would suggest you change from:

    export PS1=”\e[01;31m(live):\W \$ \e[00m”

    to something like:

    export PS1=”\e[01;31m(live):\W # \e[00m”

    (change from $ to #) to show that the user is actually root, not a regular user.

    umount /proc && umount /sys && umount /dev/pts
    can just be
    umount /proc /sys /dev/pts

    though I guess that’s just personel preference.

    You can also change:

    mkdir -p binary/live && mkdir -p binary/isolinux

    to

    mkdir -pv binary/{live,isolinux}

    but that’s just getting fancy.

    Also, mksquashfs is not installed by default. As you know, it’s part of the squashfs-tools package.

    isolinux.bin is part of the syslinux package, which is not installed by default either.

    Thanks again!

    Reply
  3. mouseroot

    So ive been trying to get a background image to show up and I just cannot figure it out.
    all online example have yielded the same results…no background splash so if you have any suggestions im all ears

    Reply
  4. Pingback: Modifying Debian Live Boot

  5. vastone

    I have successfully used this to build the ISO … I cannot login at all. I went through the steps to change the passwd. Is root the login name? No matter what combination I use, I cannot log in as the passwors is incorrect. Great guide!

    Reply
    1. netblue30 Post author

      Thanks! Yes, root should be the login name if you have a password configured.

      You can also configure automatic login. For this you add –autologin on getty lines in chroot/etc/inittab file:

      1:2345:respawn:/sbin/getty –autologin 38400 tty1
      2:23:respawn:/sbin/getty –autologin 38400 tty2

      Reply
  6. Marcello DL

    Hello, thank you for a very handy tutorial as the full procedure at the debian live site is overkill for my necessities.
    I have doubts about your dd line, in my system you do not get anything out of /dev/null – what works for me is
    dd if=/dev/zero of=live-rw bs=100M count=1

    Reply
  7. Pingback: Debian-based distribution

  8. farizluqman

    Hello, this is a very useful guide! I’ll credit you in my project for the excellent tutorial.

    Anyway, I think instead of directly exiting the chroot environment, clear all the bash history first, then exit:

    cat /dev/null > ~/.bash_history && history -c && exit

    just my 2 penny :)

    Reply
  9. Pingback: debian live cd | linux experts

  10. Alma Slape

    I’ve tried so many other half-baked tutorials… your instructions were right on the money !

    I installed a full gnome desktop with a user. To access the desktop inside a seperate window…
    I had to do 1 extra step…
    $ mount –bind /tmp /chroot/tmp

    Then…
    -Outside the chroot as user: $ Xephyr :1 -screen 1024×768 -ac
    -Inside the chroot as user: $ export DISPLAY=localhost:1
    -Inside the chroot as user: $ gnome-session
    or, if you want ‘classic gnome’, $ gnome-session –session=gnome-classic

    Presto ! you can tweak to your heart’s desire, as the desktop will appear when booted.

    Reply
  11. Pingback: Debian Livesystem bauen « Rprengel's Blog

  12. Mark

    Great post.
    Quick question, does anyone know if you can capture kernel modules in the Live-Build? I’m asking because I tried and noticed once I boot with the live image the zfs modules are not loaded. Not only that, I noticed that “/lib/modules/3.2.0-4-amd64/updates/dkms” does not exist in the live image, nor in the build environment. I did install ZFS in chroot and I was able to run commands from it, but it seems it did not get “captured”.

    Anyone seen this?

    Reply
    1. netblue30 Post author

      Thanks!

      When everything else fails, add “insmod your_module” in /etc/rc.local. The commands from this file are the last thing run at startup.

      Reply
  13. Sennako

    There are new machine-id areas used in Debian Testing amd 64…
    systemd is using: /etc/machine-id

    Will this change your tutorial for the ‘machine-id’ instruction ?

    Thank you.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s