UNIX / Linux Tutorial
2.10.1 System Startup Files | 2.10.2 Setting The Host Name | 2.11 What To Do In An
Emergency | 2.11.1 Recovery With A Maintenance Diskette | 2.11.2 Fixing The root Password
2.11.3 Trashed File Systems | 2.11.4 Recovering Lost Files | 2.11.5 Trashed Libraries
2.10.1 System Startup Files When the system boots, a number of scripts are executed automatically by the system before any user logs in. Here is a description of what happens. At bootup time, the kernel spawns the process /etc/init. Init is a program which reads its configuration file, /etc/inittab, and spawns other processes based on the contents of this file. One of the important processes started from inittab is the /etc/getty process started on each virtual console. The getty process grabs the VC for use, and starts a login process on the VC. This allows you to login on each VC. If /etc/inittab does not contain a getty process for a certain VC, you will not be able to login on that VC. Another process executed from /etc/inittab is /etc/rc, the main system initialization file. This file is a simple shell script which executes any initialization commands needed at boot time, such as mounting the file systems and initializing swap space. On some systems, init executes the file /etc/init.d/rc. Your system may execute other initialization scripts as well. For example /etc/rc.local which usually contains initialization commands specific to your own system, such as setting the host name (see the next section). rc.local may be started from /etc/rc or from /etc/inittab directly. 2.10.2 Setting The Host Name In a networked environment, the host name is used to uniquely identify a particular machine, while on a standalone machine, the host name simply gives the system personality and charm. It's like naming a pet: you can always address to your dog as "The dog," but it's much more interesting to assign the dog a name such as spot or woofie. Setting the system's host name is a simple matter of using the hostname command. If you are on a network, your host name should be the full host name of your machine, such as goober.norelco.com. If you are not on a network of any kind, you can choose an arbitrary host and domain name, such as loomer.vpizza.com, shoop.nowhere.edu , or floof.org. The host name must appear in the file /etc/hosts, which assigns an IP address to each host. Even if your machine is not on a network, you should include your own host name in /etc/hosts. If you are not on a TCP/IP network, and your host name is floof.org, simply include the following line in /etc/hosts: 127.0.0.1 floof . org localhost
This assigns your host name, floof.org, to the loopback address 127.0.0.1. The loopback interface is present whether the machine is connected to a network or not. The localhost alias is always assigned to this address. If you are on a TCP/IP network, your actual IP address and host name should appear in /etc/hosts. For example, if your host name is goober.norelco.com, and your IP address is 128.253.154.32, add the following line to /etc/hosts: 128.253.154.32 goober.norelco.com To set your host name, simply use the hostname command. For example, the command: # hostname -S goober.norelco.com sets the host name to goober.norelco.com. In most cases, the hostname command is executed from one of the system startup files, like /etc/rc or /etc/rc.local. Edit these two files and change the hostname command found there to set your own host name. Upon rebooting, the system will use the new name. 2.11 What To Do In An Emergency On some occasions, the system administrator will be faced with the problem of recovering from a complete disaster, such as forgetting the root password or trashing file systems. The best advice is, don't panic. Everyone makes stupid mistakes—that's the best way to learn about system administration: the hard way. Linux is not an unstable version of UNIX. In fact, I have had fewer problems with system hangs than with commercial versions of UNIX on many platforms. Linux also benefits from a strong complement of wizards who can help you out of a bind. (The double entendre is intended.) The first step to fixing any problem yourself is finding out what it is. Poke around, and see how things work. Much of the time, a system administrator posts a desperate plea for help before he or she looks into the problem at all. You'll find that fixing problems yourself is actually very easy. It is the path to enlightenment and guru hood. There are a few times when reinstalling the system from scratch is necessary. Many new users accidentally delete some essential system file, and immediately reach for the installation disks. This is not a good idea. Before taking such drastic measures, investigate the problem and ask others for help. In many cases, you can recover your system from a maintenance diskette. 2.11.1 Recovery With A Maintenance Diskette One indispensable tool of the system administrator is the so-called "boot/root disk," a floppy that can be booted for a complete Linux system, independent of your hard drive. Boot/root disks are actually very simple—you create a root file system on the floppy, place all of the necessary utilities on it, and install LILO and a bootable kernel on the floppy. Another technique is to use one floppy for the kernel and another for the root file system. In any case, the result is the same: you are running a Linux system completely from the floppy drive. The canonical example of a boot/root disk is the Slackware boot disks. These diskettes contain a bootable kernel and a root file system, all on floppy. They are intended to be used to install the Slackware distribution, but come in handy when doing system maintenance. The H.J Lu boot/root disk, available from /pub/Linux/GCC/rootdisk on sunsite.unc.edu, is another example of a maintenance disk. If you're ambitious, you can create your own. In most cases, however, a ready-made boot/root disk is much easier to use and probably will be more complete. Using a boot/root disk is very simple. Boot the disk on your system, and login as root (usually with no password). In order to access the files on the hard drive, you will need to mount the file systems by hand. For example, the command: # mount -t ext2 /dev/hda2 /mnt will mount an ext2fs file system on /dev/hda2 under /mnt. Remember that / is now on the boot/root disk itself; you need to mount your hard drive file systems under some directory in order to access the files. Therefore, /etc/passwd on your hard drive is now /mnt/etc/passwd if you mount your root file system on /mnt. 2.11.2 Fixing The root Password If you forget your root password, this is not a problem, surprisingly. Boot the boot/root disk, mount the root file system on /mnt, and blank out the password field for root in /mnt/etc/passwd, as in this example: root::0:0:root:/:/bin/sh Now root has no password. When you reboot from the hard drive you should be able to login as root and reset the password using passwd. Aren't you glad that you learned how to use vi? On your boot/root disk, editors like Emacs probably aren't available, but vi should be. 2.11.3 Trashed File Systems If you somehow trash a file systems, you can run e2fsck or the appropriate form of fsck for the file system type. In most cases, it is safest to correct any damaged data on the hard drive file systems from floppy. One common cause of file system damage is a damaged super block. The super block is the "header" of the file system that contains information about its status, size, free blocks, and so forth. If you damage the super block, by accidentally writing data directly to the file system's partition table for example, the system probably will not recognize the file system at all. Attempt to mount the file system will fail, and e2fsck won't be able to fix the problem. Happily, an ext2fs file system type saves copies of the superblock at "block group" boundaries on the drive, usually every 8K blocks. To tell e2fsck to use a copy of the superblock, use a command like: # e2fsck -b 8193 partition where partition is the partition on which the file system resides. The -b 8193 option tells e2fsck to use the copy of the superblock stored at block 8193 in the file system. 2.11.4 Recovering Lost Files If you accidentally delete an important file on your system, there's no way to "undelete"it. However, you can copy the relevant files from the floppy to your hard drive. If you delete /bin/login, for example, which allows you to login, simply boot the boot/root floppy, mount the root file system on /mnt, and use the command: # cp -a /bin/login /mnt/bin/login The -a option tells cp to preserve the permissions on the file(s) being copied. Of course, if the files you deleted aren't essential system files that have counterparts on the boot/root floppy, you're out of luck. If you make backups however, you can always restore them. 2.11.5 Trashed Libraries If you accidentally trash your libraries or symbolic links in /lib, more than likely the commands which depend on the libraries will no longer work. The easiest solution is to boot your boot/root floppy, mount your root file system, and fix the libraries in /mnt/lib.
1.1 Introduction 1.2.10 Referring To Home Directories 1.3.4 Copying Files
1.6 Exploring The File System 1.8 Wildcards 1.9.3 Pipes 1.10.3 Permissions Dependencies
1.12.4 Stopping And Restarting Jobs 1.13.3 Inserting Text 1.13.9 Including Other Files
1.14.3 Shell Initialization Scripts System Administration 2.3.1 The /etc/imitate file
2.4 Managing File Systems 2.6 Managing Users 2.6.5 Groups 2.7.2 gzip and compress
2.8.3 Making Backups To Tape Devices 2.9.1 Upgrading The Kernel
2.9.3 Installing A Device Driver Module
BOOK: LINUX QUICK COMMAND REFERENCE
http://personal.atl.bellsouth.net/~psadler
© copyright KnowledgeWorks, Inc. (2001)