Kaydet (Commit) c668fc99 authored tarafından Your Name's avatar Your Name

parçaladım

üst 42065ba1
......@@ -13,16 +13,21 @@ generate_rootfs(){
run_modules(){
for i in $(ls /scripts | sort)
do
debug "Running $i"
. /scripts/$i
done
}
mount_handler(){
msg "Mount handler running"
/busybox mount -t devtmpfs dev /dev || true
/busybox mount -t proc proc /proc || true
/busybox mount -t sysfs sys /sys || true
/busybox mount -t tmpfs tmpfs /tmp || true
/busybox mount -t tmpfs tmpfs /run || true
/busybox mount -t devtmpfs dev /dev -o nosuid,noexec,nodev || true
/busybox mount -t proc proc /proc -o nosuid,noexec,nodev || true
/busybox mount -t sysfs sys /sys -o nosuid,noexec,nodev || true
/busybox mount -t tmpfs tmpfs /tmp -o nosuid,noexec,nodev || true
/busybox mount -t tmpfs tmpfs /run -o nosuid,noexec,nodev || true
if [ -e /sys/firmware/efi ]; then
msg "UEFI mode detected."
mount -t efivarfs efivarfs /sys/firmware/efi/efivars -o nosuid,nodev,noexec
fi
}
parse_cmdline(){
for i in $(cat /proc/cmdline)
......@@ -30,37 +35,20 @@ parse_cmdline(){
export $i
done
}
start_dmesg(){
msg "Starting dmesg"
/busybox dmesg -n 1 || true
}
msg() {
echo -e " ${C_GREEN}*${C_CLEAR} ${@}"
}
debug() {
[ ! -n "$debug" ] || echo -e " ${C_BLUE}*${C_CLEAR} ${@}"
}
warn() {
echo -e " ${C_YELLOW}*${C_CLEAR} ${@}"
}
err() {
echo -e " ${C_RED}*${C_CLEAR} ${@}"
}
is_file_avaiable(){
disktmp=$(mktemp)
rm -rf $disktmp
rm -f $disktmp
mkdir -p $disktmp || true
mount -t auto "$1" $disktmp 2>/dev/null
[ -f "$disktmp/$2" ] && [ -b "$1" ]
status=$?
umount $disktmp 2>/dev/null
umount -lf $disktmp 2>/dev/null
return $status
}
fallback_shell(){
warn "Booting dead. Now you are in initial ramdisk."
/busybox setsid cttyhack /bin/sh || /busybox sh
}
detect_root(){
......
#!/busybox ash
. /vars
. /functions
generate_rootfs
start_dmesg
mount_handler
parse_cmdline
detect_root
run_modules
generate_rootfs || fallback_shell
mount_handler || fallback_shell
parse_cmdline || fallback_shell
detect_root || fallback_shell
run_modules || fallback_shell
while true
do
/busybox sleep 999
......
#!/busybox sh
[ -n $debug ] && clear
msg "Starting SulinOS"
msg "Starting GNU/Linux"
[ ! -n $quiet ] && exec >/dev/null
msg "Starting dmesg"
/busybox dmesg -n 1 || true
#!/busybox sh
common_boot(){
debug "Moving mountpoints"
mount --move /sys /rootfs/kernel/sys
mount --move /proc /rootfs/kernel/proc
mount --move /dev /rootfs/kernel/dev
mount --move /tmp /rootfs/tmp
mount --move /run /rootfs/run
}
live_boot(){
list=$(ls /sys/class/block/ | grep ".*[0-9]$" | grep -v loop | grep -v ram | grep -v nbd | sed "s|^|/dev/|g")
for part in $list
do
debug "Looking for $part"
if is_file_avaiable "$part" "main.sfs"
then
debug "Detected live media: $part"
export root=$part
fi
done
mkdir -p /rootfs/a # upper
mkdir -p /rootfs/b # workdir
mkdir -p /root/a # upper
mkdir -p /root/b # workdir
mkdir -p /live_root/
mkdir -p /source/ # lower
mkdir -p /output
echo -e "Rootfs:\033[32;1m $root\033[;0m"
debug "Mounting live media"
mount -t auto $root /output
mount /output/main.sfs /source
umount /rootfs/a 2>/dev/null
umount /rootfs/b 2>/dev/null
mount -t overlay -o lowerdir=/source/,upperdir=/rootfs/a/,workdir=/rootfs/b overlay /live_root
mount -t tmpfs -o size=100% none /rootfs/a
mount -t tmpfs -o size=100% none /rootfs/b
mount --move /sys /live_boot/sys
mount --move /proc /live_boot/proc
mount --move /dev /live_boot/dev
mount --move /tmp /live_boot/tmp
mount --move /run /live_boot/run
exec switch_root /live_root /sbin/init "$@" || /busybox sh
umount /root/a 2>/dev/null
umount /root/b 2>/dev/null
debug "Creating overlayfs"
mount -t overlay -o lowerdir=/source/,upperdir=/root/a/,workdir=/root/b overlay /rootfs
mount -t tmpfs -o size=100% none /root/a
mount -t tmpfs -o size=100% none /root/b
common_boot
}
normal_boot(){
debug "Mounting rootfs"
mkdir -p /rootfs
mkdir -p /newroot
mount -t auto $root /newroot
debug "Creating tmpfs for /"
mount -t tmpfs tmpfs /rootfs
mkdir -p /rootfs/tmp
mkdir -p /rootfs/run
debug "Creating symlinks"
ln -s kernel/dev /rootfs/dev
ln -s kernel/sys /rootfs/sys
ln -s kernel/proc /rootfs/proc
for i in boot bin lib32 etc kernel lib64 sbin usr data lib root var
do
debug "Binding /$i"
mkdir -p /rootfs/$i
mount --bind /newroot/$i /rootfs/$i
done
mount --move /sys /rootfs/kernel/sys
mount --move /proc /rootfs/kernel/proc
mount --move /dev /rootfs/kernel/dev
mount --move /tmp /rootfs/tmp
mount --move /run /rootfs/run
exec switch_root /rootfs /sbin/init "$@" || /busybox sh
common_boot
}
clasic_boot(){
debug "Mounting rootfs"
mkdir -p /rootfs
mount -t auto $root /newroot
mount --move /sys /rootfs/kernel/sys
mount --move /proc /rootfs/kernel/proc
mount --move /dev /rootfs/kernel/dev
mount --move /tmp /rootfs/tmp
mount --move /run /rootfs/run
exec switch_root /rootfs /sbin/init "$@" || /busybox sh
common_boot
}
if [ "$boot" == "live" ]; then
msg "Booting from live-media"
live_boot
......
if [ -f /new_root/etc/os-release ]; then
msg "Wellcome to $(cat /new_root/etc/os-release | grep '^NAME=' | head -n 1 | sed 's/^.*=//g')"
else
msg "Wellcome to GNU/Linux..."
fi
[ -d "/new_root/$subdir" ] || subdir="/"
debug "Subdir=$subdir"
[ ! -n $init ] || init=/sbin/init
debug "init=$init"
if [ -f /new_root/$subdir/etc/initrd.local ]; then
msg "Running local initrd scripts"
. /new_root/$subdir/etc/initrd.local || true
fi
debug "Switching root"
exec env -i \
"TERM=$TERM" \
switch_root "/rootfs/$subdir" $init "$@" || fallback_shell
PATH=/bin:/usr/bin:/usr/sbin:/sbin
TERM=linux
rootfstype=ext4
C_BLACK='\e[1;30m'
C_RED='\e[1;31m'
C_GREEN='\e[1;32m'
C_YELLOW='\e[1;33m'
C_BLUE='\e[1;34m'
C_PURPLE='\e[1;35m'
C_CYAN='\e[1;36m'
C_WHITE='\e[1;37m'
C_CLEAR='\e[m'
if [ -t 0 ];then
C_BLACK='\e[1;30m'
C_RED='\e[1;31m'
C_GREEN='\e[1;32m'
C_YELLOW='\e[1;33m'
C_BLUE='\e[1;34m'
C_PURPLE='\e[1;35m'
C_CYAN='\e[1;36m'
C_WHITE='\e[1;37m'
C_CLEAR='\e[m'
fi
msg() {
echo -e " ${C_GREEN}*${C_CLEAR} ${@}"
}
debug() {
[ ! -n "$debug" ] || echo -e " ${C_BLUE}*${C_CLEAR} ${@}"
}
warn() {
echo -e " ${C_YELLOW}*${C_CLEAR} ${@}"
}
err() {
echo -e " ${C_RED}*${C_CLEAR} ${@}"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment