Building an hybrid Debian Live ISO with xorriso
Lets build a Debian Jessie live ISO that will include any useful tools, like chntpw for changing/deleting forgotten Windows passwords, Foremost/TestDisk/Recoverdm for recovering lost data or corrupted partitions. Some sort of swiss knife, if you’re into these sort of things.
My host system is Debian Jessie, meaning some commands won’t work on previous versions like Wheezy. The final ISO will be generated with xorriso, and it will be an hybrid iso, that can be burned on CDs or copied onto USB drives.
First lets setup the host machine installing the required packages:
sudo apt-get install debootstrap squashfs-tools syslinux isolinux syslinux-common xorriso mkdir -p livebuild/rootdir && cd livebuild
Let’s have a 32bit OS useful on older PCs as well as newer ones. I prefer using the minimal installation variant, meaning some packages will not be included. Also, you should replace the repository’s url with the fastest mirror available for your country. Once packages are downloaded and installed into rootdir/, we chroot and start tweaking our system:
sudo debootstrap --arch=i386 --variant=minbase jessie rootdir http://ftp.it.debian.org/debian sudo chroot
We are now inside the chroot environment, lets customize our build. The last two lines allow us to install packages without locales and don’t get errors about locales not configured.
mount none -t proc /proc mount none -t sysfs /sys mount none -t devpts /dev/pts echo 'DebianLive' > /etc/hostname echo '127.0.0.1 localhost' > /etc/hosts echo '127.0.0.1 DebianLive' >> /etc/hosts echo '::1 localhost ip6-localhost ip6-loopback' >> /etc/hosts echo 'ff02::1 ip6-allnodes' >> /etc/hosts echo 'ff02::2 ip6-allrouters' >> /etc/hosts echo 'export LANG="C"' >> /etc/bash.bashrc echo 'export LC_ALL="C"' >> /etc/bash.bashrc
Optional, you could add contrib and non-free repositories to install proprietary drivers, sometimes mandatory.
echo "deb http://ftp.it.debian.org/debian jessie main contrib non-free" > /etc/apt/sources.list echo "APT::Install-Recommends \"0\"; APT::Install-Suggests \"0\";" > /etc/apt/apt.conf.d/01noinstallrecommends apt-get update
Install i686 kernel with pae for machines with RAM >4Gb (on Jessie i386 kernel has been ditched in favour of i686) and networking firmware:
apt-get install linux-image-3.16.0-4-686-pae firmware-linux-free firmware-linux-nonfree firmware-atheros firmware-realtek firmware-ralink firmware-iwlwifi ntfs-3g dosfstools memtest86+ live-boot
Replace systemd with SysV. This step is optional but saves us a few MBs:
apt-get purge systemd systemd-sysvapt-get install sysvinit sysvinit-core
Finally, installing utilities. Include everything you want (even a full-fledged GNOME environment) noting that some standard applications (like man and nano) are not included in the minbase install, and you should remember to install them:
apt-get install nano wicd-curses chntpw cmospwd testdisk foremost chkrootkit man less console-data kbd
Clean up, unmount filesystems and exit the chroot environment:
apt-get autoremove && apt-get clean rm -rf /tmp/* umount /proc /sys /dev/pts exit
We are now out of the chroot environment! We can start building our iso. Copy the kernel and syslinux files in our image folder:
mkdir -p image/{live,isolinux} cp rootdir/boot/vmlinuz* image/live/vmlinuz cp rootdir/boot/initrd* image/live/initrd cp rootdir/boot/memtest86+.bin image/live/memtest86+.bin cp rootdir/boot/memtest86+_multiboot.bin image/live/memtest86+_multiboot.bin cp /usr/lib/ISOLINUX/isolinux.bin image/isolinux/ cp /usr/lib/syslinux/modules/bios/* image/isolinux/
Create a file under image/isolinux and call it isolinux.cfg, and add these lines to it. This will be the syslinux configuration, giving us a small boot menu that gives us choice about what to boot. And yes, memtest is useful:
UI menu.c32 prompt 0 menu title Debian Live timeout 30 label Debian Live menu label ^Debian Live menu default kernel /live/vmlinuz append initrd=/live/initrd boot=live label hdt menu label ^Hardware Detection Tool (HDT) kernel hdt.c32 text help HDT displays low-level information about the systems hardware. endtext label Memtest86+ menu label ^Memory Failure Detection (memtest86+) /live/memtest86+.bin label Memtest86+ (multiboot) menu label ^Memory Failure Detection (memtest86+) /live/memtest86+_multiboot.bin
At the end, we build the Squashfs filesystem and put it on our hybrid ISO using xorriso.
sudo mksquashfs rootdir/ image/live/filesystem.squashfs -e boot
xorriso -as mkisofs -r -J -joliet-long -l -cache-inodes -isohybrid-mbr /usr/lib/ISOLINUX/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 debianlive.iso image
And here it is our ready to flash (or burn) iso image! Flash it on a usb stick with dd, being careful replacing /dev/sdxY with your usb drive (you can check with lsblk or sudo fdisk -l). It wouldn’t be nice dd’ ing that iso to your hard drive.
sudo dd if=debianlive.iso of=/dev/sdxY bs=4M; sync
My ISO was approximately 150Mb. I didnt chose to install X.org and a window manager. Copying that on a usb drive means that we’ll lose the remaining space on the usb drive. To avoid this, partition the remaining (unallocated) space with fdisk, parted or a graphical frontend like gparted, even if Windows is not capable of mounting any partition other than the first. No problems instead on Linux.