create-custom-debian-live-usb-stick-stretch
Table of Contents
Create custom debian live usb-stick (stretch, amd64)
Install necessary packages on the build system
root@host:~# apt-get install debootstrap syslinux isolinux squashfs-tools genisoimage memtest86+ rsync [ ... ]
Create directory structure & install base image
root@host:~# mkdir /root/shtf-stick && cd /root/shtf-stick root@host:~/shtf-stick# debootstrap --arch=amd64 --variant=minbase stretch chroot http://http.at.debian.org/debian/ [ ... ]
Perform basic configuration
root@host:~/shtf-stick# chroot ./chroot root@host:/# echo shtf > /etc/hostname root@host:/# passwd root Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully 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 && \ dbus-uuidgen > /var/lib/dbus/machine-id root@host:/# apt-get install --no-install-recommends --yes linux-image-amd64 firmware-linux-free systemd-sysv live-boot kbd console-data [ ... ]
Install additional packages
root@host:/# apt-get install --no-install-recommends --yes \ 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 less curl tcpdump dosfstools syslinux partclone vim pv \ firefox-esr chntpw lvm2 mdadm keepassx gdisk gnupg duplicity s3cmd bzip2 lsof screen mc htop iproute2 inetutils-ping inetutils-traceroute netcat-openbsd [ ... ]
Cleanup & leave chroot environment
root@host:/# rm -f /vmlinuz* /initrd.img* /var/lib/dbus/machine-id && \ apt-get clean && \ rm /etc/resolv.conf && \ umount -lf /proc /sys /dev/pts root@host:/# exit exit root@debian:~/shtf-stick# umount -lf $(mount | awk '/shtf-stick/ { print $3 }') root@host:~/shtf-stick# rm chroot/root/.bash_history
Create filesystem & boot config
root@host:~/shtf-stick# mkdir -p image/{live,isolinux} && \ mksquashfs chroot image/live/filesystem.squashfs -e boot Parallel mksquashfs: Using 1 processor Creating 4.0 filesystem on image/live/filesystem.squashfs, block size 131072. [=========================================================================================================================/] 25507/25507 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 305495.00 Kbytes (298.33 Mbytes) 39.71% of uncompressed filesystem size (769303.94 Kbytes) Inode table size 311570 bytes (304.27 Kbytes) 29.08% of uncompressed inode table size (1071399 bytes) Directory table size 300335 bytes (293.30 Kbytes) 42.66% of uncompressed directory table size (703968 bytes) Number of duplicate files found 809 Number of inodes 30836 Number of files 21710 Number of fragments 2182 Number of symbolic links 6003 Number of device nodes 8 Number of fifo nodes 0 Number of socket nodes 0 Number of directories 3115 Number of ids (unique uids + gids) 10 Number of uids 2 root (0) systemd-timesync (100) Number of gids 9 root (0) shadow (42) utmp (43) rtkit (109) tty (5) systemd-journal (101) staff (50) adm (4) mail (8) root@host:~/shtf-stick# root@host:~/shtf-stick# cp chroot/boot/vmlinuz-* image/live/vmlinuz1 && \ cp chroot/boot/initrd.img-* image/live/initrd1 root@host:~/shtf-stick# cat > image/isolinux/isolinux.cfg << _EOF_ UI menu.c32 prompt 0 menu title The Shit Has Hit The Fan timeout 300 label Debian Live 4.9.0-3-amd64 menu label ^Debian Live 4.9.0-3-amd64 menu default kernel /live/vmlinuz1 append initrd=/live/initrd1 boot=live label memtest86+ menu label ^Memory Failure Detection (memtest86+) kernel /live/memtest _EOF_ root@host:~/shtf-stick#
Create CD image
root@host:~/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 && \ 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-$(date +%Y%m%d_%H%M).iso . && \ cd ..
Prepare USB stick
root@host:~/shtf-stick# export DEVICE=/dev/sdc root@host:~/shtf-stick# dd if=/dev/zero of=${DEVICE} 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:~/shtf-stick# fdisk ${DEVICE} 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:~/shtf-stick# mkdosfs -F 32 -I ${DEVICE}1 mkfs.fat 3.0.27 (2014-11-12) root@host:~/shtf-stick#
Create USB Stick
root@host:~/shtf-stick# export DEVICE=/dev/sdc root@host:~/shtf-stick# syslinux -i ${DEVICE}1 root@host:~/shtf-stick# dd if=/usr/lib/syslinux/mbr/mbr.bin of=${DEVICE} 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:~/shtf-stick# mkdir /mnt/usb; \ mount ${DEVICE}1 /mnt/usb root@host:~/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/ && date +%Y%m%d_%H%M > /mnt/usb/CREATED && umount /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:~/shtf-stick#
Source: http://willhaley.com/blog/create-a-custom-debian-stretch-live-environment-ubuntu-17-zesty/
create-custom-debian-live-usb-stick-stretch.txt · Last modified: 2017/11/13 17:34 by baumi