mirror of
https://github.com/andreili/SBC_builder.git
synced 2025-08-23 19:04:06 +02:00
134 lines
4.1 KiB
Plaintext
134 lines
4.1 KiB
Plaintext
#!/bin/busybox sh
|
|
|
|
. /etc/init.def
|
|
. /etc/init.script
|
|
|
|
CONSOLE="/dev/$(get_active_console)"
|
|
exec 0<>${CONSOLE} 1<>${CONSOLE} 2<>${CONSOLE}
|
|
|
|
run mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null
|
|
run mount -t devtmpfs -o exec,nosuid,mode=0755,size=10M udev /dev
|
|
run mkdir -m 0755 /dev/pts
|
|
run mount -t devpts -o gid=5,mode=0620 devpts /dev/pts
|
|
run mkdir -m 1777 /dev/shm
|
|
run mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm
|
|
|
|
mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1
|
|
mount -o remount,rw / >/dev/null 2>&1
|
|
mount -t tmpfs -o rw,nosuid,nodev,relatime,mode=755 none /run 2>&1
|
|
mkdir /run/initramfs
|
|
|
|
if [ ! -s /etc/ld.so.cache ]
|
|
then
|
|
# Looks like we were unable to run ldconfig during initramfs generation
|
|
hash ldconfig >/dev/null 2>&1 && run ldconfig
|
|
fi
|
|
|
|
# Set up symlinks
|
|
run busybox --install -s
|
|
|
|
# Handle kernel command-line parameters
|
|
CMDLINE=$(cat /proc/cmdline 2>/dev/null)
|
|
for x in ${CMDLINE}
|
|
do
|
|
case "${x}" in
|
|
quiet|quiet_genkernel)
|
|
QUIET=1
|
|
;;
|
|
loglevel=*)
|
|
CONSOLE_LOGLEVEL=${x#*=}
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if ! is_quiet
|
|
then
|
|
# Prevent superfluous printks from being printed to the console
|
|
echo ${CONSOLE_LOGLEVEL} > /proc/sys/kernel/printk
|
|
fi
|
|
|
|
good_msg "Initial ramdisk script. Linux kernel ${KV}"
|
|
log_msg "COMMAND: 'echo "" > /proc/sys/kernel/hotplug'"
|
|
echo "" > /proc/sys/kernel/hotplug
|
|
|
|
#run mkdir -p "${NEW_ROOT}"
|
|
CHROOT="${NEW_ROOT}"
|
|
run mount -n -t tmpfs tmpfs ${NEW_ROOT}
|
|
DEVICES=$(devicelist)
|
|
run findmediamount "cdrom" "/livecd" "REAL_ROOT" "${CDROOT_PATH}" "${DEVICES}" || run_emergency_shell
|
|
run mount -o remount,ro "${CDROOT_PATH}"
|
|
run findmediamount "rw_part" "/rw_part" "RW_ROOT" "${RW_MNT}" "${DEVICES}" || run_emergency_shell
|
|
#sh
|
|
CHROOT=${NEW_ROOT}
|
|
|
|
run cd "${CHROOT}"
|
|
good_msg 'Mounting squashfs filesystem'
|
|
upperdir="${RW_MNT}/.upper"
|
|
workdir="${RW_MNT}/.work"
|
|
for i in "${RW_MNT}" "${STATIC}" "${OVERLAY}" "${upperdir}" "${workdir}"
|
|
do
|
|
[ ! -d "${i}" ] && run mkdir -p "${i}"
|
|
done
|
|
run mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOP}" "${STATIC}" || run_emergency_shell
|
|
if [ -d ${CDROOT_PATH}/modules ]
|
|
then
|
|
good_msg "Adding all modules in ${CDROOT_PATH}/modules"
|
|
for module in "${CDROOT_PATH}/modules/"*.lzm; do
|
|
mod=${module##*/}
|
|
mod=${mod//-/_}
|
|
mod=${mod%.*}
|
|
if [ ! -d "${OVERLAY}/.${mod}" ]
|
|
then
|
|
run mkdir -p "${OVERLAY}/.${mod}" || run_emergency_shell
|
|
fi
|
|
run mount -o loop,ro "${module}" "${OVERLAY}/.${mod}" || run_emergency_shell
|
|
mod_path="${mod_path}:${OVERLAY}/.${mod}"
|
|
# Assign variable with paths to modules mount point
|
|
mods="${mods} ${OVERLAY}/.${mod}"
|
|
done
|
|
fi
|
|
run mount -t overlay overlay -o lowerdir="${STATIC}${mod_path}",upperdir="${upperdir}",workdir="${workdir}" "${NEW_ROOT}" || run_emergency_shell
|
|
for i in "${RW_MNT}" "${STATIC}" "${CDROOT_PATH}" ${mods}
|
|
do
|
|
[ ! -d "${NEW_ROOT}${i}" ] && run mkdir -p "${NEW_ROOT}${i}"
|
|
run mount --move "${i}" "${NEW_ROOT}${i}" || run_emergency_shell
|
|
done
|
|
|
|
#for m in ${MODULES}; do
|
|
# run insmod "${NEW_ROOT}${m}"
|
|
#done
|
|
|
|
# Let Init scripts know that we booted from CD
|
|
export CDBOOT
|
|
CDBOOT=1
|
|
|
|
run udevadm settle --timeout=120
|
|
run udevadm control --exit
|
|
init=${REAL_INIT:-/sbin/init}
|
|
|
|
# uncomment for debug
|
|
#run_emergency_shell
|
|
|
|
while true
|
|
do
|
|
if ! mountpoint "${CHROOT}" 1>/dev/null 2>&1
|
|
then
|
|
bad_msg "${CHROOT} is not a mountpoint; Was root device (${REAL_ROOT}) not mounted?"
|
|
elif ! chroot "${CHROOT}" /usr/bin/test -x /${init#/} 1>/dev/null 2>&1
|
|
then
|
|
mounted_root_device=$(mountpoint -n /newroot 2>/dev/null | awk '{ print $1 }')
|
|
bad_msg "init (${init}) not found in mounted root device (${mounted_root_device})!"
|
|
else
|
|
break
|
|
fi
|
|
run_emergency_shell
|
|
done
|
|
|
|
good_msg "Restoring console log level (${CONSOLE_LOGLEVEL}) ..."
|
|
echo ${CONSOLE_LOGLEVEL} > /proc/sys/kernel/printk && log_msg "COMMAND: 'echo \"${CONSOLE_LOGLEVEL}\" > /proc/sys/kernel/printk'"
|
|
good_msg "Switching to real root: switch_root ${CHROOT} ${init} ${init_opts}"
|
|
#sh
|
|
exec switch_root "${CHROOT}" "${init}" ${init_opts}
|
|
|
|
exit 1
|