Linux Section 5 - Troubleshooting and Maintenance                   

   Contact
   Search
   C
   C++
   Visual Basic
   Java
   JavaScript
   DHTML
   Style Sheets
   About
   Active X
   TDC Binding
   PHP
   Perl and CGI
   Flash
   XML
   SQL
   Messages
   Chat
   MCSE
   Linux
   Cabling   
   ActionScript
   Downloads
   E-Cards   
 
    
    

Repairing Common Problems in Linux

I. Losing the Boot Loader                           Video: http://www.youtube.com/watch?v=PA6-VujA0kM

A common problem people have with Linux installations when they combine them with Windows into multi-partition, multi-boot configurations is that when they go to upgrade or install a new version of Windows, they lose the ability to boot into their Linux installation. This is because on installation of the Windows boot loader, both Vista/2008 and XP/2003 will terminate other boot loaders with extreme prejudice. Linux can be a bit more polite, it will peek and if it sees other operating systems it will add them to the boot loader menu in GRUB, allowing you to choose any previous operating system that you had before. Linux will also “disappear” when someone runs “fixboot” or “fixmbr” from recovery console to clean a boot sector virus or corrupt MBR. When this happens, the Linux system partition is still there but hidden, it simply requires that GRUB be re-installed as a boot loader. There are several ways to do this depending on the flavor of Linux you are using:

A. In Ubuntu, Grub may be reinstalled by: 

1. Booting up with the “Live!” Ubuntu CD or DVD. 
2. After booting is complete, open a terminal or console from “Accessories”. 
3. The root Linux system partition will appear to be in place. You will find
    “/boot/grub”.his is not from the hard drive, however, it is from the “Live!”
     CD or DVD file system.
4. To access the file system on the hard drive, use the command “sudo fdisk –l” to
     see a listing of all partitions and physical drives on the system and their device
     labels.
5. Find the partition that your Linux system is on. It will be ext2 or ext3 .If it says
    “Type 82”, you don’t want that, that’s your swap partition. You want “Type 83”,
    your Linux system partition.
6. Once you have located it, use the command “mount” to see if the “Live!” CD/DVD
    has already mounted it. It should have.
5. If it is not mounted, use the command “sudo mount –t ext2 /dev/hd0 /media”.
4. To access configuration files and the entire file system, “cd” to the directory
    where the partition is mounted. You will be able to see, edit and manipulate the
    file system just as if it were mounted to the root “\” mount point. Type “pwd”
    to see where you are.  
5. You can then check the “grub.conf” file to check your configuration by accessing the
    “/boot/grub” folder of the root directory mounted to “/media/dev???”, where the ???
    is whatever name the subdirectory has been given that the partition mounts to. In other
    words, where you would go to “/boot/grub” if you had booted off your hard drive, you
    must go to the relative path of “/media/dev???/boot/grub/grub.conf” because you booted
    off of the “Live!” CD.
6. Use the “cat” command or “vim” to view your “grub.conf” file and see which physical hard
    drive and partition it is installed on. Example: (hd0,1) = 1st physical drive, 2nd partition.
7. Enter the following sequence of commands to change to the grub prompt and reinstall
    it to the MBR (substituting where your Linux system partition is in place of “(hd0,0)“ ):

                                                      
#> grub
                                                       #> root (hd0,0)
                                                       #> setup (hd0)

8. The GRUB boot loader is reinstalled. You may now boot both Linux and Windows.


B. In Fedora, Grub can be reinstalled by:

1. Booting up with CD # 1 and pressing “F5” to interrupt the normal boot process. 
2. Type “linux rescue” at the prompt when it appears. 
3. After booting is complete, logon. The root Linux system partition will be mounted
    to a directory called “/mnt/sysimage/”. 
4. To access configuration files and the entire file system, “cd” to this directory and
    you will be able to see, edit and manipulate the file system just as if it were mounted
    to the root “\” mount point. Type “pwd” to see where you are.  
5. You can then check the “grub.conf” file to check your configuration by accessing the
    “/boot/grub” folder of the root directory mounted to “/mnt/sysimage”. In other words,
    where you would go to “/boot/grub” if you had booted off your hard drive, you must go
    to the relative path of “/mnt/sysimage/boot/grub/grub.conf” because you booted off
    of the CD . Again, this is because you have mounted the drive with the rescue disk,
    otherwise it would just be “/boot/grub/grub.conf “. 
6. Open a console or terminal and CD to “/mnt/sysimage/boot/grub/grub.conf”.
7. Use the “cat” command or vim to view your grub.conf file and see which physical hard
    drive and partition it is installed on. Example: (hd0,1) = 1st physical drive, 2nd partition.
8. Enter the following sequence of commands to change to the grub prompt and reinstall
    it to the MBR (substituting where your Linux system partition is in place of “(hd0,0)“ ):

                                                      
#> grub
                                                       #> root (hd0,0)
                                                       #> setup (hd0)

