Basic Linux Training
Lesson 6: Essential System Management
Table of Contents
Actually, once the system is installed and you tweak the configuration to suit your needs, Linux pretty much runs itself. Your main duties will be routine tasks - like managing accounts (you may want to create accounts for other users), backups (let a cron job do it), upgrading (which we'll cover in the next lesson), and some other one time or occasional tasks.
Of course, emergencies can and do happen. If you understand something about where your configuration files are and what they do, you're way ahead of the game. This is when you may need that vmlinuz floppy to boot Linux. Also, knowing which configuration files you can edit directly and which have to be created through a utility program will save you an enormous amount of grief when you're under the gun to get your system up and running again.
Redirecting the standard output stream will come in very handy when you need to send e-mail or post on newsgroup to get some help. You should experiment around with this to familiarize yourself with it before you need it. The information in Running Linux on page 98 is very basic, and there is some additional information in Linux in a Nutshell on page 137.
After you have booted up successfully, you might want to take a look at the bootup messages more carefully. You can issue the command dmesg to display it on screen, or redirect it to a file using dmesg > filename.
Some other useful commands that you should be familiar with are:
Check these in you man pages, or Linux in a Nutshell. This is just a handful of the hundreds of commands available.
username:password(encrypted):UID:GID:GECOS:homedirectory:shellOnly use this file to check for current user information. Don't edit this file to add new users.
Adding an account is relatively easy. Use the adduser command.
Deleting an account is much more involved, and it is usually better to simply disable the account by adding an asterisk (*) before the password for that user in /etc/passwd. Later, when you have time, you will have remove the user's home directory, delete the user from any group files, kill any cron or at jobs the user has running, delete the user's mail file in /etc/spool/mail and, of course, remove the user's entry from /etc/passwd.
Since the passwords are encrypted, forgetting your password will mean you have to boot the system from a floppy, mount the /root partition (if necessary), remove the existing password from /etc/passwd. Reboot from hard disk, login as root, and create a new password using the passwd command.
Take a look at this basic password file (which is more or less typical for stand-alone computers):
root::0:0:root:/root:/bin/bash bin:*:1:1:bin:/bin: daemon:*2:2:daemon:/sbin: adm:*:3:4 adm:/var/adm: lp:*:4:7:lp:/var/spool/lpd: sync:*:5:0:sync:/sbin:/bin/sync shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown halt:*:7:0:halt:/sbin:/sbin/halt mail:*:8:12:mail:/var/spool/mail: news:*:9:13:news:/usr/lib/news: uucp:*:10:14:uucp:/var/spool/uucppublic: operator:*:11:0:operator:/root:/bin/bash games:*:12:100:games:/usr/games: man:*:13:15:man:/usr/man: postmaster:*:14:12:postmaster:/var/spool/mail:/bin/bash nobody:*:-2:100:nobody:/dev/null: ftp:*:404:1::/home/ftp:/bin/bash guest:*:405:100:guest:/dev/null:/dev/null henryw:Oi.UVcBA9I/Hg:501:100:Henry White:/home/henryw:/bin/bashNot too many real, live, flesh and bone users, are there?
groupname:password:GID:user1,...,usernnNote that if there is no password, you still have to enter the extra colon in the file.
A basic group file looks like this:
root::0:root bin::1:root,bin,daemon daemon::2:root,bin,daemon sys::3:root,bin,adm adm::4:root,adm,daemon tty::5: disk::6:root,adm lp::7:p mem::8: kmem::9: wheel::10:root floppy::11:root mail::12:mail news::13:news uucp::14:uucp man::15:man users::100:games nogroup::-2:
When you have a job you want to run at a specific time, you can use at if it's an one time procedure.
Using the at command is very simple: issue the at command and specify the time of execution, press Enter then the command, Enter and Ctrl-D.
The batch command combines commands and runs with a lower priority than running them in the background. Unlike background tasks which are killed when you logoff the system, batch commands continue until the system is shutdown. Another important difference is that background tasks will interrupt you for output or confirmation; batch will send this to you as a mail message.
For repetitive procedures, you will use cron.
To use cron, you first create a text file (with any name other than crontab) with six fields separated by a space. The first five fields are: minute, hour, day of the month, month, day of the week; the sixth field is the command to be run. You can use asterisks ( * ) to indicate commands are to be run in every instance of the field. Also note that days of the week begin with 0 for Sunday, and that times are specified in 24 hour format. You can also specify ranges rather specific days and times, use a hyphen ( - ) if the range is inclusive or commas ( , ) if it is not. After creating the file, install it by using the crontab command - this will create and install the cron file and save a copy of the original under your username in /usr/lib/crontab. If you want to modify your cron configuration, edit this copy of the original file, then install it using crontab as before. If you want to remove the file use crontab -r.
The rc.S looks like this:
#!/bin/sh # # /etc/rc.d/rc.S: System initialization script. # # Mostly written by: Patrick J. Volkerding,<email@example.com> # PATH=/sbin:/usr/sbin:/bin:/usr/bin # enable swapping /sbin/swapon -a # Start update. /sbin/update & # Test to see if the root partition is read-only, like it ought to be. READWRITE=no if echo -n >>: "Testing filesystem status"; then rm -f "Testing filesystem status" READWRITE=yes fi # Check the integrity of all filesystems if [ ! $READWRITE = yes ]; then /sbin/fsck -A -a # If there was a failure, drop into single-user mode. if [ $? -gt 1 ] ; then echo echo echo "**************************************" echo "fsck returned error code - REBOOT NOW!" echo "**************************************" echo echo /bin/login fi # Remount the root filesystem in read-write mode echo "Remounting root device with read-write enabled." /sbin/mount -w -n -o remount / if [ $? -gt 0 ] ; then echo echo "Attempt to remount root device as read-write failed! This is going to" echo "cause serious problems... " echo echo "If you're using the UMSDOS filesystem, you **MUST** mount the root partition" echo "read-write! You can make sure the root filesystem is getting mounted " echo "read-write with the 'rw' flag to Loadlin:" echo echo "loadlin vmlinuz root=/dev/hda1 rw (replace /dev/hda1 with your root device)" echo echo "Normal bootdisks can be made to mount a system read-write with the rdev command:" echo echo "rdev -R /dev/fd0 0" echo echo "You can also get into your system by using a bootkernel disk with a command" echo "like this on the LILO prompt line: (change the root partition name as needed)" echo echo "LILO: mount root=/dev/hda1 rw" echo echo "Please press ENTER to continue, then reboot and use one of the above methods to" echo -n "get into your machine and start looking for the problem. " read junk; fi else echo "Testing filesystem status: read-write filesystem" if [ ! -d /DOS ]; then # no warn for UMSDOS (kind of a bad test, but...) cat << EOF *** ERROR: Root partition has already been mounted read-write. Cannot check! For filesystem checking to work properly, your system must initially mount the root partition as read only. Please modify your kernel with 'rdev' so that it does this. If you're booting with LILO, add a line: read-only to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it. If you boot from a kernel on a floppy disk, put it in the drive and type: rdev -R /dev/fd0 1 If you boot from a bootkernel disk, or with Loadlin, you can add the 'ro' flag. This will fix the problem *AND* eliminate this annoying message. :^) EOF echo -n "Press ENTER to continue. " read junk; fi fi # remove /etc/mtab* so that mount will create it with a root entry /bin/rm -f /etc/mtab* /etc/nologin /var/run/utmp \ /etc/shutdownpid /var/run/*.pid # mount file systems in fstab (and create an entry for /) # but not NFS because TCP/IP is not yet configured /sbin/mount -avt nonfs # Looks like we have to create this. cat /dev/null > /var/run/utmp # Configure the system clock. # This can be changed if your system keeps GMT. if [ -x /sbin/clock ]; then /sbin/clock -s fi # Setup the /etc/issue and /etc/motd to reflect the current kernel level: # THESE WIPE ANY CHANGES YOU MAKE TO /ETC/ISSUE AND /ETC/MOTD WITH EACH # BOOT. COMMENT THEM OUT IF YOU WANT TO MAKE CUSTOM VERSIONS. echo > /etc/issue echo Welcome to Linux `/bin/uname -a | /bin/cut -d\ -f3`. >> /etc/issue echo >>: /etc/issue echo "`/bin/uname -a | /bin/cut -d\ -f1,3`." > /etc/motd # This loads any kernel modules that are needed. These might be required to # use your CD-ROM drive, bus mouse, ethernet card, or other optional hardware. if [ -x /etc/rc.d/rc.modules ]; then . /etc/rc.d/rc.modules fi # Initialize PCMCIA devices: if [ -x /etc/rc.d/rc.pcmcia ] ; then . /etc/rc.d/rc.pcmcia start fi # Run serial port setup script: # (CAREFUL! This can make some systems hang if the rc.serial script isn't # set up correctly. If this happens, you may have to edit the file from a # boot disk) # # . /etc/rc.d/rc.serial
The motd looks like this:
The issue script looks like this:
Welcome to Linux 2.0.30.
Textbook: A Practical Guide to Linux
Terms and Concepts:
Define and add these to your glossary:
Once you've added definitions to these, e-mail me a copy of your updated glossary.
Continue with the tutorials:
With any suggestions or questions please feel free to contact us