110 lines
2.8 KiB
Bash
110 lines
2.8 KiB
Bash
#!/bin/sh
|
|
|
|
problem()
|
|
{
|
|
printf "Encountered a problem!\n\nDropping you to a shell.\n\n"
|
|
sh
|
|
}
|
|
|
|
no_device()
|
|
{
|
|
printf "The device %s, which is supposed to contain the\n" $1
|
|
printf "root file system, does not exist.\n"
|
|
printf "Please fix this problem and exit this shell.\n\n"
|
|
}
|
|
|
|
no_mount()
|
|
{
|
|
printf "Could not mount device %s\n" $1
|
|
printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n"
|
|
printf "Maybe the device is formatted with an unsupported file system?\n\n"
|
|
printf "Or maybe filesystem type autodetection went wrong, in which case\n"
|
|
printf "you should add the rootfstype=... parameter to the kernel command line.\n\n"
|
|
printf "Available partitions:\n"
|
|
}
|
|
|
|
do_mount_root()
|
|
{
|
|
mkdir /.root
|
|
[ -n "$rootflags" ] && rootflags="$rootflags,"
|
|
rootflags="$rootflags$ro"
|
|
|
|
case "$root" in
|
|
/dev/* ) device=$root ;;
|
|
UUID=* ) eval $root; device="$(findfs UUID=$UUID)" ;;
|
|
PARTUUID=*) eval $root; device="/dev/disk/by-partuuid/$PARTUUID" ;;
|
|
LABEL=* ) eval $root; device="/dev/disk/by-label/$LABEL" ;;
|
|
"" ) echo "No root device specified." ; problem ;;
|
|
esac
|
|
|
|
while [ ! -b "$device" ] ; do
|
|
no_device $device
|
|
problem
|
|
done
|
|
|
|
if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then
|
|
no_mount $device
|
|
cat /proc/partitions
|
|
while true ; do sleep 10000 ; done
|
|
else
|
|
echo "Successfully mounted device $root"
|
|
fi
|
|
}
|
|
|
|
init=/sbin/init
|
|
root=
|
|
rootdelay=
|
|
rootfstype=auto
|
|
ro="ro"
|
|
rootflags=
|
|
device=
|
|
resume=
|
|
noresume=false
|
|
|
|
mount -n -t devtmpfs devtmpfs /dev
|
|
mount -n -t proc proc /proc
|
|
mount -n -t sysfs sys /sys
|
|
mount -n -t tmpfs run /run
|
|
|
|
mkdir -p /dev/pts
|
|
|
|
#mountpoint -q proc || mount -t proc proc proc
|
|
#mountpoint -q sys || mount -t sysfs sys sys
|
|
#mknod /dev/null c 1 3
|
|
#if ! mountpoint -q dev
|
|
#then
|
|
# mount -t tmpfs -o size=64k,mode=0755 tmpfs dev
|
|
#mount -t tmpfs -o mode=1777 tmpfs tmp
|
|
#mkdir -p dev/pts
|
|
#mdev -s
|
|
#fi
|
|
|
|
read -r cmdline < /proc/cmdline
|
|
|
|
for param in $cmdline ; do
|
|
case $param in
|
|
init=* ) init=${param#init=} ;;
|
|
root=* ) root=${param#root=} ;;
|
|
rootdelay=* ) rootdelay=${param#rootdelay=} ;;
|
|
rootfstype=*) rootfstype=${param#rootfstype=} ;;
|
|
rootflags=* ) rootflags=${param#rootflags=} ;;
|
|
resume=* ) resume=${param#resume=} ;;
|
|
noresume ) noresume=true ;;
|
|
ro ) ro="ro" ;;
|
|
rw ) ro="rw" ;;
|
|
esac
|
|
done
|
|
|
|
if [ -n "$rootdelay" ]; then sleep "$rootdelay"; fi
|
|
do_mount_root
|
|
|
|
for i in dev proc sys; do
|
|
[ -d /.root/$i ] || mkdir /.root/$i
|
|
mount -o bind /$i /.root/$i
|
|
done
|
|
mount -t devpts none /.root/dev/pts
|
|
|
|
echo 0 > /proc/sys/kernel/printk
|
|
|
|
exec switch_root /.root "$init" "$@"
|