For several years I had problems running Linux systems. Problems with my level of
confidence, that is. If something went wrong during an install, I would panic at what to do next because I would simply not know what to do next. I would usually end up reinstalling an entire distribution to try to get things right again. In this article I’m going to give some basic tips on what you need to learn in order not to panic if something goes wrong.
My first tip is to tell you that you must learn the command line, or at least learn enough
about how to use it to begin the rescue of whatever has gone wrong. I know a lot of people
don’t want to learn the command line but there are times when it will save your bacon when
you know what commands to execute to get out of a jam.
You know how to get a command line, don’t you? If you boot up and get a black screen,
try the key combination ctrl-alt-F1. F1 through F6 on most distributions will give you a
console screen to work with if X doesn’t start up.
I used to mess around a lot with trying to tweak my /etc/X11/xorg.conf file, trying to
tweak my graphics card to see if I could get more performance out of it, but usually not
really knowing if what I was doing was going to work right or not. More often than not
when rebooting after a tweak of this file I would get a black screen or something obviously
not working right. How to make it right? Well, the first thing that should be done before
even starting to edit your xorg.conf file is to make a copy of it. cp it to xorg.conf.sav or
whatever you want to call it so you will have a saved copy of a known, working configuration
file. If your tweak fails, and it will eventually if you try this, you will have a good copy of
the original to copy back into place to get X working again. I got bit by this many times
before I finally learned to have a good backup copy of the original. This is also a good
practice when editing any system file. Always make a copy of the good, working file
because Murphy’s Law is always in effect.
My next tip is to tell you that you should learn how to use a command line editor.
If you are editing a system file and reboot and find X is not working and you have only
a command line to work with and you forgot to make a good copy of the file before you
started, what now? You will have to edit the file you screwed up in order to get things
working right again. Edit it with what? X is not working. You don’t have your favorite
gedit or other graphical editor to use. What now? This is where you must have knowledge
of a command line editor. I use vim here but there are others. Pick an editor and learn
how to use it. Practice with it until you have at least a basic knowledge of how to use
it to edit a file. Don’t wait until it’s too late.
Ok, so you’ve partitioned your harddisk and installed a new Linux distribution on a
partition to try it out and compare it to the one you use most of the time. Only thing is,
when you reboot after installing you find that the new distribution has taken over the
grub bootloader and your favorite system is not even on the menu. Oops! What to do
now? I’m going to walk you thru it.
I’m going to be talking about grub, the Grand Unified Bootloader, because that is
what I use here and know, and specifically grub legacy. There is a grub2 now so if your
system uses it you will have to refer to its documentation but the tips I give here will
still probably be useful.
When grub boots up it gets its information from a file in /boot/grub called “menu.lst”.
Only thing is, every distribution will have its own menu.lst and sometimes when you
install a new distribution to try out it will install its own bootloader and use its own menu.lst,
making your other distributions disappear from the boot menu. Some distributions look
for and try to include other existing distributions on your harddisk but they don’t always
get it right so you have to be ready to make things right yourself.
There are three ways to go about setting things right again. One way is to edit the menu.lst
of the new distribution you have just installed and put in the file the info to let it find the
other distributions on bootup. Another way is to run grub’s setup but tell it to use the
menu.lst of your favorite distribution instead of the new one you have just installed. The third
method is to copy over the menu.lst from your favorite distribution into the /boot/grub folder
of the distribution you just installed. No matter which method you use you will have to edit menu.lst.
Let’s use the first method I mentioned. Let’s also assume you are booted up into the new
distribution you have just installed and that you are logged in as root user. You will have to be
root to edit menu.lst and to mount partitions.
You will have to know the partition where your favorite distribution is located in order to
get to its /boot/grub/menu.lst. On my system my favorite distro, Ubuntu, and the one I use
all the time, is located on /dev/sda1. I will use that as an example. To get at its menu.lst,
I would, typing into a terminal program as root user, issue the commands “mkdir /mnt/sda1″
and “mount /dev/sda1 /mnt/sda1″. The favorite distro would now be mounted at /mnt/sda1
and can be navigated like any other folder. If you are logged in as root user you could open
up gedit or whatever graphical editor you have and open /mnt/sda1/boot/grub/menu.lst.
Then open up a new tab in the editor and open the file /boot/grub/menu.lst. What you are
going to do is copy and paste the menu items from the first menu.lst into the second menu.lst.
Every menu item begins with a line that says “title” and includes all lines until the next “title”,
or the end of file. My first menu item, for example, is:
title Ubuntu 9.10, kernel 2.6.31-17-generic
uuid 10303124-0581-496b-8e94-815a2cb0b1d0
kernel /boot/vmlinuz-2.6.31-17-generic root=UUID=10303124-0581-496b-8e94-815a2cb0b1d0 ro quiet splash vga=0×324
initrd /boot/initrd.img-2.6.31-17-generic
and this is what I would copy over to the second menu.lst.
You also have to tell grub where this distro is located on the disk.
Since I already know this is located at /dev/sda1 I would add the
line “root (hd0,0)” to the menu item like so:
title Ubuntu 9.10, kernel 2.6.31-17-generic
root (hd0,0)
uuid 10303124-0581-496b-8e94-815a2cb0b1d0
kernel /boot/vmlinuz-2.6.31-17-generic root=UUID=10303124-0581-496b-8e94-815a2cb0b1d0 ro quiet splash vga=0×324
initrd /boot/initrd.img-2.6.31-17-generic
In grubspeak (hd0,0)=/dev/sda1, (hd0,1)=/dev/sda2, (hd1,0)=/dev/sdb1, etc.
Usually, anyway. With today’s removable USB drives these disk designations
can change but the main harddisk in the computer is usually always hd0 and
the first partition on it is 0 or sda1.
As far as I know. Somebody feel free to correct me if I am wrong.
Where you copy these menu items to in the second menu.lst makes a difference.
They will show up in the boot menu in the order you have them in the file so you
can arrange these menu items to where you like them but the system which will
be booted by default on bootup if you take no action is determined by the line
“default 0″ which will be located near the top of the file. Menu numbering starts
at zero so for instance if you wanted the first menu item to be the default boot
your line would be:
default 0
and if you wanted the second menu item to boot as default you would use:
default 1
and so on.
After you have copied over all the menu items you want from the first
menu.lst, save the second menu.lst and then you should be ready on next
reboot with a boot menu with everything you want. I know it’s hard to keep
all these hd0’s and sda1’s straight in your head but with some practice you
will finally get it figured out and be able muck about with your OS with confidence.
I hope all that made sense. If not, feel free to ask questions.
teryc