9. The GRUB boot loader is reinstalled. You may now boot both Linux and Windows.


II. Recovering a System with a Lost Password    
Video:  http://www.youtube.com/watch?v=q0euqsewex8

What do you do if you forget or do not have the root password? Similar to the process above,
use a “Live!” or bootable Linux CD to mount the file system and edit the “passwd” file.

1. Boot up with an Ubuntu “Live!” or Fedora CD or DVD.
2. If using Fedora, hit the "F5" button and type "linux rescue" to boot.
3. Mount the root partition in read/write mode to /mnt/sysimage.
4. CD to "/mnt/sysimage/etc" and “sudo vim” the “/etc/passwd” file.
    Remember that you are not really in "/" when you see "/".
5. With the passwd file open, delete everything between the first two colons
     for the account you want to crack. Usually this is “root”.  Removing the hash
     value will allow login as root without a password.
6. If shadow passwords are enabled, then perform this procedure with the
    “/etc/shadow” file.

III. Rescuing a Damaged Linux File System              Video: http://www.youtube.com/watch?v=q0Vy57uGzc8

In Fedora, boot up with a red hat Fedora Core install CD/DVD and press “F5” to interrupt the normal boot process.  Then type “linux rescue” at the prompt. Alternatively, use an Ubuntu or Fedora “Live!” CD/DVD to boot and mount the file system. 

In Fedora, when using a rescue CD, the root Linux system partition will be mounted to a directory called “/mnt/sysimage/”.  When using Ubuntu and Fedora “Live!” CDs, look for where the system partition is mounted with the “mount” command. If it is not mounted, use the command “sudo fdisk –l-“ to see where the physical drive and partition are. Then use the command “sudo mount –t ext2 /dev/??? /media” to mount the partition, where “???” would be the type and number such as “sda1” or “hdb2”.   

Once the system partition is mounted, you can “cd” to the “/etc” folder and edit inittab, fstab, or dozens of other configuration files and subdirectories that control daemon start-up and may interfere with the boot process. 

For corrupt file systems or inode problems, run “fsck -f” to perform a thorough check of the file system and repair errors and inode problems. Use “fsck -y” or “fsck –f -y” if you don’t want to be prompted for each file, directory or inode that fsck attempts to repair. Alternatively, “e2fsck” may be run. This is equivalent to running “chkdsk” or “scandisk” in Windows, and many times does the trick after a reboot.

Video: Booting off the "Live!" CD = http://www.youtube.com/watch?v=r9wbrpDPlyc

Other Stuff
grub-md5-crypt = creates an encrypted boot password for grub booting.

In addition to modifying the menu and adding operating systems, you may also change the splash
image displayed on boot with grub by modifying the “splashimage=” line to point to whatever your
“*.xpm.gz” file is (like a Windows bitmap).


Recompiling and Customizing the Linux Kernel
modprobe = checks prerequisite modules have been loaded before specified module.

insmod = same as modprobe but doesn’t require the full path
rmmod = remove module
lsmod = list modules inserted into kernel

 /etc/modprobe.conf – holds modules to be inserted into kernel automatically using the modprobe command at boot time.


Steps to Recompile the Linux Kernel

1. Download the rpm source code file from:

http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/

2. cd to the directory of the rpm and create a spec file by typing “rpm -ivh” + “file name”:

rpm -ivh kernel-2.6.14*

3. Check to see if the spec file was created.  Do “ls /usr/src/redhat/SPECS” to see if a file such as “kernel-2.6.spec” is there.

4. Now type the following command to install the source into /usr/src/redhat/BUILD/kernel-2.6.14/linux-2.6.14:

            rpmbuild -bp --target=noarch  /usr/src/redhat/SPECS/kernel-2.6.spec

5. Now move the source to the default location:

           mv  /usr/src/redhat/BUILD/kernel-2.6.14/linux-2.6.14  /usr/src/linux-2.6.14

6. cd to the directory you created and moved the source to:

           cd /usr/src/linux-2.6.14

 7. Run the command “make mrproper” from within the directory to put the kernel source in a clean
    state.

8. cd to the directory “/usr/src”. Create a softlink called “linux” to the source file using:

       ln -s  /usr/src/linux-2.6.14  linux

9. “cd” to /usr/src/<kernel-version> and use the make commands:

make mrproper = remove/clean files created by previous recompiles

make oldconfig = save current settings into file in case you want to go back.

make config – text interface asking what modules to compile into kernel.

make menuconfig – like “make config”, but with an ASCII menu.

make xconfig = graphical “make config”

make gconfig = graphical “make config”

Note: The above are text-based and GUI options. You must at least run “make oldconfig” and “make config”. You can hold down the “Enter” key to accept all the defaults if you do not want to wade through thousands of options.

10. Type “make clean” to remove any unused files before compiling.

11. make bzImage = compiles the kernel.  You can just type “make” for short.  This
      will create a bzip compressed kernel in /usr/src/linux/arch/i386/boot/bzImage.

