View previous topic :: View next topic |
Author |
Message |
defer- Tux's lil' helper
Joined: 11 Jun 2007 Posts: 140 Location: Finland
|
Posted: Fri Sep 19, 2014 12:18 pm Post subject: How does gentoo startup / init work? |
|
|
I would like to create custom init to get fast startup and shutdown times. I created sinit[1] ebuild and installed it. I chaged savedconfig and created /etc/rc script. My current setup boots fine to X but shutdown and module loading doesn't work.
How does Gentoo sysvinit/openrc startup work? What does init execute and how does openrc execute init scripts on startup or shutdown? What is needed for working system?
[1] http://git.suckless.org/sinit/
[2] /etc/rc
Code: |
#!/usr/bin/env bash
if [[ "$1" = "start" ]]; then
echo "Starting up Gentoo Linux"
mkdir -p /proc
mkdir -p /sys
mount -n -t proc -o nosuid,noexec,nodev proc /proc
mount -n -t sysfs -o nosuid,noexec,nodev sysfs /sys
mount -n -t tmpfs -o nosuid,mode=0755 dev /dev
mkdir -p /dev/pts
mount -n -t devpts -o gid=5,mode=0620 devpts /dev/pts
echo Running smdev
smdev -s
echo Setting smdev as the kernel hotplug
echo /bin/smdev > /proc/sys/kernel/hotplug
echo Loading kernel modules
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -b -a 2>/dev/null
echo Remounting root as read-write
mount -o remount,rw /
echo Mounting filesystems
mount -a
hostname dfr-laptop
/sbin/agetty --noclear 38400 tty1 linux &
/sbin/agetty --noclear 38400 tty2 linux &
elif [[ "$1" = "reboot" ]]; then
echo "Rebooting Gentoo Linux"
killall5 -s KILL
echo Remounting root as read-only
mount -o remount,ro /
echo Unmounting filesystems
umount -a
sync
sleep 1
wait
reboot
elif [[ "$1" = "shutdown" ]]; then
echo "Shutting down Gentoo Linux"
killall5 -s KILL
echo Remounting root as read-only
mount -o remount,ro /
echo Unmounting filesystems
umount -a
sync
sleep 1
wait
halt
else
echo "Unknown command"
fi
|
_________________ https://github.com/defer- |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Fri Sep 19, 2014 10:27 pm Post subject: |
|
|
First off, lose the awfully fscked-up shebang: #!/usr/bin/env bash is wrong on so many levels. Just use #!/bin/sh and learn to write portable sh.
Most of that looks ok, but I'd separate out into functions, and use a simple case. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Sun Oct 12, 2014 12:56 am Post subject: Re: How does gentoo startup / init work? |
|
|
defer- wrote: | How does Gentoo sysvinit/openrc startup work? What does init execute and how does openrc execute init scripts on startup or shutdown? What is needed for working system? |
As with every Linux (and indeed Unix that I know of), "init" means pid1: it doesn't do very much, but it is configured via /etc/inittab -- the file is pretty well-commented. Though you really shouldn't edit it in general, in your case you likely need to.
pid1 must be robust, and simply-coded, since it must run for the entire uptime of the machine. It is the first process started by the kernel, and if it exits (or crashes), the kernel panics (ie: completely halts) and all your in-flight data is lost, FS may be corrupted, etc. ie: Game Over.
For this reason, it's not worth redoing pid1: complexity is much better handled elsewhere, in the default case by openrc (command: /sbin/rc) which you can see is run by init on entry to the various run-levels. So we still use sysvinit, since there's nothing more that would sanely be added to pid1. ie: sys-apps/sysvinit
Read man 8 init for more information; man runscript and man rc if you want to know more about openrc. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|