A simple bash init scheme for LFS
After MrScoville's thread about init, I've been experimenting with a bash script for init. It does work and looks normal starting and stopping. I didn't invent this idea (see the references).
The system for the experiment is a clone of my main BLFS system. The original init was Busybox which was removed along with its inittab and four symlinks. My collection of custom-made initscripts in /etc/init.d remains and those are called by the bash init just like Busybox did. The bash init itself was created from my 1, 2, and 3 scripts that I originally used with Runit but have continued to use almost unchanged with Busybox. Script 1 has calls to initscripts with start arguments for the usual system initialization stuff. Script 2 is a short script to prepare for shutdown. And script 3 calls the usual initscripts with stop arguments for shut down. Well, those three scripts were merged together unchanged and in order to create the init for this project. An agetty command was inserted at the end of the startup stuff to create a virtual terminal for login. So when the kernel starts the init, it in turn runs the various initialization scripts in /etc/init.d as usual. When the process arrives at the agetty for login, the init progress stops right there until that terminal is logged out. The init is PID 1 and can never exit or the kernel panics. Anyway, at this point I have my usual BLFS system in front of me. I can't tell the difference. To begin the shutdown process I only have to exit Fluxbox to return to the tty command prompt and then log out of the virtual terminal. Logging out of the tty turns loose the waiting init which continues down the commands for shutting down. That also proceeds normally and looks good. I eventually created a small auxiliary Perl script to do those logouts from the Fluxbox menu. The init ends by deciding to reboot or poweroff and uses Magic SysRq codes to do those. Below are the two files used in this project just to illustrate the method in my case. Any set of existing initscripts could be used with this method. The Perl shutdown helper script is simple to alter as needed. Code:
#!/bin/sh Code:
#!/usr/bin/perl Some references: http://www.linux.it/~rubini/docs/init/ https://major.io/2009/01/29/linux-em...agic-commands/ https://felipec.wordpress.com/2013/11/04/init/ |
you beat me to it!
I have been doing much the same thing, I may post mine ( when I can do the documentation ) as a comparison, I do have service scripts that can monitor apps and relaunch if needed, and i also use the init scripts used with busybox, I've only tried this in a VM at the moment, trying to find the time to go the whole hog and put it on my main system. |
I for one would like to see that when you have it ready. I can say right now that the idea works just fine and looks normal onscreen. The little issues I've encountered so far are either not important to me, or I have fixed them (or will). Right now I'm tweaking and playing with the little Perl script that is called from my Fluxbox menu to do the terminations of any user stuff and lastly X and the tty which makes init start the shutdown steps. Although that's not really necessary since it's a simple matter to manually exit the graphical session and then manually logout of the virtual terminal.
|
i'm away from my machine at the moment but i wilk collect the scripts together and upload them to git and post some details here.
to be continued .... |
Well here you go this is a work in progress but seems pretty stable I have been using it to start up my desktop on my main machine via my xinitrc, start ing the desktop. wm, panels etc etc.
I have only used it as an init in a VM so far but it also seems pretty stable there as well there is a short movie in the git repo showing the boot sequence. Get the repo with Code:
git clone https://github.com/KeithDHedger/StartupServices.git BACKUP ALL RELEVANT FILES YOU HAVE BEEN WARNED!!!!! I think I got everything in the repo but let me know if anything is missing, I hate documenting so bear with me! |
I wanted to let you know that I installed your init system, and it works very well on my BLFS system. Congratulations on an impressive piece of work. But dude, that ain't simple. You've put some serious work into that. It's nice though having a sophisticated init but written in bash so amateurs like me can read and follow it more easily. I especially liked the multiple ttys that respawn. Installation instructions are good.
Over time I have strayed so far from the standard LFS init stuff that I replaced the initscripts and function file with mine. It still works normally. Some comments and questions...
|
Thx for good review!
Like yourself I have strayed quite a bit from the lfs/blfs book an so some of the init scripts have been mucked about with while I have tried other things, I will go through and clean upnthe bits you have point3d out, it's probably overdue anyway! I'll post back later with more details, I'm not at my machine at the moment. |
1)
I don't use iptables, my router has a pretty good firewall, but if you have a basic iptables script i'll add it to the repo. 2) Removed, don't know how that creapt in the random start up script from BLFS Boot Scripts handles this. 3) Alsa should be configured by a standard udev rules, so doesn't actually need an init script, have a look at '/lib64/udev/rules.d/90-alsa-restore.rules', that line just makes sure any changes are saved. 4) No I don't intend to include all the BLFS scripts in the repo thay are easily added by the user, the BLFS scripts Makefile can/should be use when installing a start up script and it will put the file in the correct place and create a symlink, that's why I kept the folder hierarchy the same so it would be compatable. 5) Agreed, done. 6) The /lib/lsb/init-functions script is part of the BLFS Boot Scripts and really should be installed for 3rd party start up scripts, in fact if you have installed any start up scripts from (B)LFS you probably already have it installed, both it and my own functions script basically do the same thing and have grown a bit organically, there is some duplication, I will rewrite the functions script to incorporate all the needed sub routines but it may take a while! 7) Correct only needed in startups, this was a hangover from my main system which still uses busybox init, ( I was lazy and just copied the folders 'as is' ), removed from repo. |
Removed the vbox scripts/links as they are installed by the virtualbox installer and don't belong in the repo.
|
1 Attachment(s)
When you have some time from your real life, here are some more things to consider...
1. Things in /etc/rc.d/init.d that are not used and maybe should go: halt2. In /etc/StartupServices/startups/1, should $1 in line 7 be $i? As it is now, it just prints "start" on a line by itself. Code:
#!/bin/sh Code:
[ -r /etc/hostname ] && HOSTNAME=`cat /etc/hostname` Attachment 24763P.P.S.: When you get this project polished, you should think of a name for it. Then introduce it in a new thread where it can be post #1. |
I am in rhe process of cleaning up, found a bug that i need to fix 1st, but I will look at the rest of ghis tomorrow, I have fixed some of this especially the visual bit, but must have forgot to do a commit before I shutdown ... to be continued
|
Quote:
Removed all except halt this is used by checkfs 2) Leftover debug code, removed. 3) Done. Fixed the visual stuff but needs more work, do a git pull for the changes, I wont post anymore here ( sorry for hijacking your thread! ) I will start a new one soon. |
Quote:
|
nah its fine it needs to go in its own thread not a problem
|
|
All times are GMT -5. The time now is 10:29 AM. |