You are not logged in.

#1 2017-05-30 18:28:06

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,000

An easy way to recover when your bootloader gets borked.(systemd)

Ok this is just a really quick and easy way to reinstall grub2 in cases where the OS isn't bootable by normal means. It's saved me much time and butt-pains, so time to share.

Ok there's this super cool live iso utility, that allows you to boot from disk. When it's fired up, apparently scans the harddrive on the system you're running it on and will let someone select and boot them. It's called Supergrubdisk2 and comes highly recommended.

Works on bios and uefi systems and supports Window$ OS's too. Have been times when I screwed up grub and thus couldn't boot normally and used this to get the OS to fire up and do repairs. As follows ...

Easy way to reinstall grub2 to the ESP partition on a gpt/uefi 64bit OS. After using supergrubdisk2 to boot the OS, pop open a terminal and reinstall grub2 like so.

sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi

Believe on a 32bit gpt-uefi system, would only have to change the above command to be --target=x86-efi to install the proper type/version of grub for that kind of OS. Same goes for other config's such as bios pc's etc. Should only require minor changes to the command to install the right type of grub2 to get you back up and running. Also goes w/o saying this doesn't work for each and every type of grub2 borkage. Though if grub2 in the ESP has been corrupted and many other situations or in similar cases grub2 on mbr(with the proper changes to the command used), this will fix ya up fine and fast.

That's a wrap and ...


Vll! smile

Last edited by BLizgreat! (2017-05-30 19:02:31)

Offline

#2 2017-05-30 18:33:12

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: An easy way to recover when your bootloader gets borked.(systemd)

Thanks BLiz!

The Debian Wiki has a few more tips on the subject:

https://wiki.debian.org/GrubEFIReinstall


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#3 2017-05-30 18:38:10

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,000

Re: An easy way to recover when your bootloader gets borked.(systemd)

^ Thanks to you too for the add Hoas. I ended up imploding that 32bit OS install I've been ranting about. Turned around and had to reinstall/recreate it, after a couple hours of butt-pain of course. Though turns out I'd been right, this time around like a moron I did allow it to install it's 32bit grub2 bootloader to the systems ESP and ? It failed and couldn't boot the 64 OS.

Reboot, welcome to that dam grub> rescue screen many of us know and love. tongue So at that point remembered the goodness of supergrubdisk2 boot from disk feature. Download, copy iso to usb, fire up ... boot from disk and reinstall grub2 64bit. Was back in business in no time flat, thank goodness.

You guys here at BL team if possible might want to include this feature in the iso. Have seen some distro's which do have it and can really, really, REALLY come in handy in my opinion fellow nixers. smile All kidding aside has saved me mucho time and pain over the years.

Last edited by BLizgreat! (2017-05-30 18:43:49)

Offline

#4 2017-05-30 18:54:51

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: An easy way to recover when your bootloader gets borked.(systemd)

BLizgreat! wrote:

You guys here at BL team if possible might want to include this feature in the iso.

I would just use a chroot from the live ISO image glasses

Presuming that the system is on /dev/sda2 and the EFI system partition (ESP) is /dev/sda1:

# mount /dev/sda2 /mnt
# mount /dev/sda1 /mnt/boot/efi # mount other partitions as required
# for i in /proc /sys /dev /dev/pts; do mount --bind $i /mnt$i; done
# chroot /mnt /bin/bash
# grub-install /dev/sda
# grub-update
# exit
# reboot

That method also works for non-UEFI systems (no need to mount the ESP for those, ofc).

EDIT: the "#" symbol is used here to indicate that root permissions are required, use this command to attain a root shell:

sudo -i

Last edited by Head_on_a_Stick (2017-05-30 18:58:19)


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#5 2017-05-30 19:04:52

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,000

Re: An easy way to recover when your bootloader gets borked.(systemd)

Hey nice write-up Hoas, another thanks + add. Started to do it that way too but for whatever reason this method popped into mind and went with it instead. To me ... just easier than the chroot, mount this, that, this, that ... then umount all of it etc process.

Though good add and will no doubt come in handy for plenty of other nixers. If/when grub borkage befalls. VlH! = Viva la Hoas! smile

Thing about suggesting adding this feature to iso. Just figured it shouldn't be overly hard to figure out how and supergrubdisk2 is tiny size-wise. Could make the iso a tad more useful I guess. Obviously people want to keep a live media on-hand regardless. Think including useful things in it for repairs/recovery ... poss malware scans etc isn't a bad idea for distro maintainers everywhere to consider.

Nope more babble about the above. If someone is going to devote a usb drive to the iso, then does make sense to get as much out of the space on it as possible. Being an uber-anal efficiency dork, have long remained a fan of multiboot software. Stuff like Sardu and similar have always just made sense, shrugs.

Like burning a dang multi-gb dvd and end up leaving tons of the disc-space unused to me is simply stupid. Though also long since came to be a fan of cd-dvdrw (rewriteable) disc drives too. Just an afterthought babble brainfart fellas. smile

Sighs DAMMIT! Also goes without saying someone can install additional software in live session and use it to fix or do stuff ... whatever. Still liking the idea of above and feel it's a valid suggestion and perhaps something whoever may want to consider for the future of BL ?

Last edited by BLizgreat! (2017-05-30 19:35:50)

Offline

#6 2017-05-30 19:36:24

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 8,759
Website

Re: An easy way to recover when your bootloader gets borked.(systemd)

BLizgreat! wrote:

Still liking the idea of above and feel it's a valid suggestion and perhaps something whoever may want to consider for the future of BL ?

Feel free to open a thread in Development & Suggestions, your idea may get lost in the noise here.


“Et ignotas animum dimittit in artes.” — Ovid, Metamorphoses, VIII., 18.

Forum Rules   •   How to report a problem   •   Software that rocks

Offline

#7 2017-05-30 19:42:02

damo
....moderator....
Registered: 2015-08-20
Posts: 4,925

Re: An easy way to recover when your bootloader gets borked.(systemd)

Head_on_a_Stick wrote:

....
I would just use a chroot from the live ISO image...

And as described by the Doctor: How to chroot into #! on disk when you can not boot via grub


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#8 2017-05-30 20:38:48

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,000

Re: An easy way to recover when your bootloader gets borked.(systemd)

^ Thanks Damo smile

That'll do it for folks with bios-mbr systems surely. If wasn't so dang lazy would try to flesh this how to out better to confirm and supply more instructions for more config's. Though you guys have pretty much gotten that covered with your adds. Looks like grub2 gpt-uefi and bios-mbr are now fully covered here. As such ... feel totally ok with continuing to be a lazy person.

Vll! wink

Last edited by BLizgreat! (2017-05-30 20:41:46)

Offline

#9 2019-02-15 08:41:08

BLizgreat!
Resident Babbler - vll!
Registered: 2015-10-03
Posts: 1,000

Re: An easy way to recover when your bootloader gets borked.(systemd)

Ultra simple way to reinstall grub if someone is still in the dinosaur tech situation. Aka: mbr which am a proud member of that group at the moment. If you can boot the os, or were to do so with the above mentioned utility (or gnu/Linux iso with the capability.) No muss/fuss, open a terminal and

sudo grub-install /dev/sda

Reinstalls grub to the mbr of the sda drive. Which would of course be assuming the drive with the mbr they're wanting to install grub on is sda. Giving that operating system control of the boot process. If not adapt this to fit your needs.

Ps, also no doubt that very thing was covered by Xaos52 (hope he's doing well.) The Crunchbang forum has deteriorated to the point may as well show the relevant cmd here.

Last edited by BLizgreat! (2019-02-15 08:56:54)

Offline

Board footer

Powered by FluxBB