Debian - Modify Live CD / USB and add SSH login on boot
How to modify a (Debian) Live CD ISO and enable SSH login
The easiest way to modify an ISO would have been to open the file like a compressed zip file, edit the appropriate files and then put it back. But this is not possible, because the ISO file structure is a read-only system and in there is a squashfs file system containing the destination file system also in the need of re-creation. So if you want to modify something on an ISO built this way, then you will have to extract the ISO, then extract the squashfs file system, do your edits, recreate the squashfs and then recreate the ISO. Also add that the ISO needs to be bootable. Here follows instructions how to do that.
# downloading the ISO the regular way you like # install required software: sudo apt-get install genisoimage p7zip-full squashfs-tools # extract the ISO: 7z x <iso_file>.iso # a folder is new created with contents of the ISO file. Find the name of the folder: ls -la # go to the folder that contain the ISO and find the filesystem.squashfs file: cd <folder with ISO contents> find -t file|grep "filesystem\.squashfs" # filesystem.squashfs is sometimes in live folder cd live # make a working directory mkdir workdir mv filesystem.squashfs workdir cd workdir # extract squashfs file (reduce CPU usage to lower the temperature) unsquashfs -processors 1 filesystem.squashfs # remove the old filesystem.squashfs file: # NOTE: it will disturb the re-creation if kept, remove it rm filesystem.squashfs # the contents of the squashfs is in squashfs-root folder, go there and edit cd squashfs-root/etc/ssh/ # open sshd_config - replace vi with the editor you like vi sshd_config # enable ssh root login PermitRootLogin yes PasswordAuthentication yes # remake the squashfs filesystem out of the squashfs-root folder: mksquashfs squashfs-root filesystem.squashfs -b 1024k -comp xz -Xbcj x86 -e boot -processors 1 # beware: the above command runs the CPU very hot, set the processor usage wisely mv filesystem.squashfs cd .. rm -rf workdir # move out until you are there at the same level as the original .iso file, repeat until there: cd .. # generate the new ISO image genisoimage -r -V "Label Of ISO" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o <isofile>.iso <folder with ISO contents>
Test in virtual machine using qemu
# to test it using qemu: apt-get install qemu qemu-system-x86_64 -boot d -cdrom <new iso name>.iso -m 512 -net user,hostfwd=tcp::10022-:22 -net nic
Thanks goes to the following: https://unix.stackexchange.com/questions/70738/what-is-the-fastest-way-to-extract-an-iso https://unix.stackexchange.com/questions/80305/mounting-a-squashfs-filesystem-in-read-write https://bbs.archlinux.org/viewtopic.php?id=106087 https://unix.stackexchange.com/questions/124681/ssh-from-host-to-guest-using-qemu http://www.zoyinc.com/?p=2510
This is a personal note. Last updated: 2017-09-15 02:17:30.