Monday 25 June 2012

Boot Ubuntu Linux into Rescue mode to fix system

 Q:How do I boot my Ubuntu Linux server into Rescue mode to fix system?

A. You can boot Ubuntu Linux into rescue mode when things go wrong, there are several ways to work on fixing them. However, you must understand your system and what to fix in case of emergency.

Use this mode only if your system is unbootable. It is also recommended that you make backup of important data.

=> Start Computer / reboot computer

=> Put your Ubuntu install CD
=> Make sure BIOS is set to boot from CD

=> Now booting will start from Ubuntu install CD

=> You will see various option screen - select Recover a broken system

You will system is booting in to rescue mode; system will ask about Network and other information. This is required to setup rescue environment.

Now you will prompted to select root partition or device.
Next it will try to mount root device and it will notify the same.
Now you will see common rescue mode option such as Reinstall GRUB or open / execute a shell etc.

Now you are in rescue mode and you need to use your own knowledge to rescue the system. When things go wrong, there are several ways to work on fixing them.

Few things to remember....

The rescue-mode CD mounts your root filesystem at /target directory. Open or execute a shell and change directory to /target

# ls /target
# cd /target
# mount
 
If you need to run fsck command use fdisk -l command to find out partition name. Usually they are located at /dev/discs/discX/partY. For example repair 2nd partition (not mounted as /target) you may type command:

# ls -l /dev/discs/disc0
# fsck.ext3 /dev/discs/disc0/part1

To exit type command : # sync ;sync
# exit
# reboot
 
As I said earlier in rescue mode, there is no single command that I can recommend to fix problem. You need to use your own knowledge to rescue the system and don't forget to read command documentation before using any command.

Ubuntu Rescue Mode Step by step:

1.How to gain root user access without login?

  1. Easiest method (will not work if GRUB menu password is set)
    1. Boot-up computer
    2. If GRUB menu is hidden, press Esc to enter the GRUB menu
    3. Select Ubuntu, kernel 2.6.12-8-386 (recovery mode)
       
    4. Press Enter to boot
  2. Another method is described at How to use a Ubuntu installation CD to gain root user access?
2. How to modify kernel boot-up arguments, to gain root user access?

  1. Boot-up computer
  2. If GRUB menu is hidden, press Esc to enter the GRUB menu
  3. If GRUB password is set, press p to unlock the GRUB menu
  4. Select Ubuntu, kernel 2.6.12-8-386
     
  5. Press e to edit the commands before booting
  6. Select kernel /boot/vmlinuz-2.6.12-8-386 root=/dev/hda2 ro quiet splash
     
  7. Press e to edit the selected command in the boot sequence
  8. Add rw init=/bin/bash to the end of the arguments

    grub edit> kernel /boot/vmlinuz-2.6.12-8-386 root=/dev/hda2 ro quiet splash rw init=/bin/bash
     
  9. Press b to boot
3. How to use a Ubuntu installation CD to gain root user access?

  1. Boot-up computer into Ubuntu Installation CD
  2. At “boot:” prompt, add “rescue” to the argument
    boot: rescue
     
  3. Follow the instructions on screen
4. How to change root user/main user password if forgotten?

  1. Read How to gain root user access without login?
     
  2. To change root user password
    # passwd root
     
  3. To change main user password
    # passwd system_main_username
5. How to change GRUB menu password if forgotten?


  1. grub
    
    grub> md5crypt
    Password: ****** (ubuntu)
    Encrypted: $1$ZWnke0$1fzDBVjUcT1Mpdd4u/T961 (encrypted password)
    grub> quit
    
    sudo cp /boot/grub/menu.lst /boot/grub/menu.lst_backup
    sudo gedit /boot/grub/menu.lst

  2. Find this line
    ...
        password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
    ...
  3. Replace with the following line
    password --md5 $1$ZWnke0$1fzDBVjUcT1Mpdd4u/T961 (encrypted password above)
                                
  4. Save the edited file (sample/menu.lst_changegrubpasswordforgotten)
6. How to restore GRUB menu after Windows installation?

  1. Read How to use a Ubuntu installation CD to gain root user access?
     
  2. Assuming that /dev/hda is the location of /boot partition

  3. # grub-install /dev/hda

7. How to add Windows entry into GRUB menu?

  1. If you need to reinstall GRUB, read How do I check disk space and view the partition table?
     
  2. Launch System->Administration->Boot
     
  3. Click on Add.
  4. Choose a name such as "Windows XP" and the OS type is unknown.
  5. Assuming that /dev/hda1 is the location of Windows partition, choose that from the drop-down list
8. How to read Linux partitions (ext2, ext3) in Windows?

  1. Download Ext2fs

1 comment: