LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 07-05-2021, 12:56 PM   #1
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Rep: Reputation: 3
Repair Grub 2 distro's on 1 hard disk


I'd like to know how to repair Grub with a Ubuntu (20.04) live USB stick.

I've got one swap partition and two ext4 partitions, both with a Linux distro on it.

I'm going to (have to) upgrade my Linux distro. For this I'll have to do some resizing with GParted first. Gparted warns me about the risk of Grub getting corrupted. I'm afraid I can't restart my computer after this. I forgot how I configured Grub (years ago). If I'm not mistaken then Grub installs something on the MBR and then looks at one of your partitions for Grub itself and its config files.

These are my particulars:
Code:
sudo fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0007240f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1      1945710592  1953523711     3906560   82  Linux swap / Solaris
/dev/sda2      1863788544  1945710591    40961024   83  Linux
/dev/sda3   *        2048  1043722239   521860096   83  Linux

Partition table entries are not in disk order
Code:
sudo blkid
/dev/sda2: UUID="bla bla" TYPE="ext4" 
/dev/sda1: UUID="bla bla" TYPE="swap" 
/dev/sda3: UUID="bla bla" TYPE="ext4"
Sda3 contains my current distro (which isn't supported anymore). Sda2 needs to be expanded using Gparted after which I intend to install Ubuntu 20.04 LTS on it. I have a sneakin' suspicion that the partition that Grub uses to start up my computer is sda3 because it has an asterisk (*) next to it.

How do I repair Grub from Live USB-stick in case of a disaster?
 
Old 07-05-2021, 02:11 PM   #2
colorpurple21859
LQ Veteran
 
Registered: Jan 2008
Location: florida panhandle
Distribution: Slackware Debian, Fedora, others
Posts: 7,396

Rep: Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594Reputation: 1594
Are you going to upgrade or do a fresh install? Post the /etc/fstab of the distro your going to keep

Last edited by colorpurple21859; 07-05-2021 at 02:13 PM.
 
Old 07-05-2021, 02:38 PM   #3
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by colorpurple21859 View Post
Are you going to upgrade or do a fresh install? Post the /etc/fstab of the distro your going to keep
I am going to do a fresh install on the partition I don't use which is sda2. I don't see the added value of my current /etc/fstab (which is on sda3 and does not contain more info than fdisk -l and blkid) in this regard.

Its contents is:
Code:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system>                            <mount point>   <type>  <options>          <dump>  <pass>
UUID=bla bla     /             ext4    defaults            0       1
UUID=bla bla   none            swap    sw                  0       0

Last edited by MeneerJansen; 07-05-2021 at 02:40 PM.
 
Old 07-05-2021, 02:52 PM   #4
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Original Poster
Rep: Reputation: 3
Let me ask it a different way. If I format the Linux partition that I don't use, will Grub still work and start my current distro?
 
Old 07-05-2021, 05:04 PM   #5
lovemeslk
Member
 
Registered: Feb 2020
Location: Rantoul IL
Distribution: Slackware
Posts: 350

Rep: Reputation: 72
Quote:
I'd like to know how to repair Grub with a Ubuntu (20.04) live USB stick.
this was your bootable device "*"
Code:
/dev/sda3   *        2048  1043722239   521860096   83  Linux
In live
Code:
sudo  grub-grub-install /dev/sda3 
sudo mkdir -p /mnt/sda3 
sudo mount /dev/sda3 /mnt/sda3
sudo grub-mkconfig  -o /mnt/sda3/boot/grub/grub.cfg
Swap file for first partition if it works for you.

Last edited by lovemeslk; 07-05-2021 at 05:12 PM.
 
Old 07-05-2021, 05:08 PM   #6
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,573

Rep: Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499
Quote:
Let me ask it a different way. If I format the Linux partition that I don't use, will Grub still work and start my current distro?
That would be the expected behavior. sda2 seems to be large enough (about 23GB) for a minimal install of Ubuntu so could do the install there and make sure you use the default install of Grub (/dev/sda) which will install some Grub code in the MBR and the rest of Grub on the Ubuntu filesystem partition (sda2). During the installation of Grub, it will (or should) update Grub and include the OS on sda3. You can then shrink sda3 and enlarge sda2. You need to do this from a usb/dvd and ensure that the partitions being modified are unmounted. The warning you get from GParted is standard any time you are moving a partition with boot files on it which would be sda3 as you have no other partition on which it would be. If you resize sda3 by moving it to the right to make contiguous unallocated space to enlarge sda2, you will not only be resizing the partition but moving all the data from the beginning of sda3 to its new location. THis includes boot files, hence the warning. The process is the same if you do it before installing Ubuntu or after. The advantage of first installing Ubuntu on sda2 is that you will have your bootloader there and moving files on sda3 won't create a problem with that. Make sure you backup personal data before doing anything.

Your fdisk output shows you have a large amount of unallocated space, why not use that?
 
1 members found this post helpful.
Old 07-06-2021, 04:48 AM   #7
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by yancek View Post
That would be the expected behavior. sda2 seems to be large enough (about 23GB) for a minimal install of Ubuntu so could do the install there and make sure you use the default install of Grub (/dev/sda) which will install some Grub code in the MBR and the rest of Grub on the Ubuntu filesystem partition (sda2). During the installation of Grub, it will (or should) update Grub and include the OS on sda3. You can then shrink sda3 and enlarge sda2. You need to do this from a usb/dvd and ensure that the partitions being modified are unmounted. The warning you get from GParted is standard any time you are moving a partition with boot files on it which would be sda3 as you have no other partition on which it would be. If you resize sda3 by moving it to the right to make contiguous unallocated space to enlarge sda2, you will not only be resizing the partition but moving all the data from the beginning of sda3 to its new location. THis includes boot files, hence the warning. The process is the same if you do it before installing Ubuntu or after. The advantage of first installing Ubuntu on sda2 is that you will have your bootloader there and moving files on sda3 won't create a problem with that. Make sure you backup personal data before doing anything.

Your fdisk output shows you have a large amount of unallocated space, why not use that?
I've already shrunken sda3 (which contains the distro I'm currently using). Gparted did not complain about that. It does, however, complain about expanding sda2.

I still don't understand how Grub works with partitions exactly. Is Grub on my MBR and is that startup screen that I see on the MBR itself? And do each of the menu entries in Grub simply point to one of the partitions that Linux is on to continue the rest of Grubs startup process from that specific partition? Is Grub on both my partitions? Can I happily format sda2 as long as I still have a working Linux distro on sda3? Without installing Linux on sda2?

Does Grub need sda2 even though I want to start the Linux distro on sda3?

Last edited by MeneerJansen; 07-06-2021 at 05:24 AM.
 
Old 07-06-2021, 05:17 AM   #8
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by lovemeslk View Post
this was your bootable device "*"
Code:
/dev/sda3   *        2048  1043722239   521860096   83  Linux
In live
Code:
sudo  grub-grub-install /dev/sda3 
sudo mkdir -p /mnt/sda3 
sudo mount /dev/sda3 /mnt/sda3
sudo grub-mkconfig  -o /mnt/sda3/boot/grub/grub.cfg
Swap file for first partition if it works for you.
I think there's a typo. One cannot install Grub to a partition only to a hard disk. I think the command: "grub-grub-install /dev/sda3"
Should be:
Code:
sudo grub-install /dev/sda
Notice the omission of one of the "grub-" and the "3". Can I also do this for sda2 (the non-bootable partition) if I want to format sda3 later when I've installed a new Linux distro on sda2?

I divided my hard disk in two partitions so I can install a new Linux distro if my current one is no longer supported. For safety the old one is then still on the other partition for a few weeks. Yes: I never buy a new PC. This requires me to wipe one of those partitions every few years but I can't remember for the life of me if that'll get me into trouble with Grub (been using Linux as my default OS for 15 years but I'm getting old).

Last edited by MeneerJansen; 07-06-2021 at 05:25 AM.
 
Old 07-06-2021, 06:22 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,153

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Stop worrying about the details - the people developing the boot code have a much better understanding of what's required than you. Your assertions re where install can occur are also incorrect.

Install the new system, enjoy the result that will allow you to choose which system to boot.
 
Old 07-06-2021, 06:38 AM   #10
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by syg00 View Post
Stop worrying about the details - the people developing the boot code have a much better understanding of what's required than you. Your assertions re where install can occur are also incorrect.

Install the new system, enjoy the result that will allow you to choose which system to boot.
I understand what you're trying to say. But this requires me to potentially mess up one of my partitions (because of the resizing by Gparted). Said action can leave me with a non-booting system, even if it's only for a few hours.

After successfully installing a new Linux distro on the 3nd partition I can never be sure about wiping my "old" linux installation on the 2nd partition. Again, because that might leave me w/ a non-bootable system and it might not, unless I understand how to manage Grub.

I hope that you can understand that I use my computer on a daily basis and that, for me, it is not very acceptable to loose control over it. Even if its only for a day or so... That's not worring 'bout details.

Somebody out there must know if we as Linux users can wipe/overwrite a partition that we don't use without getting into trouble w/ Grub.
 
1 members found this post helpful.
Old 07-06-2021, 06:54 AM   #11
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,573

Rep: Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499Reputation: 2499
Quote:
I still don't understand how Grub works with partitions exactly. Is Grub on my MBR and is that startup screen that I see on the MBR itself?
Yes to the first part of your question and no to the second. The MBR is tiny and 95%+ of the Grub files are on your Linux partition and the boot menu you see when you boot is from the grub.cfg file on your partition.

If you want to understand Grub2, their manual is available on line at the link below.

https://www.gnu.org/software/grub/manual/grub/grub.html

If you want detailed information on your system boot files, use boot repair from the link below with the 2nd option, using the ppa. When you do that select the Create BootInfo Summary option which will give you a link which you can review or post here if you don't understand it. Boot repair will tell you which partition is used to boot your systems.

https://help.ubuntu.com/community/Boot-Repair

Quote:
After successfully installing a new Linux distro on the 3nd partition I can never be sure about wiping my "old" linux installation on the 2nd partition.
If you use the defaults for the boot (Grub) installation, the last OS you installed will have code in the MBR pointing to its partition. Again, boot repair will give you all this info.
 
Old 07-06-2021, 10:13 AM   #12
MeneerJansen
LQ Newbie
 
Registered: Aug 2020
Location: Holland
Posts: 10

Original Poster
Rep: Reputation: 3
Thank you all for the help.

Took the plunge and indeed one can wipe a Linux partition that one doesn't use. On the partition that you want to keep using you should configure Grub. In case of disaster use Live USB stick.

If you can still boot from the Linux distro that you want to keep using, do:
Code:
sudo grub-install /dev/sda
If you know for sure that this has been done before (e.g. during installation) you can simply do:
Code:
sudo update-grub
In case of disaster, boot from Live USB-stick. If the partition that you want to keep using is sda3 do:
Code:
sudo mount /dev/sda3 /mnt
sudo grub-install --boot-directory=/mnt/boot /dev/sda
(notice the omission of the "3" in that last command)

You might also want to run just to be sure:
Code:
sudo update-grub

Last edited by MeneerJansen; 07-06-2021 at 10:16 AM.
 
1 members found this post helpful.
Old 07-13-2021, 07:15 AM   #13
Mantra
Member
 
Registered: Jun 2018
Posts: 57

Rep: Reputation: Disabled
Just a warning for anyone doing this on a system with old installs on - there is the additional (potential) problem/conflict between BIOS and UEFI installation options, and whether or not an efi partition is used. May or may not be a problem, depending on your setup.
 
Old 07-18-2021, 01:51 AM   #14
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,878
Blog Entries: 1

Rep: Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078Reputation: 2078
Quote:
Originally Posted by MeneerJansen View Post
...I'm going to (have to) upgrade my Linux distro. For this I'll have to do some resizing with GParted first....
Code:
   Device Boot      Start         End      Blocks   Id  System
/dev/sda3   *        2048  1043722239   521860096   83  Linux
/dev/sda2      1863788544  1945710591    40961024   83  Linux
/dev/sda1      1945710592  1953523711     3906560   82  Linux swap / Solaris
I rearranged the output in logical order. This shows a massive amount of freespace available in between the two type 0x83 partitions. Another could be created between them, or one or both expanded to utilize that freespace. No shrinking of an existing partition would be required.

By default, installing or upgrading either existing installation offline, using standard 20.04 installation media, will result in 20.04 assuming boot duty. The likelihood of needing a repair afterward is rather slight, but even if it happened, repair would be a rather simple process as long as you can boot the same media from which you installed or upgraded. By default, the install/upgrade process will also include a Grub menu selection for booting the other installation in addition to the default one for 20.04. These are the same default behaviors of most distros.
 
Old 09-21-2021, 09:10 PM   #15
bluzerdeep
LQ Newbie
 
Registered: Sep 2021
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by Mantra View Post
Just a warning for anyone doing this on a system with old installs on - there is the additional (potential) problem/conflict between BIOS and UEFI installation options, and whether or not an efi partition is used. May or may not be a problem, depending on your setup.
i have a dump question... can i install Linux beside windows and i use both probably without causing problems from one to another?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Boot Repair Tool - Repair The Most Boot Related Problems LXer Syndicated Linux News 0 06-21-2017 09:49 PM
Message: A database connection error has been detected, we are attempting to repair the server, if the repair does not resolve the issue, pl deva420patra Linux - Server 4 11-23-2016 07:40 AM
Infinite Grub Loop: GRUB GRUB GRUB GRUB GRUB GRUB GRUB GRUB GRUB GRUB... beeblequix MEPIS 2 11-02-2013 10:56 PM
LXer: Super GRUB Disk--A GRUB Repair Utility LXer Syndicated Linux News 0 09-20-2008 10:20 PM
I need a Linux OS other than Ubuntu which has a repair disk or repair software jhmac77 Linux - Newbie 1 03-17-2008 07:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 06:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration