Guest User

Untitled

a guest
Oct 8th, 2020
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. rescue_shell() {
  4. echo "$@"
  5. echo "Dropping to a shell."
  6. exec /bin/sh
  7. }
  8.  
  9. mount_boot() {
  10. mount -o rw /dev/mmcblk0p1 /mnt/boot
  11. }
  12.  
  13. mount_root() {
  14. for cmd in $(cat /proc/cmdline) ; do
  15. case $cmd in
  16. root=*)
  17. type=$(echo $cmd | cut -d= -f2)
  18. echo "Mounting rootfs"
  19. if [ $type == "LABEL" ] || [ $type == "UUID" ]; then # PARTUUID ?
  20. uuid=$(echo $cmd | cut -d= -f3)
  21. mount -o rw $(findfs "$type"="$uuid") /mnt/root
  22. else # mount like /dev/sda1
  23. mount -o rw $(echo $cmd | cut -d= -f2) /mnt/root
  24. fi
  25. ;;
  26. esac
  27. done
  28. }
  29.  
  30. load_network() {
  31. ifup -a
  32. ip=`ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*'`
  33. echo "IP: $ip"
  34. }
  35.  
  36. # temporarily mount proc and sys
  37. mount -t proc none /proc
  38. mount -t sysfs none /sys
  39. mount -t devtmpfs none /dev
  40.  
  41. # disable kernel messages from popping onto the screen
  42. echo 0 > /proc/sys/kernel/printk
  43.  
  44. # clear the screen
  45. clear
  46.  
  47. echo "Recovery Mode"
  48. echo "Waiting for disks..."
  49. sleep 5
  50. echo "Disks ready!"
  51.  
  52. load_network
  53.  
  54. /bin/hello_try
  55.  
  56. # mounting boot on /mnt/boot
  57. mount_boot || rescue_shell "Error while boot mounting!"
  58. # mounting rootfs on /mnt/root
  59. mount_root || rescue_shell "Error while root mounting!"
  60.  
  61. #ln -s /mnt/root/etc/fstab /etc/fstab
  62.  
  63. echo "All done. Trying to boot..."
  64.  
  65. rescue_shell # debug only
  66.  
  67. # clean up. The init process will remount proc sys and dev later
  68. umount /proc
  69. umount /sys
  70. umount /dev
  71.  
  72. # switch to the real root and execute init
  73. exec switch_root /mnt/root /sbin/init
  74.  
RAW Paste Data