first working Live Kit

pull/5/head
Tomas M 2012-09-07 04:28:43 -05:00
parent 528d3ea214
commit 1b585a9212
4 changed files with 109 additions and 32 deletions

View File

@ -1,6 +1,7 @@
UI /boot/vesamenu.c32 UI /boot/vesamenu.c32
TIMEOUT 140 TIMEOUT 140
MENU ROWS 4
MENU CLEAR MENU CLEAR
MENU BACKGROUND /boot/bootlogo.png MENU BACKGROUND /boot/bootlogo.png

View File

@ -1,4 +1,14 @@
#!/bin/bash #!/bin/bash
# we're using precompiled busybox i486 binary, which runs on 64bit systems as well!
wget -O ./busybox http://busybox.net/downloads/binaries/latest/busybox-i486 # Automatically determine the architecture we're building on:
if [ -z "$MYARCH" ]; then
case "$( uname -m )" in
i?86) export MYARCH=i486 ;;
arm*) export MYARCH=arm ;;
# Unless $MYARCH is already set, use uname -m for all other archs:
*) export MYARCH=$( uname -m ) ;;
esac
fi
wget -O ./busybox http://busybox.net/downloads/binaries/latest/busybox-$MYARCH
chmod a+x ./busybox chmod a+x ./busybox

View File

@ -4,12 +4,16 @@
MEMORYDIR=/memory MEMORYDIR=/memory
UNIONDIR=/union UNIONDIR=/union
DATADIR=/mnt/data
BUNDLESDIR=/mnt/bundles
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
. /.config . /.config
. /livekitlib . /livekitlib
header "Starting $LIVEKITNAME ..."
init_proc init_proc
init_devs init_devs
init_aufs init_aufs
@ -17,21 +21,18 @@ init_zram
init_union $MEMORYDIR $UNIONDIR init_union $MEMORYDIR $UNIONDIR
# find data dir with filesystem bundles # find data dir with filesystem bundles
DATA="$(find_data $LIVEKITNAME)" DATA="$(find_data $LIVEKITNAME $DATADIR)"
# copy to RAM if needed # copy to RAM if needed
# add data to union # add data to union
union_append_bundles "$DATA" union_append_bundles "$DATA" "$BUNDLESDIR" "$UNIONDIR"
# create empty fstab
fstab_create "$UNIONDIR"
mkdir /m header "Live Kit phase ends, starting $LIVEKITNAME"
mount /dev/sr0 /m change_root "$UNIONDIR"
modprobe squashfs
mkdir /s
mount -o loop -t squashfs /m/mylinux/core.sb /s
# possibly switch root
# testing message header "!!ERROR!!"
echo "If you see this message, then something went terribly wrong. Sorry!"
/bin/sh /bin/sh

View File

