SCF Advanced Search

  • Total Posts: 35052
  • Total Topics: 10516
  • Online Today: 1622
  • Online Ever: 51419
  • (01. January 2010., 10:27:49)

Author Topic: reconfigure grub automatically re-add all boot entries  (Read 2065 times)

0 Members and 1 Guest are viewing this topic.


  • SCF VIP Member
  • *****
  • Posts: 3530
  • KARMA: 153
  • Gender: Female
I like the way the add the small script to scan for any mountable devices... Then add them all! I'm testing this on Solux linux but so far so good - up to the reboot :) And...




When you install Windows, Windows assumes it is the only operating system (OS) on the machine, or at least it does not account for Linux. So it replaces GRUB with its own boot loader. What you have to do is replace the Windows boot loader with GRUB. I've seen various instructions for replacing GRUB by mucking around with GRUB commands or some such, but to me the easiest way is to simply chroot into your install and run update-grub. chroot is great because it allows you to work on your actual install, instead of trying to redirect things here and there. It is really clean.

Here's how:

    Boot from the live CD or live USB, in "Try Ubuntu" mode.
    Determine the partition number of your main partition. GParted (which should already be installed, by default, on the live session) can help you here. I'm going to assume in this answer that it's /dev/sda2, but make sure you use the correct partition number for your system!

    Mount your partition:

Code: [Select]
sudo mount /dev/sda2 /mnt  #Replace sda2 with your partition number
    Bind mount some other necessary stuff:

Code: [Select]
for i in /sys /proc /run /dev; do sudo mount --bind "$i" "/mnt$i"; done
    If Ubuntu is installed in EFI mode (see this answer if you're unsure), use GParted to find your EFI partition. It will have a label of EFI. Mount this partition, replacing sdXY with the actual partition number for your system:

Code: [Select]
sudo mount /dev/sdXY /mnt/boot/efi
    chroot into your Ubuntu install:

Code: [Select]
sudo chroot /mnt
    At this point, you're in your install, not the live session, and running as root. Update grub:

Code: [Select]
    If you get errors or if going up to step 7 didn't fix your problem, go to step 8. (Otherwise, it is optional.)

    Depending on your situation, you might have to reinstall grub:

Code: [Select]
grub-install /dev/sda    update-grub # In order to find and add windows to grub menu.

    If everything worked without errors, then you're all set:

Code: [Select]
Code: [Select]
sudo reboot
    At this point, you should be able to boot normally.

If you cannot boot normally, and didn't do step 8 because there were no error messages, try again with step 8.

    Sometimes giving GRUB2 the correct configuration for your partitions is not enough, and you must actually install it (or reinstall it) to the Master Boot Record, which step 8 does. Experience helping users in chat has shown that step 8 is sometimes necessary even when no error messages are shown.

More information about bitcoin, altcoin & crypto in general? GO TO

Cuisvis hominis est errare, nullius nisi insipientis in errore persevare... So why not get the real SCForum employees to help YOUR troubled computer!!! SCF Remote PC Assist

Samker's Computer Forum -

Sponsored Links:


  • SCF VIP Member
  • *****
  • Posts: 3530
  • KARMA: 153
  • Gender: Female
Re: reconfigure grub automatically re-add all boot entries
« Reply #1 on: 11. May 2017., 12:24:48 »
Same as below, but for btrfs root file systems...

 Grub Install and Btrfs Root File System
Sun 17 May 2015
Tags linux grub
Posted by Logan   

Recently, the Linux operating system on my laptop no longer boots. It seems that the boot sector for GRUB bootloader is corrupted. I tried to reinstall GRUB with an Ubuntu LiveCD; however, I have encountered some problem related to Btrfs file system (which is the file system for my root mount point /.)

After several attempts, I finally reinstalled GRUB to the hard disk. I feel that it will be good idea to write the steps down, since I can't find any useful suggestion at the time of writing.

Before changing anything, it will be better to understand the situation beforehand. Check the status and find the correct device file with sudo fdisk -l command or the GParted GUI tool.

For example, on my laptop, the main hard drive is /dev/SDA, and according to the result of fdisk:

    /dev/SDA1 is the partition for the EFI firmwares, which is a FAT32 partition.
    /dev/SDA4 is the root file system for the Linux installation, which is a Btrfs partition.

Besides, I would like to reinstall GRUB to /dev/SDA.

After gathering the necessary information, we can start our work. In summary, there are three steps:

    Mount the file systems.
    Switch to the root file system with chroot command and fix the problem inside the chroot.
    Unmount the file systems.

I will elobrate them in the following paragraphs.
Mount the File Systems

First, create a directory as a mount point for root file system:

$ sudo mkdir mnt

Second, mount the root file system with:

$ sudo mount -o subvol=@ /dev/SDA4 mnt

Notice that it is required to specify the Btrfs subvolume with the -o subvol= option. We will explain this later. On the default Ubuntu installation, the subvolume for the root file system is named after @.

Third, mount the special file system for the chroot:

$ for i in dev dev/pts sys proc run; do sudo mount --bind /$i mnt/$i; done

Fourth, if you are using UEFI, you should mount the EFI boot partition as well:

$ sudo mount /dev/SDA1 mnt/boot/efi

Change Root and Reinstall GRUB

Now, we can switch to the root file system with the chroot command:

$ sudo chroot mnt

In the chroot, we can reinstall the GRUB bootloader with:

> grub-install /dev/SDA

Remarks: If you see the error messages like "cannot find a device for ...", then it is possible that some partition is not mounted properly. As a result, grub-probe can't detect the devices for the existing configuration.

For example, in my first attempt, I have seen the following error message:

    grub-install: error: cannot find a device for /boot/grub (is /dev mounted?)

This is due to the fact that the Btrfs subvolume was mentioned in the configuration file but I didn't specify the subvol= option when I was mounting the root file system in the first attempt. If you encounter similar error messages, double check the /etc/fstab and the mount options.

Now, we can verify the GRUB installation and update the configuration files with:

> grub-install --recheck /dev/SDA

> update-grub

Finally, leave the chroot with:

> exit

Unmount the File Systems

Now, we would like to unmount the file systems so that the changes can be flushed properly.

First, unmount the EFI partition (if available):

$ sudo umount mnt/boot/efi

Second, unmount the special file systems:

$ for i in run proc sys dev/pts dev; do sudo umount mnt/$i; done

Third, unmount the root file systems and delete the mount point:

$ sudo umount mnt

$ sudo rmdir mnt

That's all. You can reboot the computer now! Hoping this will fix your problem.
More information about bitcoin, altcoin & crypto in general? GO TO

Cuisvis hominis est errare, nullius nisi insipientis in errore persevare... So why not get the real SCForum employees to help YOUR troubled computer!!! SCF Remote PC Assist


With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name: Email:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
Second Anti-Bot trap, type or simply copy-paste below (only the red letters)

Enter your email address to receive daily email with ' - Samker's Computer Forum' newest content:

Terms of Use | Privacy Policy | Advertising