SCF Advanced Search



Members
  • Total Members: 14197
  • Latest: Levine
Stats
  • Total Posts: 43459
  • Total Topics: 16548
  • Online today: 2997
  • Online ever: 51419
  • (01. January 2010., 10:27:49)
Users Online
Users: 4
Guests: 2973
Total: 2977









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

0 Members and 1 Guest are viewing this topic.

devnullius

  • SCF VIP Member
  • *****
  • Posts: 3614
  • KARMA: 157
  • Gender: Female
    • SCForum.info
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...

Peace!

Devnullius

SOURCE: https://askubuntu.com/questions/88384/how-can-i-repair-grub-how-to-get-ubuntu-back-after-installing-windows


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]
update-grub
    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]
exit   
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  j.gs/7385484/btc

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 http://goo.gl/n1ONa9

Samker's Computer Forum - SCforum.info


devnullius

  • SCF VIP Member
  • *****
  • Posts: 3614
  • KARMA: 157
  • Gender: Female
    • SCForum.info
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...

http://logan.tw/posts/2015/05/17/grub-install-and-btrfs-root-file-system/

 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.
Preparation

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.
Steps

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  j.gs/7385484/btc

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 http://goo.gl/n1ONa9

RuskinF

  • SCF Member
  • **
  • Posts: 64
  • KARMA: 5
  • Gender: Male
Re: reconfigure grub automatically re-add all boot entries
« Reply #2 on: 15. June 2020., 12:59:27 »
What is your actual question about the grub boot menu?
I would like to add one more thing.
Every time you update your Windows partition, the Windows boot menu is rewritten and you lose the access to your Linux Distro.
Id that the reason why you posted this post in the first place?

devnullius

  • SCF VIP Member
  • *****
  • Posts: 3614
  • KARMA: 157
  • Gender: Female
    • SCForum.info
Re: reconfigure grub automatically re-add all boot entries
« Reply #3 on: 19. June 2020., 17:45:55 »

Id that the reason why you posted this post in the first place?

Honest too god... TL;DR xD
More information about bitcoin, altcoin & crypto in general? GO TO  j.gs/7385484/btc

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 http://goo.gl/n1ONa9

Hoa Dao

  • Guest
Re: reconfigure grub automatically re-add all boot entries
« Reply #4 on: 23. February 2022., 17:08:29 »
Your article is very good and useful, thank you for sharing, bk8 hopes that next time you will have more good articles to send to all readers.

Samker's Computer Forum - SCforum.info

Re: reconfigure grub automatically re-add all boot entries
« Reply #4 on: 23. February 2022., 17:08:29 »

 

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:
Verification:
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):www.codekids.ba:

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

Kursevi programiranja za ucenike u Sarajevu

Terms of Use | Privacy Policy | Advertising
TinyPortal 2.3.1 © 2005-2023