1
0
Fork 0
mirror of https://github.com/pygos/build.git synced 2024-11-17 00:47:10 +01:00
build/pkg/initrd/initrd.skel
David Oberhollenzer 077f72f529 Some rootfs restructuring
- Dedicate home directory for root user (classic /root)
 - Root homedirectory is overlay mounted
 - Allows us to have an empty user directory that we directly
   mount, i.e. without using overlay fs

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
2018-01-30 14:02:09 +01:00

114 lines
2.3 KiB
Bash

#!/bin/sh
PATH=/bin
/bin/busybox --install
busybox sleep 1
busybox mount -t proc proc /proc
busybox mount -t sysfs sysfs /sys
busybox mount -t devtmpfs none /dev
root_sfs=""
root=""
overlay_dev=""
singleuser=0
for param in `cat /proc/cmdline`; do
case $param in
root=*)
root="${param##root=}"
;;
root_sfs=*)
root_sfs="${param##root_sfs=}"
;;
overlay_dev=*)
overlay_dev="${param##overlay_dev=}"
;;
single*)
singleuser=1
;;
esac
done
if [ -z "${root}" ]; then
echo "No root drive specified!"
exec /bin/busybox sh
fi
if [ -z "${root_sfs}" ]; then
echo "No squashfs image specified!"
exec /bin/busybox sh
fi
while [ ! -e ${root} ]; do
echo "Waiting for root"
busybox sleep 1
done
# file system setup
overlay_mount() {
local lower=/newroot/${1}
local upper=/newroot/${2}
local work=/newroot/${2}_work
local target=/newroot/${3}
mount -t overlay overlay -olowerdir=${lower},upperdir=${upper},workdir=${work} ${target}
}
bind_mount() {
mount --bind /newroot/${1} /newroot/${2}
}
mount ${root} /images
if [ ! -e /images/${root_sfs} ]; then
echo "${root_sfs} not found!"
exec /bin/busybox sh
exit 1
fi
mount -t squashfs /images/${root_sfs} /newroot
mount -t devtmpfs none /newroot/dev
mount -t proc proc /newroot/proc
mount -t sysfs sysfs /newroot/sys
mount -t tmpfs none /newroot/tmp
mount -t tmpfs none /newroot/var
mount -t tmpfs none /newroot/run
chmod 755 /newroot/var
mkdir -p /newroot/run/log/journal
mkdir -p /newroot/var/log/fsck
mkdir -p /newroot/var/log/nginx
mkdir -p /newroot/var/log/mpd
mkdir -p /newroot/var/spool/
mkdir -p /newroot/var/lib/
mkdir -p /newroot/var/tmp
ln -s /run /newroot/var/run
ln -s /run/lock /newroot/var/lock
if [ ! -z "$overlay_dev" ]; then
while [ ! -e ${overlay_dev} ]; do
echo "Waiting for overlay device"
busybox sleep 1
done
mount ${overlay_dev} /newroot/cfg/overlay
overlay_mount "cfg/preserve/etc" "cfg/overlay/etc" "etc"
overlay_mount "cfg/preserve/var_lib" "cfg/overlay/var_lib" "var/lib"
overlay_mount "cfg/preserve/root" "cfg/overlay/root" "root"
else
bind_mount "cfg/preserve/etc" "etc"
bind_mount "cfg/preserve/var_lib" "var/lib"
bind_mount "cfg/preserve/root" "root"
fi
# cleanup mounts
umount -l /images
umount -l /dev
umount /sys
umount /proc
unset -v singleuser overlay_dev root root_sfs
exec /bin/busybox switch_root /newroot /bin/bash --login