Monday 26 November 2018

Fixing Operating System Boot Problems


We all at one time experience booting up issues with our computers.
Your computer may fail to boot an operating system when you perform on of the following actions:
    • Delete a Partition
    • Move a Partition
    • Install another operating system and overwrite the Master Boot Record

Luckily, we can always solve boot up failure. If your computer does not use GRUB then you are advised to consult documentation for your boot loader to learn how to fix the problem. In this article I'll deal with the case of a computer that uses a GRUB boot loader.



In the case of where you have deleted a partition that maybe initially had an Operating System in it, then you’ll have to do the installation of that OS on a new partition you could create.

If you happened to have moved a partition or in installing another OS, changed the Master Boot Record, then at boot up, your computer may have brought you a GRUB command line interface.

To boot to your OS from command line interface GRUB, follow the following:
  
1. Check the present partitions:
         ls

2. Identify the partition containing the operating system you wish to boot to. Usually the partitions are labeled in the form e.g. (hd0,msdos7). Set the prefix as the partition you wish to boot to and where the grub boot loader files are:
         set prefix=(hd0,msdos7)/boot/grub

3. Now set your partition to boot from the root directory:
         set root=(hd0,msdos7)

4. Final commands as follows:
         insmod normal

5. To now initialize booting up:
         normal

You will now have a successful  boot up to your OS. Just make sure after booting up and login, you fix the problem completely.

Final fix is to ensure that the partitions UUIDs are correctly assigned.
Open a terminal window and type to locate block device attributes:
        blkid

This will show the type of content (e.g. file system or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).
In another terminal window open using you favorite text editor the file /etc/fstab. Compare and ensure that the UUID seen in terminal window of blkid is same as that in the file /etc/fstab. Do some editing in case they are different, changing the ones on the /etc/fstab file.

                                  Fixing GRUB Boot Problems

The Grand Unified Boot Loader (GRUB) is used by many GNU/Linux distros. To fix GRUB boot loader problems, first identify which major version of GRUB was used.

There are two major version of GRUB:
    • GRUB, also known as GRUB 2, covers version 1.98 and higher. Works with both GGUID partition tables (GPT) and msdos partition tables.
    • GRUB Legacy, traditionally known as GRUB, covers version 0.9x and earlier. GRUB Legacy works with msdos partition tables only.

Restoring GRUB 2 Boot Loader
To restore GRUB 2 Boot Loader: 
Boot from Live media such as Gparted Live or your GNU/Linux distro image. Open a terminal window.

Determine which partition contains the / file system for your GNU/Linux distribution. Use GParted to list the partitions on your disk device. Look for a partition that contains your GNU/Linux / file system. This Linux partition will likely use a file system such as ext2, ext3, ext4, or btrfs.

If the / partition is on LVM then the Logical Volume Manager must be active. LVM can be started with the command:
        vgchange -a y

With LVM, the equivalent of a disk partition is a Logical Volume. Logical Volumes can be listed with the command:
         lvscan

If the / partition is on RAID, then the RAID must be active. Linux Software RAID can be started with the command:
        mdadm --assemble –scan

Create a mount point directory by entering (as root):
         mkdir /mnt/mydir

You can also create a mount point on the /tmp directory, i.e.:
          mkdir /tmp/mydir

Mount the / partition on the mount point directory e.g. if the / file system is contained in the /dev/sda7 partition:
          mount /dev/sda7 /mnt/mydir

You can also use the whole /mnt directory as your mount point too so you don't have to create another mount point directory and use /mnt as the mount directory itself (since it's usually empty anyway):
           mount /dev/sda7 /mnt

If you have a separate /boot partition, for example at /dev/sda3, then an extra step is required. Mount the /boot partition at /tmp/mydir/boot by entering (as root):
            mount /dev/sda3 /mnt/mydir/boot
 
If you do not know whether you have a separate boot partition then you probably do not and can ignore this step.

Prepare to change the root environment by entering (as root):
          mount --bind /dev /mnt/mydir/dev
          mount --bind /dev/pts /mnt/mydir/dev/pts
          mount --bind /proc /mnt/mydir/proc
          mount --bind /sys /mnt/mydir/sys

Change the root environment by entering (as root):
          chroot /mnt/mydir

Reinstall GRUB 2 on the boot device. Note that the device name is used and not the partition name. For example, if the / partition is /dev/sda5 then the device is /dev/sda.
For Debian, Ubuntu, and other offshoot GNU/Linux distributions, enter the command (as root):
           grub-install /dev/sda
For CentOS, Fedora, openSUSE and other offshoot GNU/Linux distributions, enter the command (as root):
           grub2-install /dev/sda
Exit the chroot environment by entering (as root):
           exit

Remember to unmount in the correct order using the following steps: 
          umount /mnt/mydir/dev/pts
          umount /mnt/mydir/dev
          umount /mnt/mydir/proc
          umount /mnt/mydir/sys
          umount /mnt/mydir

Just to help you see and detect the OSs in your system
          os-prober

Update the grub configuration file:
          update-grub

To confirm the fix, the OSs detected by os-prober have to be also detected and added into the grub configuration file when you run update-grub.
OSs Detected and Added into the GRUB configuration file

That's our fixing complete. Everything should work correctly without any problems.
You can now reboot your computer.

No comments:

Post a Comment

Let's Talk Anonymity: A Short Treatise On Anonymity

The internet takes a very serious position in our everyday lives. We do a lot of activities over the web, some of which we would like our ...