pull/5/head
Tomas M 2012-09-06 12:28:08 -05:00
parent ffbcc57bbe
commit 445fe3906b
3 changed files with 112 additions and 45 deletions

View File

@ -2,53 +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/>
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
. /.config
. /linuxkitlib
mount -n -t proc proc /proc
mount -n -t sysfs sysfs /sys
mount -n -o remount,rw rootfs /
ln -sf /proc/mounts /etc/mtab # this allows us to use umount -a
# Don't print kernel messages to konsole any longer
echo "0" >/proc/sys/kernel/printk
# Activate zram (auto-compression of RAM)
# Compressed RAM consumes 1/2 or even 1/4 of original size
# Setup static size of 500MB
echo "Setting dynamic RAM compression using ZRAM"
modprobe zram
echo $((512*1024*1024)) > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0 -p 32767
echo 100 > /proc/sys/vm/swappiness
MEMORYDIR=/memory MEMORYDIR=/memory
UNIONDIR=/union UNIONDIR=/union
# Setup empty union export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
mkdir $MEMORYDIR
mkdir $UNIONDIR
mount -t ramfs ramfs $MEMORYDIR
mount -t aufs -o xino=$MEMORYDIR/xino,br=$MEMORYDIR none $UNIONDIR
# find LiveKit data . /.config
. /livekitlib
init_proc
init_devs
init_aufs
init_zram
init_union $MEMORYDIR $UNIONDIR
# find data dir with filesystem bundles
DATA="$(find_data $LIVEKITNAME)"
# copy to RAM if needed
# add data to union # add data to union
union_append_bundles "$DATA"
# possibly switch root
# testing message # testing message
echo echo "If you see this message, then something went terribly wrong. Sorry!"
echo
echo
echo " If you see this message, then the test passed OK."
echo " Thank you for testing. That's all for now :)"
echo " It's now safe to turn off your computer ..."
echo
echo
echo
echo
/bin/bash /bin/bash

View File

@ -35,19 +35,20 @@ copy_including_deps()
rm -Rf $INITRAMFS rm -Rf $INITRAMFS
mkdir -p $INITRAMFS/{bin,dev,etc,lib,lib64,mnt,proc,root,run,sbin,sys,tmp,usr,var/log} mkdir -p $INITRAMFS/{bin,dev,etc,lib,lib64,mnt,proc,root,run,sbin,sys,tmp,usr,var/log}
modprobe zram #tar -C $INITRAMFS -xf initrd-tree.tar.gz
copy_including_deps /dev/zram0 #rm $INITRAMFS/* 2>/dev/null # only files
#copy_including_deps /lib64/libc.so.*
#copy_including_deps /lib64/libm.so.*
copy_including_deps /dev/console /dev/null /dev/fb0 /dev/zero
copy_including_deps /dev/ram /dev/systty /dev/fuse copy_including_deps /dev/ram /dev/systty /dev/fuse
copy_including_deps /dev/tty /dev/tty? copy_including_deps /dev/tty /dev/tty?
copy_including_deps /bin/bash /bin/mount /bin/mkdir copy_including_deps /bin/bash /bin/mount /bin/umount /bin/mkdir
copy_including_deps /bin/ln /bin/cat /bin/ls /bin/free copy_including_deps /bin/ln /bin/cat /bin/ls /bin/free
copy_including_deps /sbin/blkid /sbin/swapon /sbin/mkswap /sbin/modprobe copy_including_deps /sbin/blkid /sbin/swapon /sbin/mkswap /sbin/modprobe
copy_including_deps /bin/grep /bin/egrep /bin/cut /bin/tr copy_including_deps /bin/grep /bin/egrep /bin/cut /bin/tr
copy_including_deps /sbin/lsmod copy_including_deps /sbin/lsmod
copy_including_deps /sbin/fdisk copy_including_deps /sbin/fdisk
copy_including_deps /bin/uname
copy_including_deps /usr/bin/vi copy_including_deps /usr/bin/vi
copy_including_deps /usr/bin/strace copy_including_deps /usr/bin/strace
@ -71,4 +72,4 @@ 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

@ -97,3 +97,92 @@ create_bundle()
mksquashfs "$1" "$2" -comp xz -b 512K $3 $4 $5 $6 $7 $8 $9>/dev/null mksquashfs "$1" "$2" -comp xz -b 512K $3 $4 $5 $6 $7 $8 $9>/dev/null
} }
# mount virtual filesystems like proc etc
#
init_proc()
{
debug_log "vfs_mount_init"
mount -n -t proc proc /proc
echo "0" >/proc/sys/kernel/printk
mount -n -t sysfs sysfs /sys
mount -n -o remount,rw rootfs /
ln -sf /proc/mounts /etc/mtab
}
# make sure some devices are there
init_devs()
{
if [ ! -e /dev/console ]; then mknod dev/console c 5 1; fi
if [ ! -e /dev/null ]; then mknod dev/null c 1 3; fi
if [ ! -e /dev/zram0 ]; then mknod dev/zram0 b 252 0; fi
}
# Activate zram (auto-compression of RAM)
# Compressed RAM consumes 1/2 or even 1/4 of original size
# Setup static size of 500MB
#
init_zram()
{
debug_log "init_zram"
echo "Setting dynamic RAM compression using ZRAM"
modprobe zram
echo 536870912 > /sys/block/zram0/disksize # 512MB
mkswap /dev/zram0
swapon /dev/zram0 -p 32767
echo 100 > /proc/sys/vm/swappiness
}
# load the AUFS kernel module if needed
#
init_aufs()
{
debug_log "init_aufs"
# TODO maybe check here if aufs support is working at all
# and procude useful error message if user has no aufs
modprobe aufs 2>/dev/null
}
# Setup empty union
# $1 = memory directory (tmpfs will be mounted there)
# $2 = union directory where to mount the union
#
init_union()
{
debug_log "init_union"
mkdir -p "$1"
mkdir -p "$2"
mount -t ramfs ramfs "$1"
mount -t aufs -o xino=$1/xino,br=$1 none "$2"
}
# Find LIVEKIT data by mounting all devices
# If found, retain mounted disk
find_data()
{
debug_log "find_data"
local DEVICE FS MNT
MNT=/mnt
blkid -o device | while read DEVICE; do
FS=$(blkid -s TYPE -o value $DEVICE)
# TODO: if fs = ntfs then mount ntfs-3g, if fs=dos then mount vfat
mount -o ro "$DEVICE" $MNT -t "$FS" 2>/dev/null
if [ -d "$MNT/$LIVEKITNAME" ]; then
echo $MNT
return
fi
umount $MNT 2>/dev/null
done
}
mount_device()
{
echo "A"
}
union_append_bundles()
{
echo "B"
}