HOWTO Initng
From Gentoo Linux Wiki
--Qupada 11:01, 29 April 2006 (UTC)
| Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
Contents |
[edit] Introduction
Initng is a full replacement of the old and in many ways deprecated sysvinit tool. It is designed with speed in mind, doing as much as possible asynchronously. In other words: It will boot your system faster, give you more control over the boot process, and provide you with additional statistics.
The basic premise is that startup commands can be launched as soon as their dependencies are met. This limits the effect of bottlenecks like I/O operations; while one program is performing I/O, another can be utilizing the processor. Initng tracks the individual service dependencies in its configuration files.
Warning: initng is still in beta development. It would be unwise to unmerge sysvinit and attempt to rely on initng alone. Don't say you weren't warned.
Related discussion in gentoo forums here
[edit] Installation
[edit] Using the standard ebuild
There is an ebuild in the portage tree for initng, but it is masked by the ~x86 keyword. (initng is still in beta). (You no longer need to put the keyword in package.keywords unless it is -*)
echo "sys-apps/initng" >> /etc/portage/package.keywords emerge initng -av emerge initng-ifiles -av
[edit] Using the Official InitNG overlay
The easiest way to use the official InitNG portage overlay is with layman. The InitNG overlays are slightly more up to date than the Gentoo overlays and recommended by the InitNG developers.
Just
emerge layman layman -f layman -a initng
You might also need to modify make.conf to use layman's overlays, instructions should be given when you emerge layman.
Unlike the ebuild in the official portage tree, the ebuilds in the Initng overlay have several additional USE flags that can enable various plugins and some other features.
[edit] Using the Subversion Ebuild
For those who want the absolute latest, bleeding edge version, there is now a subversion ebuild in portage. This tends to be fairly stable, and to be quite a few steps ahead of the standard ebuild.
Just
emerge =initng-9999
It is masked, but if you want to experiment, you probably already know how to handle this.
If you have old portage tree Just:
emerge initng-svn
Admittedly, it should be masked, but right now it isn't.
Warning: If you have emerged the standard ebuild, and want to change to the svn ebuild, first unmerge the standard one:
emerge -C initng emerge initng-svn
The two should block each other, but right now, they don't.
[edit] Adding init scripts to the default runlevel
If you have used rc-update to add any services to your default runlevel, these will not work with initng, therefore you will need to use ng-update to add your services to the initng default runlevel. For example, to add gdm, you would run:
ng-update add gdm default
[edit] Configuring the Bootloader
To use initng, you will have to modify your bootloader configuration.
Be warned: If you get this wrong, your system may no longer boot.
When you create the new entry, to boot using initng, leave the old entry (booting using sysvinit) in the configuration file: initng is still in beta, and somewhat unstable. It also has a habit of crashing if an init script doesn't work. If you can't boot, you will want to be able to boot using sysvinit, so you can change the initng configuration.
[edit] LILO
If you are using Lilo as your bootloader, you will need to create a new entry in /etc/lilo.conf. Open the file in a text editor, copy your existing entry (giving it a new name), and add the following line:
append = "init=/sbin/initng"
For example:
| File: /etc/lilo.conf |
# Working image = /boot/kernel-2.6.11-gentoo-r9 root = /dev/hda2 label = Gentoo-2.6.11-r9 read-only # init-ng Test image = /boot/kernel-2.6.11-gentoo-r9 root = /dev/hda2 label = Gentoo-2.6.11-r9-initng append = "init=/sbin/initng" read-only |
[edit] GRUB
If you are using GRUB as your bootloader, you will need to create a new entry in /boot/grub/grub.conf. You may need to mount /boot first. Open the file in a text editor, copy your existing entry (giving it a new name), and add the following to the end of the "kernel" line:
init=/sbin/initng
For example:
| File: /boot/grub/grub.conf |
hiddenmenu timeout 5 default 0 fallback 1 splashimage=(hd0,0)/grub/splash.xpm.gz # Working title GNU/Linux 2.6.11-gentoo-r9 root (hd0,0) kernel /kernel-2.6.11-gentoo-r9 root=/dev/hda2 # init-ng Test title GNU/Linux 2.6.11-gentoo-r9 (init-ng) root (hd0,0) kernel /kernel-2.6.11-gentoo-r9 root=/dev/hda2 init=/sbin/initng |
[edit] Usage
[edit] ngc
ngc is used to start and stop services in initng. For example, to restart xinetd:
ngc -r daemon/xinetd
This is analgous to the old (in sysvinit):
/etc/init.d/xinetd restart
Note: The scripts in /etc/init.d/ will not work if initng was used to boot. Similarly, ngc will not work if sysvinit was used to boot.
[edit] ng-update
ng-update is very similar to rc-update:
ng-update show
to show all available init scripts, and which runlevel(s) they're called by.
ng-update add xinetd default
adds xinetd to the default runlevel
[edit] Man pages
There are now man pages for initng, and its components:
man initng man ngc man ng-update etc...
[edit] Init scripts
Few developers of software packages and daemons are releasing their own initng scripts. This means that the majority of initng scripts you'll be using are maintained by the initng community.
User contributed scripts are often placed in the svn repository fairly quickly (and into the ebuild soon thereafter). If you can't find the script you need in /etc/initng or one of its subdirectories, please consider creating your own and posting it in the official initng forum or e-mailing it to the author.
[edit] Migration
First run etc-update or dispatch-conf to ensure that you have the most up-to-date scripts.
Then run the following script which will:
- Migrate runlevels in sysvinit to initng
- 'boot' to 'system'
- 'single' to 'single'
- 'default' to 'default'
- everything else to 'default'
- Report ERROR (in color!) when a script you have installed in sysvinit doesn't exist in initng
ls -1 /etc/runlevels/ | while read RUNLEVEL
do ls -1 /etc/runlevels/${RUNLEVEL}/ | while read DAEMON
do HAS_D=`find /etc/initng -iname ${DAEMON}.i`
if [ ! -n "$HAS_D" ]; then
echo -en '\E[47;31m'"\033[1mERROR\033[0m: ${DAEMON}.i not found.\n"
fi
if [ -n "$HAS_D" ]; then
if [ "$RUNLEVEL" = "boot" ]; then
NG_LEVEL="system"
elif [ "$RUNLEVEL" = "single" ]; then
NG_LEVEL="single"
else
NG_LEVEL="default"
fi
DAEMON_NAME=`echo ${HAS_D} | sed -e 's/\/etc\/initng\/\(.*\)\.i/\1/'`
ng-update add ${DAEMON_NAME} ${NG_LEVEL}
fi
done
done
Or if you aren't ready to migrate but want to know what scripts you would need to create yourself just run this part of the above script:
ls -1 /etc/runlevels/ | while read RUNLEVEL
do ls -1 /etc/runlevels/${RUNLEVEL}/ | while read DAEMON
do HAS_D=`find /etc/initng -iname ${DAEMON}.i`
if [ ! -n "$HAS_D" ]; then
echo "${DAEMON}"
fi
done
done
Or you could also compare the output of
cd rc-update -s > sysinitv.all ng-update s > initng.all diff sysinitv.all initng.all
[edit] Missing a script?
If you have a service you want to run, that doesn't have an initng script yet, do the following:
1. Check the initng forum to see if someone else has written it already.
2. If not, you'll have to write it yourself:
- Browse through some of the existing scripts to see the syntax
- Check to see if there's a sysvinit script in /etc/init.d/: You can use it to base the initng script on.
- Write the script.
- Test it first by trying to start it with ngc
- If that succeeds, add it to a runlevel (probably default) to test it. Make sure that you still have the option of booting using sysvinit, as, if your script crashes initng, you'll need that to boot again.
3. Or... Check out initng's plugins at initng plugins page. These can execute bash scripts and more. Some are still under development.
[edit] Some example scripts
This is an example of a customized network interface script:
| File: eth0 init script |
# eth0 is static.
service net/eth0 {
depends = system/initial system/checkroot system/modules
use = system/static-modules system/coldplug
start {
echo "Starting net/$NAME now"
ifconfig $NAME 10.0.0.1 netmask 255.255.255.0
route add -net 0.0.0.0 gw 10.0.0.138
}
stop {
echo "Stopping net/$NAME now"
ifconfig $NAME down
}
}
|
This is an example of a script for an uptime daemon:
| File: uptimed init script |
service daemon/uptimed {
need = system/initial system/checkroot
daemon = /usr/sbin/uptimed
pid_file = /var/run/uptimed
}
|
This is an example of a netplugd initialization script:
| File: netplugd init script |
daemon daemon/netplugd/* {
#*/
need = system/mountfs system/modules;
use = system/static-modules system/coldplug;
exec daemon = /sbin/netplugd;
exec_args daemon = -D -i ${NAME} -c /dev/null -P -p /var/run/netplugd.${NAME}.pid;
pid_file = /var/run/netplugd.${NAME}.pid;
}
service daemon/netplugd {
need = system/mountfs system/modules;
use = system/static-modules system/coldplug;
script start = {
for IF in `cat /proc/net/dev | awk 'BEGIN { FS=":" } /eth|wlan/ { gsub(/\W/,"",$1); print $1;}' ` ; do
/sbin/ngc -u daemon/netplugd/$IF &> /dev/null
done
};
script stop = {
for IF in `cat /proc/net/dev | awk 'BEGIN { FS=":" } /eth|wlan/ { gsub(/\W/,"",$1); print $1;}'` ; do
/sbin/ngc -d daemon/netplugd/$IF &> /dev/null
done
};
}
|
[edit] Troubleshooting
[edit] Problems with Xorg and nVidia Cards
If you are having trouble starting X and you have an nVidia card, it may be that the necessary device files are not being created.
Note that this is not a problem with initng: the same is the case with sysvinit except that by default /etc/conf.d/rc is set to tarball all your device files on shutdown and reload them on startup from this archive.
| File: /etc/conf.d/rc |
RC_DEVICE_TARBALL="yes" |
Since initng does not pay any attention to this you do not have your device files saved from some previous boot. You would have trouble starting X if you changed this option to no with sysvinit as well.
The solution is to run /sbin/NVmakedevices.sh on startup when appropriate by adding something like the following to /etc/conf.d/local.start:
| File: Example /etc/conf.d/local.start |
if [ ! -e /dev/nvidia0 ]; then
/sbin/NVmakedevices.sh
fi
|
Finally, if you're still having problems because this isn't done before your login manager has started, add "system/local" (without the quotes) to the line of your login manager's init script that begins "need =" (for example: /etc/initng/daemon/kdm.i). This will ensure that your nVidia device files have been created and are ready for use when X starts.
[edit] Problem with alsasound
In order to get alsasound working you need to have coldplug added to the system runlevel:
ng-update add coldplug system
or just add system/alsasound/cards to the default runlevel (it loads the modules your sound card need).
[edit] Usefull links
website: http://initng.org/
forum: http://forum.initng.org/