12. Copy this compressed kernel to the directory  /boot  .

13. Rename the bzImage file  “vmlinuz-<kernel-version>” using the mv command, so:

        mv  bzImage  vmlinuz-2.6.14_FC4

14. Copy the  /usr/src/linux/System.map file to the  /boot  directory as well with:

        cp 
/usr/src/linux/System.map  /boot

15. Type:

            make all
            make modules_install
            make install

16. Create a ramdisk image.  Necessary for grub/loading.        Type: 

            mkinitrd –v  /boot/initrd-2.6.14_FC4  2.6.14-prep

Note: The 1st argument is what you want to name the RAMDISK image. The 2nd argument is whatever the directory is called for the kernel you want to use located in the directory “ /lib/modules” on your system.

17. Add lines to /boot/grub/grub.conf to add the image to the boot menu, unless it was added automatically with the previous commands. Example: vi /boot/grub/grub.conf  .
 

patch = patches the Linux kernel.  Syntax = patch ThePatchFile .


System Confguration
mkbootdisk = creates a Linux boot disk.
ldd = identify shared libraries required by programs.  Example:  ldd /usr/xmms
ldconfig = updated shared libraries when changed.


Advanced Installation Options
1. Kickstart Files = Like a Windows “answer” file for automated installation.   To open this program, click RedHat -> System Tools -> KickStart .  This will let you create a ks.cfg file.

2. FIPS – First non-destructive Interactive Partition Splitter. Like “Partition Magic” for Linux.  Available for download from: http://www.igd.fhg.de/~aschaefe/fips/ .  This free tool allows you to resize partitions, so you could set up a multiboot of Linux/Windows without having to reinstall your Windows installation.

3. Using the Windows “boot.ini” file and loader  - You may use the Windows boot loader and boot.ini file to load Linux, if you prefer, instead of using grub/LILO to boot Windows, when setting up a multiboot configuration.  To do this:

1. Be sure Windows is insalled on 1st primary partition.

2. Be sure that NTLOADER is installed on the hard drive’s MBR.

3. Install GRUB, specifying that it be installed on the 1st sector of the partition
    rather than the MBR (note: this is not the default setup option.)

4. Reboot PC after finishing installation with Fedora Core 4 CD # 1.

5. Press [F5} and type “linux rescue” to enter rescue mode.

6. Format a floppy with FAT file system.  Insert it into the drive.

7. Mount it with “mount –t vfat /dev/fd0 /hold”  .

8. “cd” to the directory “/hold” .

9. Create a bootable image file of GRUB wherever you installed it. Use:

    dd if=/dev/hda1 bs=512 count=1 of=linboot.bin  .

10. Copy the “linboot.bin file” you just made to the Windows primary partition
      using the disk you just made.

11. Add a line to the “boot.ini” file to point to the linboot.bin file:

      C:\linboot.bin=”Red Hat Fedora Core 4”
 

Troubleshooting Device Files
/dev/MAKEDEV
= remakes device files if deleted or missing such as /dev/fd0 .  Don’t
                          need to know major/minor/type.

mknod = also creates device files, but must know major/minor/type.

Major number = device driver in Linux kernel

Minor number = the device itself

Type = f (floppy), hd (hard drive), etc.

Note: Device files are located in the /dev folder.

character devices = transfer data by characters, like tape drives .

block devices = transfer data in blocks, like hard drives, floppies and cdroms.


Nice Software to Install for Linux (My personal "must have it" list.)

1.   RealPlayer10Gold http://www.real.com (play videos/audios) tar.gz file.

2.   Flash Player http://www.macromedis.com (play flash media) RPM file.

3.  ntfs kernel rpm – Allows your kernel version to mount NTFS partitions.  Great for multiboot systems, you can make a NTFS data partition and share it between your Windows operating systems and Linux.  On my laptop and desktop, I have multiboots with Windows 98, 2003, XP Professional and Linux Fedora Core 4, so this comes in handy as a space saver, allowing me to use one data partition for all operating systems (except 98, which is only used once in a while anyway).

4.   xmms – The Linux media player.  Plays sound files.  Run from command line.

5.   xmms MP3 plugin – allows xmms to play MP3s.

6.   xmms VQF plugin – allows xmms to play vqfs.

7.   mplayer = allows playing avis and DivX videos.  Run from command line.

8.   ogle – DVD player, add associated libraries. Video player. RPM.

9.   JRE – Java Runtime Environment – allows Java applets and programs.  You have to make a softlink in the Mozilla plugin subdirectory to the Java run time I norder for applets to work.

10.    J2SDK – Java compiler and developer.

11.   wine – an RPM that allows running and installing Windows applications in Linux.    
  It “fools” software into thinking its running on Windows.  I was able to get halflife and
  Office 200 to work with this on a Linux machine.  It gets better every year.

12.    marlin  - wave file editor.

 
NIS (Network Information Service)
Used to coordinate many Unix/Linux computers on a network so they can share the
same configuration files.  

©2005 C. Germany