Advertisement
Guest User

init_2013.02.16

a guest
Feb 16th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.31 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. . /etc/initrd.defaults
  4. . /etc/initrd.scripts
  5.  
  6. splash() {
  7. return 0
  8. }
  9.  
  10. [ -e /etc/initrd.splash ] && . /etc/initrd.splash
  11.  
  12. # Clean input/output
  13. exec >${CONSOLE} <${CONSOLE} 2>&1
  14.  
  15. if [ "$$" != '1' ]
  16. then
  17. echo '/linuxrc has to be run as the init process as the one'
  18. echo 'with a PID of 1. Try adding init="/linuxrc" to the'
  19. echo 'kernel command line or running "exec /linuxrc".'
  20. exit 1
  21. fi
  22.  
  23. mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1
  24. mount -o remount,rw / >/dev/null 2>&1
  25.  
  26. # Set up symlinks
  27. /bin/busybox --install -s
  28.  
  29. if [ "$0" = '/init' ]
  30. then
  31. [ -e /linuxrc ] && rm /linuxrc
  32. fi
  33.  
  34. quiet_kmsg
  35.  
  36. CMDLINE=$(cat /proc/cmdline)
  37. # Scan CMDLINE for any specified real_root= or cdroot arguments
  38. FAKE_ROOT=''
  39. FAKE_INIT=''
  40. REAL_ROOTFLAGS=''
  41. ROOTFSTYPE='auto'
  42. CRYPT_SILENT=0
  43.  
  44. mkdir -p /etc/cmdline /etc/modprobe.d
  45. for x in ${CMDLINE}
  46. do
  47. case "${x}" in
  48. real_root=*)
  49. REAL_ROOT=${x#*=}
  50. ;;
  51. root=*)
  52. FAKE_ROOT=${x#*=}
  53. ;;
  54. subdir=*)
  55. SUBDIR=${x#*=}
  56. ;;
  57. real_init=*)
  58. REAL_INIT=${x#*=}
  59. ;;
  60. init=*)
  61. FAKE_INIT=${x#*=}
  62. ;;
  63. init_opts=*)
  64. INIT_OPTS=${x#*=}
  65. ;;
  66. # Livecd options
  67. cdroot)
  68. CDROOT=1
  69. ;;
  70. cdroot=*)
  71. CDROOT=1
  72. CDROOT_DEV=${x#*=}
  73. ;;
  74. cdroot_type=*)
  75. CDROOT_TYPE=${x#*=}
  76. ;;
  77. cdroot_marker=*)
  78. CDROOT_MARKER=${x#*=}
  79. ;;
  80. # Start livecd loop, looptype options
  81. loop=*)
  82. LOOP=${x#*=}
  83. ;;
  84. looptype=*)
  85. LOOPTYPE=${x#*=}
  86. ;;
  87. isoboot=*)
  88. ISOBOOT=${x#*=}
  89. ;;
  90. # Start Volume manager options
  91. dolvm)
  92. USE_LVM_NORMAL=1
  93. ;;
  94. dolvm2)
  95. bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
  96. USE_LVM_NORMAL=1
  97. ;;
  98. domdadm)
  99. USE_MDADM=1
  100. ;;
  101. dodmraid)
  102. USE_DMRAID_NORMAL=1
  103. ;;
  104. dodmraid=*)
  105. DMRAID_OPTS=${x#*=}
  106. USE_DMRAID_NORMAL=1
  107. ;;
  108. domultipath)
  109. good_msg "Booting with multipath activated."
  110. USE_MULTIPATH_NORMAL=1
  111. ;;
  112. dozfs*)
  113. USE_ZFS=1
  114.  
  115. if [ "${x#*=}" = 'force' ]
  116. then
  117. ZPOOL_FORCE=-f
  118. fi
  119. ;;
  120. # Debug Options
  121. debug)
  122. DEBUG='yes'
  123. ;;
  124. # Scan delay options
  125. scandelay=*)
  126. SDELAY=${x#*=}
  127. ;;
  128. scandelay)
  129. SDELAY=3
  130. ;;
  131. # Module no-loads
  132. doload=*)
  133. MDOLIST=${x#*=}
  134. MDOLIST=$(echo ${MDOLIST} | sed -e 's/,/ /g')
  135. ;;
  136. nodetect)
  137. NODETECT=1
  138. ;;
  139. noload=*)
  140. MLIST=${x#*=}
  141. MLIST="$(echo ${MLIST} | sed -e 's/,/ /g')"
  142. export MLIST
  143. ;;
  144. # Redirect output to a specific tty
  145. CONSOLE=*|console=*)
  146. CONSOLE=${x#*=}
  147. CONSOLE=$(basename ${CONSOLE})
  148. # exec >${CONSOLE} <${CONSOLE} 2>&1
  149. ;;
  150. # /dev/md
  151. lvmraid=*)
  152. RAID_DEVICES="${x#*=}"
  153. RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e 's/,/ /g')"
  154. USE_LVM_NORMAL=1
  155. ;;
  156. part=*)
  157. MDPART=${x#*=}
  158. ;;
  159. # NFS
  160. ip=*)
  161. IP=${x#*=}
  162. ;;
  163. nfsroot=*)
  164. NFSROOT=${x#*=}
  165. ;;
  166. # iSCSI
  167. iscsi_initiatorname=*)
  168. ISCSI_INITIATORNAME=${x#*=}
  169. ;;
  170. iscsi_target=*)
  171. ISCSI_TARGET=${x#*=}
  172. ;;
  173. iscsi_tgpt=*)
  174. ISCSI_TGPT=${x#*=}
  175. ;;
  176. iscsi_address=*)
  177. ISCSI_ADDRESS=${x#*=}
  178. ;;
  179. iscsi_port=*)
  180. ISCSI_PORT=${x#*=}
  181. ;;
  182. iscsi_username=*)
  183. ISCSI_USERNAME=${x#*=}
  184. ;;
  185. iscsi_password=*)
  186. ISCSI_PASSWORD=${x#*=}
  187. ;;
  188. iscsi_username_in=*)
  189. ISCSI_USERNAME_IN=${x#*=}
  190. ;;
  191. iscsi_password_in=*)
  192. ISCSI_PASSWORD_IN=${x#*=}
  193. ;;
  194. iscsi_debug=*)
  195. ISCSI_DEBUG=${x#*=}
  196. ;;
  197. iscsi_noibft)
  198. ISCSI_NOIBFT=1
  199. ;;
  200. # Crypto
  201. crypt_root=*)
  202. CRYPT_ROOT=${x#*=}
  203. ;;
  204. crypt_swap=*)
  205. CRYPT_SWAP=${x#*=}
  206. ;;
  207. root_key=*)
  208. CRYPT_ROOT_KEY=${x#*=}
  209. ;;
  210. root_keydev=*)
  211. CRYPT_ROOT_KEYDEV=${x#*=}
  212. ;;
  213. root_trim=*)
  214. CRYPT_ROOT_TRIM=${x#*=}
  215. ;;
  216.  
  217. swap_key=*)
  218. CRYPT_SWAP_KEY=${x#*=}
  219. ;;
  220. swap_keydev=*)
  221. CRYPT_SWAP_KEYDEV=${x#*=}
  222. ;;
  223. real_resume=*|resume=*)
  224. REAL_RESUME=${x#*=}
  225. ;;
  226. noresume)
  227. NORESUME=1
  228. ;;
  229. crypt_silent)
  230. CRYPT_SILENT=1
  231. ;;
  232. real_rootflags=*)
  233. REAL_ROOTFLAGS=${x#*=}
  234. ;;
  235. rootfstype=*)
  236. ROOTFSTYPE=${x#*=}
  237. ;;
  238. keymap=*)
  239. keymap=${x#*=}
  240. ;;
  241. aufs)
  242. USE_AUFS_NORMAL=1
  243. ;;
  244. unionfs)
  245. if [ ! -x /sbin/unionfs ]
  246. then
  247. USE_UNIONFS_NORMAL=0
  248. bad_msg 'unionfs binary not found: aborting use of unionfs!'
  249. else
  250. USE_UNIONFS_NORMAL=1
  251. fi
  252. ;;
  253. nounionfs)
  254. USE_UNIONFS_NORMAL=0
  255. ;;
  256. *=*)
  257. case "${x%%=*}" in
  258. *.*)
  259. echo "${x#*.}" >> "/etc/module_options/${x%%.*}.conf"
  260. ;;
  261. esac
  262. ;;
  263. esac
  264. done
  265.  
  266. if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
  267. then
  268. REAL_ROOT="${FAKE_ROOT}"
  269. fi
  270. if [ -z "${REAL_INIT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_INIT}" != "/linuxrc" \) ]
  271. then
  272. REAL_INIT="${FAKE_INIT}"
  273. fi
  274.  
  275. # Set variables based on the value of REAL_ROOT
  276. case "${REAL_ROOT}" in
  277. ZFS=*)
  278. ZFS_POOL=${REAL_ROOT#*=}
  279. ZFS_POOL=${ZFS_POOL%%/*}
  280. USE_ZFS=1
  281. ;;
  282. ZFS)
  283. USE_ZFS=1
  284. ;;
  285. esac
  286.  
  287. # Verify that it is safe to use ZFS
  288. if [ "USE_ZFS" = "1" ]
  289. then
  290. if [ -x /sbin/zfs -a -x /sbin/zpool ]
  291. then
  292. MY_HWOPTS="${MY_HWOPTS} zfs"
  293. else
  294. USE_ZFS=0
  295.  
  296. [ -x /sbin/zfs ] || bad_msg '/sbin/zfs not found!'
  297. [ -x /sbin/zpool ] || bad_msg '/sbin/zpool not found!'
  298. bad_msg 'Aborting use of zfs!'
  299. fi
  300. fi
  301.  
  302. splash 'init'
  303.  
  304. cmdline_hwopts
  305.  
  306. # Mount devfs
  307. mount_devfs
  308.  
  309. # Mount sysfs
  310. mount_sysfs
  311.  
  312. # Initialize mdev
  313. if [ "${KV_2_6_OR_GREATER}" ]
  314. then
  315. good_msg 'Activating mdev'
  316.  
  317. # Serialize hotplug events
  318. touch /dev/mdev.seq
  319.  
  320. # Setup hotplugging for firmware loading
  321. echo /sbin/mdev > /proc/sys/kernel/hotplug
  322. fi
  323.  
  324. # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
  325. if [ -z "${DO_modules}" ]
  326. then
  327. good_msg 'Skipping module load; disabled via commandline'
  328. elif [ -d "/lib/modules/${KV}" ]
  329. then
  330. good_msg 'Loading modules'
  331. # Load appropriate kernel modules
  332. if [ "${NODETECT}" != '1' ]
  333. then
  334. for modules in ${MY_HWOPTS}
  335. do
  336. modules_scan ${modules}
  337. done
  338. fi
  339. # Always eval doload=...
  340. modules_load ${MDOLIST}
  341. else
  342. good_msg 'Skipping module load; no modules in the ramdisk!'
  343. fi
  344.  
  345. # Ensure that device nodes are properly configured
  346. if [ "${KV_2_6_OR_GREATER}" ]
  347. then
  348. mdev -s || bad_msg "mdev -s failed"
  349. fi
  350.  
  351. # Apply scan delay if specified
  352. sdelay
  353.  
  354. # Setup slow USB bits
  355. setup_slowusb
  356.  
  357. cd /
  358.  
  359. # if doslowusb is passed, pause other 10 seconds here, after mdev load
  360. [ "${DO_slowusb}" ] && sleep 10
  361.  
  362. # Start iSCSI
  363. if [ -e /bin/iscsistart ]
  364. then
  365. startiscsi
  366. fi
  367.  
  368. # Setup btrfs, see bug 303529
  369. setup_btrfsctl
  370.  
  371. # Setup md device nodes if they dont exist
  372. setup_md_device
  373.  
  374. # Scan volumes
  375. startVolumes
  376.  
  377. setup_keymap
  378.  
  379. # Initialize LUKS root device except for livecd's
  380. if [ "${CDROOT}" != 1 ]
  381. then
  382. startLUKS
  383. if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
  384. then
  385. case "${REAL_RESUME}" in
  386. LABEL=*|UUID=*)
  387.  
  388. RESUME_DEV=""
  389. retval=1
  390.  
  391. if [ ${retval} -ne 0 ]; then
  392. RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
  393. retval=$?
  394. fi
  395.  
  396. if [ ${retval} -ne 0 ]; then
  397. RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
  398. retval=$?
  399. fi
  400.  
  401. if [ ${retval} -ne 0 ]; then
  402. RESUME_DEV=$(blkid -o device -l -t "${REAL_RESUME}")
  403. retval=$?
  404. fi
  405.  
  406. if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
  407. good_msg "Detected real_resume=${RESUME_DEV}"
  408. REAL_RESUME="${RESUME_DEV}"
  409. fi
  410. ;;
  411. esac
  412.  
  413. do_resume
  414. fi
  415. fi
  416.  
  417. mkdir -p "${NEW_ROOT}"
  418. CHROOT="${NEW_ROOT}"
  419.  
  420. # Run debug shell if requested
  421. rundebugshell
  422.  
  423. if [ "${CDROOT}" = '1' ]
  424. then
  425. good_msg "Making tmpfs for ${NEW_ROOT}"
  426. mount -n -t tmpfs tmpfs "${NEW_ROOT}"
  427.  
  428. for i in dev mnt proc run sys tmp mnt/livecd mnt/key tmp/.initrd mnt/gentoo
  429. do
  430. mkdir -p "${NEW_ROOT}/${i}"
  431. chmod 755 "${NEW_ROOT}/${i}"
  432. done
  433. [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
  434. [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
  435. [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
  436.  
  437. # For SGI LiveCDs ...
  438. if [ "${LOOPTYPE}" = "sgimips" ]
  439. then
  440. [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
  441. [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
  442. fi
  443.  
  444. # Required for splash to work. Not an issue with the initrd as this
  445. # device isn't created there and is not needed.
  446. if [ -e /dev/tty1 ]
  447. then
  448. [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
  449. fi
  450.  
  451. if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
  452. then
  453. bootstrapCD
  454. fi
  455.  
  456. if [ "${REAL_ROOT}" = '' ]
  457. then
  458. echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
  459.  
  460. COUNTER=0
  461. while [ ${COUNTER} -lt 3 ]; do
  462. sleep 3
  463. echo -n '.'
  464. let COUNTER=${COUNTER}+1
  465. done
  466.  
  467. sleep 1
  468. echo -e "${NORMAL}"
  469. bootstrapCD
  470. fi
  471.  
  472. if [ "${REAL_ROOT}" = '' ]
  473. then
  474. # Undo stuff
  475. umount "${NEW_ROOT}/dev" 2>/dev/null
  476. umount "${NEW_ROOT}/sys" 2>/dev/null
  477. umount /sys 2>/dev/null
  478.  
  479. umount "${NEW_ROOT}"
  480. rm -rf "${NEW_ROOT}/*"
  481.  
  482. bad_msg 'Could not find CD to boot, something else needed!'
  483. CDROOT=0
  484. fi
  485. fi
  486.  
  487. # Determine root device
  488. good_msg 'Determining root device...'
  489. while true
  490. do
  491. while [ "${got_good_root}" != '1' ]
  492. do
  493. case "${REAL_ROOT}" in
  494. LABEL=*|UUID=*)
  495.  
  496. ROOT_DEV=""
  497. retval=1
  498.  
  499. if [ ${retval} -ne 0 ]; then
  500. ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
  501. retval=$?
  502. fi
  503.  
  504. if [ ${retval} -ne 0 ]; then
  505. ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
  506. retval=$?
  507. fi
  508.  
  509. if [ ${retval} -ne 0 ]; then
  510. ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
  511. retval=$?
  512. fi
  513.  
  514. if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
  515. good_msg "Detected real_root=${ROOT_DEV}"
  516. REAL_ROOT="${ROOT_DEV}"
  517. else
  518. prompt_user "REAL_ROOT" "root block device"
  519. got_good_root=0
  520. continue
  521. fi
  522. ;;
  523. ZFS*)
  524. if [ "${USE_ZFS}" = '0' ]; then
  525. prompt_user "REAL_ROOT" "root block device"
  526. continue
  527. fi
  528.  
  529. ROOT_DEV="${REAL_ROOT#*=}"
  530. if [ "${ROOT_DEV}" != 'ZFS' ]
  531. then
  532. if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
  533. then
  534. got_good_root=1;
  535. REAL_ROOT=${ROOT_DEV}
  536. ROOTFSTYPE=zfs
  537. else
  538. bad_msg "${ROOT_DEV} is not a filesystem"
  539. prompt_user "REAL_ROOT" "root block device"
  540. got_good_root=0
  541. continue
  542. fi
  543. else
  544. BOOTFS=$(/sbin/zpool list -H -o bootfs)
  545. if [ "${BOOTFS}" != '-' ]
  546. then
  547.  
  548. for i in ${BOOTFS}
  549. do
  550.  
  551. zfs get type ${i} > /dev/null
  552. retval=$?
  553.  
  554. if [ ${retval} -eq 0 ]; then
  555. got_good_root=1
  556. REAL_ROOT=${i}
  557. ROOTFSTYPE=zfs
  558. break
  559. fi
  560.  
  561. done;
  562.  
  563. else
  564. got_good_root=0
  565. fi
  566.  
  567. fi
  568.  
  569. if [ ${got_good_root} -ne 1 ]; then
  570. prompt_user "REAL_ROOT" "root block device"
  571. got_good_root=0
  572. fi
  573.  
  574. continue
  575. ;;
  576. esac
  577.  
  578. if [ "${REAL_ROOT}" = '' ]
  579. then
  580. # No REAL_ROOT determined/specified. Prompt user for root block device.
  581. prompt_user "REAL_ROOT" "root block device"
  582. got_good_root=0
  583.  
  584. # Check for a block device or /dev/nfs
  585. elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
  586. then
  587. got_good_root=1
  588.  
  589. else
  590. bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
  591. REAL_ROOT=""
  592. got_good_root=0
  593. fi
  594. done
  595.  
  596.  
  597. if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
  598. then
  599. # CD already mounted; no further checks necessary
  600. break
  601. elif [ "${LOOPTYPE}" = "sgimips" ]
  602. then
  603. # sgimips mounts the livecd root partition directly
  604. # there is no isofs filesystem to worry about
  605. break
  606. else
  607. good_msg "Mounting $REAL_ROOT as root..."
  608.  
  609. if [ "${ROOTFSTYPE}" = 'zfs' ]
  610. then
  611. if [ "zfs get -H -o value mountpoint ${REAL_ROOT}" = 'legacy' ]
  612. then
  613. MOUNT_STATE=rw
  614. else
  615. MOUNT_STATE=rw,zfsutil
  616. fi
  617. else
  618. MOUNT_STATE=ro
  619. fi
  620.  
  621. # Try to mount the device as ${NEW_ROOT}
  622. if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
  623. findnfsmount
  624. else
  625. # If $REAL_ROOT is a symlink
  626. # Resolve it like util-linux mount does
  627. [ -L ${REAL_ROOT} ] && REAL_ROOT=`readlink ${REAL_ROOT}`
  628. # mount ro so fsck doesn't barf later
  629. if [ "${REAL_ROOTFLAGS}" = '' ]; then
  630. good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
  631. mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
  632. else
  633. good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
  634. mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
  635. fi
  636. fi
  637.  
  638. # If mount is successful break out of the loop
  639. # else not a good root and start over.
  640. if [ "$?" = '0' ]
  641. then
  642. if [ -d ${NEW_ROOT}/dev -a -x "${NEW_ROOT}${REAL_INIT:-/sbin/init}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
  643. then
  644. break
  645. else
  646. bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
  647. got_good_root=0
  648. REAL_ROOT=''
  649. fi
  650. else
  651. bad_msg "Could not mount specified ROOT, try again"
  652. got_good_root=0
  653. REAL_ROOT=''
  654. fi
  655. fi
  656. done
  657. # End determine root device
  658.  
  659. #verbose_kmsg
  660.  
  661. # If CD root is set determine the looptype to boot
  662. if [ "${CDROOT}" = '1' ]
  663. then
  664. good_msg 'Determining looptype ...'
  665. cd "${NEW_ROOT}"
  666.  
  667. # Find loop and looptype
  668. [ -z "${LOOP}" ] && find_loop
  669. [ -z "${LOOPTYPE}" ] && find_looptype
  670.  
  671. cache_cd_contents
  672.  
  673. # If encrypted, find key and mount, otherwise mount as usual
  674. if [ -n "${CRYPT_ROOT}" ]
  675. then
  676. CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/${CDROOT_MARKER})"
  677. CRYPT_ROOT='/dev/loop0'
  678. good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
  679.  
  680. losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
  681. test_success 'Preparing loop filesystem'
  682.  
  683. startLUKS
  684.  
  685. case ${LOOPTYPE} in
  686. normal)
  687. MOUNTTYPE="ext2"
  688. ;;
  689. *)
  690. MOUNTTYPE="${LOOPTYPE}"
  691. ;;
  692. esac
  693. mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
  694. test_success 'Mount filesystem'
  695. FS_LOCATION='mnt/livecd'
  696. # Setup the loopback mounts, if unencrypted
  697. else
  698. if [ "${LOOPTYPE}" = 'normal' ]
  699. then
  700. good_msg 'Mounting loop filesystem'
  701. mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
  702. test_success 'Mount filesystem'
  703. FS_LOCATION='mnt/livecd'
  704. elif [ "${LOOPTYPE}" = 'squashfs' ]
  705. then
  706. if [ "${USE_AUFS_NORMAL}" != '1' ]; then
  707. good_msg 'Mounting squashfs filesystem'
  708. _CACHED_SQUASHFS_PATH="${NEW_ROOT}/mnt/${LOOP}"
  709. _squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" # Default to uncached
  710. # Upgrade to cached version if possible
  711. [ "${DO_cache}" -a -f "${_CACHED_SQUASHFS_PATH}" ] \
  712. && _squashfs_path=${_CACHED_SQUASHFS_PATH}
  713. mount -t squashfs -o loop,ro "${_squashfs_path}" "${NEW_ROOT}/mnt/livecd" || {
  714. bad_msg "Squashfs filesystem could not be mounted, dropping into shell."
  715. if [ -e /proc/filesystems ]; then
  716. fgrep -q squashfs /proc/filesystems || \
  717. bad_msg "HINT: Your kernel does not know filesystem \"squashfs\"."
  718. fi
  719. do_rundebugshell
  720. }
  721. else
  722. good_msg 'Mounting squashfs & aufs filesystems'
  723. setup_squashfs_aufs
  724. test_success 'Mount filesystem'
  725. fi
  726. FS_LOCATION='mnt/livecd'
  727. elif [ "${LOOPTYPE}" = 'gcloop' ]
  728. then
  729. good_msg 'Mounting gcloop filesystem'
  730. echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
  731. test_success 'losetup the loop device'
  732.  
  733. mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
  734. test_success 'Mount the losetup loop device'
  735. FS_LOCATION='mnt/livecd'
  736. elif [ "${LOOPTYPE}" = 'zisofs' ]
  737. then
  738. FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
  739. elif [ "${LOOPTYPE}" = 'noloop' ]
  740. then
  741. FS_LOCATION="${CDROOT_PATH/\/}"
  742. elif [ "${LOOPTYPE}" = 'sgimips' ]
  743. then
  744. # getdvhoff finds the starting offset (in bytes) of the squashfs
  745. # partition on the cdrom and returns this offset for losetup
  746. #
  747. # All currently supported SGI Systems use SCSI CD-ROMs, so
  748. # so we know that the CD-ROM is usually going to be /dev/sr0.
  749. #
  750. # We use the value given to losetup to set /dev/loop0 to point
  751. # to the liveCD root partition, and then mount /dev/loop0 as
  752. # the LiveCD rootfs
  753. good_msg 'Locating the SGI LiveCD Root Partition'
  754. echo ' ' | \
  755. losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
  756. "${NEW_ROOT}${CDROOT_DEV}" \
  757. "${NEW_ROOT}${REAL_ROOT}"
  758. test_success 'losetup /dev/sr0 /dev/loop0'
  759.  
  760. good_msg 'Mounting the Root Partition'
  761. mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
  762. test_success 'mount /dev/loop0 /'
  763. FS_LOCATION='mnt/livecd'
  764. fi
  765. fi
  766.  
  767.  
  768.  
  769. # Unpacking additional packages from NFS mount
  770. # This is useful for adding kernel modules to /lib
  771. # We do this now, so that additional packages can add whereever they want.
  772. if [ "${REAL_ROOT}" = '/dev/nfs' ]
  773. then
  774. if [ -e "${CDROOT_PATH}/add" ]
  775. then
  776. for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
  777. do
  778. tarname=$(basename ${targz})
  779. good_msg "Adding additional package ${tarname}"
  780. (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
  781. done
  782. fi
  783. fi
  784.  
  785.  
  786. if [ "${USE_UNIONFS_NORMAL}" = '1' ]
  787. then
  788. setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
  789. CHROOT=/union
  790. elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
  791.  
  792. good_msg "Copying read-write image contents to tmpfs"
  793. # Copy over stuff that should be writable
  794. (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") || {
  795. bad_msg "Copying failed, dropping into a shell."
  796. do_rundebugshell
  797. }
  798.  
  799. # Now we do the links.
  800. for x in ${ROOT_LINKS}
  801. do
  802. if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
  803. then
  804. ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
  805. else
  806. # List all subdirectories of x
  807. find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
  808. do
  809. # Strip the prefix of the FS_LOCATION
  810. directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
  811.  
  812. # Skip this directory if we already linked a parent directory
  813. if [ "${current_parent}" != '' ]; then
  814. var=$(echo "${directory}" | grep "^${current_parent}")
  815. if [ "${var}" != '' ]; then
  816. continue
  817. fi
  818. fi
  819. # Test if the directory exists already
  820. if [ -e "/${NEW_ROOT}/${directory}" ]
  821. then
  822. # It does exist, link all the individual files
  823. for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
  824. do
  825. if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
  826. ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
  827. fi
  828. done
  829. else
  830. # It does not exist, make a link to the livecd
  831. ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
  832. current_parent="${directory}"
  833. fi
  834. done
  835. fi
  836. done
  837.  
  838. mkdir initramfs proc tmp sys run 2>/dev/null
  839. chmod 1777 tmp
  840.  
  841. # have handy /mnt/cdrom (CDROOT_PATH) as well
  842. _new_cdroot="${NEW_ROOT}${CDROOT_PATH}"
  843. [ ! -d "${_new_cdroot}" ] && mkdir -p "${_new_cdroot}"
  844. mount --bind "${CDROOT_PATH}" "${_new_cdroot}"
  845.  
  846. fi
  847.  
  848. #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
  849. #if [ "${UML}" = 'UML' ]
  850. #then
  851. # # UML Fixes
  852. # good_msg 'Updating for uml system'
  853. #fi
  854.  
  855. # Let Init scripts know that we booted from CD
  856. export CDBOOT
  857. CDBOOT=1
  858. else
  859. if [ "${USE_UNIONFS_NORMAL}" = '1' ]
  860. then
  861. mkdir /union_changes
  862. mount -t tmpfs tmpfs /union_changes
  863. setup_unionfs /union_changes ${NEW_ROOT}
  864. mkdir -p ${UNION}/tmp/.initrd
  865. fi
  866. fi
  867.  
  868. # Mount the additional things as required by udev & systemd
  869. if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
  870. fslist=$(get_mounts_list)
  871. else
  872. fslist="/usr"
  873. fi
  874.  
  875. for fs in $fslist; do
  876. dev=$(get_mount_device $fs)
  877. [ -z "${dev}" ] && continue
  878. # Resolve it like util-linux mount does
  879. [ -L ${dev} ] && dev=`readlink ${dev}`
  880. # In this case, it's probably part of the filesystem
  881. # and not a mountpoint
  882. [ -z "$dev" ] && continue
  883. fstype=$(get_mount_fstype $fs)
  884. if get_mount_options $fs | fgrep -q bind ; then
  885. opts='bind'
  886. dev=${NEW_ROOT}${dev}
  887. else
  888. # ro must be trailing, and the options will always contain at least 'defaults'
  889. opts="$(get_mount_options $fs | strip_mount_options),ro"
  890. fi
  891. mnt=${NEW_ROOT}${fs}
  892. cmd="mount -t $fstype -o $opts $dev $mnt"
  893. good_msg "Mounting $dev as ${fs}: $cmd"
  894. if ! $cmd; then
  895. bad_msg "Unable to mount $dev for $fs"
  896. fi
  897. done
  898.  
  899. # Execute script on the cdrom just before boot to update things if necessary
  900. cdupdate
  901.  
  902. if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
  903. then
  904. good_msg "Entering ${SUBDIR} to boot"
  905. CHROOT="${CHROOT}/${SUBDIR}"
  906. fi
  907.  
  908. verbose_kmsg
  909.  
  910. echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
  911.  
  912. cd "${CHROOT}"
  913. mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null
  914. echo -ne "${BOLD}.${NORMAL}"
  915.  
  916. # If devtmpfs is mounted, try move it to the new root
  917. # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
  918. for fs in /dev /sys /proc
  919. do
  920. if grep -qs "$fs" /proc/mounts
  921. then
  922. if ! mount --move $fs "${CHROOT}"$fs
  923. then
  924. umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
  925. fi
  926. fi
  927. done
  928.  
  929. if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
  930. then
  931. echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
  932. elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
  933. then
  934. echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
  935. fi
  936.  
  937. echo -e "${BOLD}.${NORMAL}"
  938.  
  939. exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
  940.  
  941. # If we get here, something bad has happened
  942. splash 'verbose'
  943.  
  944. echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
  945. echo "boot correctly. Trying to open a shell..."
  946. echo
  947. exec /bin/bash
  948. exec /bin/sh
  949. exec /bin/ash
  950. exec /bin/dash
  951. exec sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement