mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-31 22:47:51 +00:00
implement booting from an nbd root with an nfs overlay. adds 5 new kernel cmdline options: * netboot set this option on cmdline to boot from an nbd root device on the network. * nbdroot=host:portnumber short for nbdserver=host nbdport=portnumber * nbdserver=host the hostname or ip address to mount the root device from. if nbdroot and nbdserver aren't set, 192.168.1.1 will be used. * nbdport=portnumber the port number to mount the root device from. if nbdroot and nbdport aren't set, port number 2000 will be used. * nfsoverlay=host:/path/to/overlay the path to mount the writable overlay directory from. if not set, 192.168.1.1:/var/lib/overlay will be used.
This commit is contained in:
parent
0cad06d6e5
commit
1e42a73c7c
@ -27,9 +27,15 @@ IMAGE_SYSTEM="SYSTEM"
|
||||
IMAGE_KERNEL="KERNEL"
|
||||
REBOOT="0"
|
||||
|
||||
# defaults for booting from an nbd root
|
||||
NBD_ROOT_SERVER="192.168.1.1"
|
||||
NBD_ROOT_PORT="2000"
|
||||
NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
|
||||
|
||||
# mount all needed special filesystems
|
||||
/bin/busybox mount -t devtmpfs none /dev
|
||||
/bin/busybox mount -t proc none /proc
|
||||
/bin/busybox mount -t sysfs none /sys
|
||||
|
||||
# hide kernel log messages on console
|
||||
echo '1 4 1 7' > /proc/sys/kernel/printk
|
||||
@ -49,6 +55,23 @@ REBOOT="0"
|
||||
fastboot)
|
||||
FASTBOOT=yes
|
||||
;;
|
||||
netboot)
|
||||
NETBOOT=yes
|
||||
;;
|
||||
nbdroot=*)
|
||||
nbdroot="${arg#nbdroot=}"
|
||||
NBD_ROOT_SERVER=$( echo "${nbdroot}" | /bin/busybox sed 's/:.*//')
|
||||
NBD_ROOT_PORT=$( echo "${nbdroot}" | /bin/busybox sed 's/.*://')
|
||||
;;
|
||||
nbdserver=*)
|
||||
NBD_ROOT_SERVER="${arg#nbdserver=}"
|
||||
;;
|
||||
nbdport=*)
|
||||
NBD_ROOT_PORT="${arg#nbdport=}"
|
||||
;;
|
||||
nfsoverlay=*)
|
||||
NFS_OVERLAY="${arg#nfsoverlay=}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@ -85,7 +108,12 @@ REBOOT="0"
|
||||
progress "trying to mount $1 ..."
|
||||
for i in 1 2 3 4 5 6 7 8 9 10; do
|
||||
ERR_ENV=1
|
||||
$IONICE /bin/busybox mount -o $3 $1 $2 > /dev/null 2>&1
|
||||
if [ -z "$4" ]; then
|
||||
mount_opts="-o $3 $1 $2"
|
||||
else
|
||||
mount_opts="-t $4 -o $3 $1 $2"
|
||||
fi
|
||||
$IONICE /bin/busybox mount $mount_opts > /dev/null 2>&1
|
||||
[ "$?" -eq "0" ] && ERR_ENV=0 && break
|
||||
/bin/busybox usleep 1000000
|
||||
done
|
||||
@ -103,39 +131,80 @@ REBOOT="0"
|
||||
fi
|
||||
}
|
||||
|
||||
mount_nbd() {
|
||||
retry_nr=0
|
||||
retry_delay=20
|
||||
OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :`
|
||||
|
||||
while [ ${retry_nr} -lt ${retry_delay} ] && [ ! -e /sysroot/sbin/init ]; do
|
||||
[ ${retry_nr} -gt 0 ] && \
|
||||
$IONICE /bin/busybox nbd-client $NBD_ROOT_SERVER $NBD_ROOT_PORT /dev/nbd0 && \
|
||||
mount_part "/dev/nbd0" "/sysroot" "ro" "squashfs"
|
||||
|
||||
retry_nr=$(( ${retry_nr} + 1 ))
|
||||
|
||||
[ ! -e /sysroot/sbin/init ] && /bin/sleep 1
|
||||
|
||||
[ ${retry_nr} -gt 0 ]
|
||||
done
|
||||
|
||||
if [ ! -e /sysroot/sbin/init ]; then
|
||||
error "INIT_2" "Could not mount NBD root from $NBD_ROOT_SERVER port $NBD_ROOT_PORT"
|
||||
debug_shell
|
||||
fi
|
||||
|
||||
mount_part "$NFS_OVERLAY" "/sysroot/storage" "rw,nolock,retrans=10" "nfs"
|
||||
|
||||
if [ ! -d /sysroot/storage/$OVERLAY_DIR ]; then
|
||||
mkdir /sysroot/storage/$OVERLAY_DIR
|
||||
fi
|
||||
|
||||
/bin/busybox umount /sysroot/storage
|
||||
mount_part "$NFS_OVERLAY/$OVERLAY_DIR" "/sysroot/storage" "rw,nolock" "nfs"
|
||||
}
|
||||
|
||||
mount_disk() {
|
||||
mount_part "$boot" "/flash" "ro,noatime"
|
||||
|
||||
if [ -n "$disk" ]; then
|
||||
mount_part "$disk" "/storage" "rw,noatime"
|
||||
update "Kernel" "$IMAGE_KERNEL" "/flash/$IMAGE_KERNEL"
|
||||
update "System" "$IMAGE_SYSTEM" "/flash/$IMAGE_SYSTEM"
|
||||
|
||||
if test "$REBOOT" -eq "1"; then
|
||||
echo "System reboots now..." && \
|
||||
/bin/busybox reboot
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "/flash/$IMAGE_SYSTEM" ]; then
|
||||
mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
|
||||
[ "$ERR_ENV" -ne "0" ] && debug_shell
|
||||
else
|
||||
error "INIT_2" "Could not find system."
|
||||
debug_shell
|
||||
fi
|
||||
|
||||
# move /flash and /storage to /sysroot
|
||||
/bin/busybox mount --move /flash /sysroot/flash
|
||||
|
||||
if [ -n "$disk" ]; then
|
||||
/bin/busybox mount --move /storage /sysroot/storage
|
||||
fi
|
||||
}
|
||||
|
||||
show_splash
|
||||
|
||||
mount_part "$boot" "/flash" "ro,noatime"
|
||||
|
||||
if [ -n "$disk" ]; then
|
||||
mount_part "$disk" "/storage" "rw,noatime"
|
||||
update "Kernel" "$IMAGE_KERNEL" "/flash/$IMAGE_KERNEL"
|
||||
update "System" "$IMAGE_SYSTEM" "/flash/$IMAGE_SYSTEM"
|
||||
|
||||
if test "$REBOOT" -eq "1"; then
|
||||
echo "System reboots now..." && \
|
||||
/bin/busybox reboot
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "/flash/$IMAGE_SYSTEM" ]; then
|
||||
mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
|
||||
[ "$ERR_ENV" -ne "0" ] && debug_shell
|
||||
if [ -z "$NETBOOT" ]; then
|
||||
mount_disk
|
||||
else
|
||||
error "INIT_2" "Could not find system."
|
||||
debug_shell
|
||||
mount_nbd
|
||||
fi
|
||||
|
||||
# move /flash and /storage to /sysroot
|
||||
/bin/busybox mount --move /flash /sysroot/flash
|
||||
|
||||
if [ -n "$disk" ]; then
|
||||
/bin/busybox mount --move /storage /sysroot/storage
|
||||
fi
|
||||
|
||||
# unmount all other filesystems
|
||||
# unmount all other filesystems
|
||||
/bin/busybox umount /dev
|
||||
/bin/busybox umount /proc
|
||||
/bin/busybox umount /sys
|
||||
|
||||
# switch to new sysroot and start real init
|
||||
exec /bin/busybox switch_root /sysroot /sbin/init
|
||||
|
Loading…
x
Reference in New Issue
Block a user