Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PATH=/bin:/usr/bin:/usr/sbin:/sbin
- udevd_running=0
- if [ -x /usr/bin/systemd-timestamp ]; then
- RD_TIMESTAMP=$(systemd-timestamp)
- fi
- . /usr/lib/initcpio/init_functions
- mount -t proc proc /proc -o nosuid,noexec,nodev
- mount -t sysfs sys /sys -o nosuid,noexec,nodev
- mount -t devtmpfs dev /dev -o mode=0755,nosuid
- mount -t tmpfs run /run -o nosuid,nodev,mode=0755
- mkdir -m755 /run/initramfs
- # parse the kernel command line
- parse_cmdline
- for d in ${disablehooks//,/ }; do
- [ -e "/hooks/$d" ] && chmod 644 "/hooks/$d"
- done
- #. /config
- run_hookfunctions 'run_earlyhook' 'early hook' $EARLYHOOKS
- [ -n "${earlymodules//[[:space:]]}" ] && modprobe -qab ${earlymodules//,/ }
- [ -n "${MODULES//[[:space:]]}" ] && modprobe -qab $MODULES
- # If rootdelay is empty or not a non-negative integer, set it to 10
- if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then
- rootdelay=10
- fi
- run_hookfunctions 'run_hook' 'hook' $HOOKS
- # honor the old behavior of break=y as a synonym for break=premount
- if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then
- echo ":: Pre-mount break requested, type 'exit' to resume operation"
- launch_interactive_shell
- fi
- rootdev=$(resolve_device "$root") && root=$rootdev
- unset rootdev
- #fsck_root
- ######################################################
- # Make /new_root
- mkdir /new_root
- # Mount root at /new_root
- #${mount_handler:-default_mount_handler} /new_root
- echo -e "Switching / to tmpfs..."
- mount -t tmpfs tmpfs /new_root
- run_hookfunctions 'run_latehook' 'late hook' $LATEHOOKS
- run_hookfunctions 'run_cleanuphook' 'cleanup hook' $CLEANUPHOOKS
- # Stop udevd if is running
- if [ "${udevd_running}" -eq 1 ]; then
- udevadm control --exit
- udevadm info --cleanup-db
- fi
- # Copy root
- echo -e "Copying root..."
- for i in $(ls -a /); do
- case "$i" in
- .|..) ;;
- mnt) mkdir /new_root/mnt;;
- proc) mkdir /new_root/proc;;
- sys) mkdir /new_root/sys;;
- dev) mkdir /new_root/dev;;
- run) mkdir /new_root/run;;
- new_root) ;;
- *) cp -a /$i /new_root
- esac
- done
- # Create mountpoints
- mkdir /new_root/mnt/sda1
- mkdir /new_root/mnt/sda2
- mkdir /new_root/mnt/sda3
- mkdir /new_root/mnt/sda4
- init=${init:-/sbin/init}
- echo -e "Switching root..."
- exec env -i \
- "TERM=$TERM" \
- "RD_TIMESTAMP=$RD_TIMESTAMP" \
- /sbin/switch_root /new_root $init "$@"
- ######################################################
- ## Mount root at /new_root
- #${mount_handler:-default_mount_handler} /new_root
- #run_hookfunctions 'run_latehook' 'late hook' $LATEHOOKS
- #run_hookfunctions 'run_cleanuphook' 'cleanup hook' $CLEANUPHOOKS
- init=${init:-/sbin/init}
- if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
- # Nothing got mounted on /new_root. This is the end, we don't know what to do anymore
- # We fall back into a shell, but the shell has now PID 1
- # This way, manual recovery is still possible.
- err "Failed to mount the real root device."
- echo "Bailing out, you are on your own. Good luck."
- echo
- launch_interactive_shell --exec
- elif [ ! -x "/new_root${init}" ]; then
- # Successfully mounted /new_root, but ${init} is missing
- # The same logic as above applies
- err "Root device mounted successfully, but ${init} does not exist."
- echo "Bailing out, you are on your own. Good luck."
- echo
- launch_interactive_shell --exec
- fi
- if [ "${break}" = "postmount" ]; then
- echo ":: Post-mount break requested, type 'exit' to resume operation"
- launch_interactive_shell
- fi
- exec env -i \
- "TERM=$TERM" \
- "RD_TIMESTAMP=$RD_TIMESTAMP" \
- /sbin/switch_root /new_root $init "$@"
- # vim: set ft=sh ts=4 sw=4 et:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement