live_hook 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/bash
  2. # See: https://gitlab.com/tearch-linux/applications-and-tools/mkinitcpio-teaiso
  3. live_mount(){
  4. mkdir -p /pisi/a # upper
  5. mkdir -p /pisi/b # workdir
  6. mkdir -p /live_root/
  7. mkdir -p /new_root/
  8. mkdir -p /source/ # lower
  9. mount $root /new_root/ 2> /dev/null
  10. mount /new_root/live/pisi.sfs /source/ 2> /dev/null
  11. mount -t overlay -o lowerdir=/source/,upperdir=/pisi/a/,workdir=/pisi/b overlay /live_root
  12. mount -t tmpfs -o size=100% none /pisi/a
  13. mount -t tmpfs -o size=100% none /pisi/b
  14. [ -d /source/merge/ ] && cp -prfv /source/merge/* /live_root/
  15. mount --bind /live_root /new_root/
  16. mkdir /new_root/cdrom/ 2> /dev/null
  17. mkdir /new_root/source/ 2> /dev/null
  18. mount $root /new_root/cdrom/ 2> /dev/null
  19. mount /new_root/cdrom/live/pisi.sfs /new_root/source/ 2> /dev/null
  20. [ "$home" != "" ] && mount $home /new_root/home 2>/dev/null
  21. }
  22. is_file_avaiable(){
  23. disktmp=$(mktemp)
  24. rm -f $disktmp
  25. mkdir -p $disktmp || true
  26. timeout 10 mount -t auto "$1" $disktmp &>/dev/null
  27. [ -f "$disktmp/$2" ] && [ -b "$1" ]
  28. status=$?
  29. umount -lf $disktmp 2>/dev/null
  30. return $status
  31. }
  32. run_hook() {
  33. # live-boot
  34. if cat /proc/cmdline | grep "boot=live" >/dev/null ; then
  35. while [ "$root" == "" ] ; do
  36. list=$(ls /sys/class/block/ | grep ".*[0-9]$" | grep -v loop | grep -v ram | grep -v nbd | grep -v fd | sed "s|^|/dev/|g")
  37. for part in $list
  38. do
  39. sleep 0.1
  40. echo "Looking for: $part"
  41. if is_file_avaiable "$part" "/live/pisi.sfs"
  42. then
  43. export root=$part
  44. elif is_file_avaiable "$part" "/mount-me"
  45. then
  46. export home=$part
  47. fi
  48. done
  49. done
  50. export mount_handler="live_mount"
  51. fi
  52. }
  53. run_latehook(){
  54. if ! cat /proc/cmdline | grep "init=" ; then
  55. export init=/sbin/init
  56. fi
  57. sleep 0.3
  58. }