Advertisement
tourloupis

'local' file for generating initramfs image

Dec 29th, 2014
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.41 KB | None | 0 0
  1. # Local filesystem mounting         -*- shell-script -*-
  2.  
  3. pre_mountroot()
  4. {
  5.     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
  6.     run_scripts /scripts/local-top
  7.     [ "$quiet" != "y" ] && log_end_msg
  8.  
  9.     # Don't wait for a root device that doesn't have a corresponding
  10.     # device in /dev (ie, mtd0)
  11.     if [ "${ROOT#/dev}" = "${ROOT}" ]; then
  12.         return
  13.     fi
  14.  
  15.     while [ -z "${FSTYPE}" ]; do
  16.         FSTYPE=$(wait-for-root "${ROOT}" ${ROOTDELAY:-30})
  17.  
  18.         # Load ubi with the correct MTD partition and return since
  19.         # fstype doesn't work with a char device like ubi.
  20.         if [ -n "$UBIMTD" ]; then
  21.             modprobe ubi mtd=$UBIMTD
  22.             return
  23.         fi
  24.  
  25.         # Run failure hooks, hoping one of them can fix up the system
  26.         # and we can restart the wait loop.  If they all fail, abort
  27.         # and move on to the panic handler and shell.
  28.         if [ -z "${FSTYPE}" ] && ! try_failure_hooks; then
  29.             break
  30.         fi
  31.     done
  32.  
  33.     # We've given up, but we'll let the user fix matters if they can
  34.     while [ -z "${FSTYPE}" -a ! -e "${ROOT}" ]; do
  35.         # give hint about renamed root
  36.         case "${ROOT}" in
  37.         /dev/hd*)
  38.             suffix="${ROOT#/dev/hd}"
  39.             major="${suffix%[[:digit:]]}"
  40.             major="${major%[[:digit:]]}"
  41.             if [ -d "/sys/block/sd${major}" ]; then
  42.                 echo "WARNING bootdevice may be renamed. Try root=/dev/sd${suffix}"
  43.             fi
  44.             ;;
  45.         /dev/sd*)
  46.             suffix="${ROOT#/dev/sd}"
  47.             major="${suffix%[[:digit:]]}"
  48.             major="${major%[[:digit:]]}"
  49.             if [ -d "/sys/block/hd${major}" ]; then
  50.                 echo "WARNING bootdevice may be renamed. Try root=/dev/hd${suffix}"
  51.             fi
  52.             ;;
  53.         esac
  54.         echo "Gave up waiting for root device.  Common problems:"
  55.         echo " - Boot args (cat /proc/cmdline)"
  56.         echo "   - Check rootdelay= (did the system wait long enough?)"
  57.         echo "   - Check root= (did the system wait for the right device?)"
  58.         echo " - Missing modules (cat /proc/modules; ls /dev)"
  59.         panic "ALERT!  ${ROOT} does not exist.  Dropping to a shell!"
  60.     done
  61. }
  62.  
  63. mountroot()
  64. {
  65.     pre_mountroot
  66.  
  67.     # Get the root filesystem type if not set
  68.     if [ -z "${ROOTFSTYPE}" ]; then
  69.         [ -n "${FSTYPE}" ] || FSTYPE=$(blkid -s TYPE -o value "${ROOT}")
  70.         ROOTFSTYPE="${FSTYPE}"
  71.     else
  72.         FSTYPE=${ROOTFSTYPE}
  73.     fi
  74.  
  75.     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
  76.     run_scripts /scripts/local-premount
  77.     [ "$quiet" != "y" ] && log_end_msg
  78.  
  79.     if [ "${readonly}" = "y" ] && \
  80.        [ -z "$LOOP" ]; then
  81.         roflag=-r
  82.     else
  83.         roflag=-w
  84.     fi
  85.  
  86.     # FIXME This has no error checking
  87.     [ -n "${FSTYPE}" ] && modprobe ${FSTYPE}
  88.  
  89.     # FIXME This has no error checking
  90.     # Mount root
  91.     mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt}
  92.     mountroot_status="$?"
  93.     if [ "$LOOP" ]; then
  94.         if [ "$mountroot_status" != 0 ]; then
  95.             if [ ${FSTYPE} = ntfs ] || [ ${FSTYPE} = vfat ]; then
  96.                 panic "
  97. Could not mount the partition ${ROOT}.
  98. This could also happen if the file system is not clean because of an operating
  99. system crash, an interrupted boot process, an improper shutdown, or unplugging
  100. of a removable device without first unmounting or ejecting it.  To fix this,
  101. simply reboot into Windows, let it fully start, log in, run 'chkdsk /r', then
  102. gracefully shut down and reboot back into Windows. After this you should be
  103. able to reboot again and resume the installation.
  104. (filesystem = ${FSTYPE}, error code = $mountroot_status)
  105. "
  106.             fi
  107.         fi
  108.    
  109.         mkdir -p /host
  110.         mount -o move ${rootmnt} /host
  111.  
  112.         while [ ! -e "/host/${LOOP#/}" ]; do
  113.             panic "ALERT!  /host/${LOOP#/} does not exist.  Dropping to a shell!"
  114.         done
  115.  
  116.         # Get the loop filesystem type if not set
  117.         if [ -z "${LOOPFSTYPE}" ]; then
  118.             eval $(fstype < "/host/${LOOP#/}")
  119.         else
  120.             FSTYPE="${LOOPFSTYPE}"
  121.         fi
  122.         if [ "$FSTYPE" = "unknown" ] && [ -x /sbin/blkid ]; then
  123.             FSTYPE=$(/sbin/blkid -s TYPE -o value "/host/${LOOP#/}")
  124.             [ -z "$FSTYPE" ] && FSTYPE="unknown"
  125.         fi
  126.  
  127.         if [ ${readonly} = y ]; then
  128.             roflag=-r
  129.         else
  130.             roflag=-w
  131.         fi
  132.  
  133.         # FIXME This has no error checking
  134.         modprobe loop
  135.         modprobe ${FSTYPE}
  136.  
  137.         # FIXME This has no error checking
  138.         # mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} "/host/${LOOP#/}" ${rootmnt}
  139.         loopdev=`losetup -f`
  140.         losetup ${loopdev} "/host/${LOOP#/}"
  141.         mount ${roflag} -t ${FSTYPE} ${LOOPFLAGS} ${loopdev} ${rootmnt}
  142.  
  143.         if [ -d ${rootmnt}/host ]; then
  144.             mount -o move /host ${rootmnt}/host
  145.         fi
  146.     fi
  147.  
  148.     [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
  149.     run_scripts /scripts/local-bottom
  150.     [ "$quiet" != "y" ] && log_end_msg
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement