fix broken repo
This commit is contained in:
+127
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -x
|
||||
cd "$(dirname $(readlink -f ${0}))"||exit 1
|
||||
|
||||
. ../.config
|
||||
|
||||
INITRAMFS="/tmp/MlbInitRd"
|
||||
trap "rm -rf ${INITRAMFS}&&exit 1" 2 3 6 15
|
||||
|
||||
# copy file to initramfs tree, including
|
||||
# all library dependencies (as shown by ldd)
|
||||
# $1 = file to copy (full path)
|
||||
copy_including_deps()
|
||||
{
|
||||
# if source doesn't exist or target exists, do nothing
|
||||
if [ ! -e "$1" -o -e "$INITRAMFS"/"$1" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
cp -R --parents "$1" "$INITRAMFS"
|
||||
if [ -L "$1" ]; then
|
||||
DIR="$(dirname "$1")"
|
||||
LNK="$(readlink "$1")"
|
||||
copy_including_deps "$(cd "$DIR"; realpath -s "$LNK")"
|
||||
fi
|
||||
|
||||
ldd "$1" 2>/dev/null | sed -r "s/.*=>|[(].*//g" | sed -r "s/^\\s+|\\s+\$//" \
|
||||
| while read LIB; do
|
||||
copy_including_deps "$LIB"
|
||||
done
|
||||
|
||||
for MOD in $(find "$1" -type f -name "*.ko"); do
|
||||
for DEP in $(cat /$LMK/modules.dep | fgrep /$(basename $MOD):); do
|
||||
copy_including_deps "/$LMK/$DEP"
|
||||
done
|
||||
done
|
||||
|
||||
shift
|
||||
if [ "$1" != "" ]; then
|
||||
copy_including_deps "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
rm -Rf $INITRAMFS
|
||||
mkdir -p $INITRAMFS/{bin,dev,etc,lib,lib64,mnt,proc,root,run,sys,tmp,usr,var/log}
|
||||
mkdir -p $INITRAMFS/usr/{sbin,bin}
|
||||
ln -s bin $INITRAMFS/sbin
|
||||
|
||||
# If bb is not found use all static prebuilt
|
||||
copy_including_deps /bin/busybox || { cp static/busybox $INITRAMFS/bin;static="true"; }
|
||||
for i in $($INITRAMFS/bin/busybox --list|egrep -v "tar|init"); do [ ! -e $INITRAMFS/bin/$i ]&&ln -sf busybox $INITRAMFS/bin/$i; done
|
||||
|
||||
mknod $INITRAMFS/dev/console c 5 1
|
||||
mknod $INITRAMFS/dev/null c 1 3
|
||||
mknod $INITRAMFS/dev/ram0 b 1 0
|
||||
mknod $INITRAMFS/dev/tty1 c 4 1
|
||||
mknod $INITRAMFS/dev/tty2 c 4 2
|
||||
mknod $INITRAMFS/dev/tty3 c 4 3
|
||||
mknod $INITRAMFS/dev/tty4 c 4 4
|
||||
|
||||
copy_including_deps /$LMK/kernel/fs
|
||||
for LINE in $(find /$LMK/kernel/ | grep crc32c); do
|
||||
copy_including_deps $LINE
|
||||
done
|
||||
copy_including_deps /$LMK/kernel/drivers/staging/zsmalloc # needed by zram
|
||||
copy_including_deps /$LMK/kernel/drivers/block/zram
|
||||
copy_including_deps /$LMK/kernel/drivers/block/loop.*
|
||||
# usb drivers
|
||||
copy_including_deps /$LMK/kernel/drivers/usb/storage/usb-storage.*
|
||||
copy_including_deps /$LMK/kernel/drivers/usb/host
|
||||
copy_including_deps /$LMK/kernel/drivers/usb/common
|
||||
copy_including_deps /$LMK/kernel/drivers/usb/core
|
||||
copy_including_deps /$LMK/kernel/drivers/hid/usbhid
|
||||
copy_including_deps /$LMK/kernel/drivers/hid/hid.*
|
||||
copy_including_deps /$LMK/kernel/drivers/hid/uhid.*
|
||||
copy_including_deps /$LMK/kernel/drivers/hid/hid-generic.*
|
||||
# disk and cdrom drivers
|
||||
copy_including_deps /$LMK/kernel/drivers/cdrom
|
||||
copy_including_deps /$LMK/kernel/drivers/scsi/sr_mod.*
|
||||
copy_including_deps /$LMK/kernel/drivers/scsi/sd_mod.*
|
||||
copy_including_deps /$LMK/kernel/drivers/scsi/scsi_mod.*
|
||||
copy_including_deps /$LMK/kernel/drivers/scsi/sg.*
|
||||
copy_including_deps /$LMK/kernel/drivers/ata
|
||||
copy_including_deps /$LMK/kernel/drivers/nvme
|
||||
copy_including_deps /$LMK/kernel/drivers/mmc
|
||||
|
||||
# copy all custom-built modules
|
||||
copy_including_deps /$LMK/updates
|
||||
copy_including_deps /$LMK/modules.*
|
||||
|
||||
cp static/mount.dynfilefs $INITRAMFS/bin
|
||||
cp static/fsck $INITRAMFS/bin
|
||||
[[ ${static} ]]&&cp static/bash $INITRAMFS/bin||copy_including_deps /bin/bash
|
||||
[[ ${static} ]]&&cp static/tar $INITRAMFS/bin||copy_including_deps /bin/tar||copy_including_deps /usr/bin/tar
|
||||
[[ ${static} ]]&&cp static/e2fsck $INITRAMFS/bin||copy_including_deps /sbin/e2fsck
|
||||
[[ ${static} ]]&&cp static/fsck.fat $INITRAMFS/bin||copy_including_deps /sbin/fsck.fat
|
||||
[[ ${static} ]]&&cp static/f2fs $INITRAMFS/bin||copy_including_deps /sbin/fsck.f2fs
|
||||
[[ ${static} ]]&&cp static/mdadm $INITRAMFS/bin||copy_including_deps /sbin/mdadm
|
||||
[[ ${static} ]]&&cp static/mount.ntfs-3g $INITRAMFS/bin||copy_including_deps /sbin/mount.ntfs-3g
|
||||
#[[ ${static} ]]&&cp static/blkid $INITRAMFS/bin||copy_including_deps /sbin/blkid
|
||||
#copy_including_deps /usr/bin/eject || cp static/eject $INITRAMFS/bin
|
||||
|
||||
# trim modules.order file. Perhaps we could remove it entirely
|
||||
MODULEORDER="$(cd "$INITRAMFS/$LMK/"; find -name "*.ko" | sed -r "s:^./::g" | tr "\n" "|" | sed -r "s:[.]:.:g")"
|
||||
cat $INITRAMFS/$LMK/modules.order | sed -r "s/.ko.gz\$/.ko/" | grep -E "$MODULEORDER"/foo/bar > $INITRAMFS/$LMK/_
|
||||
mv $INITRAMFS/$LMK/_ $INITRAMFS/$LMK/modules.order
|
||||
|
||||
depmod -b $INITRAMFS $(ls $INITRAMFS/lib/modules | sort)
|
||||
|
||||
echo "root::0:0::/root:/bin/sh" >$INITRAMFS/etc/passwd
|
||||
touch $INITRAMFS/etc/{m,fs}tab
|
||||
|
||||
cp shutdown $INITRAMFS
|
||||
cp functions $INITRAMFS/lib
|
||||
cp init $INITRAMFS
|
||||
ln -s ../init $INITRAMFS/bin/init
|
||||
cp ../.config $INITRAMFS/lib
|
||||
chmod a+x -R $INITRAMFS
|
||||
|
||||
cd $INITRAMFS
|
||||
find | cpio -R root:root -o -H newc 2>/dev/null | gzip -cf9 >$INITRAMFS.img
|
||||
echo $INITRAMFS.img
|
||||
|
||||
cd ..
|
||||
rm -rf $INITRAMFS
|
||||
[[ ${static} ]]&&exit 2||exit 0
|
||||
@@ -0,0 +1,200 @@
|
||||
# shellcheck disable=SC2148
|
||||
export PATH=".:/:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
export LD_LIBRARY_PATH="/lib:/lib/i386-linux-gnu:/lib64:/lib64/x86_64-linux-gnu:/lib/x86_64-linux-gnu:/usr/lib/i386-linux-gnu:/usr/lib64/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu"
|
||||
export MEMORY="/memory"
|
||||
export MODULES="${MEMORY}/modules"
|
||||
export CHANGES_MNT="${MEMORY}/changes"
|
||||
export CHANGES="${CHANGES_MNT}/changes"
|
||||
export WORK="${CHANGES_MNT}/work"
|
||||
export UNION="${MEMORY}/union"
|
||||
export DATAMNT="${MEMORY}/data"
|
||||
export SYSTEM="${MEMORY}/system"
|
||||
export SHELL_IS_ENABLED="_SHELL_ENABLED_"
|
||||
|
||||
progress()
|
||||
{
|
||||
sh -c "${1}" >/dev/null 2>&1&
|
||||
local pid="${!}"
|
||||
while :; do
|
||||
if [ -d /proc/${pid} ]; then
|
||||
echo -n "."
|
||||
sleep 0.25
|
||||
else
|
||||
echo -en " DONE!\n"
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
grepCmdLine()
|
||||
{
|
||||
for i in `</proc/cmdline`; do egrep "^${1}|^${1}=.*" <<<${i}|cut -f2 -d=; done
|
||||
return ${?}
|
||||
}
|
||||
d()
|
||||
{
|
||||
grepCmdLine debug >/dev/null 2>&1
|
||||
return ${?}
|
||||
}
|
||||
isShellEnabled()
|
||||
{
|
||||
d&&echo -n "Is 'shell' bootloader variable set? "
|
||||
if grepCmdLine shell; then
|
||||
d&&echo -en "Yes\n"
|
||||
sed -i "s/_SHELL_ENABLED_/true/g" /lib/functions >/dev/null 2>&1
|
||||
echo "[!] Reloading /lib/functions"
|
||||
if . /lib/functions; then
|
||||
echo -en "Done\n"
|
||||
else
|
||||
echo -en "Failed\n"
|
||||
emergencyShell
|
||||
fi
|
||||
else
|
||||
d&&echo -en "No\n"
|
||||
fi
|
||||
}
|
||||
isZramEnabled()
|
||||
{
|
||||
d&&echo -n "Is zram supported? "
|
||||
if [ -e /sys/block/zram0/disksize ]; then
|
||||
d&&echo -en "Yes\n"
|
||||
echo 536870912 >/sys/block/zram0/disksize
|
||||
mkswap /dev/zram0 >/dev/null 2>&1
|
||||
swapon /dev/zram0 >/dev/null 2>&1
|
||||
echo 100 >/proc/sys/vm/swappiness
|
||||
else
|
||||
d&&echo -en "No\n"
|
||||
fi
|
||||
}
|
||||
findData()
|
||||
{
|
||||
d&&echo -n "Searching ${DISTRO} in /dev -> "
|
||||
#local from="$(grepCmdLine from)"
|
||||
for i in ${root:-/dev/[hmnsv][dmrv][0-9a-z]*}; do
|
||||
d&&echo -n "${i#/dev/} "
|
||||
mount -o ro ${i} ${DATAMNT} >/dev/null 2>&1
|
||||
sleep 0.5
|
||||
#[[ ${from} ]]&&mount ${DATAMNT}/${from} ${DATAMNT} >/dev/null 2>&1
|
||||
if [ -e ${DATAMNT}/${DISTRO}/system.sfs ]; then
|
||||
d&&echo -e "\nFound ${DISTRO} in ${i}"
|
||||
grepCmdLine fsck&&fsck ${i} >/dev/null 2>&1||true
|
||||
d&&echo -n "Is 'toram' bootloader variable set and enought RAM space? "
|
||||
if grepCmdLine toram; local a=${?}&&[[ "$(grep MemFree /proc/meminfo|awk '{print $2}')" -gt $(("$(du ${DATAMNT}|tail -n1|awk '{print $1}')"-"$(du ${DATAMNT}/changes|tail -n1|awk '{print $1}')")) ]]; then
|
||||
d&&echo -en "Yes\n"
|
||||
mkdir -p /tmp/data
|
||||
d&&echo -n "Copying to RAM "
|
||||
d&&progress "tar -c -C ${DATAMNT} --exclude ./changes -f - . | tar -xf - -C /tmp/data"
|
||||
umount -f ${DATAMNT} >/dev/null 2>&1
|
||||
#[[ ${from} ]]&&umount -f ${DATAMNT} >/dev/null 2>&1
|
||||
mv -f /tmp/data/* ${DATAMNT} >/dev/null 2>&1
|
||||
rm -rf /tmp/data >/dev/null 2>&1
|
||||
else
|
||||
d&&if [[ "${a}" != "0" ]]; then echo -ne "Not requested by bootloader or low RAM space!\n"; else echo -ne "Internal error? Trying tmpfs, so data after power-off will be erased permanently!\n"; fi
|
||||
mount -o remount,rw ${DATAMNT} >/dev/null 2>&1||true
|
||||
fi
|
||||
mount ${DATAMNT}/${DISTRO}/system.sfs ${SYSTEM} >/dev/null 2>&1
|
||||
sleep 0.5
|
||||
break
|
||||
else
|
||||
umount -f ${DATAMNT} >/dev/null 2>&1
|
||||
fi
|
||||
done
|
||||
if ! grep -q ${SYSTEM} /proc/mounts; then
|
||||
d&&echo "Can not find compatible distro!"
|
||||
emergencyShell
|
||||
fi
|
||||
}
|
||||
findModules()
|
||||
{
|
||||
d&&echo -n "Trying to mount modules from ${DATAMNT}/${DISTRO}/modules -> "
|
||||
if ls ${DATAMNT}/${DISTRO}/modules/*.sfs >/dev/null 2>&1; then
|
||||
for i in $(find ${DATAMNT}/${DISTRO}/modules -maxdepth 1 -type f -name "*.sfs"|sort); do
|
||||
mkdir -p ${MODULES}/$(basename ${i} .sfs)
|
||||
d&&echo -n "$(basename ${i}) "
|
||||
mount ${i} ${MODULES}/$(basename ${i} .sfs) >/dev/null 2>&1
|
||||
done
|
||||
d&&echo -en "Done\n"
|
||||
else
|
||||
d&&echo -en "Failed, modules not found! Continuing...\n"
|
||||
fi
|
||||
}
|
||||
mountOverlay()
|
||||
{
|
||||
if grep -q ${MODULES} /proc/mounts; then
|
||||
mount -t overlay -o lowerdir=${SYSTEM}:$(find ${MODULES} -mindepth 1 -maxdepth 1 | tac | tr "\n" ":" | sed -r "s/:$//"),upperdir=${CHANGES},workdir=${WORK} overlay ${UNION}
|
||||
else
|
||||
mount -t overlay -o lowerdir=${SYSTEM},upperdir=${CHANGES},workdir=${WORK} overlay ${UNION}
|
||||
fi
|
||||
}
|
||||
persistentChanges()
|
||||
{
|
||||
if ! grepCmdLine perch&&grepCmdLine toram; then
|
||||
return
|
||||
fi
|
||||
local CHANGES T1 T2 EXISTS
|
||||
CHANGES=$DATAMNT/changes
|
||||
T1="$CHANGES/.empty"
|
||||
T2="$T1"2
|
||||
mkdir -p "$2"
|
||||
touch "$T1" 2>/dev/null && rm -f "$T1" 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
return
|
||||
fi
|
||||
d&&echo "Testing persistent changes for posix compatibility"
|
||||
touch "$T1" && ln -sf "$T1" "$T2" 2>/dev/null && \
|
||||
chmod +x "$T1" 2>/dev/null && test -x "$T1" && \
|
||||
chmod -x "$T1" 2>/dev/null && test ! -x "$T1" && \
|
||||
rm "$T1" "$T2" 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
d&&echo "Activating native persistent changes"
|
||||
mount --bind "$CHANGES" "$2" >/dev/null 2>&1
|
||||
return
|
||||
fi
|
||||
if [ -e "$CHANGES/changes.dat.0" ]; then
|
||||
d&&echo "Restoring persistent changes"
|
||||
EXISTS="true"
|
||||
else
|
||||
d&&echo "Creating new persistent changes"
|
||||
EXISTS=""
|
||||
fi
|
||||
mount.dynfilefs -f "$CHANGES/changes.dat" -s 16000 -m "$2" -p 4000 >/dev/null 2>&1
|
||||
[ ! "$EXISTS" ] && mke2fs -F -L "DATA" "$2/virtual.dat" >/dev/null 2>&1
|
||||
grepCmdLine fsck && fsck ${2}/virtual.dat >/dev/null 2>&1
|
||||
mount "$2/virtual.dat" "$2" >/dev/null 2>&1
|
||||
rm "$T1" "$T2" >/dev/null 2>&1
|
||||
rmdir "$2/lost+found" >/dev/null 2>&1
|
||||
}
|
||||
debugShell()
|
||||
{
|
||||
if [ "$SHELL_IS_ENABLED" = "true" ]; then
|
||||
echo -e "Debug shell!\nControl+D or 'exit' to contiunue boot.\n"
|
||||
setsid cttyhack sh
|
||||
fi
|
||||
}
|
||||
changeRoot()
|
||||
{
|
||||
cd "$1"
|
||||
umount -f /sys /proc
|
||||
cat <<eot >etc/fstab
|
||||
proc /proc proc defaults 0 0
|
||||
sysfs /sys sysfs defaults 0 0
|
||||
devpts /dev/pts devpts gid=5,mode=620 0 0
|
||||
tmpfs /dev/shm tmpfs defaults 0 0
|
||||
overlay / overlay defaults 0 0
|
||||
eot
|
||||
mkdir -p run
|
||||
mount -t tmpfs tmpfs run
|
||||
mkdir -p run/initramfs
|
||||
mount -o remount,ro overlay .
|
||||
pivot_root . run/initramfs
|
||||
exec chroot . init
|
||||
}
|
||||
emergencyShell()
|
||||
{
|
||||
exec >/dev/console >&1 2>&1 <&1
|
||||
echo "Error: Please inspect '/tmp/mlb.log' file"
|
||||
export PS1="RESCUE # "
|
||||
while :; do
|
||||
echo "Rescue shell!"
|
||||
setsid cttyhack sh
|
||||
done
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
. /lib/.config
|
||||
. /lib/functions
|
||||
|
||||
if [ ! -e /lib/.escaped ]; then
|
||||
SWITCH=/m
|
||||
mkdir -p ${SWITCH}
|
||||
mount -t tmpfs -o size="100%" tmpfs ${SWITCH}
|
||||
cp -a /??* ${SWITCH} 2>/dev/null
|
||||
cd ${SWITCH}
|
||||
mount -t proc proc /proc
|
||||
echo "0" >/proc/sys/kernel/printk
|
||||
>lib/.escaped
|
||||
d&&echo "[!] Reloading ${0}"
|
||||
mount --move /proc proc
|
||||
exec switch_root . ${0}
|
||||
fi
|
||||
mount -t devtmpfs devtmpfs /dev >/dev/null 2>&1
|
||||
ln -sf /proc/self/fd /dev/fd
|
||||
exec > >(tee -i /tmp/mlb.log) 2>&1
|
||||
d&&echo "'debug' bootloader variable is set!"&&set -x
|
||||
mount -t sysfs sysfs /sys >/dev/null 2>&1
|
||||
mkdir -p ${UNION} ${DATAMNT} ${SYSTEM}
|
||||
isShellEnabled
|
||||
ln -sf /proc/mounts /etc/mtab
|
||||
find /lib/modules/`uname -r` -name "*.ko" -type f | sed -r "s:^.*/|[.]ko\$::g" | xargs -n 1 modprobe >/dev/null 2>&1
|
||||
sleep 3
|
||||
mdev -s
|
||||
debugShell
|
||||
isZramEnabled
|
||||
mdadm --assemble --scan >/dev/null 2>&1
|
||||
sleep 0.5
|
||||
debugShell
|
||||
findData
|
||||
debugShell
|
||||
findModules
|
||||
debugShell
|
||||
persistentChanges ${SYSTEM} ${CHANGES_MNT}
|
||||
mkdir -p ${CHANGES} ${WORK}
|
||||
debugShell
|
||||
mountOverlay >/dev/null 2>&1
|
||||
debugShell
|
||||
d&&echo "Starting ${DISTRO}"
|
||||
d&&sleep 2
|
||||
changeRoot "$UNION" || clear; echo "!!ERROR occured, you shouldn't be here.!!"; sleep 3
|
||||
emergencyShell
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
# Original Author: Tomas M <http://www.linux-live.org/>
|
||||
# Author: Daniel K. <http://danielisko.net, http://git.danielisko.net>
|
||||
|
||||
action="${1}"
|
||||
. /lib/.config
|
||||
. /lib/functions
|
||||
detach_loops()
|
||||
{
|
||||
losetup -a | cut -d : -f 1 | xargs -r -n 1 losetup -d
|
||||
}
|
||||
umount_all()
|
||||
{
|
||||
for i in $(tac /proc/mounts | cut -d" " -f2 | grep "^${1}"); do
|
||||
umount -fld ${i}
|
||||
detach_loops
|
||||
done
|
||||
}
|
||||
|
||||
exec </dev/console >>/dev/console 2>>/dev/console
|
||||
[ "${DEBUG_IS_ENABLED}" = "true" ]&&set -x
|
||||
debugShell
|
||||
echo "Minimal Linux Booter - Shutdown Magic!"
|
||||
echo "Entering to clean-up things before final step."
|
||||
(
|
||||
mdev -s
|
||||
sleep 1.5
|
||||
detach_loops
|
||||
umount_all /oldroot
|
||||
NR=100
|
||||
for i in $(tac /proc/mounts | cut -d" " -f2 | grep ^/oldroot/.); do
|
||||
NR=$((${NR}+1))
|
||||
mkdir -p /move/${NR}
|
||||
mount --move ${i} /move/${NR}
|
||||
umount -fld /oldroot
|
||||
done
|
||||
for i in 1 2 3 4; do
|
||||
for d in $(ls -1 /move 2>/dev/null | sort); do
|
||||
umount_all /move/${d}
|
||||
done
|
||||
done
|
||||
umount_all /memory
|
||||
) >/dev/null 2>&1
|
||||
case ${action} in
|
||||
reboot|poweroff|halt|shutdown) ${action} -f;;
|
||||
*) reboot -f;;
|
||||
esac
|
||||
emergencyShell #Last luck emergency shell after reboot doesn't work; usefull for debugging
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
dev=$1
|
||||
[ "$dev" = "" ] && exit 1
|
||||
|
||||
fs=$(blkid "$dev" | grep -o ' TYPE=".*' | cut -f 2 -d '"')
|
||||
|
||||
case $fs in
|
||||
ext2|ext3|ext4) e2fsck -y $dev ;;
|
||||
vfat|msdos) fsck.fat -y $dev ;;
|
||||
exfat) exfatfsck $dev ;;
|
||||
*) echo "(${dev}) Not supported: $fs" ; exit 1 ;;
|
||||
esac
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user