As for many systems, you can use it every day but it can happen that for some reason, your Linux won't boot and you need to know how you can do in these situations. Some Linux distributions don't offer a safe mode and automatic repair tools but you can see recovery mode which provides some options that keep your files and can repair the problem. There is also another possibility by using a Linux live CD or USB which will help to use tools or commands.
In this tutorial, I will show you how to fix some common booting issues you may encounter in Linux.
1) Repair Grub2
Ubuntu and many other Linux distributions use the GRUB2 boot loader. If GRUB2 breaks for example if you have installed Windows after installing your Ubuntu or overwrite your MBR, you won’t be able to boot into your Linux system.
GRUB 2's ability to fix boot problems has greatly improved over the original GRUB bootloader. When grub2 has booting failure it comes up with a screen showing
grub rescue prompt, which allows a number of commands to run from there.
But here I will show you a simple method to repair your GRUB 2 boot issues.
You should use a LiveCD. When you will boot in the live mode, then open the terminal and type the command below:
# update-grub2 Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.10.0-19-generic Found initrd image: /boot/initrd.img-4.10.0-19-generic Found memtest86+ image: /boot/memtest86+.elf Found memtest86+ image: /boot/memtest86+.bin done
Now you can restart your system. If the operation is not resolved, boot in liveCD mode and install 'boot-repair' packages as below
# apt-add-repository ppa:yannubuntu/boot-repair && apt-get update
# apt-get install -y boot-repair && boot-repair
When the boot repair will start, you will follow to use the "recommended repair". The operation can take several minutes so be patient. After this, you can restart your system.
2) Reset a login password forgotten
It can happen that after the boot process, you can't log into your system because you have forgotten your password or maybe you have changed your keyboard language and the input doesn't match the characters you know. The only possibility is to reset your password.
To reset your password, boot in recovery mode and access to the terminal. Enter the command below:
# mount -o remount,rw /
The command above mounts the root partition in read/write mode. Now change your password
# passwd username Enter new UNIX password: Retype new UNIX password:
If you have SELinux, enter the command below to update its parameters
# touch /.autorelabel
Now you can normally reboot your system and enter the new password
3) Unable to log in: fail to start session
It can happen on the reboot that the screen of your system goes black and soon after that the login screen comes back. This problem can appear because your graphic environment encountered some problems during a package installation or an upgrade. Or it is probably because there is little space on your machine or an issue with LightDM or Xauthority.
To resolve the issue, type the
Ctl-Alt-F1 and go t0 the terminal login. Now enter the command below:
# dpkg-reconfigure lightdm
4) View logs system boot messages
Let's discuss a few places where you should look for boot problems.
The journal is implemented with the jourlnad daemon, which handles all of the messages produced by the kernel, initrd, services, etc. It can help you to see all the errors messages related to the system boot and you can try to resolve it. To see boot-related messages from the current boot, use the
# journalctl -b -- Logs begin at Mon 2017-06-26 16:27:12 WAT, end at Mon 2017-06-26 19:18:50 WAT Jun 26 16:27:12 ubuntu-pc kernel: Linux version 4.10.0-19-generic (buildd@lcy01- Jun 26 16:27:12 ubuntu-pc kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-4.10.0- Jun 26 16:27:12 ubuntu-pc kernel: KERNEL supported cpus: Jun 26 16:27:12 ubuntu-pc kernel: Intel GenuineIntel Jun 26 16:27:12 ubuntu-pc kernel: AMD AuthenticAMD Jun 26 16:27:12 ubuntu-pc kernel: Centaur CentaurHauls Jun 26 16:27:12 ubuntu-pc kernel: Disabled fast string operations
To see the journal from the previous boot, use the
-1 relative pointer with the
# journalctl -b -1
You can have some issues due to applications. Journald makes easy to take advantage of the advanced features of the journal and to do extensive analysis and relational debugging of different application components.
Dmesg - buffer logs
Most of the boot messages are stored in the ring buffer, you can use Dmesg command to print this data. This data is also sent to syslogd or klogd (if it is running). As ring buffer size is fixed it can't hold much data, dmesg shows only the recent kernel messages.
The Data from dmesg are dumped to /var/log/message, so it is also a place to check any boot errors.
Use the following command to read the content of dmesg:
$ sudo dmesg or $ sudo cat /var/log/dmesg.log
5) Boot Error on Console
Sometimes it happens on reboot the system gets panic or some error message like "init not found" is displayed, preventing from proper booting, then as a first step you can try pass init=/bin/bash (Grub boot loader) or Linux init=/bin/bash (if Lilo boot loader). This will launch you straight into a Bash shell prompt. Then you can remount "/" file system and check /var/log/messages for any error. You can use the below command to remount "/" as read/write. Kernel panic could be because of a bad cpu or motherboard or bad memory.
# mount -o remount,rw /
If the above steps does not work, then next option is to
1) Boot from the Linux First CD (boot CD).
2) Type "boot rescue" at Linux boot prompt.
3) After the bash shell prompt show up, type "chroot /mnt/sysimage".
a) Check for any disk error
# fsck -y /dev/sda2
# fsck.ext3 /dev/sda2
Check "fdisk -l /dev/hda" to check how many partitions you have
b) If you use Grub boot loader, type "/sbin/grub-install --root-directory=/boot". If you use Lilo bootloader, type "cd /etc; lilo".
LiveCDs such as Ubuntu or Knoppix do the job of rescue booting just fine, but there are smaller, faster rescue boot disks out there. In such situations, knowing how to edit individual GRUB stanzas, use the GRUB command line but you need to be able to identify the problem. By using these techniques, you can recover from various boot problems and boot into your normal installation.