logo

live-bootstrap

Mirror of <https://github.com/fosslinux/live-bootstrap>

make_bootable.sh (1901B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2024 Gábor Stefanik <netrolller.3d@gmail.com>
  3. #
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. # find the physical disk name
  6. PHYSICAL=${DISK}
  7. # take care of e.g. "sda1"
  8. if echo "${DISK}" | grep -Eq '^[a-z]{3}[0-9]+$'
  9. then
  10. PHYSICAL=$(echo "${DISK}" | sed -E 's/^([a-z]{3})[0-9]+$/\1/')
  11. fi
  12. # take care of e.g. "mmcblk0p1"
  13. if echo "${DISK}" | grep -Eq '^[a-z0-9]{3,}p[0-9]+$'
  14. then
  15. PHYSICAL=$(echo "${DISK}" | sed -E 's/^([a-z0-9]{3,})p[0-9]+$/\1/')
  16. fi
  17. grub-install "/dev/${PHYSICAL}"
  18. cat > /boot/grub/grub.cfg <<- EOF
  19. set timeout=5
  20. set default=0
  21. menuentry 'Linux live-bootstrap' {
  22. insmod part_msdos
  23. set root='$(grub-probe -d /dev/${DISK} -t bios_hints | sed -e 's/ //g')'
  24. set gfxpayload=auto
  25. linux /boot/vmlinuz root=/dev/${DISK} rootwait rw $(cat /proc/cmdline)
  26. }
  27. EOF
  28. cat > /init <<- 'EOF'
  29. #!/usr/bin/bash
  30. cd /steps
  31. . ./bootstrap.cfg
  32. . ./env
  33. . ./helpers.sh
  34. trap 'env PATH=${PREFIX}/bin PS1="[TRAP] \w # " bash -i' ERR
  35. # /dev is automounted by the kernel at this point
  36. mount | grep '/proc' &> /dev/null || (mkdir -p /proc; mount -t proc proc /proc)
  37. mount | grep '/sys' &> /dev/null || (mkdir -p /sys; mount -t sysfs sysfs /sys)
  38. # Make /tmp a ramdisk (speeds up configure etc significantly)
  39. mount | grep '/tmp' &> /dev/null || (mkdir -p /tmp; mount -t tmpfs tmpfs /tmp)
  40. mount | grep '/dev/shm' &> /dev/null || (mkdir -p /dev/shm; mount -t tmpfs tmpfs /dev/shm)
  41. if test -f /swapfile; then
  42. swapon /swapfile
  43. fi
  44. if [ "${CHROOT}" = False ]; then
  45. dhcpcd --waitip=4
  46. fi
  47. env - PATH=${PREFIX}/bin PS1="\w # " setsid openvt -fec1 -- bash -i
  48. # ignore errors due to fstab or swapfile not existing
  49. swapoff -a &> /dev/null || true
  50. sync
  51. # sysrq to avoid device busy; then mount to wait for it to finish
  52. echo u > /proc/sysrq-trigger
  53. mount -o remount,ro /
  54. echo o > /proc/sysrq-trigger # power off
  55. while true; do sleep 1; done
  56. EOF
  57. chmod +x /init