Share Pastebin
Guest
Public paste!

electronjunkie

By: a guest | Mar 4th, 2009 | Syntax: None | Size: 4.68 KB | Hits: 55 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. # Local filesystem mounting                     -*- shell-script -*-
  2. #
  3. ################################################################
  4. # File:
  5. # /scripts/local
  6. #
  7. # Root, or / in these notes is the initrd's (busybox) root,
  8. # not your system's root!
  9. #
  10. # You need the aufs module for this to work.  To do this install
  11. # aufs on your base install, add aufs to: /etc/initramfs-tools/modules
  12. # Now using your target kernel run:
  13. # mkinitramfs -o initrd.img <kernel-name>
  14. #
  15. # make a directory, copy an initrd to it then cd to it and:
  16. #
  17. # mv initrd.img initrd.img.gz
  18. # gunzip initrd.img.gz
  19. #
  20. # make sure aufs exists somewhere in /lib/modules/<uname -r>/
  21. # After modifying local script, etc do the following in the initrd's
  22. # root folder where /bin and /lib etc is to create a new initrd:
  23. #
  24. # find ./ -print | cpio -H newc -o > ../newinitrd.img
  25. #
  26. # Now tell grub to use this initrd for a RO root filesystem
  27. ################################################################
  28. # Parameter: device node to check
  29. # Echos fstype to stdout
  30. # Return value: indicates if an fs could be recognized
  31. get_fstype ()
  32. {
  33.         local FS FSTYPE FSSIZE RET
  34.         FS="${1}"
  35.  
  36.         # vol_id has a more complete list of file systems,
  37.         # but fstype is more robust
  38.         eval $(fstype "${FS}" 2> /dev/null)
  39.         if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then
  40.                 FSTYPE=$(/lib/udev/vol_id -t "${FS}" 2> /dev/null)
  41.         fi
  42.         RET=$?
  43.  
  44.         if [ -z "${FSTYPE}" ]; then
  45.                 FSTYPE="unknown"
  46.         fi
  47.  
  48.         echo "${FSTYPE}"
  49.         return ${RET}
  50. }
  51.  
  52. # Parameter: Where to mount the filesystem
  53. mountroot ()
  54. {
  55.         [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
  56.         run_scripts /scripts/local-top
  57.         [ "$quiet" != "y" ] && log_end_msg
  58.  
  59.         wait_for_udev 10
  60.  
  61.         # If the root device hasn't shown up yet, give it a little while
  62.         # to deal with removable devices
  63.         if [ ! -e "${ROOT}" ] || ! $(get_fstype "${ROOT}" >/dev/null); then
  64.                 log_begin_msg "Waiting for root file system"
  65.  
  66.                 # Default delay is 180s
  67.                 if [ -z "${ROOTDELAY}" ]; then
  68.                         slumber=180
  69.                 else
  70.                         slumber=${ROOTDELAY}
  71.                 fi
  72.                 if [ -x /sbin/usplash_write ]; then
  73.                         /sbin/usplash_write "TIMEOUT ${slumber}" || true
  74.                 fi
  75.  
  76.                 slumber=$(( ${slumber} * 10 ))
  77.                 while [ ! -e "${ROOT}" ] \
  78.                 || ! $(get_fstype "${ROOT}" >/dev/null); do
  79.                         /bin/sleep 0.1
  80.                         slumber=$(( ${slumber} - 1 ))
  81.                         [ ${slumber} -gt 0 ] || break
  82.                 done
  83.  
  84.                 if [ ${slumber} -gt 0 ]; then
  85.                         log_end_msg 0
  86.                 else
  87.                         log_end_msg 1 || true
  88.                 fi
  89.                 if [ -x /sbin/usplash_write ]; then
  90.                         /sbin/usplash_write "TIMEOUT 15" || true
  91.                 fi
  92.         fi
  93.  
  94.         # We've given up, but we'll let the user fix matters if they can
  95.         while [ ! -e "${ROOT}" ]; do
  96.                 # give hint about renamed root
  97.                 case "${ROOT}" in
  98.                 /dev/hd*)
  99.                         suffix="${ROOT#/dev/hd}"
  100.                         major="${suffix%[[:digit:]]}"
  101.                         major="${major%[[:digit:]]}"
  102.                         if [ -d "/sys/block/sd${major}" ]; then
  103.                                 echo "WARNING bootdevice may be renamed. Try root=/dev/sd${suffix}"
  104.                         fi
  105.                         ;;
  106.                 /dev/sd*)
  107.                         suffix="${ROOT#/dev/sd}"
  108.                         major="${suffix%[[:digit:]]}"
  109.                         major="${major%[[:digit:]]}"
  110.                         if [ -d "/sys/block/hd${major}" ]; then
  111.                                 echo "WARNING bootdevice may be renamed. Try root=/dev/hd${suffix}"
  112.                         fi
  113.                         ;;
  114.                 esac
  115.                 echo "Gave up waiting for root device.  Common problems:"
  116.                 echo " - Boot args (cat /proc/cmdline)"
  117.                 echo "   - Check rootdelay= (did the system wait long enough?)"
  118.                 echo "   - Check root= (did the system wait for the right device?)"
  119.                 echo " - Missing modules (cat /proc/modules; ls /dev)"
  120.                 panic "ALERT!  ${ROOT} does not exist.  Dropping to a shell!"
  121.         done
  122.  
  123.         # Get the root filesystem type if not set
  124.         if [ -z "${ROOTFSTYPE}" ]; then
  125.                 FSTYPE=$(get_fstype "${ROOT}")
  126.         else
  127.                 FSTYPE=${ROOTFSTYPE}
  128.         fi
  129.  
  130.         [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
  131.         run_scripts /scripts/local-premount
  132.         [ "$quiet" != "y" ] && log_end_msg
  133.  
  134.         if [ "${readonly}" = "y" ]; then
  135.                 roflag=-r
  136.         else
  137.                 roflag=-w
  138.         fi
  139.  
  140.         # FIXME This has no error checking
  141.  
  142.         modprobe ${FSTYPE}
  143. ##########################################################################
  144. ###### Mod'd by Brian Phelps aka Electronjunkie ##########################
  145.  
  146.          mkdir /root/.tmpfs
  147.          mkdir /root/.rootfs
  148.  
  149.          mount -r -t ext2 /dev/sda1 /root/.rootfs
  150.  
  151.          modprobe aufs
  152.          modprobe loop
  153.          mount -t tmpfs -o size=20M tmpfs /root/.tmpfs
  154.  
  155.          mount -t aufs  -o br:/root/.tmpfs=rw:/root/.rootfs=ro none /root/
  156.          mv /root/etc/fstab /root/etc/fstab.defunct
  157.  
  158. #########################################################################
  159.  
  160.         # FIXME This has no error checking
  161.         # Mount root
  162.  
  163.         [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
  164.         run_scripts /scripts/local-bottom
  165.         [ "$quiet" != "y" ] && log_end_msg
  166. }