Giter Site home page Giter Site logo

mlfs-s6-bootscripts's Introduction

Musl-LFS-S6-Bootscripts

Bootscripts for Musl-LFS (MLFS) using S6 & S6-rc

This is based on the works of Artix Linux (http://www.artixlinux.org/), Skarnet (https://skarnet.org), Adelie Linux (www.adelielinux.org)and ideas from reddit user VerbosePineMarten.

The aim of this project is to create the scripts and files to boot a MLFS/LFS system with S6 and S6-rc. This will replace the LFS bootscripts that LFS uses (to boot a LFS system with SysVinit).

Requirements

The following can be found at Skarnet (https://skarnet.org/).

  • skalibs 2.11.1.x (required by execline)
  • execline 2.8.2.x (required by s6-rc)
  • s6 2.1.0.x (required by s6-rc)
  • s6-linux-utils
  • s6-portable-utils (statically built)
  • s6-rc 0.5.3.x (New service format)
  • s6-linux-init (1.x.x.x)
  • utmps

Directions

Copy boot directories and scripts. Do not just copy entire git directory, as it will copy unneeded dot files:

# Enter chroot for target system first, otherwise adjust paths accordingly
cp -ar s6 /etc/
cp -av vconsole.conf /etc/
install -v -m755 modules-load /usr/bin/
install -v -m755 tmpfiles /bin/
# Compile a basic database for boot
s6-rc-compile /etc/s6/db/basic /etc/s6/sv 
ln -sv /etc/s6/db/basic /etc/s6/db/current
# Copy necessary scripts to boot, reboot, and poweroff system
install -v -m755 s6/base/bin/* /sbin/
mv /etc/s6/base/scripts /etc/s6/scripts
# Re-initialize s6 init base
rm -rf /etc/s6/base
s6-linux-init-maker -1 -f /etc/s6/skel -p "/bin:/sbin:/usr/bin"    \
                    -D default -G "/sbin/agetty -L -8 tty1 115200" \
                    -c /etc/s6/base -t 2 -L -u root -U utmp /etc/s6/base
rm -rf /etc/s6/base/scripts
cp -r /etc/s6/scripts /etc/s6/base/scripts

# Copy scripts to bring NIC's up and down
install -v -m755 if* /sbin/
mkdir -pv /lib/services
install -v -m755 net-services/* /lib/services/

For logging services, create the log user as root:

groupadd -g 983 s6log &&
useradd -c "S6-Log User" -d / \
        -u 983 -g s6log -s /usr/bin/false s6log

Make sure the directory for dmesg logging is owned by the log user

mkdir -pv /var/log/dmesg
chown -v s6log:s6log /var/log/

For utmps, create a utmp user:

useradd -c "utmps user" -d /run/utmps \
        -u 984 -g utmp -s /bin/false utmp

Make sure the directory for wtmp is owned by utmp user:

mkdir -pv /var/log/utmps
mv -v /var/log/wtmp /var/log/utmps/
chown -vR utmp:utmp /var/log/utmps
ln -sv utmps/wtmp /var/log/wtmp

Bootscripts no longer require system boot with a initramfs image. But kernel parameters should boot with root filesystem as read-only for checking root filesystem at boot (i.e. linux root=/dev/sda2 ro) You may use scripts from BLFS or Musl-LFS to build one. Script requires cpio installed.

# Copy the script to /sbin:
install -v -m755 mkinitrd/mkinitramfs /sbin/
# Copy the configuration:
mkdir -p /usr/share/mkinitramfs 
install -v -m644 mkinitrd/init.in /usr/share/mkinitramfs/ 
# To use, use the kernel version:
mkinitramfs $(uname -r)

Layout

Directories in s6:

  • base - Base directory for s6-linux-init
  • base/run-image - Directory copied to /run at beginning of boot
  • base/scripts - Scripts to shutdown and start system via s6-linux-init
  • base/env - Enviromental varibles to set at boot
  • db - Compiled databases for boot
  • db/current - Compiled database to use for boot
  • skel - Default startup/shutdown scripts
  • sv - Source definitions for databases and services
  • scripts - Small scripts used by services compiled from sv
  • doc/mock-boot-tree - Use command tree to see how the layout of sv

Scripts:

  • rc.local - Additional shell commands to execute on bootup
  • s6.conf - Global configuration of s6-rc services

mkinitrd:

  • mkinitramfs - Script to make a basic initramfs
  • init.in - Configuration for script.

Setting up Networking at Boot:

# install net-services:
mkdir -v /lib/services
install -v -m644 net-services/* /lib/services/
# install helper scripts to bring up and down interfaces:
install -v -m755 if* /sbin/

Each interface should have configuration files in /etc/sysconfig. For example:

/etc/sysconfig/ifconfig.wlan0              # config for a wifi card
/etc/sysconfig/wpa_supplicant-wlan0.conf   # config for wpa_supplicant for same wifi card

Examples are in net-configs

Usage

To disable/enable services, modify the contents of /etc/s6/sv/services/contents.d. Then compile a new database to use for the next boot.

For example, to enable dbus service:

# Install dbus service scripts (dbus-srv, dbus-log) to /etc/s6/sv/

# Add dbus script to list of services to start at boot:
touch /etc/s6/sv/services/contents.d/dbus-srv

# Compile a new database for boot
s6-rc-compile /etc/s6/db/${new_db} /etc/s6/sv

# Link new database to boot
mv -v /etc/s6/db/current /etc/s6/db/previous
ln -sv /etc/s6/db/${new_db} /etc/s6/db/current

Services an be enabled or disabled after boot:

# Enable a service that was not enabled at boot
sudo s6-rc -u change ${service_name}

# Disable a service
sudo s6-rc -d change ${service_name}

# To see the list of services to enable/disable:
ls /run/service/*

Changelog since 4.x.x

  • Updated service format: Bundles now use contents.d & dependencies.d directories instead of contents & dependencies files
  • Improved service dependacies: Previous format had issues some services starting before required service(s) executed
  • /tmp directory now cleaned during boot and during shutdown
  • System clock now set from hardware clock
  • Most commands in service scripts use commands from s6-linux-utils or s6-portable-utils
  • Cleaned up boot messages that are logged in /run/uncaught-logs/current

mlfs-s6-bootscripts's People

Contributors

dslm4515 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mlfs-s6-bootscripts's Issues

Pros and cons of using shell instead of execline

Hey there,

I noticed that you recently moved away from execline and rewrote your bootscripts in shell.

If I may ask:

  • Why did you do that?
  • Is it for the sake of simplicity?
  • Are you planning on removing execline?
  • Have you noticed any real benefits?

Good luck with your endeavours!

Mount procfs & sysfs Conditionally

Some kernels(?) or initrd's may automatically mount procfs and sysfs before these bootscripts. This causes some boot scripts to fail and break the system boot.

Therefore, boot scripts should only mount these virtual file systems when the kernel doesn't.

Missing wtmp service

utmp service is generated automatically with s6-linux-init configured with --enable-utmps ... but no wtmp service is made or provided by s6-linux-init .

Per skarnet website:

Note that you will still have to create a wtmpd service yourself and activate it later in the boot sequence, after a writable filesystem is mounted, because the wtmp database is supposed to be persistent and should live on a real filesystem. s6-linux-init cannot do that for you, because it only handles the early part of the boot sequence, before filesystems are mounted.

I will need to create a wtmp service with utmps after root filesystem is mounted and writable. Most likely wtmp will be in /var/log/utmps

Missing /etc/s6/skel

The README suggests that the s6/ directory should include skel, which (after copy to /etc) is then used as input to -f skeldir when calling s6-linux-init-maker.

This directory doesn't exist in the repo. Is this by mistake? Or do I need to generate it?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.