@ -9,7 +9,7 @@
# ================================================================= # =================================================================
# global variable # global variable
DEBUG_IS_ENABLED=$(cat /proc/cmdline 2>/dev/null | grep debug) DEBUG_IS_ENABLED="$(cat /proc/cmdline 2>/dev/null | grep debug)"
debug_log() debug_log()
{ {
@ -59,7 +59,7 @@ debug_shell()
{ {
if [ "$DEBUG_IS_ENABLED" ]; then if [ "$DEBUG_IS_ENABLED" ]; then
show_debug_banner show_debug_banner
bash < /dev/console sh < /dev/console
echo echo
fi fi
} }
@ -71,7 +71,7 @@ fatal()
echolog "Something went wrong and we can't continue. This should never happen." echolog "Something went wrong and we can't continue. This should never happen."
echolog "Please reboot your computer with Ctrl+Alt+Delete ..." echolog "Please reboot your computer with Ctrl+Alt+Delete ..."
echolog echolog
bash < /dev/console sh < /dev/console
} }
@ -115,9 +115,9 @@ init_devs()
{ {
echo /sbin/mdev > /proc/sys/kernel/hotplug echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s mdev -s
modprobe zram modprobe zram 2>/dev/null
modprobe loop modprobe loop 2>/dev/null
modprobe squashfs modprobe squashfs 2>/dev/null
} }
# Activate zram (auto-compression of RAM) # Activate zram (auto-compression of RAM)
@ -157,33 +157,98 @@ init_union()
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
# in order to support long filenames
# $1 = device
#
device_bestfs()
{
debug_log "device_bestfs"
local PEEK
PEEK="$(dd if="$1" bs=1k count=1 2>/dev/null | strings)"
if [ "$(echo "$PEEK" | egrep -i "FAT[13][26]")" != "" ]; then
echo "-t vfat"
# TODO: this will work only with fuse
# else if [ "$(echo "$PEEK" | egrep -i 'NTFS')" != "" ]; then
# echo "-t ntfs-3g"
fi
}
# Find LIVEKIT data by mounting all devices # Find LIVEKIT data by mounting all devices
# If found, retain mounted disk # If found, retain mounted disk
# $1 = data directory to mount
#
find_data() find_data()
{ {
debug_log "find_data" debug_log "find_data"
local DEVICE FS MNT local DEVICE FS MNT
MNT=/mnt
blkid -o device | while read DEVICE; do mkdir -p "$1"
FS=$(blkid -s TYPE -o value $DEVICE) blkid | sort | cut -d: -f 1 | while read DEVICE; do
# TODO: if fs = ntfs then mount ntfs-3g, if fs=dos then mount vfat FS="$(device_bestfs "$DEVICE")"
mount -o ro "$DEVICE" $MNT -t "$FS" 2>/dev/null mount -r "$DEVICE" "$1" $FS
if [ -d "$MNT/$LIVEKITNAME" ]; then if [ -d "$1/$LIVEKITNAME" ]; then
echo $MNT echo "$1/$LIVEKITNAME"
return return
fi fi
umount $MNT 2>/dev/null umount "$1" 2>/dev/null
done done
} }
mount_device() # Mount squashfs filesystem bundles
{ # and add them to union
echo "A" # $1 = directory where to search for bundles
} # $2 = directory where to mount bundles
# $3 = directory where union is mounted
#
union_append_bundles() union_append_bundles()
{ {
echo "B" ls -1 "$1" | grep '.sb$' | sort | while read BUNDLE; do
mkdir -p "$2/$BUNDLE"
mount -o loop -t squashfs "$1/$BUNDLE" "$2/$BUNDLE"
mount -o remount,add:1:"$2/$BUNDLE" none "$3"
done
}
# Create empty fstab properly
# $1 = root directory
#
fstab_create()
{
local FSTAB
FSTAB="$1/etc/fstab"
echo aufs / aufs defaults 0 0 > $FSTAB
echo proc /proc proc defaults 0 0 >> $FSTAB
echo sysfs /sys sysfs defaults 0 0 >> $FSTAB
echo devpts /dev/pts devpts gid=5,mode=620 0 0 >> $FSTAB
echo tmpfs /dev/shm tmpfs defaults 0 0 >> $FSTAB
}
# Change root and execute init
# $1 = where to change root
#
change_root()
{
cd "$1"
# make sure important devices are in union
if [ ! -e dev/console ]; then mknod dev/console c 5 1; fi
if [ ! -e dev/null ]; then mknod dev/null c 1 3; fi
# find chroot and init
if [ -x bin/chroot ]; then CHROOT=bin/chroot; fi
if [ -x sbin/chroot ]; then CHROOT=sbin/chroot; fi
if [ -x usr/bin/chroot ]; then CHROOT=usr/bin/chroot; fi
if [ -x usr/sbin/chroot ]; then CHROOT=usr/sbin/chroot; fi
if [ "$CHROOT" = "" ]; then fatal "Can't find executable chroot command"; fi
if [ -x bin/init ]; then INIT=bin/init; fi
if [ -x sbin/init ]; then INIT=sbin/init; fi
if [ "$INIT" = "" ]; then fatal "Can't find executable init command"; fi
mount -n -o remount,ro aufs .
exec $CHROOT . $INIT <dev/console >dev/console 2>&1
} }