diff --git a/initramfs/init b/initramfs/init
index 2ad7832..f52bc22 100644
--- a/initramfs/init
+++ b/initramfs/init
@@ -2,34 +2,22 @@
# Initial script for Linux Live Kit
# Author: Tomas M
-# This is needed to enable pivot_root
-# We simply switch initramfs to mounted ramfs
-if [ ! -r /lib/root_switched ]; then
- 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
. /lib/.config
. /lib/livekitlib
+transfer_initramfs
+
+MEMORY=/memory
+CHANGES=$MEMORY/changes
+UNION=$MEMORY/union
+DATAMNT=$MEMORY/data
+BUNDLES=$MEMORY/bundles
+
header "Starting $LIVEKITNAME ..."
-init_proc
+init_proc_sysfs
init_devs
init_aufs
init_zram
@@ -50,5 +38,5 @@ fstab_create "$UNION"
header "Live Kit phase ends, starting $LIVEKITNAME"
change_root "$UNION"
-header "!!ERROR!!"
+header "!!ERROR occured, you shouldn't be here.!!"
/bin/sh
diff --git a/initramfs/initramfs_create b/initramfs/initramfs_create
index 0b4ba4a..924b743 100755
--- a/initramfs/initramfs_create
+++ b/initramfs/initramfs_create
@@ -62,6 +62,7 @@ mknod $INITRAMFS/dev/tty4 c 4 4
#done
copy_including_deps /usr/bin/strace
+copy_including_deps /usr/bin/lsof
# TODO: add all comon filesystems which are NOT compiled in kernel already
copy_including_deps /$LMK/kernel/fs/squashfs
@@ -74,8 +75,12 @@ depmod -b $INITRAMFS
echo "root::0:0::/root:/bin/bash" >$INITRAMFS/etc/passwd
touch $INITRAMFS/etc/{m,fs}tab
-cp init $INITRAMFS/
+cp init $INITRAMFS
chmod a+x $INITRAMFS/init
+cp cleanup $INITRAMFS/lib
+chmod a+x $INITRAMFS/lib/cleanup
+ln -s ../init $INITRAMFS/bin/init
+ln -s ../init $INITRAMFS/sbin/init
cp ../livekitlib $INITRAMFS/lib/
cp ../.config $INITRAMFS/lib/
@@ -84,4 +89,4 @@ find . -print | cpio -o -H newc 2>/dev/null | gzip -f --best >$INITRAMFS.img
echo $INITRAMFS.img
cd ..
-#rm -Rf $INITRAMFS
+rm -Rf $INITRAMFS
diff --git a/livekitlib b/livekitlib
index e0028a7..e21566f 100644
--- a/livekitlib
+++ b/livekitlib
@@ -98,9 +98,27 @@ create_bundle()
}
+# Move entire initramfs tree to ramfs mount.
+# It's a bit tricky but is necessray to enable pivot_root
+# even for initramfs boot image
+#
+transfer_initramfs()
+{
+ if [ ! -r /lib/initramfs_escaped ]; then
+ echo "switch root from initramfs to ramfs"
+ SWITCH=/m # one letter directory
+ mkdir -p $SWITCH
+ mount -t ramfs ramfs $SWITCH
+ cp -a /??* $SWITCH 2>/dev/null # only copy two-and-more-letter directories
+ cd $SWITCH
+ echo "This file indicates that we successfully escaped initramfs" > $SWITCH/lib/initramfs_escaped
+ exec switch_root -c /dev/console . $0
+ fi
+}
+
# mount virtual filesystems like proc etc
#
-init_proc()
+init_proc_sysfs()
{
debug_log "vfs_mount_init"
mount -n -t proc proc /proc
@@ -231,6 +249,8 @@ fstab_create()
#
change_root()
{
+ umount /proc
+ umount /sys
cd "$1"
# make sure important devices are in union
@@ -248,9 +268,8 @@ change_root()
if [ -x sbin/init ]; then INIT=sbin/init; fi
if [ "$INIT" = "" ]; then fatal "Can't find executable init command"; fi
- mkdir -p mnt/memory
+ mkdir -p mnt/live
mount -n -o remount,ro aufs .
- pivot_root . mnt/memory
- exec $CHROOT . $INIT dev/console 2>&1
-# exec switch_root -c /dev/console . $INIT
+ pivot_root . mnt/live
+ exec $CHROOT . $INIT < dev/console > dev/console 2>&1
}
\ No newline at end of file