Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
140 lines (113 sloc) 4.3 KB
#!/bin/bash
# From https://unix.stackexchange.com/questions/382817/uefi-bios-bootable-live-debian-stretch-amd64-with-persistence
if [[ ${EUID} -ne 0 ]]; then
echo "this script must be executed with elevated privileges"
exit 1
fi
iso=$1
dev=$2
if [[ -z "${iso}" || ! -f ${iso} || ! -s ${iso} ]]; then
echo "parameter 1 must be source ISO image"
exit 1
fi
if [[ -z "${dev}" || ! -b ${dev} ]]; then
echo "param 2 must be target block device"
exit 1
fi
echo "unmounting old partitions"
umount ${dev}*
sleep 1
dd if=/dev/zero of=${dev} bs=1M count=16 iflag=fullblock
sleep 1
echo "creating partitions"
parted ${dev} --script mktable msdos
parted ${dev} --script mkpart primary fat16 1MiB 3GiB
parted ${dev} --script mkpart primary ext4 3GiB 100%
parted ${dev} --script set 1 boot on
echo "syncing and probing new paritions"
sync
partprobe
sleep 1
echo "creating file systems"
mkfs.vfat -n LIVE ${dev}1
mkfs.ext4 -m 0 -F -O ^64bit -L persistence -E lazy_itable_init=0,lazy_journal_init=0 ${dev}2
echo "creating temporary mount locations"
tmp=$(mktemp --tmpdir --directory debianlive.XXXXX)
tmplive=${tmp}/live
tmppersistence=${tmp}/persistence
tmpiso=${tmp}/iso
tmpall="${tmplive} ${tmppersistence} ${tmpiso}"
echo "mounting resources"
mkdir ${tmpall}
mount ${dev}1 ${tmplive}
mount ${dev}2 ${tmppersistence}
mount -oro ${iso} ${tmpiso}
echo "copying iso image filesystem contents"
cp -ar ${tmpiso}/* ${tmplive}
sync
echo "creating persistence.conf"
echo "/ union" > ${tmppersistence}/persistence.conf
# Firefox cache in tmpfs
echo "forcing Firefox to have it's cache in tmpfs"
# https://askubuntu.com/questions/12098/what-does-outputting-to-dev-null-accomplish-in-bash-scripts
if [ `id -u user 2>&1 | grep "no such user" |wc -c` -eq 0 ]; then
echo ""
echo "The user \"user\" exists on this system."
echo ""
mkdir -p ${tmppersistence}/rw/home/user/.cache/
sync
sleep 1
# This is the command for which we need so many others for "user"
ln -s /tmp ${tmppersistence}/rw/home/user/.cache/mozilla
sync
sleep 1
chown -R user ${tmppersistence}/rw/home/user/
chgrp -R user ${tmppersistence}/rw/home/user/
sync
else
echo ""
echo "The user \"user\" does not exist on this system. Add and remove required."
echo ""
# https://www.cyberciti.biz/tips/howto-write-shell-script-to-add-user.html
# perl -e 'print crypt("live", "salt"),"\n"'
# https://wiki.archlinux.org/index.php/users_and_groups
# this automatically also adds the group "user", password is "live"
useradd -m -p sa/dqaR.MHunQ user
sync
sleep 1
mkdir -p ${tmppersistence}/rw/home/user/.cache/
# This is the command for which we need so many others for "user"
ln -s /tmp ${tmppersistence}/rw/home/user/.cache/mozilla
chown -R user ${tmppersistence}/rw/home/user/
chgrp -R user ${tmppersistence}/rw/home/user/
sync
sleep 1
# this automatically also removes the group "user"
userdel -r user
sync
fi
echo "installing grub"
grub-install --target=i386-pc --boot-directory=${tmplive}/boot/ ${dev}
echo "installing syslinux"
dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr/mbr.bin of=${dev}
syslinux --install ${dev}1
echo "fixing isolinux folder/files"
mv ${tmplive}/isolinux ${tmplive}/syslinux
mv ${tmplive}/syslinux/isolinux.bin ${tmplive}/syslinux/syslinux.bin
mv ${tmplive}/syslinux/isolinux.cfg ${tmplive}/syslinux/syslinux.cfg
echo "fixing grub splash screen"
sed --in-place 's#isolinux/splash#syslinux/splash#' ${tmplive}/boot/grub/grub.cfg
echo "configuring persistence kernel parameter"
sed --in-place '0,/boot=live/{s/\(boot=live .*\)$/\1 persistence/}' ${tmplive}/boot/grub/grub.cfg ${tmplive}/syslinux/menu.cfg
echo "setting timeout of 5 seconds"
echo "" >> ${tmplive}/boot/grub/grub.cfg
echo "set timeout=5" >> ${tmplive}/boot/grub/grub.cfg
echo "" >> ${tmplive}/boot/grub/grub.cfg
sed --in-place 's#timeout 0#timeout 50#' ${tmplive}/syslinux/syslinux.cfg
echo "configuring keyboard layout and locales"
# http://debian-live.alioth.debian.org/live-manual/stable/manual/html/live-manual.en.html
# egrep -i '(^!|english)' /usr/share/X11/xkb/rules/base.lst
sed --in-place '0,/boot=live/{s/\(boot=live .*\)$/\1 keyboard-layouts=us locales=en_US.UTF-8,ro_RO.UTF-8/}' ${tmplive}/boot/grub/grub.cfg ${tmplive}/syslinux/menu.cfg
echo "cleaning up"
umount ${tmpall}
rmdir ${tmpall} ${tmp}
You can’t perform that action at this time.