Advertisement
Guest User

Skeleton /init for minimal initramfs

a guest
Jan 30th, 2017
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #!/command/execlineb -S0
  2.  
  3. # Skeleton /init for minimal initramfs.
  4. # (C) 2016-2017 Laurent Bercot, wtfpl license.
  5.  
  6. /command/export PATH /command
  7. /command/cd /
  8. if { s6-echo "\n initramfs (minimal)\n" }
  9.  
  10. if { s6-mount -wt sysfs sys /sys }
  11. if { s6-mount -wt proc proc /proc }
  12.  
  13. # Just in case the kernel config says not to mount devtmpfs at boot
  14. foreground { redirfd -w 2 /dev/null s6-mount -wt devtmpfs dev /dev }
  15.  
  16. # If you need to manually load modules, do it here, but in some cases the
  17. # coldplug will initiate request_module() actions, so depending on the
  18. # hardware you're expecting, you could have a /sbin/modprobe and a
  19. # /etc/mdev.conf with a MODALIAS definition instead.
  20. # If you have hardware with weird /sys definitions, or expect
  21. # specific /dev devices, you should definitely have an appropriate
  22. # /etc/mdev.conf anyway.
  23.  
  24. if { redirfd -w 1 /proc/sys/kernel/hotplug s6-echo /sbin/mdev }
  25. if { /sbin/mdev -s } # coldplug
  26. if { redirfd -w 1 /proc/sys/kernel/hotplug s6-echo }
  27.  
  28. # Coldplug done, you have a snapshot of your hardware in /dev.
  29. # Now you need to name your rootfs and its type; you can hardcode them
  30. # like it's done here, or substitute ROOTFS and ROOTFSTYPE with the
  31. # result of your rootfs detection.
  32.  
  33. define ROOTFS sda1 # Replace with your own
  34. define ROOTFSTYPE ext4 # detection routines!
  35.  
  36. if { s6-mount -rt ${ROOTFSTYPE} /dev/${ROOTFS} /rootfs }
  37.  
  38. if { s6-mount -o move /sys /rootfs/sys }
  39. if { s6-mount -o move /proc /rootfs/proc }
  40. if { s6-mount -o move /dev /rootfs/dev }
  41.  
  42. cd /rootfs
  43.  
  44. # OK, all done. Now we're going to delete everything in the initramfs,
  45. # so we're relying on binaries existing in the rootfs to do our job
  46. # in order to avoid sweeping the rug off our own feet.
  47. # You could use busybox's switch_root instead, but you'll still
  48. # have to rely on binaries existing on the rootfs after you
  49. # chroot into it.
  50.  
  51. ./command/if
  52. {
  53. ./command/pipeline { ./command/s6-ls -a -x rootfs / }
  54. ./command/forstdin -p -d"\n" i
  55. ./command/importas -u i i
  56. ./command/s6-rmrf /${i}
  57. }
  58. ./command/if { ./command/s6-mount -o move . / }
  59. ./command/s6-chroot .
  60.  
  61. /command/unexport ?
  62. /command/unexport PATH
  63. /command/tryexec { /sbin/init $@ }
  64. /command/tryexec { /bin/init $@ }
  65. /etc/init $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement