1
0
Fork 0
mirror of https://github.com/pygos/build.git synced 2024-12-23 23:50:51 +01:00

Move filesystem setup to init

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-04-06 23:27:26 +02:00
parent 08c7fe9b4f
commit 8239578deb

View file

@ -46,72 +46,6 @@ while [ ! -e ${root} ]; do
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}
}
setup_vfs() {
local root=${1}
mount -t proc proc $root/proc
mount -t sysfs sysfs $root/sys
mount -t devtmpfs none $root/dev
# setup /dev
[ -e $root/dev/fd ] || ln -snf /proc/self/fd $root/dev/fd
[ -e $root/dev/stdin ] || ln -snf /proc/self/fd/0 $root/dev/stdin
[ -e $root/dev/stdout ] || ln -snf /proc/self/fd/1 $root/dev/stdout
[ -e $root/dev/stderr ] || ln -snf /proc/self/fd/2 $root/dev/stderr
[ -e $root/proc/kcore ] && ln -snf /proc/kcore $root/dev/core
for x in \
"mqueue dev/mqueue 1777 ,nodev mqueue" \
"devpts dev/pts 0755 ,gid=5,mode=0620 devpts" \
"tmpfs dev/shm 1777 ,nodev,mode=1777 shm" \
; do
set -- $x
grep -Eq "[[:space:]]+$1$" /proc/filesystems || continue
if [ ! -d "$root/$2" ]; then
mkdir -m $3 -p "$root/$2" >/dev/null 2>&1 || \
echo "Could not create $root/$2!"
fi
if [ -d "$root/$2" ]; then
mount -t $1 -o noexec,nosuid$4 $5 "$root/$2"
fi
done
# set up additional mounts in /proc and /sys
for x in \
"sys/kernel/security securityfs nodev,noexec,nosuid" \
"sys/kernel/config configfs nodev,noexec,nosuid" \
"sys/fs/fuse/connections fusectl nodev,noexec,nosuid" \
"sys/firmware/efi/efivars efivarfs ro" \
"proc/sys/fs/binfmt_misc binfmt_misc nodev,noexec,nosuid" \
; do
set -- $x
if [ -d "$root/$1" ]; then
if grep -qs $2 "$root/proc/filesystems"; then
echo "Mounting $2 filesystem"
mount -n -t $2 -o $3 $2 "$root/$1"
fi
fi
done
unset -v x
}
mount ${root} /images
if [ ! -e /images/${root_sfs} ]; then
@ -121,21 +55,6 @@ if [ ! -e /images/${root_sfs} ]; then
fi
mount -t squashfs /images/${root_sfs} /newroot
setup_vfs "/newroot"
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
@ -144,14 +63,9 @@ if [ ! -z "$overlay_dev" ]; then
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"
chroot /newroot mount -n -t overlay overlay -olowerdir=/cfg/preserve/etc,upperdir=/cfg/overlay/etc,workdir=/cfg/overlay/etc_work /etc
else
bind_mount "cfg/preserve/etc" "etc"
bind_mount "cfg/preserve/var_lib" "var/lib"
bind_mount "cfg/preserve/root" "root"
chroot /newroot mount -n --bind /cfg/preserve/etc /etc
fi
# cleanup mounts