Table of Contents

Create custom debian live usb-stick (jessie)

Updated Version for Debian Stretch

Install necessary packages on the build system

root@host:~# apt-get install debootstrap syslinux isolinux squashfs-tools genisoimage memtest86+ rsync dosfstools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  mtools syslinux-common
Suggested packages:
  wodim cdrkit-doc hwtools memtester kernel-patch-badram memtest86 floppyd
  openssh-server
The following NEW packages will be installed:
  debootstrap genisoimage memtest86+ mtools rsync squashfs-tools syslinux
  syslinux-common
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,579 kB of archives.
After this operation, 9,360 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
[ ... ]

Create directory structure & install base image

root@host:~# mkdir /tmp/shtf-stick && cd /tmp/shtf-stick
 
root@host:/tmp/shtf-stick# debootstrap --arch=i386 --variant=minbase jessie chroot http://http.at.debian.org/debian/
[ ... ]

Perform basic configuration

root@host:/tmp/shtf-stick# mount -o bind /dev ./chroot/dev && cp /etc/resolv.conf ./chroot/etc/resolv.conf
root@host:/tmp/shtf-stick# chroot ./chroot
 
root@host:/# mount none -t proc /proc && \
mount none -t sysfs /sys && \
mount none -t devpts /dev/pts && \
export HOME=/root && \
export LC_ALL=C && \
apt-get update && \
apt-get install dialog dbus --yes --force-yes && \
dbus-uuidgen > /var/lib/dbus/machine-id
Ign http://ftp.at.debian.org jessie InRelease
Hit http://ftp.at.debian.org jessie Release.gpg
Hit http://ftp.at.debian.org jessie Release
Get:1 http://ftp.at.debian.org jessie/main i386 Packages [6768 kB]
Get:2 http://ftp.at.debian.org jessie/main Translation-en [4582 kB]
Fetched 11.4 MB in 10s (1108 kB/s)                                                                                                           
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  libcap-ng0 libdbus-1-3 libexpat1
Suggested packages:
  dbus-x11
The following NEW packages will be installed:
  dbus dialog libcap-ng0 libdbus-1-3 libexpat1
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 861 kB of archives.
After this operation, 2781 kB of additional disk space will be used.
[ ... ]
 
root@host:/# echo shtf > /etc/hostname
root@host:/# passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

Install additional packages

root@host:/# apt-get install --no-install-recommends --yes \
linux-image-3.16.0-4-686-pae live-boot \
network-manager net-tools wireless-tools wpagui tcpdump wget openssh-client \
blackbox xserver-xorg-core xserver-xorg xinit xterm \
pciutils usbutils gparted ntfs-3g hfsprogs rsync dosfstools syslinux partclone vim pv \
iceweasel chntpw lvm2 mdadm mc htop keepassx gdisk
 
[ ... ]
 
