System control exercise
[ Note: 2 new behaviors as of Fedora Core 5, since this exercise was written
1) if you have a USB keyboard, when you tell the kernel to call the shell directly as below ( init= ), you arrive at the shell prompt with a dead keyboard. While this doesn't detract from the intended demonstration of kernel parameter passing, in that it shows it worked after all, doing the needed hard reboot doesn't feel good. Non-USB keyboards are fine.
2) MAC address spoofing via /etc/sysconfig files no longer works. The script was rewritten between Fedora 4 and Fedora 5 and contains logic to refuse setting the MAC address to one different than that seen on the NIC. Spoofing is still entirely possible ( "ip link set eth0 address 00:11:22:33:44:55" ) it's just that the sysconfig script is no longer willing to participate in doing it. Omit the attempt at that particular change here.
Additionally, the "before" members of the "before and after" file versions below may differ from what you find on your machine. ]
Passing kernel boot parameters
Boot your system and at the GRUB menu, press the "a" key to supply custom parameters to the kernel. From the line that appears in the resulting editor remove the "quiet" parameter and append the following two additional parameters:
FOO=bar init=/bin/bash
then press Enter to start the boot.
After the system has booted, examine the environment variables by issuing the command:
env
Note the presence and value of FOO, and the smaller-than-usual population of variables. Examine the list of processes by issuing the command:
ps -ef
When you get the error message telling you what you must do to enable the ps command (namely, get something mounted onto /proc) do it, then issue ps again. Note the smaller-than-usual population of processes, the absence of the process "init" as process number 1, the absence of "login" processes, and the process number ( 1! ) belonging to bash.
At this point we want to reboot to a full, normal environment. The "reboot" command works here. But what will happen if you just terminate bash? Do so with the usual command:
exit
Then, turn the machine off and back on again to get up and running normally again.
Exercising control over bootup scripts by setting values in sysconfig's files
A variety of scripts run during bootup. Many of them use files in /etc/sysconfig as the source of values for variables that condition their behavior and operation. For example, in the course of bootup events the kernel calls the init program, which calls mingetty, which calls login, which calls the shell, which calls profile. The point is, profile lies in this path and will get called. profile (fullname: /etc/profile) in turn ends up calling lang.sh (fullname: /etc/profile.d/land.sh) which calls/runs /etc/sysconfig/i18n. The only code in i18n is a few lines to set some variables, but these critically determine the localization behavior (language in which error messages appear, format of dates and monetary expressions, etc) for the duration of the shell session.
Run this command:
locale
Note the values. Other values are available to be set, to view them run:
locale -a
Now change a couple of them, then re-run locale to see the changes you made. Run these commands:
export LC_TIME=french
export LANG=spanish
locale
See the changes? To see their effect, run for example these commands:
rm <file that does not exist>
ls -l [note the reported date stamps]
cal
date
Avez-vous remarque les changements de langue qui ont eu lieu comme resultat... OH, Sorry, so did you notice the language changes resulting from the new values of these variables? What we have done here manually can be arranged to take place on the next boot, as we will do below.
Modifying tunable kernel parameters in the /proc virtual directory
View all the kernel parameters that sysctl can configure by running
sysctl -a | less
(scroll down and up with ctrl-B/PgDn and ctrl-F/PgUp, exit with q).
The hostname is controlled by one of them, /proc/sys/kernel/hostname You can view the current hostname with any of the following commands, which illustrate the 3 methods of access to the information in /proc. Perform all three:
filesystem method:
cat /proc/sys/kernel/hostname
sysctl command method: sysctl
kernel.hostname
dedicated utility method: hostname
And you can change it to, say, starfish with any of the following.
filesystem
method:
echo starfish > /proc/sys/kernel/hostname
sysctl command method: sysctl -w kernel.hostname=starfish
dedicated utility method: hostname starfish
Run these to vary the hostname, using one of the viewer commands each time to confirm. (If you log out and back in, or log in on another virtual terminal, the default shell prompt which includes the hostname will reflect the change.) Finally, change the hostname back to what it was originally.
Arranging to do it at boot time
Without rebooting, we have seen dynamic and immediate effects of changing values of certain environment variables and kernel parameters. As well, there are easy related mechanisms to set both whenever the system boots. For environment variable values, you enter their desired values in files under /etc/sysconfig. For kernel parameter values, you enter them in /etc/sysctl.conf. We will set up certain changes and then reboot to see the effect. Before going ahead, we will make backup copies of the 3 files we intend to modify. Please run these commands:
cp /etc/sysconfig/network /etc/sysconfig/network.org
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.org
cp /etc/sysctl.conf /etc/sysctl.conf.org
Suppose we want the system to boot up French, and we want to spoof our ethernet address. We also want to change the hostname to "garcon." The file we'll use to make our system French is /etc/sysconfig/i18n; the one for setting the ethernet address is /etc/sysconfig/network. And hostname will be controlled via the /etc/sysctl.conf file that tells sysctl, which runs during bootup, what to set.
Edit /etc/sysconfig/i18n, changing it as follows:
|
LANG="en_US.UTF-8" from: SYSFONT="latarcyrheb-sun16" to: SUPPORTED="en_US.UTF-8:en_US:en" |
LANG="fr_FR.UTF-8" SYSFONT="latarcyrheb-sun16" SUPPORTED="fr_FR.UTF-8:fr_FR:fr" |
This has no effect yet, but it will when you reboot.
Edit /etc/sysconfig/network by adding the single line MACADDR=11:22:33:44:55:66. Your file will look something like this, before and after:
|
DEVICE=eth0 BOOTPROTO=none from: IPADDR=192.168.3.12 to: NETMASK=255.255.255.0 ONBOOT=yes |
DEVICE=eth0 BOOTPROTO=none IPADDR=192.168.3.12 NETMASK=255.255.255.0 ONBOOT=yes MACADDR=11:22:33:44:55:66 |
No effect yet, but you'll see it following a reboot.
The new MACADDR variable will cause the ethernet software to utilize 11:22:33:44:55:66 as the address of its frames, rather than the one found in the NIC firmware which would otherwise be used. (Note the interesting implication that the security value of MAC address filtering, much used in wireless networking, is zero.) To see the aftereffect, you need to note the status quo ante, so run the command
ifconfig eth0
The first line will look like:
eth0 Link encap:Ethernet HWaddr 00:C0:4F:5E:35:69
Note the ethernet address ("HWaddr") shown in your computer's output. It's going to change.
To control the hostname we'll set sysctl to apply our chosen value, garcon, upon reboot. To do that, edit /etc/sysctl.conf, adding the following final line to it:
kernel.hostname=garcon
With the three changes you've made, you're ready to execute the following command:
reboot
When the system is back up, make sure the changes took effect. To do so, run the following commands and examine their output:
cal
ifconfig eth0
hostname
When satisfied, restore the original versions of the controlling files.
cp /etc/sysconfig/network.org /etc/sysconfig/network
cp /etc/sysconfig/i18n.org /etc/sysconfig/i18n
cp /etc/sysctl.conf.org /etc/sysctl.conf
Then reboot and go on your way.