punkwalrus (punkwalrus) wrote,

LPI 102 Exam notes: 14 days until the exam

Since I goof off and LJ so much, I have decided to hijack the process and write my study notes and thoughts. But they are probably totally boring for those not interested in Linux. These notes may be very long and disjointed, so... I put them...

For those interested, think there needs to be corrections, have neat trivia, or have some things to say: COMMENTS ARE ENCOURAGED!!!
Booting a Linux system

One final thing about kernels: if you need to pass options to the kernel itself, this has to be done on the kernel command line in LILO or GRUB. Modular options are contained in:

/etc/modules.conf for Linux 2.4.x systems
/etc/modprobe.conf or /etc/modprobe.d/* for Linux 2.6.x systems

You can see kernel boot messages via the command "dmesg," but if your system has been up for a while, the boot messages get lost because dmesg has a finite limit. Some distros will dump it to /var/log/boot.log or something so you will always have a copy of messages fom the more recent boot. But not always, so you may want to put it in /etc/rc.local as the last thing to execute.

All system logs are kept in /var/log, the most famous of which is /var/log/messages. You should read one for a while. Go ahead, I'll wait. There is also secure, which has login messages, mail.log, which has your mail logs, and a lot of other applications also put their log messages here.

Run Levels
When Linux boot, there's various "run levels" to tell the initialized services when to run.

0 - Halt the system. Dead stop.
1 - "Single user mode," which is the most basic bare minimum needed to have a working system. No networking or services run. This can also be stated by "s" or "S" for single. You can only access the system via console/keyboard, obviously.
2 - Most basic multiuser. This is the default non-GUI for Debian, and Red hat it does not have NFS avialble
3 - Default multiuser for Red Hat based systems, non-GUI. Debian does not use this runlevel, typically.
4 - Typically unused by anybody.
5 - For Red Hat, this is like runlevel 3, but with GUI enabled.
6 - Reboot the system.

Obviously, don't use init 0 or 6 for default runlevels, or your system will shut down or reboot continuiosly on booting. Doh! Runlevels are set in /etc/inittab:


In this case, this is runlevel 3 on a headless box where video would be pointless.

To change the init runlevel from root is easy:

init 6

Is the same as "reboot." Older users may use "telinit" but these days, it's just a link to "init".

The command runlevel will show you the previous runlevel followed by the current one. "3 5" will tell you that you were in level 3, but went to 5. "N 3" means nothing was before (like the machine turned on) and you are currently in runlevel 3.

Okay, here's a good thing to know: suppose you have a system where you need the root password because the admin has a heart attack from too many cases of BAWLS and Cheetos, and you need into the system. Reboot it to single mode (init 1) and then type "passwd" at the root prompt. Now, most distros will let you do this, but some are more stubborn and you'll get a root login/password prompt anyway. There are ways around this too.

If you are already at the prompt (on the console, not over network), simply type "init 1" and there you go. But that never happens, right? If you were at the prompt, you probably don't need the password.

If you have LILO, it's pretty simple. When you boot, at the prompt, type:

boot: linux single

In some systems, "boot" is "LILO" instead.

But GRUB is a little more difficult. From the boot menu:

1. Highlight the kernel you wish to boot into, and hit "e" on the keyboard
2. This will bring you to the various boot lines. Select the one that starts with "kernel" and hit "e" again
3. At the end of the line, hit space, and type either single or 1
4. Some systems are locked down harder than that. If this is the case, go to the end of that line, hit space, and type single init=/bin/bash
5. Hit enter and then type "b" for boot

This will come in handy. Write it down somewhere. One day, it will save your ass, and will do so more than once.

When the init process boots, the run levels themselves are kind of arbitrary without some listing of what to do with each setp. This is accomplished by "rc" scripts in the /etc directory.

The scripts for running thing, usually services and prep work, are in the directory /etc/init.d/

The file "/etc/rc" is a script that changes the runlevels. There's a series of 7 directories after that, labeled /etc/rc.0/ through /etc/rc6.d/ (which will be hereby called /etc/rcX.d/ to refer to them all. These contain only symbolic links to scripts in /etc/init.d/ as shown here for my CentOS /etc/rc3.d/ directory (only the middle, there's a lot here):

[... stuff]
lrwxrwxrwx 1 root root 19 Mar 16 15:20 K92ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 15 Mar 16 15:28 K95kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 25 Mar 16 13:21 K99readahead_later -> ../init.d/readahead_later
lrwxrwxrwx 1 root root 23 Mar 16 13:20 S00microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx 1 root root 22 Jul 1 10:01 S02lvm2-monitor -> ../init.d/lvm2-monitor
lrwxrwxrwx 1 root root 25 Mar 16 13:21 S04readahead_early -> ../init.d/readahead_early
lrwxrwxrwx 1 root root 18 Mar 16 13:05 S06cpuspeed -> ../init.d/cpuspeed
[... more stuff]

Those that start with "S" stands for "start" and those with "K" are "kill." The number specify what order they need to be run. Most of the time, "kill"
just ensures a service installed will NOT run, except for init 0, 1, and 6, where most of them will kill anything running to go into single user or halt/reboot.

There are various other ones to look at:

Red Hat like distros:
/etc/rc.sysinit is the first thing run. You should leave this alone, because many upgrades will replace this script, and then what will you do, Mr. Smartypants?
/etc/rc.local is the last thing run. This is kind of like a "Startup" folder for various programs you want to run after the system has finished booting. This is not replaced by any upgrade.

Debian-esque distros:
/etc/init.d/rcS is the first thing run
There is no "rc.local" for Debian, but those who need it will create it in /etc/init.d/rc.local, and then create symbolic links in /etc/rcX.d/S99local

To run a service by hand, most of the time, a good program will have put itself in the init.d directory with BASIC "start | stop" options. For instance:

/etc/init.d/httpd start

Will start the Apache web server. I mean, if you didn't have it set to run at boot. But httpd has super options, like "reload" or "restart." Many other scripts aren't as snazzy, so you usually can find out what it supports by running just the script:

# /etc/init.d/httpd
Usage: httpd {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}

Red Hat distros went one further with making this shit simple:

The command chkconfig will add/remove services from runlevels. It defaults to 3 and 5, but you can specify on the command line.

service "whatever" is a shortcut for /etc/init.d/whatever, but it has to be added as a service via chkconfig.

See the man pages for details on these two commands, I don't think this is on the LPI, but it's nifty anyway. I think it can be added to Debian via a package.

Last but not least is "shutdown" and all its options. Some of the more common ones are:

shutdown -r now [reboot now]
shutdown -r +5 ATTENTION - Rebooting system in 5 minutes [Reboot in 5 minutes after you send a message to all logged in users]
shutdown -h 00:05 [halt/shut down at 5 min past midnight]
shutdown -c Sorry, false alarm [cancel shut down in progress with message to all logged in users]

See the man page for more goodies.

There are other commands to do this, like halt, reboot, and poweroff. If these are called in run level 1-5, they call shutdown instead. In run levels 1 and 6, they have other options for repair, like syncing dists, not writing to wtmp, shut off things in a certain order, and so on. See the man pages for those things.

Disclaimer: While I have been managing Linux systems for almost 10 years now, but I am mostly self-taught. I have a RHCT certification, but I am taking the LPI and CompTIA Linux+ exams to "flesh out" some of the gaps that occur from too much real-world experience versus my lack of good old fashioned book learnin'. This entry in no way assures you my thoughts are correct, I will have frequent misspellings, and they may or may not help you pass the LPI. HUGE parts of the exam will be missing because I already know half of it by heart, so using me as your only study guide is a terrible idea. Please read this entry with a healthy amount of skepticism, and PLEASE feel free to correct or add comments! My ego is hardy enough to admit when I am wrong.
Tags: linux, lpi
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded