Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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?
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.
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?
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.
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.
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.
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.
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.
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.
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.
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.
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'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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.