eibo

initramfs script

Feb 21st, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.60 KB | None | 0 0
  1. #!/bin/busybox sh
  2.  
  3. echo "Loading, please wait..."
  4.  
  5. # /bin/mount, otherwise busybox builtin would get used
  6. echo -n "Mounting /sys and /proc..."
  7. /bin/mount -t sysfs -o nodev,noexec,nosuid none /sys
  8. /bin/mount -t proc -o nodev,noexec,nosuid none /proc
  9. echo "Done."
  10.  
  11. # Export relevant variables
  12. export TARGET=/root
  13.  
  14. echo -n "Loading essential drivers..."
  15. if [ -e /etc/modules ]; then
  16.     cat /etc/modules | while read m; do
  17.         # Skip empty lines
  18.         if [ -z "$m" ];  then
  19.             continue
  20.         fi
  21.         # Skip comments - d?ash removes whitespace prefix
  22.         com=$(printf "%.1s" "${m}")
  23.         if [ "$com" = "#" ]; then
  24.             continue
  25.         fi
  26.         modprobe $m
  27.     done
  28. fi
  29. echo "Done."
  30.  
  31. # pxelinux sets BOOTIF to 01-??-??-??-??-??-?? (MAC)
  32. bootif_mac=""
  33. IFS='-'
  34. for x in ${BOOTIF} ; do
  35.     bootif_mac="$bootif_mac:$x"
  36. done
  37. unset IFS
  38. bootif_mac=${bootif_mac#:*:}
  39.  
  40. # find DEVICE to bootif_mac
  41. for device in /sys/class/net/* ; do
  42.     if [ -f "$device/address" ]; then
  43.         current_mac=$(cat "$device/address")
  44.         if [ "$bootif_mac" = "$current_mac" ]; then
  45.             DEVICE=${device##*/}
  46.             break
  47.         fi
  48.     fi
  49. done
  50.  
  51. echo "Starting network..."
  52.  
  53. # Loopback
  54. ifconfig lo up
  55.  
  56. # Ethernet
  57. ifconfig ${DEVICE} up
  58.  
  59. # DHCP
  60. udhcpc -i ${DEVICE} -q -s /sbin/setup-net
  61.  
  62. # source output of script /sbin/setup-net (HOSTNAME, SERVER)
  63. . /tmp/net.conf
  64.  
  65. echo "Network Done."
  66.  
  67. echo -n "Mounting root file system..."
  68.  
  69. NFSOPTS="nfsvers=3,udp,nolock,retrans=10"
  70.  
  71. # mount the xino dir
  72. /bin/mount -t tmpfs -o size=16M none /aufs/xino
  73.  
  74. # mount the clients specific dir
  75. /bin/mount -t nfs -o rw,${NFSOPTS} ${SERVER}:/target/export/${HOSTNAME} /aufs/private
  76.  
  77. # mount the clients general dir
  78. /bin/mount -t nfs -o ro,${NFSOPTS} ${SERVER}:/target/export/clients /aufs/clients
  79.  
  80. # mount the server root dir
  81. /bin/mount -t nfs -o ro,${NFSOPTS} ${SERVER}:/target/ /aufs/server
  82.  
  83. # do the union
  84. /bin/mount -t aufs -o noplink,xino=/aufs/xino/root,dirs=/aufs/private=rw:/aufs/clients=ro+wh:/aufs/server=ro none ${TARGET}
  85.  
  86. echo "Done."
  87.  
  88. # Kludge for strange aufs behaviour
  89. # whithout this, mounted directories will be lost on command-completion
  90. # don't ask me why this works
  91. echo "ls /root > /dev/null"
  92.  
  93. /bin/mount --move /aufs/xino ${TARGET}/aufs/xino
  94. /bin/mount --move /aufs/private ${TARGET}/aufs/private
  95. /bin/mount --move /aufs/clients ${TARGET}/aufs/clients
  96. /bin/mount --move /aufs/server ${TARGET}/aufs/server
  97.  
  98. # Move virtual filesystems over to the real filesystem
  99. /bin/mount --move /sys ${TARGET}/sys
  100. /bin/mount --move /proc ${TARGET}/proc
  101.  
  102. # Chain to real filesystem
  103. exec /bin/run-init ${TARGET} /sbin/init "$@" <${TARGET}/dev/console >${TARGET}/dev/console
Advertisement
Add Comment
Please, Sign In to add comment