Docs/Support/Emergencies
From Mandriva Community Wiki
Sooner or later you are going to have an emergency situation where essential tools no longer work for you. Maybe you can't start X, so there are no GUI tools. What can you do now?
[edit] Preparing for Emergencies
- There are some things you can do now to make life more bearable when the worst happens.
- Learn how to dig into your box. If anything weird happens, take the time to get some idea about it. Do not panic, think of it as a minor incident, a warning, an emergency drill. Take note of every change you made before and make from now on so you can go back. Unless you messed up with the partitioning, there is a high probability that you can pull yourself back on firm land.
- Back up your personal information as often as you can. Disks are affordable. I use a cron job to mount a backup drive once a day, mirror what I want to keep and unmount it. At that rythm, that thing should last a century. You can actually store the changes from day to day, but that is an other chapter.
- What to back up: I remember hearing of a Jewish tradition that you should give away things that you have not touched for a year. Usually, your personal files are in /home/yourID, and system config files are in /etc. More and more programs tend to store info in /var/lib, so you may want to store some part of it.
- Install and try out these packages, get used to them before you really need them -
- Documentation: apropos, man, info and howtos. Various formats, from man to html, and how to read them without X.
- Disk and file system problems: fdisk, fsck, mount. Everything one wants to know before screwing up.
- Hardware check: lspci, usbview, /proc, dmidecode, lm_sensors.
- Command line: ls, grep, find, pipes and redirection, pico/nano/vi/emacs, and perl for dummies.
[edit] Command line tools known as beginner-friendly
- Editors: nano
- File manager: mc
- Browser: links
If you've never done it, you can use the CLI to install these. Open a Konsole, type 'su' [no parens are typed - just su] to be root, then type 'urpmi nano' to install it. Then use nano to look at /var/log/messages [the ^R style commands in nano mean ctrl & R pressed at the same time].
[edit] What's where
When you have a problem, you're going to have to look around to see what happened. Information you need may be in several different places, even for one program. 'man [someprogramname]' will sometimes give you the files associated with that program, but somehow it seems they don't for the program you are looking for. :-)
[edit] The Root Directory
- /bin : Essential user command binaries (for use by all users) [bash, cp, ls, etc] These files are available at boot.
- /boot : Static files of the boot loader. The kernel and other files necessary to boot the system live here.
- /dev : Device files & directories [ide, cdrom, floppy, printers, etc]
- /etc : Host-specific system configuration files
- [cups, devfs, foomatic, kde, printer, samba, ssh, udev, webmin, etc]
- /etc/syslog.conf file: Controls what system and kernel messages will be logged, and where they will be logged.
- /etc/X11 : Configuration for the X Window System
- /etc/rc.d: Scripts that are run when the system starts.
- /etc/rc.d/init.d: The scripts that control starting and stopping of system services. See /usr/share/doc/initscripts-<version>/sysvinitfiles
- /etc/sysconfig: This directory has config files for varius system scripts. See /usr/share/doc/initscripts-<version>/sysconfig.txt
- /home : User home directories [BACK THIS ONE UP!]
- In home will be a directory for each user: /home/anne, /home/jim, /home/tom, etc.
- These user directories contain all the files and directories associated with each user. All your stuff is here, which is why you want to back it up regularly.
- In each user directory there will be 'hidden' directories and files starting with a ., such as .kde. In the CLI, 'ls' will not list these hidden files, 'ls -a' will show them. Hidden directories typically contain configuration information for that user, and some program [.Mail, .mc, .gimp, etc]. Lots of config files are named '[programname]rc'.
- /initrd : Used to create Initial RAM disk when installing a new kernel. DON'T mess with this one
- /lib : Essential shared libraries and kernel modules
- /mnt : Mount point for temporarily mounted filesystems [cdrom, floppy, camera, etc]
- /opt : Add-on application software packages [may be empty on some systems]
- /proc : Processes running on the box - The process file system is created by the kernel. Do not create your own directories here.
- /root : Home directory for the root user [drakx, tmp - DON'T mess with these]
- /sbin : System binaries & scripts needed to boot the system.
- [addpart, dump, fdisk, fsck, hotplug, lilo, mnt, udev, etc]]
- /sys : This is another virtual file system. It is part of the udev setup, and describes the system hardware.
- /tmp : Temporary files
- /usr : Read-only data and files, not supposed to be modified while the system runs, although not all software will follow this guidance.
- Programs and files in the /usr directory tree may not be available when the system boots. The /usr file system is sometimes a separate partition. When it is, it will get mounted after the system boots, along with the other non-root file systems.
- /usr/bin : Most user commands [BIG directory; user-installed software]
- /usr/etc : ????? [may be empty on some systems]
- /usr/games : Used by games on the box [may be big on some systems :-)]
- /usr/include : Directory for standard include files. [may be empty on some systems]
- /usr/lib : Libraries for programming and packages [BIG directory] - These are not required at boot time.
- /usr/local : This set of directories are for files that you compile yourself, from source, and want to be available to everyone. It is also the place for scripts used the same way.
- /usr/sbin : System binaries and scripts that are not required to boot the system.
- /usr/share : Data and files that do not depend on the kind of CPU being used
- Has config files, especially in /usr/share/config
- /usr/share/applications : has your .desktop files for what's on the desktop
- /usr/share/apps : Data for many installed programs
- /usr/share/man : Manual pages
- /usr/src : Source code [may be empty on some systems] The kernel source gets installed here.
- /usr/tmp : On Mandriva, this is a symlink to /var/tmp.
- /usr/X11R6 : X system files
- /var : Data and files that WILL be modified while the system runs.
- /var/cache : Application cache data
- /var/catman : ?????
- /var/db : ?????
- /var/lib : Variable state information
- /var/lib/rpm/alternatives : Some config files
- /var/local : ?????
- /var/lock : Lock files
- /var/log : Log files and directories
- [lots of log files here to tell you what happened - read as root]
- /var/log/messages is a summary of several log files. Try 'less /var/log/messages' from the CLI.
- /var/mail : User mailbox files
- /var/opt : Variable data for /opt
- /var/run : Run-time variable data
- /var/spool : Application spool data
- /var/spool/lpd : Line-printer daemon print queues
- /var/tmp : Temporary files preserved between system reboots
- /var/yp : Network Information Service (NIS) database files [may be empty]
- [under /var, there will be other directories in addition to the above, depending on what is installed on your box. Some may be empty]
Note that some programs may NOT follow the 'standard' locations given above
[edit] Troubleshooting techniques
Here are some ideas for helping you decide just what is wrong and what to do about it.
- The lilo/grub menu is gone after installing Windows. One solution, re-install the boot loader
- The thing won't boot. Where does it fail? Is it time for the rescue CD? A live CD? 1.BIOS 2.Boot loader 3.initrd 4.initscripts
- The beast got rebellious, but we can get in through the ssh (back) door.
- To be honest, if X died, I do not remember getting anything back that way, but at least, issuing a remote init 6 (reboot, check /etc/inittab) command feels better than hitting the reset button. (ssh root@badbox init 6)
One example of troubleshooting a problem using only the CLI
[edit] What do these error messages mean?
You are probably in trouble ;)
Note for discussion: Are there any error messages that are so frequently seen that they should be explained here? If not, we'll delete this paragraph. Or, if there are any good places describing error mesages [which can be too extensive to list here] we could give the links
[edit] Are there any web sites that help?
Thinking that X is broken too, use tools like lynx, links, wget and curl to fetch info from the web.
Links makes it easy to get back to the TWiki. It is a text-based web browser, with a menu that appears when you hit Esc. Make sure you know the TWiki URL - http://mandriva.vmlinuz.ca/.
Midnight Commander (mc) is a great cli file manager. It will let you do almost anythign to a file or directory that you can do with your GUI file manager.
[edit] Help that may already be on your system
util-linux: The /usr/share/doc/util-linux-<version> directory contains some handy README files for using different utilities.
- README.cfdisk - curses based fdisk program Think of it as a menu based fdisk for partitioning you hard drive.
- README.fdisk - the Linux partition table editor The standard partition table tool.
- README.rescuept - recover a lost partition table Searches for partitions to help you rebuild a partition table.
[edit] Recovering the partition table
The first thing to keep in mind is that if you have just deleted the partition table on the drive with Linux on it is DO NOT reboot the system without fixing the problem first! The system will keep working without the partition table, using stored information, but it will not be able to boot from the drive. So you will want to try and fix it while you still have access to the tools to do it with. If you reboot, or shutdown the machine, you will need a bootable CD with the tools to recover the partition table. The rescue mode of the install CD will not do this for you. (I need to double check this - nothing in the menu or the console commands will...)
[edit] Diskdrake - works in both the GUI and CLI modes
In the CLI mode, you can move between icons with the Tab key. To select a menu item, use the arrow keys highlight it, then hit Tab until the Ok button is highlighted, and hit Enter.
To try and recover a lost partition table, try the following steps:
- Select the empty space entry.
- Select More.
- Highlight *Rescue partition table* and hit Enter.
- Cross your fingers and hope for the best.
I didn't have much luck with the Rescue partition table option in my tests, but you may have better luck. The other two options in the *More* menu work better. You can Save partition table to a file, and Restore partition table from a file. You might want to save the partition table to a floppy as a backup, in case something destroys it, or before trying to change things, so you can go back to your starting point.
One thing I do not like about diskdrake is that it is not consistant about how you navigate through the menus. For selecting things like the disk partition to work on, you highlight the entry, and then Tab to Ok, but in the More menu, you highlight the menu entry, and hit Enter. If you Tab to Ok first, you exit the menu.
[edit] testdisk - works in the CLI
Testdisk is a menu driven program, using the curses interface. The up arrow and down arror keys are used to select from the list of drives, and the left arrowf and right arrow keys to select the commands/menus. You hit Enter to run the selected option on the selected drive.
Nice features:
- It explains the highlighted menu item below the menu.
- It asks you to confirm before running destructive options.
It worked well in my tests, recovering the partition table on the drive where diskdrake failed.
[edit] Using the rescue mode of the Install CD
To use the rescue mode of the install CD, follow these steps:
- Boot from the Mandriva install CD
- At the prompt, hit F1 for more options.
- Enter rescue at the prompt.
This will bring up a menu. (It may take a moment to load.) Your menu options are:
- Re-install Boot loader - This will usually install the Mandriva boot loader for you automatically. This is the option you will usually need if you had to re-install Windows, and you no longer get the Mandriva boot menu.
- Restore Windows Boot loader - Use this if you are going to remove Linux from the drive.
- Mount your partitions under /mnt - This will set things up so you can edit config files on your Linux system. This can also be done manually from the console. The advantage here is that it will also mount everything in fstab for you. For example, if you have a separate /home partition, it will get mounted on /mnt/home. So everything will be set up for using chroot to get your normal root environment. This option may fail, or may not mount all partitions if file has problems. If you see error messages when using this option, that is probably the case.
- Go to console - This will drop you to the Command Line Interface (CLI). You can use text and curses based tools to fix your system. It is usually a good idea to run Mount your partitions under /mnt before using this option. If you do so without errrors, you can run chroot /mnt and have your normal root file system. You will no longer be limited to the tools from rescue mode, but will be able to use all the normal command line tools. But if your /etc/fstab file is messed up, you may be more limited, depending on how your system is partitioned.
- Reboot - Do a proper shutdown and restart the system.
- Doc: - This is a brief explanation of when to use the rescue mode.
If Re-install Boot loader does not work, and/or Mount you partitions under /mnt produces errors, then it is time to check /etc/fstab to make sure it matches your system. Until I get a chance to write it, (or someone else does it...), please consult your local Linux geek, or ask on the mailing list.
This is based on the 9.2 and 10.1 install CDs.
[edit] Restoring the Boot Loader
Restoring the MBR (Master Boot Record) is a simple affair, regardless of whether lilo or grub is in use.
With lilo simply execute:
# lilo -v
With grub execute:
# grub --device-map=/boot/grub/device.map grub> root (hd0,0) grub> setup (hd0) grub> quit
Chances are, unless the MBR has been overwritten by another program, you will not need to reinstall grub in this fashion. Grub is a little more fault-tolerant than LILO is.