Setting up keyboard-configuration (1.123) ...
 
 Package configuration
 --------------------------------------------------------------------------------------------------------------------------------------------
 
 
                                  +----------------Configuring keyboard-configuration-------------------+
                                  ¦ Please select the layout matching the keyboard for this machine.    ¦  
                                  ¦                                                                     ¦  
                                  ¦ Keyboard layout:                                                    ¦  
                                  ¦ +-----------------------------------------------------------------+ ¦  
                                  ¦ ¦English (US)                                                     ¦ ¦  
                                  ¦ ¦English (US) - Cherokee                                          ¦ ¦  
                                  ¦ ¦English (US) - English (Colemak)                                 ¦ ¦  
                                  ¦ ¦English (US) - English (Dvorak alternative international no dead ¦ ¦  
                                  ¦ ¦English (US) - English (Dvorak)                                  ¦ ¦  
                                  ¦ ¦English (US) - English (Dvorak, international with dead keys)    ¦ ¦  
                                  ¦ ¦English (US) - English (Macintosh)                               ¦ ¦  
                                  ¦ ¦English (US) - English (US, alternative international)           ¦ ¦  
                                  ¦ ¦English (US) - English (US, international with dead keys)        ¦ ¦  
                                  ¦ ¦English (US) - English (US, with euro on 5)                      ¦ ¦  
                                  ¦ ¦English (US) - English (Workman)                                 ¦ ¦  
                                  ¦ ¦English (US) - English (Workman, international with dead keys)   ¦ ¦  
                                  ¦ ¦English (US) - English (classic Dvorak)                          ¦ ¦  
                                  ¦ ¦English (US) - English (international AltGr dead keys)           ¦ ¦  
                                  ¦ ¦English (US) - English (left handed Dvorak)                      ¦ ¦  
                                  ¦ ¦English (US) - English (programmer Dvorak)                       ¦ ¦  
                                  ¦ ¦English (US) - English (right handed Dvorak)                     ¦ ¦  
                                  ¦ ¦English (US) - English (the divide/multiply keys toggle the layo ¦ ¦  
                                  ¦ ¦English (US) - Russian (US, phonetic)                            ¦ ¦  
                                  ¦ ¦English (US) - Serbo-Croatian (US)                               ¦ ¦  
                                  ¦ ¦Other                                                            ¦ ¦  
                                  ¦ +-----------------------------------------------------------------+ ¦  
                                  +---------------------------------------------------------------------¦  
                                  ¦                     <  OK  >           <Cancel>                     ¦  
                                  +---------------------------------------------------------------------+  
                                     
 
 
[ ... ]

Install duplicity (just to get the dependencies resolved)

root@host:/# echo nameserver $NAMESERVERIP > /etc/resolv.conf
root@host:/# echo "deb http://http.at.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/backports.list
root@host:/# apt-get update
root@host:/# apt-get -t jessie-backports install duplicity python-boto

Install most recent version of duplicity from debian testing

Check path of packages!

root@host:/# cd /tmp
root@host:/tmp# wget http://ftp.at.debian.org/debian/pool/main/p/python-lockfile/python-lockfile_0.12.2-2_all.deb
root@host:/tmp# wget http://ftp.at.debian.org/debian/pool/main/d/duplicity/duplicity_0.7.12-1_i386.deb
root@host:/tmp# dpkg -i python-lockfile_0.12.2-1_all.deb
root@host:/tmp# dpkg -i duplicity_0.7.06-2_i386.deb
root@host:/tmp# cd ..

Cleanup & leave chroot environment

root@host:/# rm -f /var/lib/dbus/machine-id && \
apt-get clean && \
rm -rf /tmp/* && \
rm /etc/resolv.conf && \
umount -lf /proc && \
umount -lf /sys && \
umount -lf /dev/pts
 
root@host:/# exit
exit
root@host:/tmp/shtf-stick# umount -lf chroot/dev
root@host:/tmp/shtf-stick# rm chroot/root/.bash_history

Create filesystem & boot config

root@host:/tmp/shtf-stick# mkdir -p image/{live,isolinux}
 
root@host:/tmp/shtf-stick# mksquashfs chroot image/live/filesystem.squashfs -e boot
Parallel mksquashfs: Using 2 processors
Creating 4.0 filesystem on image/live/filesystem.squashfs, block size 131072.
[=========================================================================================================================\] 20760/20760 100%
 
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments, compressed xattrs
    duplicates are removed
Filesystem size 270068.48 Kbytes (263.74 Mbytes)
    39.38% of uncompressed filesystem size (685752.56 Kbytes)
Inode table size 233267 bytes (227.80 Kbytes)
    31.56% of uncompressed inode table size (739230 bytes)
Directory table size 204617 bytes (199.82 Kbytes)
    43.37% of uncompressed directory table size (471758 bytes)
Xattr table size 37 bytes (0.04 Kbytes)
    92.50% of uncompressed xattr table size (40 bytes)
Number of duplicate files found 904
Number of inodes 21913
Number of files 17237
Number of fragments 1777
Number of symbolic links  2135
Number of device nodes 37
Number of fifo nodes 0
Number of socket nodes 3
Number of directories 2501
Number of ids (unique uids + gids) 13
Number of uids 2
    root (0)
    messagebus (104)
Number of gids 12
    root (0)
    tty (5)
    kmem (15)
    disk (6)
    shadow (42)
    crontab (107)
    utmp (43)
    netdev (108)
    messagebus (109)
    staff (50)
    adm (4)
    mail (8)
root@host:/tmp/shtf-stick# 
root@host:/tmp/shtf-stick# cp chroot/boot/vmlinuz-3.16.0-4-686-pae image/live/vmlinuz1
root@host:/tmp/shtf-stick# cp chroot/boot/initrd.img-3.16.0-4-686-pae image/live/initrd1
 
root@host:/tmp/shtf-stick# cat > image/isolinux/isolinux.cfg 
UI menu.c32
 
prompt 0
menu title The Shit Has Hit The Fan
 
timeout 300
 
label Debian Live 3.16.0-4-686-pae
menu label ^Debian Live 3.16.0-4-686-pae
menu default
kernel /live/vmlinuz1
append initrd=/live/initrd1 boot=live
 
label memtest86+
menu label ^Memory Failure Detection (memtest86+)
kernel /live/memtest
 
^D
root@host:/tmp/shtf-stick#

Create CD image

root@host:/tmp/shtf-stick# cp /usr/lib/ISOLINUX/isolinux.bin image/isolinux/ && \
cp /usr/lib/syslinux/modules/bios/menu.c32 image/isolinux/ && \
cp /usr/lib/syslinux/modules/bios/libmenu.c32 image/isolinux/ && \
cp /usr/lib/syslinux/modules/bios/libutil.c32 image/isolinux/ && \
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 image/isolinux/ && \
cp /usr/share/misc/pci.ids image/isolinux/ && \
cp /boot/memtest86+.bin image/live/memtest
 
root@host:/tmp/shtf-stick# cd image && \
genisoimage -rational-rock -volid "SHTF" -cache-inodes -joliet -full-iso9660-filenames -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -output ../debian-shtf.iso . && \
cd ..

Prepare USB stick

root@host:/tmp/shtf-stick# dd if=/dev/zero of=/dev/sdc bs=1k count=100
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 1.5086 s, 67.9 kB/s
root@host:/tmp/shtf-stick# fdisk /dev/sdc
 
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x374a220b.
 
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-2005431, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-2005431, default 2005431): 
 
Created a new partition 1 of type 'Linux' and of size 978.2 MiB.
 
Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.
 
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): b
If you have created or modified any DOS 6.x partitions, please see the fdisk documentation for additional information.
Changed type of partition 'Linux' to 'W95 FAT32'.
 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
 
root@host:/tmp/shtf-stick# mkdosfs -F 32 -I /dev/sdc1
mkfs.fat 3.0.27 (2014-11-12)
 
root@host:/tmp/shtf-stick#

Create USB Stick

root@host:/tmp/shtf-stick# syslinux -i /dev/sdc1
 
root@host:/tmp/shtf-stick# dd if=/usr/lib/syslinux/mbr/mbr.bin of=/dev/sdc conv=notrunc bs=440 count=1
1+0 records in
1+0 records out
440 bytes (440 B) copied, 0.0564548 s, 7.8 kB/s
 
root@host:/tmp/shtf-stick# mkdir /mnt/usb && \
mount /dev/sdc1 /mnt/usb
 
root@host:/tmp/shtf-stick# cp /usr/lib/syslinux/modules/bios/libutil.c32 /mnt/usb/ && \
cp /usr/lib/syslinux/modules/bios/libmenu.c32 /mnt/usb/ && \
cp /usr/lib/syslinux/modules/bios/menu.c32 /mnt/usb/ && \
cp /boot/memtest86+.bin /mnt/usb/memtest && \
cp image/isolinux/isolinux.cfg /mnt/usb/syslinux.cfg && \
cp /usr/share/misc/pci.ids /mnt/usb/ && \
rsync -rv image/live /mnt/usb/
sending incremental file list
live/
live/filesystem.squashfs
live/initrd1
live/vmlinuz1
 
sent 308,553,889 bytes  received 77 bytes  88,158,276.00 bytes/sec
total size is 308,478,319  speedup is 1.00
 
root@host:/tmp/shtf-stick# umount /mnt/usb/
root@host:/tmp/shtf-stick#

Source: http://willhaley.com/blog/create-a-custom-debian-jessie-live-environment-ubuntu-16-xenial/