Last active
October 26, 2020 18:28
-
-
Save ynezz/ddeef9ffe6e3ce6db8d9f3b451bce37e to your computer and use it in GitHub Desktop.
UEFI + BIOS bootable live Debian with persistence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
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 | |
if [[ "${dev}" =~ ^.*[0-9]$ ]]; then | |
echo "target block device should be device, not a partition (must not end with digit)" | |
exit 1 | |
fi | |
echo "unmounting old partitions" | |
umount ${dev}* | |
lsblk ${dev} | |
echo "This will destroy data on ${dev}. Ctrl+C now if unsure! Press [Enter] to continue..." | |
read | |
echo "creating partitions" | |
parted ${dev} --script mktable gpt | |
parted ${dev} --script mkpart EFI fat16 1MiB 10MiB | |
parted ${dev} --script mkpart live fat16 10MiB 3GiB | |
parted ${dev} --script mkpart persistence ext4 3GiB 100% | |
parted ${dev} --script set 1 msftdata on | |
parted ${dev} --script set 2 legacy_boot on | |
parted ${dev} --script set 2 msftdata on | |
echo "syncing and probing new paritions" | |
sync | |
partprobe | |
echo "creating file systems" | |
mkfs.vfat -n EFI ${dev}1 | |
mkfs.vfat -n LIVE ${dev}2 | |
mkfs.ext4 -F -L persistence ${dev}3 | |
echo "creating temporary mount locations" | |
tmp=$(mktemp --tmpdir --directory debianlive.XXXXX) | |
tmpefi=${tmp}/efi | |
tmplive=${tmp}/live | |
tmppersistence=${tmp}/persistence | |
tmpiso=${tmp}/iso | |
tmpall="${tmpefi} ${tmplive} ${tmppersistence} ${tmpiso}" | |
echo "mounting resources" | |
mkdir ${tmpall} | |
mount ${dev}1 ${tmpefi} | |
mount ${dev}2 ${tmplive} | |
mount ${dev}3 ${tmppersistence} | |
mount -oro ${iso} ${tmpiso} | |
echo "copying iso image filesystem contents" | |
cp -ar ${tmpiso}/* ${tmpiso}/.disk ${tmplive} | |
sync | |
echo "creating persistence.conf" | |
echo "/ union" > ${tmppersistence}/persistence.conf | |
echo "installing grub" | |
grub-install --removable --target=x86_64-efi --boot-directory=${tmplive}/boot/ --efi-directory=${tmpefi} ${dev} | |
echo "installing syslinux" | |
dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/gptmbr.bin of=${dev} | |
syslinux --install ${dev}2 | |
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 kernel parameter" | |
sed --in-place '0,/boot=live/{s/\(boot=live .*\)$/\1 persistence apm=off nouveau.runpm=0/}' ${tmplive}/boot/grub/grub.cfg ${tmplive}/syslinux/menu.cfg | |
echo "cleaning up" | |
umount ${tmpall} | |
rmdir ${tmpall} ${tmp} | |
echo "sync'ing so that cached writes to USB stick are written" | |
sync | |
echo "USB stick is ready" |
I have made a yad-based enhancement on this script, and it will eventually end up here: https://github.com/linuxuser42/dabien
Main feature is that it is sending most conversation out via yad - i.e. windows based dialogs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From https://unix.stackexchange.com/questions/382817/uefi-bios-bootable-live-debian-stretch-amd64-with-persistence/382818