enable pivot_root

pull/5/head
Tomas M 2012-09-08 06:46:35 -05:00
parent 29d26277f5
commit eb7bb56f33
4 changed files with 36 additions and 17 deletions

View File

@ -9,7 +9,7 @@ MENU BACKGROUND /boot/bootlogo.png
LABEL default LABEL default
MENU LABEL Run Linux MENU LABEL Run Linux
KERNEL /boot/vmlinuz KERNEL /boot/vmlinuz
APPEND vga=769 initrd=/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 APPEND vga=769 initrd=/boot/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 debug
LABEL default LABEL default
MENU LABEL Run Linux 2 MENU LABEL Run Linux 2

View File

@ -2,15 +2,30 @@
# Initial script for Linux Live Kit # Initial script for Linux Live Kit
# Author: Tomas M <http://www.linux-live.org/> # Author: Tomas M <http://www.linux-live.org/>
MEMORYDIR=/memory # This is needed to enable pivot_root
UNIONDIR=/union # We simply switch initramfs to mounted ramfs
DATADIR=/mnt/data if [ ! -r /lib/root_switched ]; then
BUNDLESDIR=/mnt/bundles echo "switch root from initramfs to ramfs"
SWITCH=/m
mkdir -p $SWITCH
mount -t ramfs ramfs $SWITCH
cp -a /* $SWITCH 2>/dev/null
cd $SWITCH
touch $SWITCH/lib/root_switched
exec switch_root -c /dev/console . $0
fi
MOUNTDIR=/mnt
CHANGES=$MOUNTDIR/changes
MEMORY=$MOUNTDIR/memory
UNION=$MOUNTDIR/union
DATAMNT=$MOUNTDIR/data
BUNDLES=$MOUNTDIR/bundles
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
. /.config . /lib/.config
. /livekitlib . /lib/livekitlib
header "Starting $LIVEKITNAME ..." header "Starting $LIVEKITNAME ..."
@ -18,21 +33,22 @@ init_proc
init_devs init_devs
init_aufs init_aufs
init_zram init_zram
init_union $MEMORYDIR $UNIONDIR
init_union "$CHANGES" "$UNION"
# find data dir with filesystem bundles # find data dir with filesystem bundles
DATA="$(find_data $LIVEKITNAME $DATADIR)" DATA="$(find_data $DATAMNT)"
# copy to RAM if needed # copy to RAM if needed
# add data to union # add data to union
union_append_bundles "$DATA" "$BUNDLESDIR" "$UNIONDIR" union_append_bundles "$DATA" "$BUNDLES" "$UNION"
# create empty fstab # create empty fstab
fstab_create "$UNIONDIR" fstab_create "$UNION"
header "Live Kit phase ends, starting $LIVEKITNAME" header "Live Kit phase ends, starting $LIVEKITNAME"
change_root "$UNIONDIR" change_root "$UNION"
header "!!ERROR!!" header "!!ERROR!!"
/bin/sh /bin/sh

View File

@ -48,6 +48,7 @@ busybox/busybox | grep , | grep -v Copyright | tr "," " " | while read LINE; do
ln -s ../bin/busybox $INITRAMFS/sbin/$TOOL ln -s ../bin/busybox $INITRAMFS/sbin/$TOOL
done done
done done
rm $INITRAMFS/{s,}bin/init
mknod $INITRAMFS/dev/console c 5 1 mknod $INITRAMFS/dev/console c 5 1
mknod $INITRAMFS/dev/null c 1 3 mknod $INITRAMFS/dev/null c 1 3
@ -75,12 +76,12 @@ touch $INITRAMFS/etc/{m,fs}tab
cp init $INITRAMFS/ cp init $INITRAMFS/
chmod a+x $INITRAMFS/init chmod a+x $INITRAMFS/init
cp ../livekitlib $INITRAMFS/ cp ../livekitlib $INITRAMFS/lib/
cp ../.config $INITRAMFS/ cp ../.config $INITRAMFS/lib/
cd $INITRAMFS cd $INITRAMFS
find . -print | cpio -o -H newc 2>/dev/null | gzip -f --best >$INITRAMFS.img find . -print | cpio -o -H newc 2>/dev/null | gzip -f --best >$INITRAMFS.img
echo $INITRAMFS.img echo $INITRAMFS.img
cd .. cd ..
rm -Rf $INITRAMFS #rm -Rf $INITRAMFS

View File

@ -153,8 +153,7 @@ init_union()
debug_log "init_union" debug_log "init_union"
mkdir -p "$1" mkdir -p "$1"
mkdir -p "$2" mkdir -p "$2"
mount -t ramfs ramfs "$1" mount -t aufs -o xino="$1/.xino",br="$1" none "$2"
mount -t aufs -o xino=$1/xino,br=$1 none "$2"
} }
# Make sure to mount FAT12/16/32 using vfat # Make sure to mount FAT12/16/32 using vfat
@ -249,6 +248,9 @@ change_root()
if [ -x sbin/init ]; then INIT=sbin/init; fi if [ -x sbin/init ]; then INIT=sbin/init; fi
if [ "$INIT" = "" ]; then fatal "Can't find executable init command"; fi if [ "$INIT" = "" ]; then fatal "Can't find executable init command"; fi
mkdir -p mnt/memory
mount -n -o remount,ro aufs . mount -n -o remount,ro aufs .
pivot_root . mnt/memory
exec $CHROOT . $INIT <dev/console >dev/console 2>&1 exec $CHROOT . $INIT <dev/console >dev/console 2>&1
# exec switch_root -c /dev/console . $INIT
} }