Articles
[HOWTO] tweak your boot-up with rc.local
- Details
As of Porteus-v1.2 the 'Porteus settings centre' has a GUI to add startup commands or scripts to your Porteus install.
Once you get Porteus up and running and all of the packages you'd like to use installed and working, you might be interested in customizing your installation to improve your experience. One of the best tools for customizing Porteus is the file located at /etc/rc.d/rc.local.
Go ahead and open this file up. What you'll probably notice is that, other than the header information (which is all commented out) it is blank! (This may not be the case if, for example, you've used pns-tool to set your network connection, as it places a line here).
This file is a blank slate for users to add custom options to their boot procedure. 'rc.local' is a script that is run very late in the boot process, just before Porteus starts up the xorg server (or the CLI login if you're using text mode).
In order to tweak your boot process, simply add the commands you want to execute to rc.local and save it (users who boot into 'Always Fresh' mode can copy the file to rootcopy or create a module for it, and put the module in /porteus/modules).
For example, here's what my rc.local file looks like:
#!bin/sh
# /etc/rc.d/rc.local: Local system initialization script.
#
# Put any local startup commands in here. Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.
wpa_supplicant -Dwext -iwlan0 -c /etc/wpa_supplicant.conf > /dev/null 2>&1 &
/etc/rc.d/rc.FireWall start
/opt/porteus-scripts/power_saver
What do these commands do?
The first uncommented line, starting with wpa_supplicant, starts up my wifi card, using the settings in /etc/wpa_supplicant.conf. The second line starts up the built-in Porteus firewall, so I don't have to start it manually each time I boot up Porteus. The third line starts the 'power-saver' script, which slows down the clock speed on my processer. Since I run Porteus on a laptop while I'm on the go (and I'm usually doing something like editing Porteus documents, which doesn't require my system to run at full speed), this helps prolong my battery life.
Now, a warning about using rc.local:
Remember that Porteus builds its filesystem in layers (see this doc for more info), and if you have the same file in more than one layer, the last layer to be copied into the system 'wins', meaning that is the version that will be present in your live filesystem. The layers are added in this order: base modules -> user modules (those in /porteus/modules) -> 'changes' files (if you are saving your changes) -> rootcopy -> magic folders. You may wind up with multiple versions of files like rc.local; for example, you might have one in the base module '001-core.xzm', one in /porteus/modules/my-changes.xzm, and one in your rootcopy. If that is the case, only the version in your rootcopy file will be applied, so you must make sure that your rc.local file includes all of the line items from any modules and changes files before you save it to your rootcopy folder. The best way to do that is to start your system the way you normally would, and then copy the /etc/rc.d/rc.local file from your live filesystem (so that any modules or changes files have been applied), add your new commands to that, and save the resulting file to /porteus/rootcopy/etc/rc.d/rc.local. Then, you'll need to remember to only make changes to the version in your rootcopy folder -- if you try to add new commands to rc.local in a module or your saved changes, those new commands will not take effect--they will always be superseded by the version in rootcopy. Note that for these reasons, if you are building a module for use by others, you should utilize the sysvinit scripts for start-up procedures instead of rc.local. Sysvinit style scripts allow for the automatic execution of scripts with different names (so you can give them unique names and avoid having them overwrite each other in the live filesystem).
There are a number of other things you can add to this script -- what do you use in your rc.local? Post your ideas in this thread on our forum, and I'll add your suggestions to this doc.
Thanks!