mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-19 19:40:37 +02:00
switch to pure systemd bootup
This commit is contained in:
parent
fc30d67d03
commit
9fd98566c8
3 changed files with 70 additions and 66 deletions
|
@ -1,24 +1,53 @@
|
|||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# created by Tobias Powalowski <tpowa@archlinux.org>
|
||||
# Created by Tobias Powalowski <tpowa@archlinux.org>
|
||||
|
||||
_run() {
|
||||
_map _binary bash sh blkid mount mountpoint switch_root bsdcpio mkfs.btrfs setfont \
|
||||
/usr/lib/systemd/systemd-udevd udevadm systemd-tmpfiles kmod insmod modprobe \
|
||||
gzip uname cat cp dmesg grep ln ls mv rm umount lsblk rmmod cut sed find mkdir dialog
|
||||
# needed library for udevadm!
|
||||
_map _file /usr/lib/systemd/libsystemd-shared*
|
||||
_file /usr/share/terminfo/l/linux
|
||||
_file_rename /usr/share/kbd/consolefonts/ter-v16n.psf.gz /consolefont-16.psf.gz
|
||||
_file_rename /usr/share/kbd/consolefonts/ter-v32n.psf.gz /consolefont-32.psf.gz
|
||||
rules_d=/usr/lib/udev/rules.d
|
||||
_map _file ${rules_d}/50-udev-default.rules ${rules_d}/60-persistent-storage.rules \
|
||||
${rules_d}/64-btrfs.rules ${rules_d}/80-drivers.rules /usr/lib/udev/ata_id \
|
||||
/usr/lib/udev/scsi_id
|
||||
_file_rename /usr/lib/archboot/cpio/init.sh /init
|
||||
_run ()
|
||||
{
|
||||
_map _dir /cdrom /ventoy
|
||||
_map _file /etc/bash.bash_logout /etc/bash.bashrc /etc/profile /etc/shells
|
||||
_file_rename /usr/share/archboot/base/etc/dialogrc /etc/dialogrc
|
||||
### add basic apps
|
||||
_map _binary mount env bash cp mv rm grep cat mkdir echo kmod modprobe sh bsdcpio \
|
||||
mkfs.btrfs mountpoint cut grep mkdir uname find sed dialog sulogin systemctl \
|
||||
setfont gzip loadkeys systemd-tmpfiles sleep halt shutdown reboot poweroff
|
||||
### systemd
|
||||
_map _binary /usr/lib/systemd/systemd{,-sulogin-shell,-modules-load,-udevd,-sysctl,-vconsole-setup}
|
||||
_map _file /usr/lib/systemd/{lib*,system-generators/systemd-fstab-generator}
|
||||
_map _full_dir /usr/lib/modules-load.d /usr/lib/systemd/system
|
||||
_map _file /usr/share/systemd/{kbd-model-map,language-fallback-map}
|
||||
|
||||
### turn on initrd mode
|
||||
: > "${_ROOTFS}"/etc/initrd-release
|
||||
### launch systemd
|
||||
_symlink /init /usr/lib/systemd/systemd
|
||||
### disable systemd mounts:
|
||||
# disable configfs, debugfs, fuse, hugepages, mqueue and tracefs
|
||||
for i in dev-mqueue dev-hugepages sys-kernel-debug sys-kernel-tracing sys-kernel-config sys-fs-fuse-connections tmp; do
|
||||
_symlink "/etc/systemd/system/${i}.mount" /dev/null
|
||||
done
|
||||
### disable systemd targets:
|
||||
# swap cryptsetup integritysetup veritysetup
|
||||
for i in cryptsetup integritysetup remote-{veritysetup,cryptsetup} slices sockets swap timers veritysetup; do
|
||||
_symlink "/etc/systemd/system/${i}.target" /dev/null
|
||||
done
|
||||
### disable systemd services and sockets:
|
||||
for i in lvm2-{lvmpolld,monitor} systemd-{journald,repart,vconsole-setup}; do
|
||||
_symlink "/etc/systemd/system/${i}.service" /dev/null
|
||||
done
|
||||
_symlink "/etc/systemd/system/lvm2-lvmpolld.socket" /dev/null
|
||||
### adding needed files from running system
|
||||
_map _file /etc/{bash.bash_logout,bash.bashrc,profile,shells}
|
||||
### add kmod related config file(s)
|
||||
_file /usr/lib/depmod.d/search.conf
|
||||
### add vconsole
|
||||
_map _file /usr/share/terminfo/l/linux /usr/share/kbd/{consolefonts/ter-v{16,32}n.psf.gz,keymaps/i386/\
|
||||
{include/{qwerty-layout,compose,linux-with-alt-and-altgr,linux-keys-bare}.inc,qwerty/us.map.gz}} \
|
||||
/usr/share/kbd/keymaps/{include/compose.latin1,i386/include/euro{,1}.map.gz}
|
||||
_map _file /usr/lib/udev/rules.d/{50-udev-default,60-persistent-storage,64-btrfs,80-drivers,\
|
||||
90-vconsole,99-systemd}.rules /usr/lib/udev/ata_id /usr/lib/udev/scsi_id
|
||||
_BASIC_CONFIG="dialogrc hostname modprobe.d/modprobe.conf"
|
||||
for i in ${_BASIC_CONFIG}; do
|
||||
_file_rename "/usr/share/archboot/base/etc/${i}" "/etc/${i}"
|
||||
done
|
||||
# add default bash setup
|
||||
for i in .bashrc .bash_profile .bash_logout; do
|
||||
_file_rename "/etc/skel/${i}" "/root/${i}"
|
||||
|
@ -29,14 +58,13 @@ _run() {
|
|||
echo ". /etc/profile.d/custom-bash-options.sh" >> "${_ROOTFS}/root/.bashrc"
|
||||
echo "alias reboot='echo b >/proc/sysrq-trigger'" >> "${_ROOTFS}/root/.bashrc"
|
||||
echo "alias poweroff='echo o >/proc/sysrq-trigger'" >> "${_ROOTFS}/root/.bashrc"
|
||||
echo "root:x:0:root" > "${_ROOTFS}/etc/group"
|
||||
echo "root:x:0:0:/root:/bin/bash" > "${_ROOTFS}/etc/passwd"
|
||||
echo "root::0:root" > "${_ROOTFS}/etc/group"
|
||||
echo "root::0:0:root:/root:/bin/bash" > "${_ROOTFS}/etc/passwd"
|
||||
_file_rename "/usr/share/archboot/base/etc/profile.d/custom-bash-options.sh" \
|
||||
"/etc/profile.d/custom-bash-options.sh"
|
||||
_BASIC_CONFIG="os-release modprobe.d/modprobe.conf"
|
||||
for i in ${_BASIC_CONFIG}; do
|
||||
_file_rename "/usr/share/archboot/base/etc/${i}" "/etc/${i}"
|
||||
done
|
||||
_file /system-init.sh
|
||||
_file_rename /usr/share/archboot/base/etc/systemd/system/archboot-init.service /etc/systemd/system/archboot-init.service
|
||||
_file_rename /usr/share/archboot/base/etc/systemd/system/initrd-cleanup.service /etc/systemd/system/initrd-cleanup.service
|
||||
}
|
||||
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/bash
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# created by Tobias Powalowski <tpowa@archlinux.org>
|
||||
LANG=C
|
||||
_TITLE="Archboot $(uname -m) | $(uname -r) | Basic Setup | Early Userspace"
|
||||
|
@ -8,11 +8,6 @@ _dialog() {
|
|||
dialog --backtitle "${_TITLE}" "$@"
|
||||
return $?
|
||||
}
|
||||
_udev_trigger() {
|
||||
udevadm trigger --action=add --type=subsystems
|
||||
udevadm trigger --action=add --type=devices
|
||||
udevadm settle
|
||||
}
|
||||
_progress() {
|
||||
cat <<EOF
|
||||
XXX
|
||||
|
@ -32,7 +27,7 @@ _progress_wait() {
|
|||
_progress "${2}" "${3}"
|
||||
fi
|
||||
_COUNT="$((_COUNT+1))"
|
||||
read -r -t "${4}"
|
||||
sleep "${4}"
|
||||
! [[ -e /.archboot ]] && break
|
||||
done
|
||||
}
|
||||
|
@ -78,13 +73,6 @@ _first_stage() {
|
|||
_progress_wait "0" "99" "${_KEEP} Loading files..." "0.5"
|
||||
_progress "100" "${_KEEP}"
|
||||
}
|
||||
_udev_stage() {
|
||||
udevadm control -R
|
||||
_udev_trigger
|
||||
# shutdown udevd
|
||||
udevadm control --exit
|
||||
udevadm info --cleanup-db
|
||||
}
|
||||
_second_stage() {
|
||||
: >/.archboot
|
||||
_task cleanup &
|
||||
|
@ -97,38 +85,24 @@ _second_stage() {
|
|||
_task unmount &
|
||||
_progress_wait "98" "99" "${_KEEP} Unmounting archboot rootfs..." "1"
|
||||
_progress "100" "The boot medium can be safely removed now."
|
||||
read -r -t 2
|
||||
sleep -r -t 2
|
||||
# remove files and directories
|
||||
rm -r /sysroot/sysroot
|
||||
rm /sysroot/init
|
||||
}
|
||||
# mount kernel filesystems
|
||||
mount -t proc proc /proc -o nosuid,noexec,nodev
|
||||
mount -t sysfs sys /sys -o nosuid,noexec,nodev
|
||||
mount -t devtmpfs dev /dev -o mode=0755,nosuid
|
||||
mount -t tmpfs run /run -o nosuid,nodev,mode=0755
|
||||
if [ -e /sys/firmware/efi ]; then
|
||||
mount -t efivarfs efivarfs /sys/firmware/efi/efivars -o nosuid,nodev,noexec
|
||||
fi
|
||||
echo archboot >/proc/sys/kernel/hostname
|
||||
# initialize udev
|
||||
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
|
||||
systemd-tmpfiles --prefix=/dev --create --boot
|
||||
/usr/lib/systemd/systemd-udevd --daemon --resolve-names=never &>/dev/null
|
||||
_udev_trigger
|
||||
# not all devices trigger autoload!
|
||||
modprobe -q cdrom
|
||||
modprobe -q usb-storage
|
||||
modprobe -q zram
|
||||
modprobe -q zstd
|
||||
echo 1 > /proc/sys/kernel/sysrq
|
||||
echo "Initializing Console..."
|
||||
printf "\ec"
|
||||
# it needs one echo before, in order to reset the consolefont!
|
||||
setfont consolefont-16.psf.gz -C /dev/console
|
||||
setfont ter-v16n -C /dev/console
|
||||
loadkeys us
|
||||
echo "Searching 10 seconds for Archboot $(uname -m) rootfs..."
|
||||
_COUNT=0
|
||||
while true; do
|
||||
while ! [[ "${_COUNT}" == 10 ]]; do
|
||||
# dd / rufus
|
||||
mount UUID=1234-ABCD /mnt &>/dev/null && break
|
||||
# ventoy
|
||||
|
@ -140,9 +114,8 @@ while true; do
|
|||
if [[ -b /dev/sr0 ]]; then
|
||||
mount /dev/sr0 /cdrom &>/dev/null && break
|
||||
fi
|
||||
read -r -t 1
|
||||
sleep 1
|
||||
_COUNT=$((_COUNT+1))
|
||||
[[ "${_COUNT}" == 10 ]] && break
|
||||
done
|
||||
if ! [[ -f "/mnt/boot/initrd-$(uname -m).img" ]] ; then
|
||||
if ! mount /cdrom/efi.img /mnt &>/dev/null; then
|
||||
|
@ -151,17 +124,14 @@ if ! [[ -f "/mnt/boot/initrd-$(uname -m).img" ]] ; then
|
|||
echo -e "\e[1mThis needs further debugging. Please contact the archboot author.\e[m"
|
||||
echo -e "\e[1mTobias Powalowski: tpowa@archlinux.org\e[m"
|
||||
echo ""
|
||||
echo -e "\e[1;93mType 'exit' or 'reboot' for reboot.\e[m"
|
||||
echo -e "\e[1;93mType 'poweroff' for poweroff.\e[m"
|
||||
/bin/bash
|
||||
echo b >/proc/sysrq-trigger
|
||||
systemctl start emergency.service
|
||||
fi
|
||||
fi
|
||||
_first_stage | _dialog --title " Loading Kernel Modules " --gauge "${_KEEP} Loading files..." 6 75 0
|
||||
# avoid screen messup, don't run dialog on module loading!
|
||||
printf "\ec"
|
||||
# reinitialize available modules
|
||||
_udev_stage
|
||||
udevadm trigger --type=all --action=add --prioritized-subsystem=module,block,tpmrm,net,tty,input
|
||||
udevadm settle
|
||||
# autodetect screen size
|
||||
FB_SIZE="$(cut -d 'x' -f 1 "$(find /sys -wholename '*fb0/modes')" | sed -e 's#.*:##g')"
|
||||
if [[ "${FB_SIZE}" -gt '1900' ]]; then
|
||||
|
@ -172,12 +142,10 @@ fi
|
|||
# clear screen
|
||||
echo "Initializing Console..."
|
||||
printf "\ec"
|
||||
setfont consolefont-${SIZE}.psf.gz -C /dev/console
|
||||
setfont ter-v${SIZE}n -C /dev/console
|
||||
_second_stage | _dialog --title " Initializing System " --gauge "${_KEEP} Removing files..." 6 75 0
|
||||
echo 0 > /proc/sys/kernel/sysrq
|
||||
# set font size in vconsole.conf
|
||||
echo FONT=ter-v${SIZE}n >> /sysroot/etc/vconsole.conf
|
||||
printf "\ec"
|
||||
echo "Launching systemd $(udevadm --version)..."
|
||||
exec switch_root /sysroot /usr/bin/init "$@"
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Initializes archboot rootfs
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
StandardOutput=tty
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/lib/archboot/cpio/init.sh
|
Loading…
Reference in a new issue