diff --git a/bootfiles/syslinux.cfg b/bootfiles/syslinux.cfg index fc276ac..c1bb04e 100644 --- a/bootfiles/syslinux.cfg +++ b/bootfiles/syslinux.cfg @@ -1,6 +1,7 @@ UI /boot/vesamenu.c32 TIMEOUT 140 +MENU ROWS 4 MENU CLEAR MENU BACKGROUND /boot/bootlogo.png diff --git a/initramfs/busybox/update b/initramfs/busybox/update index dcd8069..b44c425 100755 --- a/initramfs/busybox/update +++ b/initramfs/busybox/update @@ -1,4 +1,14 @@ #!/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 diff --git a/initramfs/init b/initramfs/init index 298adc8..816829a 100644 --- a/initramfs/init +++ b/initramfs/init @@ -4,12 +4,16 @@ MEMORYDIR=/memory UNIONDIR=/union +DATADIR=/mnt/data +BUNDLESDIR=/mnt/bundles export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin . /.config . /livekitlib +header "Starting $LIVEKITNAME ..." + init_proc init_devs init_aufs @@ -17,21 +21,18 @@ init_zram init_union $MEMORYDIR $UNIONDIR # find data dir with filesystem bundles -DATA="$(find_data $LIVEKITNAME)" +DATA="$(find_data $LIVEKITNAME $DATADIR)" # copy to RAM if needed # add data to union -union_append_bundles "$DATA" +union_append_bundles "$DATA" "$BUNDLESDIR" "$UNIONDIR" +# create empty fstab +fstab_create "$UNIONDIR" -mkdir /m -mount /dev/sr0 /m -modprobe squashfs -mkdir /s -mount -o loop -t squashfs /m/mylinux/core.sb /s -# possibly switch root +header "Live Kit phase ends, starting $LIVEKITNAME" +change_root "$UNIONDIR" -# testing message -echo "If you see this message, then something went terribly wrong. Sorry!" +header "!!ERROR!!" /bin/sh diff --git a/livekitlib b/livekitlib index 9ee511f..5cc85a2 100644 --- a/livekitlib +++ b/livekitlib @@ -9,7 +9,7 @@ # ================================================================= # 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() { @@ -59,7 +59,7 @@ debug_shell() { if [ "$DEBUG_IS_ENABLED" ]; then show_debug_banner - bash < /dev/console + sh < /dev/console echo fi } @@ -71,7 +71,7 @@ fatal() echolog "Something went wrong and we can't continue. This should never happen." echolog "Please reboot your computer with Ctrl+Alt+Delete ..." echolog - bash < /dev/console + sh < /dev/console } @@ -115,9 +115,9 @@ init_devs() { echo /sbin/mdev > /proc/sys/kernel/hotplug mdev -s - modprobe zram - modprobe loop - modprobe squashfs + modprobe zram 2>/dev/null + modprobe loop 2>/dev/null + modprobe squashfs 2>/dev/null } # Activate zram (auto-compression of RAM) @@ -157,33 +157,98 @@ init_union() 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 # If found, retain mounted disk +# $1 = data directory to mount +# 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 + mkdir -p "$1" + blkid | sort | cut -d: -f 1 | while read DEVICE; do + FS="$(device_bestfs "$DEVICE")" + mount -r "$DEVICE" "$1" $FS + if [ -d "$1/$LIVEKITNAME" ]; then + echo "$1/$LIVEKITNAME" return fi - umount $MNT 2>/dev/null + umount "$1" 2>/dev/null done } -mount_device() -{ - echo "A" -} - +# Mount squashfs filesystem bundles +# and add them to union +# $1 = directory where to search for bundles +# $2 = directory where to mount bundles +# $3 = directory where union is mounted +# 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 2>&1 +} \ No newline at end of file