test enchants 2

This commit is contained in:
Danieliskot
2023-10-13 11:32:19 +02:00
parent 107cd03263
commit 6fb6379b4c
11 changed files with 176 additions and 191 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "ext/checkbox"]
path = ext/checkbox
url = https://github.com/pedro-hs/checkbox.sh
+1
View File
@@ -3,6 +3,7 @@ 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 Daniel 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
+1 -3
View File
@@ -6,7 +6,6 @@ This project is for supporting many CPUs architectures & extended functions unli
Note: Note:
* Your distro must have installed: * Your distro must have installed:
- squashfs-tools, - squashfs-tools,
- xorriso,
- cpio, - cpio,
- file, - file,
- gzip, - gzip,
@@ -15,7 +14,7 @@ Note:
- grep, - grep,
- rsync, - rsync,
- find-utils, - find-utils,
- syslinux-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.
@@ -28,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,
+43 -48
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eE -o pipefail . initrd/functions
exec > >(tee -i /tmp/lif.log) 2>&1 set -eET -o pipefail
exec > >(tee -i /tmp/llf.log) 2>&1
cd "$(dirname $(readlink -f ${0}))" cd "$(dirname $(readlink -f ${0}))"
cp -fv config .config cp -f $([ ${V} ]&&echo ${V}) config .config
for i in mksquashfs cpio gzip sed grep xorriso tar find file; do for i in mksquashfs cpio gzip sed grep xorriso tar find file; do
if [ ! -x "$(command -v ${i})" ]; then if [ ! -x "$(command -v ${i})" ]; then
case ${i} in case ${i} in
@@ -18,18 +19,21 @@ for i in mksquashfs cpio gzip sed grep xorriso tar find file; do
done done
main() main()
{ {
local top DATA INITRD ret tmpRoot utc v local DATA ret tmpRoot utc v krnV
echo "KERNEL=\"${kernel}}\"" >>.config echo "KERNEL=\"${kernel}}\"" >>.config
echo "LMK=\"/lib/modules/$(file -bL ${kernel} | grep -o 'version .*' | cut -d' ' -f2)\"" >>.config echo "LMK=\"/lib/modules/\"" >>.config
top="$(pwd)" krnV="$(file -bL ${kernel} | grep -o 'version .*' | cut -d' ' -f2)"
top="${PWD}"
INITRAMFS="${workTmpDir}/initRd"
DATA="${workTmpDir}/isoImage" DATA="${workTmpDir}/isoImage"
INITRD="$(initrd/create)" env DATA="${DATA}" INITRAMFS="${INITRAMFS}" V="${V}" top="${top}" initrd/create
ret="${?}" ret="${?}"
tmpRoot="${workTmpDir}/tmpRoot" tmpRoot="${workTmpDir}/tmpRoot"
mkdir -pv ${DATA}/changes ${DATA}/os/modules mkdir -p $([ ${V} ]&&echo ${V}) ${DATA}/changes ${DATA}/os/modules
rsync --force -aAP $(for i in $(awk '{print $2}' /proc/mounts) /tmp; do echo "--exclude=${i}/*"; done) / ${tmpRoot} mv -f $([ ${V} ]&&echo ${V}) ${INITRAMFS}.img ${DATA}/initrd.img
chmod +x -Rv inc2sys 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}
cp -rvf inc2sys/* ${tmpRoot} chmod +x -R $([ ${V} ]&&echo ${V}) inc2sys
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
@@ -37,70 +41,61 @@ main()
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}/os/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}/os/system.sfs ]&&break [ -e ${DATA}/os/system.sfs ]&&break
done done
mv -fv ${INITRD} ${DATA}/initrd.img cp -rf $([ ${V} ]&&echo ${V}) bootfiles/* ${DATA}
cp -rvf 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|tr [:lower:] [:upper:]):$(git -C ${top} branch --show-current 2>/dev/null|tr [:lower:] [:upper:]):GIT"||v="INFINITY:PRIVATE: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"||v="INFINITY:PRIVATE:LOCAL"
cat <<eot >.LlfMeta cat <<eot >.LlfMeta
# Built using Linux-Live-Framework technology. # Built using Linux-Live-Framework technology.
LLF_VERSION="${v}"
LLF_NAME="${DISTRO}" LLF_NAME="${DISTRO}"
LLF_VERSION="${v}"
LLF_UTC="${utc}" LLF_UTC="${utc}"
eot eot
[[ ${ret} = 2 ]]&&echo "LLF_ELF_STATIC_INITRD=\"y\"" >>.LlfMeta||echo "LLF_ELF_STATIC_INITRD=\"n\"" >>.LlfMeta [[ ${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 #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 .
return 0 #isohybrid --version >/dev/null 2>&1&&isohybrid -u /${DISTRO}-${utc}.iso
} }
chooseKernel() selectKernel()
{ {
local n=0 list local checkbox_output list krn
mapfile -t list < <(find /boot -type f | egrep "bzImage|kernel|vmlinuz" 2>/dev/null | egrep -v "init|*.old") mapfile -t list < <(find /boot -type f|egrep"bzImage|kernel|vmlinuz" 2>/dev/null|egrep -v "init|$.old"|sort -n)
if [ ${#list[@]} -gt 1 ]; then if [ ${#list[@]} -gt 1 ]; then
echo -e "Please choose your kernel to proceed:\nChoose number from ${n} to ${#list[@]}\n-----\n" . ext/checkbox/checkbox.sh checkbox.sh --message="Please choose your kernel version to proceed:" --index --options="$(for i in "${list[@]}"; do basename "${i}";done;)"
for a in "${list[@]}"; do krn="/boot/${list[${checkbox_output}]}"
echo "[${n}] - ${a}"
((n++))
done
echo "-----"
read kernel
kernel="/boot/${list[${kernel}]}"
else else
kernel="/boot/${list[0]}" krn="${list[0]}"
fi fi
kernel="${krn}"
export kernel export kernel
return 0
} }
declare -g kernel DISTRO workTmpDir V setCompatFlags
for i; do for i; do
case ${i} in case ${i} in
-i|--interactive) helper="true" ;; -i|--interactive) helper=true ;;
-k|--kernel) export kernel="${2}"; shift ;; -k|--kernel) kernel="${2}"; shift ;;
-d|--distro) DISTRO="${2}"; shift ;; -d|--distro) DISTRO="${2}"; shift ;;
-w|--workdir) workTmpDir="${2}"; shift ;; -w|--workdir) workTmpDir="${2}"; shift ;;
-D|--debug) set -x; export V="-v" ;; -D|--debug) set -x; setCompatFlags+=" -x " ;;
-C|--clean) clean="true" ;; -n|--dry-run) set -n; setCompatFlags+=" -n " ;;
-v|--verbose) set -v; V="-v" ;;
-C|--clean) clean=true ;;
--) shift; break ;; --) shift; break ;;
*) echo "Unknown option: ${i}"; exit 1 ;; *) echo "Unknown option: ${i}"; exit 1 ;;
esac esac
done done
trap '[[ ${clean} ]]&&echo "Cleaning up..."&&rm -rvf ${workTmpDir} /tmp/MlbInitRd{,.img};exit 1' 2 6 15 trap '. initrd/functions&&[[ ${clean} ]]&& { m A "\nCleaning-up";if rp "rm -rf ${workTmpDir}";then m i "Done!\n";else m w "Failed!\n";fi; };exit ${?}' HUP INT QUIT ILL TRAP ABRT TERM
export workTmpDir [[ -t 0 && ${helper} || ${helper} ]]&&if selectKernel&&main; then true else; false; fi
[[ -t 0 && ${helper} || ${helper} ]]&&if chooseKernel&&main; then true else; false; fi [[ -e ${kernel} ]]||m e "Kernel not found: ${kernel}\n"&&false
[[ ! ${helper} ]]&& { [[ -z ${DISTRO} ]]&&. .config&&m w "DISTRO not set. Using defaults: ${DISTRO}\n"||true
[[ ! -e ${kernel} ]]&&echo "[E]: Kernel not found: ${kernel}"&&false workTmpDir="${workTmpDir:-$(mktemp -d /tmp/Llf_WorkDir_XXXXXXX)}"||true
[[ -z ${DISTRO} ]]&&. .config&&echo "[W]: DISTRO not set. Using defaults: ${DISTRO}"||true mkdir -p "${workTmpDir}"
[[ -z ${workTmpDir} ]]&&workTmpDir="$(mktemp -d /tmp/Llf_WorkDir_XXXXXXX)"&&echo "[W]: workTmpDir not set. Using defaults: ${workTmpDir}"&&true
export workTmpDir
export DISTRO
mkdir -pv "${workTmpDir}"
if main; then true; else false; fi if main; then true; else false; fi
}
Submodule
+1
Submodule ext/checkbox added at 5692b6e8f0
+69 -86
View File
@@ -1,127 +1,110 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -x #set -eET -o pipefail
cd "$(dirname $(readlink -f ${0}))"||exit 1 export setCompatFlags top
grep -q -- -x <<<"${setCompatFlags}"&&set -x
grep -q -- -n <<<"${setCompatFlags}"&&set -n
grep -q -- -v <<<"${V}"&&set -v
cd "$(dirname $(readlink -f ${0}))"||false
. ../.config||false
trap 'rm -rf ${TOP}/${INITRAMFS}{,.img};exit ${?}' HUP INT QUIT ILL TRAP ABRT TERM
. ../.config #add more ELFs, if need ;)
list=(bash tar e2fsck fsck.fat f2fs mdadm mount.ntfs-3g blkid)
INITRAMFS="/tmp/LifInitRd"
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 $([ ${V} ]&&echo ${V}) ${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 $([ ${V} ]&&echo ${V}) 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
#[[ ${static} ]]&&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
+48 -43
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()
{
local pid
sh -c "${1}" >/dev/null 2>&1&
pid="${!}"
while :; do
if [ -d /proc/${pid} ]; then
echo -n "."
sleep 0.25
else
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()
@@ -48,12 +35,30 @@ m()
*) printf '%s' "${1}";; *) printf '%s' "${1}";;
esac 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&&m q "Is 'shell' bootloader variable set " d&&m q "Is 'shell' bootloader variable set "
if grepCmdLine shell; then if grepCmdLine shell; then
d&&m a "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
m A "Reloading /lib/functions " m A "Reloading /lib/functions "
if . /lib/functions; then if . /lib/functions; then
m i "Done\n" m i "Done\n"
@@ -72,40 +77,44 @@ isZramEnabled()
d&&m a "Yes\n" d&&m a "Yes\n"
m A "Enabling zram " m A "Enabling zram "
echo 536870912 >/sys/block/zram0/disksize echo 536870912 >/sys/block/zram0/disksize
mkswap /dev/zram0 >/dev/null 2>&1&&m i "Done\n"||m w "Failed\n" 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&&m i "Done\n"||m w "Failed\n" 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&&m i "No\n" d&&m i "No\n"
fi fi
} }
findData() toRam()
{ {
d&&m A "Searching ${DISTRO} in /dev -> "
local from a
from="$(grepCmdLine from)"
for i in ${root:-/dev/[hmnsv][dmrv][0-9a-z]*}; do
d&&m "${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}/.LlfMeta ]; then
d&&m i "\nFound ${DISTRO} in ${i}\n"
grepCmdLine fsck&&fsck ${i} >/dev/null 2>&1||true
d&&m q "Is 'toram' bootloader variable set and enought RAM space? " 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 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" d&&m a "Yes\n"
mkdir -p /tmp/data mkdir -p /tmp/data
d&&m A "Copying to RAM " d&&m A "Copying to RAM "
d&&progress "tar -c -C ${DATAMNT} --exclude ./changes -f - . | tar -xf - -C /tmp/data"&&m i "Done\n"||m w "Failed\n" 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 umount -f ${DATAMNT} >/dev/null 2>&1
[[ ${from} ]]&&umount -f ${DATAMNT} >/dev/null 2>&1 [[ ${from} ]]&&umount -f ${DATAMNT} >/dev/null 2>&1
mv -f /tmp/data/* ${DATAMNT} >/dev/null 2>&1 mv -f /tmp/data/* ${DATAMNT} >/dev/null 2>&1
rm -rf /tmp/data >/dev/null 2>&1 rm -rf /tmp/data >/dev/null 2>&1
else else
d&&[[ "${a}" != "0" ]]&&m e "Not requested by bootloader or low RAM space!\n"||m e "Internal error? Trying tmpfs, so data after power-off will be erased permanently!\n" 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 mount -o remount,rw ${DATAMNT} >/dev/null 2>&1||true
fi fi
}
findData()
{
d&&m A "Searching ${DISTRO} in /dev -> "
local data a
data="$(grepCmdLine from)"
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
sleep 0.5
[[ ${data} ]]&&mount ${DATAMNT}/${data} ${DATAMNT} >/dev/null 2>&1
if [[ -e ${DATAMNT}/.LlfMeta && -e ${DATAMNT}/os/system.sfs ]]; then
d&&m i "\nFound ${DISTRO} in ${i}\n"
if grepCmdLine fsck;then fsck ${i} >/dev/null 2>&1;else true;fi
toRam
mount ${DATAMNT}/os/system.sfs ${SYSTEM} >/dev/null 2>&1 mount ${DATAMNT}/os/system.sfs ${SYSTEM} >/dev/null 2>&1
sleep 0.5 sleep 0.5
break break
@@ -161,7 +170,7 @@ persistentChanges()
else else
d&&m w "Failed\n" d&&m w "Failed\n"
fi fi
if [ -e "$CHANGES/changes.dat.0" ]; then if [ -e "$CHANGES/changes.dat" ]; then
d&&m A "Restoring persistent changes\n" d&&m A "Restoring persistent changes\n"
EXISTS="true" EXISTS="true"
else else
@@ -178,14 +187,9 @@ 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
} }
pivotRoot()
{
pivot_root ${1} run/initramfs
exec chroot ${1} init
}
changeRoot() changeRoot()
{ {
cd "$1" cd "$1"
@@ -201,15 +205,16 @@ eot
mount -t tmpfs tmpfs run mount -t tmpfs tmpfs run
mkdir -p run/initramfs mkdir -p run/initramfs
mount -o remount,ro overlay . mount -o remount,ro overlay .
pivotRoot . pivot_root . run/initramfs
exec chroot . init
} }
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
} }
+2 -2
View File
@@ -11,7 +11,7 @@ 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}
@@ -29,7 +29,7 @@ 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
+2 -3
View File
@@ -17,9 +17,8 @@ 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
read -sr -N 1 -t 5 -p "[Info]: If poweroff by accident, press any key to restore your work. Waiting 5 seconds for input..."&&pivotRoot /oldroot
debugShell debugShell
echo "Linux Live Framework - Shutdown Magic!" echo "Linux Live Framework - Shutdown Magic!"
echo "Entering to clean-up things before final step." echo "Entering to clean-up things before final step."
Binary file not shown.
Binary file not shown.