5 Commits

Author SHA1 Message Date
Danieliskot 09218bf9b4 medium change set 2023-12-26 00:38:18 +01:00
daniel 51ad55627c Zaktualizuj 'initrd/create' 2023-10-20 01:56:55 +02:00
daniel 8b2ed93edf fix typos 2023-10-13 12:11:58 +02:00
Danieliskot 6fb6379b4c test enchants 2 2023-10-13 11:32:19 +02:00
Danieliskot 107cd03263 testing new enchants 2023-10-13 01:41:27 +02:00
13 changed files with 274 additions and 236 deletions
+2
View File
@@ -1 +1,3 @@
.config .config
cache/*
images/*
+3
View File
@@ -0,0 +1,3 @@
[submodule "ext/checkbox"]
path = ext/checkbox
url = https://github.com/pedro-hs/checkbox.sh
+5 -3
View File
@@ -1,7 +1,9 @@
Minimal Linux Booter Linux Live Framework
====================
Copyright (C) 2023 Tomas M <slax.org, linux-live.org>. Copyright (C) 2023 Tomas M. <slax.org, linux-live.org>.
Copyright (C) 2023 Danuel K. <danielisko.net, git.danielisko.net>. Copyright (C) 2023 Daniel K. <danielisko.net, git.danielisko.net>.
Copyright (C) 2020 Pedro Santos Arruda <github.com/pedro-hs>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
+4 -5
View File
@@ -1,12 +1,11 @@
Minimal Linux Booter Linux Live Framework
==================== ====================
This project is to minimize Linux-Live Kit (https://github.com/Tomas-M/linux-live) This project is for supporting many CPUs architectures & extended functions unlike Linux-Live Kit (https://github.com/Tomas-M/linux-live)
Note: Note:
* Your distro must have installed: * Your distro must have installed:
- squashfs-tools, - squashfs-tools,
- xorriso,
- cpio, - cpio,
- file, - file,
- gzip, - gzip,
@@ -14,7 +13,8 @@ Note:
- tar, - tar,
- grep, - grep,
- rsync, - rsync,
- syslinux-utils, - find-utils,
- grub2,
- bash, - bash,
- (Optional) mdadm. - (Optional) mdadm.
- (Optional for light "system.sfs", (if most on left then best compression)) zstd, xz, lzma, bzip2 and gzip. - (Optional for light "system.sfs", (if most on left then best compression)) zstd, xz, lzma, bzip2 and gzip.
@@ -27,7 +27,6 @@ Note:
- fdisk, - fdisk,
- cfdisk, - cfdisk,
- mke2fs, - mke2fs,
- grub2.
* You can also boot your linux distro in frugal mode (for Windows and Linux): * You can also boot your linux distro in frugal mode (for Windows and Linux):
- For Linux (All hdd free space in frugal mode): - For Linux (All hdd free space in frugal mode):
- Boot your linux distro, - Boot your linux distro,
+86 -55
View File
@@ -1,53 +1,44 @@
#!/usr/bin/env bash #!/usr/bin/env bash
for i in mksquashfs cpio gzip sed grep xorriso tar file; do cd "$(dirname $(readlink -f ${0}))"
if [ ! -x "$(command -v ${i})" ]; then exec > >(tee -i /tmp/llf.log) 2>&1
#trap 'echo $(basename ${BASH_SOURCE[0]}):${LINENO}: "${BASH_COMMAND}"' DEBUG
set -eET -o pipefail
. initrd/functions||true
for i in mksquashfs cpio gzip sed grep xorriso tar find file grub-mkrescue; do
if [ ! -x "$(type -P ${i})" ]; then
progsNotFound+=(${i})
case ${i} in case ${i} in
mksquashfs) a="squashfs-tools";; mksquashfs) a="squashfs-tools";;
readelf) a="binutils";; readelf) a="binutils";;
find) a="find-utils";;
grub-mkrescue) a="grub2";;
*) a="${i}" *) a="${i}"
esac esac
echo "Please install ${a} package to run this tool" echo "Please install ${a} package"
exit 1 false
fi fi
done done
exec > >(tee -i /tmp/mlb.log) 2>&1 main()
cd "$(dirname $(readlink -f ${0}))" || exit 1 {
cp -f config .config local DATA ret tmpRoot utc v krnV
krnV="$(file -bL ${kernel} | grep -o 'version .*' | cut -d' ' -f2)"
mapfile -t list < <(ls -A /boot | egrep "bzImage|kernel|vmlinuz" 2>/dev/null | egrep -v "init|*.old") top="${PWD}"
if [ ${#list[@]} -gt 1 ]; then INITRAMFS="${workTmpDir}/initRd"
n=0
echo -e "Please choose your kernel to proceed:\nChoose number from ${n} to ${#list[@]}\n-----\n"
for a in "${list[@]}"; do
echo "[${n}] - ${a}"
((n++))
done
echo "-----"
read kernel
kernel="/boot/${list[${kernel}]}"
unset list n
else
kernel="/boot/${list[0]}"
fi
set -x
time (
echo "KERNEL=\"${kernel}\"" >>.config
echo "LMK=\"/lib/modules/$(file -bL ${kernel} | grep -o 'version .*' | cut -d' ' -f2)\"" >>.config
unset kernel
top="$(pwd)"
. .config
workTmpDir="$(mktemp -d /tmp/Mlb_WorkDir_XXXXXXX)"
DATA="${workTmpDir}/isoImage" DATA="${workTmpDir}/isoImage"
INITRD="$(initrd/create)" cat <<eot >>.config
KERNEL='$(readlink -f ${kernel})'
LMK='/lib/modules/${krnV}'
eot
env INITRAMFS="${INITRAMFS}" V="${V}" top="${top}" LMK="/lib/modules/${krnV}" initrd/create||true
ret="${?}" ret="${?}"
tmpRoot="${workTmpDir}/tmpRoot" tmpRoot="${workTmpDir}/tmpRoot"
trap "rm -rf ${workTmpDir} /tmp/MlbInitRd{,.img}&&exit 1" 2 6 15 mkdir -p $([ ${V} ]&&echo ${V}) ${DATA}/changes ${DATA}/os/modules
mkdir -p ${DATA}/changes ${DATA}/${DISTRO}/modules mv -f $([ ${V} ]&&echo ${V}) ${INITRAMFS}.img ${DATA}/initrd.img
rsync --force -aAP $(for i in $(awk '{print $2}' /proc/mounts) /tmp; do echo "--exclude=${i}/*"; done) / ${tmpRoot} rsync --force -aA $([ ${V} ]&&echo -P) $(for i in $(awk '{print $2}' /proc/mounts) /tmp; do echo "--exclude=${i}/*"; done) $(for i in /lib/modules/*; do [[ "${i}" =~ ${krnV} ]]&&continue||echo "--exclude=${i}";done) / ${tmpRoot}
chmod +x -R inc2sys chmod +x -R $([ ${V} ]&&echo ${V}) inc2sys
cp -rf inc2sys/* ${tmpRoot} cp -rf $([ ${V} ]&&echo ${V}) inc2sys/* ${tmpRoot}
mknod ${tmpRoot}/dev/console c 5 1 mknod ${tmpRoot}/dev/console c 5 1
mknod ${tmpRoot}/dev/null c 1 3 mknod ${tmpRoot}/dev/null c 1 3
mknod ${tmpRoot}/dev/ram0 b 1 0 mknod ${tmpRoot}/dev/ram0 b 1 0
@@ -55,28 +46,68 @@ time (
mknod ${tmpRoot}/dev/tty2 c 4 2 mknod ${tmpRoot}/dev/tty2 c 4 2
mknod ${tmpRoot}/dev/tty3 c 4 3 mknod ${tmpRoot}/dev/tty3 c 4 3
mknod ${tmpRoot}/dev/tty4 c 4 4 mknod ${tmpRoot}/dev/tty4 c 4 4
for i in zstd xz lzma bzip2 gzip; do for i in zstd xz lz4 lzo gzip; do
mksquashfs ${tmpRoot} ${DATA}/${DISTRO}/system.sfs -comp ${i} -noappend -limit 50 mksquashfs ${tmpRoot} ${DATA}/os/system.sfs -comp $([ ${i} = lz4 ]&&echo echo "${i} -Xhc"||echo ${i}) $([ ${V} ]&&echo "-progress"||echo "-no-progress") -processors $(($(nproc)/6)) -noappend -limit 50
[ -e ${DATA}/${DISTRO}/system.sfs ]&&break [ -e ${DATA}/os/system.sfs ]&&break
done done
mv -f ${INITRD} ${DATA}/initrd.img cp -rf $([ ${V} ]&&echo ${V}) bootfiles/* ${DATA}
cp -rf bootfiles/* ${DATA}
for i in ${DATA}/syslinux.cfg ${DATA}/boot/grub/grub.cfg; do for i in ${DATA}/syslinux.cfg ${DATA}/boot/grub/grub.cfg; do
sed -i -r "s/__DISTRO__/${DISTRO}/" ${i} sed -i -r "s/__DISTRO__/${DISTRO}/" ${i}
done done
cp -f ${KERNEL} ${DATA}/vmlinuz cp -f $([ ${V} ]&&echo ${V}) ${KERNEL} ${DATA}/vmlinuz
cd ${DATA} cd ${DATA}
utc="$(date +%s)" utc="$(date +%s)"
v="$(git -C ${top} rev-parse HEAD 2>/dev/null)"&&v="${v}:GIT"||v="INFINITY:LOCAL" v="$(git -C ${top} rev-parse HEAD 2>/dev/null|tr [:lower:] [:upper:]):$(git -C ${top} branch --show-current 2>/dev/null|tr [:lower:] [:upper:]):GIT"||true;v="INFINITY:PRIVATE:LOCAL"
cat <<eot >.MlbMeta cat <<eot >.LlfMeta
# Built using Minimal-Linux-Booter technology. # Built using Linux-Live-Framework technology.
MLB_VERSION="${v}" LLF_NAME="${DISTRO}"
MLB_NAME="${DISTRO}" LLF_VERSION="${v}"
MLB_UTC="${utc}" LLF_UTC="${utc}"
eot eot
[[ ${ret} = 2 ]]&&echo "MLB_ELF_STATIC_INITRD=\"1\"" >>.MlbMeta||echo "MLB_ELF_STATIC_INITRD=\"0\"" >>.MlbMeta [[ ${ret} = 2 ]]&&echo "LLF_ELF_STATIC_INITRD=\"y\"" >>.LlfMeta||echo "LLF_ELF_STATIC_INITRD=\"n\"" >>.LlfMeta
xorriso -as mkisofs -o /${DISTRO}-${utc}.iso -iso-level 3 -J -R -D -A ${DISTRO} -V ${DISTRO} -no-emul-boot -boot-info-table -boot-load-size 2 -b boot/grub/i386-pc/eltorito.img -c boot/grub/grub.cat -eltorito-alt-boot -e /efi.img -no-emul-boot . grub-mkrescue $([ ${V} ]&&echo ${V}) -o /${DISTRO}-${utc}.iso --compress=xz --product-name="${DISTRO}" --product-version="v=${v} t=${UTC}" .
isohybrid --version >/dev/null 2>&1&&isohybrid -u /${DISTRO}-${utc}.iso mv -f /${DISTRO}-${utc}.iso ${top}/images/${DISTRO}-${utc}.iso
cd ${top} #xorriso -as mkisofs -o /${DISTRO}-${utc}.iso -iso-level 3 -J -R -D -A ${DISTRO} -V ${DISTRO} -no-emul-boot -boot-info-table -boot-load-size 2 -b isolinux.bin -c boot/grub/grub.cat -eltorito-alt-boot -e /efi.img -no-emul-boot .
rm -rf ${workTmpDir} #isohybrid --version >/dev/null 2>&1&&isohybrid -u /${DISTRO}-${utc}.iso
) }
selectKernel()
{
local checkbox_output list
mapfile -t list < <(find /boot -type f|egrep "bzImage|kernel|vmlinuz" 2>/dev/null|egrep -v "init|.*.old$"|sort -rn)
if [ ${#list[@]} -gt 1 ]; then
. ext/checkbox/checkbox.sh --message="Please choose your kernel version to proceed:" --index --options="$(for i in "${list[@]}"; do basename "${i}";done;)"
kernel="${list[${checkbox_output}]}"
else
kernel="${list[0]}"
fi
export kernel
}
validArgs="$(getopt --name "${0}" --options 'i::k:d:w:CDnv' --longoptions 'interactive,,kernel:,distro:,workdir:,clean,debug,dry-run,verbose' -- "$@")"
[[ ${?} -ne 0 ]]&&false
eval set -- "${validArgs}"
while :; do
case ${1} in
-i|--interactive) helper=true ;;
-k|--kernel) kernel="${2}"; shift ;;
-d|--distro) DISTRO="${2}"; shift ;;
-w|--workdir) workTmpDir="${2}"; shift ;;
-D|--debug) set -x ;;
-n|--dry-run) set -nv ;;
-v|--verbose) set -v ;;
-C|--clean) clean=true ;;
--) shift; break ;;
esac
shift
done
#shift $((OPTIND-1))
export SHELLOPTS
cp -f config .config
export V setCompatFlags clean
trap '. initrd/functions 2>/dev/null;[[ ${clean} ]]&& { m A "\nCleaning-up";if rp f "rm -rf ${workTmpDir}";then m i "\nDone!\n";else m w "\nFailed!\n";fi; };reset;exit ${?}' QUIT EXIT INT TERM
[[ ${helper} ]]&&selectKernel
[[ -z ${DISTRO} ]]&&. .config&&m w "DISTRO not set. Using defaults: ${DISTRO}\n"||true
workTmpDir="${workTmpDir:-$(mktemp -d cache/Llf_WorkDir_XXXXX_$(date +%s))}"||true
mkdir -p "${workTmpDir}"
export workTmpDir DISTRO kernel V
main
exit ${?}
Submodule
+1
Submodule ext/checkbox added at 5692b6e8f0
+1 -1
View File
@@ -8,7 +8,7 @@
# This shell script is contributed under the terms of GPL v2 by Thomas Schoenhuetl <pilleus.pulcher@arcor.de> 22.05.2007. # This shell script is contributed under the terms of GPL v2 by Thomas Schoenhuetl <pilleus.pulcher@arcor.de> 22.05.2007.
# Modified script "slax2hd" for installing Generic Linux to hdd # Modified script "slax2hd" for installing Generic Linux to hdd
# BY: Daniel K. aka *DANiO* # BY: Daniel K. aka Danieliskot <http://danielisko.net, http://git.danielisko.net>
for i in dialog fdisk cfdisk sed grep mke2fs grub-install; do for i in dialog fdisk cfdisk sed grep mke2fs grub-install; do
if [ ! -x $(command -v ${i}) ]; then if [ ! -x $(command -v ${i}) ]; then
+67 -86
View File
@@ -1,127 +1,108 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -x #set -eET -o pipefail
cd "$(dirname $(readlink -f ${0}))"||exit 1 #trap 'echo $(basename ${BASH_SOURCE[0]}):${LINENO}: "${BASH_COMMAND}"' DEBUG
export setCompatFlags top LMK setCompatFlags
trap 'rm -rf ${TOP}/${INITRAMFS}{,.img};exit ${?}' INT TERM
cd "$(dirname $(readlink -f ${0}))"||false
. ../.config||false
. ../.config #add more ELFs, if need ;)
list=(bash blkid tar e2fsck fsck.fat fsck.f2fs mdadm mount.ntfs-3g)
INITRAMFS="/tmp/MlbInitRd"
trap "rm -rf ${INITRAMFS}&&exit 1" 2 3 6 15
# copy file to initramfs tree, including # copy file to initramfs tree, including
# all library dependencies (as shown by ldd) # all library dependencies (as shown by ldd)
# $1 = file to copy (full path) # ${1} = file to copy (full path)
copy_including_deps() copy_including_deps()
{ {
# if source doesn't exist or target exists, do nothing # if source doesn't exist or target exists, do nothing
if [ ! -e "$1" -o -e "$INITRAMFS"/"$1" ]; then if [[ ! -e "${1}" || -e "${INITRAMFS}"/"${1}" || -e ${INITRAMFS}"/${2}" ]]; then
return 1 return 1
fi fi
cp -R --parents "$1" "$INITRAMFS" [ ${2} ]&&cp -r -T $([ ${V} ]&&echo ${V}) "${1}" "${INITRAMFS}/bin"||cp -r --parents $([ ${V} ]&&echo ${V}) "${1}" "${INITRAMFS}"
if [ -L "$1" ]; then if [ -L "${1}" ]; then
DIR="$(dirname "$1")" DIR="$(dirname "${1}")"
LNK="$(readlink "$1")" LNK="$(readlink "${1}")"
copy_including_deps "$(cd "$DIR"; realpath -s "$LNK")" copy_including_deps "$(cd "$DIR"; realpath -s "$LNK")"
fi fi
ldd "$1" 2>/dev/null | sed -r "s/.*=>|[(].*//g" | sed -r "s/^\\s+|\\s+\$//" \ ldd "${1}" 2>/dev/null | sed -r "s/.*=>|[(].*//g" | sed -r "s/^\\s+|\\s+\$//" \
| while read LIB; do | while read LIB; do
copy_including_deps "$LIB" copy_including_deps "$LIB"
done done
for MOD in $(find "$1" -type f -name "*.ko"); do for MOD in $(find "${1}" -type f -name "*.ko"); do
for DEP in $(cat /$LMK/modules.dep | fgrep /$(basename $MOD):); do for DEP in $(cat /$LMK/modules.dep | fgrep /$(basename $MOD):); do
copy_including_deps "/$LMK/$DEP" copy_including_deps "/$LMK/$DEP"
done done
done done
shift shift
if [ "$1" != "" ]; then if [ "${1}" != "" ]; then
copy_including_deps "$@" copy_including_deps "${@}"
fi fi
} }
incDynElf()
{
local f
f="$(type -P ${1})"
copy_including_deps ${f} /bin/$(basename ${f})
return ${?}
}
rm -Rf $INITRAMFS mkdir -p ${INITRAMFS}/{bin,dev,etc,lib{32,64,x32,},mnt,proc,root,run,sys,tmp,usr{,/local}/{sbin,bin,lib{32,64,x32,}},var/log}
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 # If bb is not found use all static prebuilt
copy_including_deps /bin/busybox || { cp static/busybox $INITRAMFS/bin;static="true"; } incDynElf busybox || { cp -f 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 for i in $(${INITRAMFS}/bin/busybox --list|egrep -v "tar|init|blkid"); do ln -sf $([ ${V} ]&&echo ${V}) busybox ${INITRAMFS}/bin/$i; done
mknod $INITRAMFS/dev/console c 5 1 mknod ${INITRAMFS}/dev/console c 5 1
mknod $INITRAMFS/dev/null c 1 3 mknod ${INITRAMFS}/dev/null c 1 3
mknod $INITRAMFS/dev/ram0 b 1 0 mknod ${INITRAMFS}/dev/ram0 b 1 0
mknod $INITRAMFS/dev/tty1 c 4 1 mknod ${INITRAMFS}/dev/tty1 c 4 1
mknod $INITRAMFS/dev/tty2 c 4 2 mknod ${INITRAMFS}/dev/tty2 c 4 2
mknod $INITRAMFS/dev/tty3 c 4 3 mknod ${INITRAMFS}/dev/tty3 c 4 3
mknod $INITRAMFS/dev/tty4 c 4 4 mknod ${INITRAMFS}/dev/tty4 c 4 4
copy_including_deps /$LMK/kernel/fs
for LINE in $(find /$LMK/kernel/ | grep crc32c); do for i in /$LMK/kernel/fs $(find /$LMK/kernel/ | grep crc32) /$LMK/kernel/drivers/staging/zsmalloc /$LMK/kernel/drivers/block/zram /$LMK/kernel/drivers/block/loop.* /$LMK/kernel/drivers/usb/storage/usb-storage.* /$LMK/kernel/drivers/usb/host /$LMK/kernel/drivers/usb/common /$LMK/kernel/drivers/usb/core /$LMK/kernel/drivers/hid/usbhid /$LMK/kernel/drivers/hid/hid.* /$LMK/kernel/drivers/hid/uhid.* /$LMK/kernel/drivers/hid/hid-generic.* /$LMK/kernel/drivers/cdrom /$LMK/kernel/drivers/scsi/sr_mod.* /$LMK/kernel/drivers/scsi/sd_mod.* /$LMK/kernel/drivers/scsi/scsi_mod.* /$LMK/kernel/drivers/scsi/sg.* /$LMK/kernel/drivers/ata /$LMK/kernel/drivers/nvme /$LMK/kernel/drivers/mmc /$LMK/updates /$LMK/modules.*; do copy_including_deps ${i};done
copy_including_deps $LINE
cp -f $([ ${V} ]&&echo ${V}) static/mount.dynfilefs static/fsck ${top}/ext/checkbox/checkbox.sh ${INITRAMFS}/bin
if [[ ${static} ]]; then
for i in "${list[@]}"; do
cp -f $([ ${V} ]&&echo ${V}) static/${i} ${INITRAMFS}/bin
done done
copy_including_deps /$LMK/kernel/drivers/staging/zsmalloc # needed by zram else
copy_including_deps /$LMK/kernel/drivers/block/zram for i in "${list[@]}"; do
copy_including_deps /$LMK/kernel/drivers/block/loop.* incDynElf ${i}
# usb drivers done
copy_including_deps /$LMK/kernel/drivers/usb/storage/usb-storage.* fi
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 # 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")" 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/_ 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 mv -f $([ ${V} ]&&echo ${V}) ${INITRAMFS}/$LMK/_ ${INITRAMFS}/$LMK/modules.order
depmod -b $INITRAMFS $(ls $INITRAMFS/lib/modules | sort) depmod -b ${INITRAMFS} $(ls ${INITRAMFS}/lib/modules | sort)
echo "root::0:0::/root:/bin/sh" >$INITRAMFS/etc/passwd echo "root::0:0::/root:/bin/bash" >${INITRAMFS}/etc/passwd
touch $INITRAMFS/etc/{m,fs}tab :>${INITRAMFS}/etc/{m,fs}tab
cp shutdown $INITRAMFS cp -f $([ ${V} ]&&echo ${V}) functions ${INITRAMFS}/lib
cp functions $INITRAMFS/lib cp -f $([ ${V} ]&&echo ${V}) init shutdown ${INITRAMFS}
cp init $INITRAMFS ln -sf $([ ${V} ]&&echo ${V}) ../init ${INITRAMFS}/bin/init
ln -s ../init $INITRAMFS/bin/init cp -f $([ ${V} ]&&echo ${V}) ../.config ${INITRAMFS}/lib
cp ../.config $INITRAMFS/lib chmod a+x -R $([ ${V} ]&&echo ${V}) ${INITRAMFS}
chmod a+x -R $INITRAMFS
cd $INITRAMFS cd ${INITRAMFS}
find | cpio -R root:root -o -H newc 2>/dev/null | gzip -cf9 >$INITRAMFS.img find lib usr{,/local}/lib -name "*.so" -exec sh -c 'ln -s ${1} lib/$(basename ${1})' _ {} \;
echo $INITRAMFS.img # for d in {s,}bin usr{,/local}/{s,}bin; do
# for f in ${d}/*; do
# ln -s ${f} bin
# done
# done
find . | cpio -R root:root -o -H newc 2>/dev/null | gzip -cf9 >${INITRAMFS}.img
cd .. cd ..
rm -rf $INITRAMFS rm -rf ${INITRAMFS}
[[ ${static} ]]&&exit 2||exit 0 [[ ${static} ]]&&exit 2||exit 0
+96 -77
View File
@@ -9,25 +9,12 @@ export WORK="${CHANGES_MNT}/work"
export UNION="${MEMORY}/union" export UNION="${MEMORY}/union"
export DATAMNT="${MEMORY}/data" export DATAMNT="${MEMORY}/data"
export SYSTEM="${MEMORY}/system" export SYSTEM="${MEMORY}/system"
export SHELL_IS_ENABLED="_SHELL_ENABLED_" export SHELL_IS_ENABLED=false
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() grepCmdLine()
{ {
for i in `</proc/cmdline`; do egrep "^${1}|^${1}=.*" <<<${i}|cut -f2 -d=; done egrep -o "(^|[[:space:]])${1}=[^[:space:]]+" /proc/cmdline | tr -d " " | cut -d "=" -f 2- | tail -n 1
#for i in $(</proc/cmdline); do egrep "^${1}|^${1}=.*" <<<${i}|cut -f2 -d=; done
return ${?} return ${?}
} }
d() d()
@@ -35,63 +22,99 @@ d()
grepCmdLine debug >/dev/null 2>&1 grepCmdLine debug >/dev/null 2>&1
return ${?} return ${?}
} }
m()
{
case "${1}" in
q) echo -e "[Question]: ${2}";;
A) echo -e "[Action]: ${2}";;
i) echo -e "[Info]: ${2}";;
w) echo -e "[Warning]: ${2}";;
e) echo -e "[Error]: ${2}";;
f) echo -e "[Fatal]: ${2}";;
*) echo -e "${1}";;
esac
}
rp()
{
local pid force
[[ ${1} = f ]]&&force=true
shift
sh -c "${1}" >/dev/null 2>&1&
pid="${!}"
while :; do
if [ -d /proc/${pid} ]; then
[ ${force} ]&&echo -n "."
d&&echo -n "."
sleep 0.25
else
break
fi
done
return ${?}
}
isShellEnabled() isShellEnabled()
{ {
d&&echo -n "Is 'shell' bootloader variable set? " d&&m q "Is 'shell' bootloader variable set "
if grepCmdLine shell; then if grepCmdLine shell; then
d&&echo -en "Yes\n" d&&m a "Yes\n"
sed -i "s/_SHELL_ENABLED_/true/g" /lib/functions >/dev/null 2>&1 sed -i "s/SHELL_IS_ENABLED=false/SHELL_IS_ENABLED=true/" /lib/functions
echo "[!] Reloading /lib/functions" m A "Reloading /lib/functions "
if . /lib/functions; then if . /lib/functions; then
echo -en "Done\n" m i "Done\n"
else else
echo -en "Failed\n" m f "Failed\n"
emergencyShell emergencyShell
fi fi
else else
d&&echo -en "No\n" d&&m a "No\n"
fi fi
} }
isZramEnabled() isZramEnabled()
{ {
d&&echo -n "Is zram supported? " d&&m q "Is zram supported? "
if [ -e /sys/block/zram0/disksize ]; then if [ -e /sys/block/zram0/disksize ]; then
d&&echo -en "Yes\n" d&&m a "Yes\n"
m A "Enabling zram "
echo 536870912 >/sys/block/zram0/disksize echo 536870912 >/sys/block/zram0/disksize
mkswap /dev/zram0 >/dev/null 2>&1 if mkswap /dev/zram0 >/dev/null 2>&1;then m i "Done\n";else m w "Failed\n";fi
swapon /dev/zram0 >/dev/null 2>&1 if swapon /dev/zram0 >/dev/null 2>&1;then m i "Done\n";else m w "Failed\n";fi
echo 100 >/proc/sys/vm/swappiness echo 100 >/proc/sys/vm/swappiness
else else
d&&echo -en "No\n" d&&m i "No\n"
fi
}
toRam()
{
d&&m q "Is 'toram' bootloader variable set and enought RAM space? "
if grepCmdLine toram; 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&&m a "Yes\n"
mkdir -p /tmp/data
d&&m A "Copying to RAM "
if progress f "tar -c -C ${DATAMNT} --exclude ./changes -f - . | tar -xf - -C /tmp/data";then dm i "Done\n";else m w "Failed\n";fi
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&&[[ "${a}" != "0" ]]&&m e "Not requested by bootloader or low RAM space!\n"||m w "Internal error? Trying tmpfs, so data after power-off will be erased permanently!\n"
mount -o remount,rw ${DATAMNT} >/dev/null 2>&1||true
fi fi
} }
findData() findData()
{ {
d&&echo -n "Searching ${DISTRO} in /dev -> " d&&m A "Searching ${DISTRO} in /dev -> "
#local from="$(grepCmdLine from)" local data a
for i in ${root:-/dev/[hmnsv][dmrv][0-9a-z]*}; do data="$(grepCmdLine from)"
d&&echo -n "${i#/dev/} " for i in ${root:-$(blkid|cut -d: -f1||echo /dev/[hmnsv][dmrv][0-9a-z]*)}; do
d&&m "${i#/dev/} "
mount -o ro ${i} ${DATAMNT} >/dev/null 2>&1 mount -o ro ${i} ${DATAMNT} >/dev/null 2>&1
sleep 0.5 sleep 0.5
#[[ ${from} ]]&&mount ${DATAMNT}/${from} ${DATAMNT} >/dev/null 2>&1 [[ ${data} ]]&&mount ${DATAMNT}/${data} ${DATAMNT} >/dev/null 2>&1
if [ -e ${DATAMNT}/${DISTRO}/system.sfs ]; then if [[ -e ${DATAMNT}/.LlfMeta && -e ${DATAMNT}/os/system.sfs ]]; then
d&&echo -e "\nFound ${DISTRO} in ${i}" d&&m i "\nFound ${DISTRO} in ${i}\n"
grepCmdLine fsck&&fsck ${i} >/dev/null 2>&1||true if grepCmdLine fsck;then fsck ${i} >/dev/null 2>&1;else true;fi
d&&echo -n "Is 'toram' bootloader variable set and enought RAM space? " toRam
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 mount ${DATAMNT}/os/system.sfs ${SYSTEM} >/dev/null 2>&1
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 sleep 0.5
break break
else else
@@ -99,22 +122,22 @@ findData()
fi fi
done done
if ! grep -q ${SYSTEM} /proc/mounts; then if ! grep -q ${SYSTEM} /proc/mounts; then
d&&echo "Can not find compatible distro!" d&&m f "Can not find compatible distro!\n"
emergencyShell emergencyShell
fi fi
} }
findModules() findModules()
{ {
d&&echo -n "Trying to mount modules from ${DATAMNT}/${DISTRO}/modules -> " d&&m A "Trying to mount modules from ${DATAMNT}/${DISTRO}/modules -> "
if ls ${DATAMNT}/${DISTRO}/modules/*.sfs >/dev/null 2>&1; then 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 for i in $(find ${DATAMNT}/${DISTRO}/modules -maxdepth 1 -type f -name "*.sfs"|sort); do
mkdir -p ${MODULES}/$(basename ${i} .sfs) mkdir -p ${MODULES}/$(basename ${i} .sfs)
d&&echo -n "$(basename ${i}) " d&&m "$(basename ${i}) "
mount ${i} ${MODULES}/$(basename ${i} .sfs) >/dev/null 2>&1 mount ${i} ${MODULES}/$(basename ${i} .sfs) >/dev/null 2>&1
done done
d&&echo -en "Done\n" d&&m i "Done\n"
else else
d&&echo -en "Failed, modules not found! Continuing...\n" d&&m w "Modules not found! Continuing...\n"
fi fi
} }
mountOverlay() mountOverlay()
@@ -128,36 +151,32 @@ mountOverlay()
persistentChanges() persistentChanges()
{ {
if ! grepCmdLine perch&&grepCmdLine toram; then if ! grepCmdLine perch&&grepCmdLine toram; then
return return ${?}
fi fi
local CHANGES T1 T2 EXISTS local CHANGES T1 T2 EXISTS
CHANGES=$DATAMNT/changes CHANGES=$DATAMNT/changes
T1="$CHANGES/.empty" T1="$CHANGES/.empty"
T2="$T1"2 T2="$T1"2
d&&m A "Testing for RW access to persistent changes...\n"
mkdir -p "$2" mkdir -p "$2"
touch "$T1" 2>/dev/null && rm -f "$T1" 2>/dev/null touch "$T1" 2>/dev/null&&rm -f "$T1" 2>/dev/null||d&&m w "Failed\n"
if [ $? -ne 0 ]; then d&&m A "Testing persistent changes for posix compatibility...\n"
return 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
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 if [ $? -eq 0 ]; then
d&&echo "Activating native persistent changes" d&&m A "Activating native persistent changes\n"
mount --bind "$CHANGES" "$2" >/dev/null 2>&1 mount --bind "$CHANGES" "$2" >/dev/null 2>&1
return return ${?}
else
d&&m w "Failed\n"
fi fi
if [ -e "$CHANGES/changes.dat.0" ]; then if [ -e "$CHANGES/changes.dat" ]; then
d&&echo "Restoring persistent changes" d&&m A "Restoring persistent changes\n"
EXISTS="true" EXISTS="true"
else else
d&&echo "Creating new persistent changes" d&&m A "Creating new persistent changes\n"
EXISTS=""
fi fi
mount.dynfilefs -f "$CHANGES/changes.dat" -s 16000 -m "$2" -p 4000 >/dev/null 2>&1 mount.dynfilefs -f "$CHANGES/changes.dat" -s 16000 -m "$2" -p 4000 >/dev/null 2>&1||d&&m e "Failed\n"
[ ! "$EXISTS" ] && mke2fs -F -L "DATA" "$2/virtual.dat" >/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 grepCmdLine fsck&&fsck ${2}/virtual.dat >/dev/null 2>&1
mount "$2/virtual.dat" "$2" >/dev/null 2>&1 mount "$2/virtual.dat" "$2" >/dev/null 2>&1
rm "$T1" "$T2" >/dev/null 2>&1 rm "$T1" "$T2" >/dev/null 2>&1
@@ -167,7 +186,7 @@ debugShell()
{ {
if [ "$SHELL_IS_ENABLED" = "true" ]; then if [ "$SHELL_IS_ENABLED" = "true" ]; then
echo -e "Debug shell!\nControl+D or 'exit' to contiunue boot.\n" echo -e "Debug shell!\nControl+D or 'exit' to contiunue boot.\n"
setsid cttyhack sh setsid cttyhack bash
fi fi
} }
changeRoot() changeRoot()
@@ -191,10 +210,10 @@ eot
emergencyShell() emergencyShell()
{ {
exec >/dev/console >&1 2>&1 <&1 exec >/dev/console >&1 2>&1 <&1
echo "Error: Please inspect '/tmp/mlb.log' file" echo "Error: Please inspect '/llf.log' file"
export PS1="RESCUE # " export PS1="RESCUE # "
while :; do while :; do
echo "Rescue shell!" echo "Rescue shell!"
setsid cttyhack sh setsid cttyhack bash
done done
} }
+4 -4
View File
@@ -11,25 +11,25 @@ if [ ! -e /lib/.escaped ]; then
cd ${SWITCH} cd ${SWITCH}
mount -t proc proc /proc mount -t proc proc /proc
echo "0" >/proc/sys/kernel/printk echo "0" >/proc/sys/kernel/printk
>lib/.escaped :>lib/.escaped
d&&echo "[!] Reloading ${0}" d&&echo "[!] Reloading ${0}"
mount --move /proc proc mount --move /proc proc
exec switch_root . ${0} exec switch_root . ${0}
fi fi
mount -t devtmpfs devtmpfs /dev >/dev/null 2>&1 mount -t devtmpfs devtmpfs /dev >/dev/null 2>&1
ln -sf /proc/self/fd /dev/fd ln -sf /proc/self/fd /dev/fd
exec > >(tee -i /tmp/mlb.log) 2>&1 exec > >(tee -i /tmp/lif.log) 2>&1
d&&echo "'debug' bootloader variable is set!"&&set -x d&&echo "'debug' bootloader variable is set!"&&set -x
mount -t sysfs sysfs /sys >/dev/null 2>&1 mount -t sysfs sysfs /sys >/dev/null 2>&1
mkdir -p ${UNION} ${DATAMNT} ${SYSTEM} mkdir -p ${UNION} ${DATAMNT} ${SYSTEM}
isShellEnabled isShellEnabled
ln -sf /proc/mounts /etc/mtab 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 find /lib/modules/$(uname -r) -name "*.ko" -type f | sed -r "s:^.*/|[.]ko\$::g" | xargs -n 1 modprobe >/dev/null 2>&1
sleep 3 sleep 3
mdev -s mdev -s
debugShell debugShell
isZramEnabled isZramEnabled
mdadm --assemble --scan >/dev/null 2>&1 mdadm --assemble --scan >/dev/null 2>&1||true
sleep 0.5 sleep 0.5
debugShell debugShell
findData findData
+4 -4
View File
@@ -17,11 +17,11 @@ umount_all()
done done
} }
exec </dev/console >>/dev/console 2>>/dev/console exec >/dev/console >&1 2>&1 <&1
[ "${DEBUG_IS_ENABLED}" = "true" ]&&set -x [[ "${DEBUG_IS_ENABLED}" = "true" ]]&&set -x
debugShell debugShell
echo "Minimal Linux Booter - Shutdown Magic!" echo "Linux Live Framework - Shutdown Magic!"
echo "Entering to clean-up things before final step." echo "Entering to clean-up things before ${action}..."
( (
mdev -s mdev -s
sleep 1.5 sleep 1.5
Binary file not shown.
Binary file not shown.