this post was submitted on 25 Feb 2024
32 points (86.4% liked)

Linux

48157 readers
707 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

The title explains it well. But I installed Mint on a 2nd partition, then deleted it since I no longer used it, and now Grub dumps me to the command line on boot :/

How do I recover?

EDIT: gonna give up. Fuck grub lmao EDIT2: Just reinstalled mint and used the grub it gives to fix everything lmfao

all 25 comments
sorted by: hot top controversial new old
[–] 12510198@lemmy.blahaj.zone 24 points 8 months ago (3 children)

As long as the kde neon partition is still there, recovery should be possible. You will need a way to boot into a linux environment like a installation media of just about any distro, where you will be able to mount your kde neon install, chroot in, and reinstall grub. Now I dont know your system or how you have it setup, but I can try and give some basic instructions.

So first things first, you are gonna want to get into a linux environment and open a terminal and start a root shell, this may be different depending on your environment, but its pretty much just:

sudo bash

or

su -l root

now if either of these ask you for a password, and its not presented somewhere, you may have to search on the internet for like installation disk default password, but hopefully sudo is just setup to run without one.

Now that you are in the root shell, you need to find the name of the block device that corresponds with your kde neon partition, the lsblk utility can be used to list all detected block devices, you are gonna want to find the one with the same size as your kde neon partition, this will likely be the one. Now if your partition has a label on it, you can use ls to look into the /dev/disk/by-label/ directory and see if you see your partitions label there, if so, you can just mount it like this:

mount /dev/disk/by-label/example-label /mnt

If the /dev/disk/by-label/ directory does not exist, it just means that none of the partitions are labeled. If you are having trouble determining what partition has your data, you can try mounting each one and looking inside, and unmounting them if it doesnt have your kde neon install like this:

mount /dev/sda1 /mnt
ls /mnt
umount /mnt

sda1 is just an example here, it may be different on your system.

Now when you have found the partition that has your kde neon install and mounted it to /mnt, you can now cd in and bind mount the special directories like this:

cd /mnt
mount -t proc /proc proc/
mount -t sysfs /sys sys/
mount --rbind /dev dev/

now if you are booting using UEFI, you will have to bind mount the efivars directory with this command:

mount --rbind /sys/firmware/efi/efivars sys/firmware/efi/efivars/

Now with everything mounted, you should be ready to chroot in and reinstall grub, you can chroot with this command:

chroot /mnt /bin/bash

Now that you are in your kde neon install, you can reinstall grub, the installation process may vary depending on if you are booting legacy BIOS or UEFI, to install grub on bios, you would run:

grub-install --target=i386-pc /dev/sda

now /dev/sda is just an example here, but you want to install it to the main disk, dont install it to a partition like sda1 or something.

But if you are on efi, there may be an extra mount involved, the EFI system partition, now if the EFI system partition gets mounted automatically in normal circumstances, you should be able to just run:

mount -a

this command will mount the partitions listed in the /etc/fstab file. If the partition was destroyed, it will have to be recreated. If it is not listed in the fstab and is not automatically mounted, you may have to seek it out manually with lsblk, it should be the smallest partition, use the mount command to mount it to /boot/efi, creating this directory if it does not already exist. If you have to create one, just make a partition with at least 16 megs of space, and format it as a FAT partition, you can use the mkfs.msdos or mkfs.fat command line utilities like this:

mkfs.msdos /dev/sda2

where /dev/sda2 is the free space that is gonna be used for the system partition, this command is destructive, and will overwrite any data on the partition, so make sure you enter the one with just free space.

Once you know what partition is your efi system partition, and you have mounted it to /boot/efi in the chroot, you can now install the UEFI version of grub, you can use this command

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

and for good measure/backup incase grub cant tell your firmware where it is located, you can install it to the removable media path where your firmware will look if it doesnt have any entries with this command:

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

And finally, once you have installed grub for either UEFI or BIOS, you can generate the config file, like this:

grub-mkconfig -o /boot/grub/grub.cfg

Now you can reboot using the reboot command like this:

reboot

it should take care of unmounting everything for you, make sure you remove whatever installation media if you are using any from your system. And hopefully it should just boot into the normal grub menu and start your kde neon install.

[–] BaalInvoker@lemmy.eco.br 3 points 8 months ago

Well, I came back to edit my previous comment explaining how to reinstall grub, but I found this piece of art of a comment explaining everything very well.

OP, you must be fine if you follow these steps above

[–] merthyr1831@lemmy.world 3 points 8 months ago* (last edited 8 months ago) (1 children)

NB: So, just a heads up, that since I've been able to boot into my KDE-neon install via grub

$ set root=(hd0,gpt2)
$ linux /boot/vmlinuz root=/dev/nvme0n1p2
$ initrd /boot/initrd.img
$ boot

I've skipped the steps regarding booting into a live image and using chroot/mount to mount the main install to the live session. If it's definitely necessary that I go that route let me know and I'll try it that way.


EDIT: My bad, grub install works fine if i run it w/ sudo

However, even after doing grub-mkconfig I'm being spat out onto the grub console when i reboot :S

[–] 12510198@lemmy.blahaj.zone 1 points 8 months ago (1 children)

This is definitely strange, but the EFI system partition will have to be mounted to install grub to it, maybe the disk got mounted as read only, could you try explicitly mounting it as rw with this command

sudo mount /dev/nvme0n1p1 /boot/efi -o rw

and then see if you can make a file as root by doing

sudo touch /boot/efi/test

if it doesnt fail on a permissions error, try installing grub again with --removable incase this error has something to do with it trying to tell the firmware what disk to look in like this

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

hopefully this will run without error and install grub, and if it does id run it again without the removable flag

[–] merthyr1831@lemmy.world 1 points 8 months ago (2 children)

It was just me not running the command with sudo, my bad!

But even then, doing install-grub and grub-mkconfig with sudo (completing w/o errors) I'm still getting spat out onto the grub console at boot. Should I try formatting the efi partition and reinstalling grub to it?

[–] 12510198@lemmy.blahaj.zone 1 points 8 months ago (1 children)

Oh its no worries, it sounds like you just need to regenerate the grub config, you can do this by running

sudo grub-mkconfig -o /boot/grub/grub.cfg

or if your distro has it, you can just run

sudo update-grub

then grub should see the config on boot and put you in the normal graphical menu

[–] merthyr1831@lemmy.world 1 points 8 months ago (1 children)

Seems to work fine, but same again, nothing :/

Is it worth me just wiping the partition and doing it from scratch?

[–] 12510198@lemmy.blahaj.zone 1 points 8 months ago (1 children)

I think anything that can be done with a fresh format can be done with the current one, when you ran grub-install after the issue with not running it as root, did you only do it with --removable? If so, the old grub is might be getting picked over the new grub installed at the removable fallback path, because it has a proper entry in the boot order. I dont know what key it is on your system, but if you can get into the boot order menu where it shows all the different boot devices, like where you can pick where you want to boot from, id look for one that just says something like "UEFI boot " or something like along those lines, it wont say like grub or your distro name, if there is such an option available, could you try booting from that option?

[–] merthyr1831@lemmy.world 1 points 8 months ago (1 children)

I ran it without the --removable flag :)

Spamming f12 for the uefi boot menu, I have 3 options (neon, ubuntu, and ubuntu) but all 3 spit me out onto the grub console

[–] 12510198@lemmy.blahaj.zone 1 points 8 months ago (1 children)

Alright, could you see what the root variable is in the grub console before manually setting it by running echo $root, and if it prints anything, could you run ls / in the grub console and see if you see like home dev etc, or the directories you would expect to see in / inside linux, and if you do see anything, could you run ls /boot/grub/ and see if you see grub.cfg. But if you are already inside linux, go ahead and install grub with --removable, it wont overwrite your current installation. I dont want you to format the efi partition, incase something goes wrong and you wont be able to boot into linux at all

[–] merthyr1831@lemmy.world 1 points 8 months ago (1 children)

So echo $root returns (hd0,gpt1). I have to set it to hd0,gpt2 to get the boot/linux dirs. I'll try --removable and get back to ya

[–] merthyr1831@lemmy.world 1 points 8 months ago

Eh, it gives me a grub-like menu but selecting any option just dumps me back into the console.

[–] BaalInvoker@lemmy.eco.br 1 points 8 months ago (2 children)

I had an issue like that in the past

Even after I run grub-mkconfig and put the efi files on the correct folder, it wasn't recognized by the UEFI

What I did was to open my BIOS and at the EFI configs, I choose manually which efi file I wanted it to open

Maybe it does the trick to you as well

[–] merthyr1831@lemmy.world 1 points 8 months ago (1 children)

Tried all the ones that my BIOS picks up but no dice :/

[–] BaalInvoker@lemmy.eco.br 1 points 8 months ago* (last edited 8 months ago) (1 children)

Can't you select the path?

Maybe your BIOS is at the wrong EFI partition

Make sure your UEFI is retrieving the correct path where you're installing your grub

Edit:

https://www.reddit.com/r/archlinux/comments/y29whd/grub_doesnt_initilize_on_acer_laptop/

Look at my issue in the past and see if it create an insight to you. Note that some of the commands may be different because I run Arch, so adapt it to your distro

[–] merthyr1831@lemmy.world 1 points 8 months ago* (last edited 8 months ago)

Afraid I got nothin' from that. It's pretty much beyond my abilities.

Im gonna try installing mint again and letting that fix my grub. if it doesnt, im gonna wipe and redo my install.

Thanks for trying :)

EDIT: Yep just stuck mint on the smallest partition the installer would let me and it "fixed" itself lol. Ah well. Until I inevitably distro hop :')

[–] merthyr1831@lemmy.world 1 points 8 months ago

Tried the 3 options I had in the UEFI boot menu but no dice on either annoyingly.

[–] KanariePieter@feddit.nl 2 points 8 months ago

Saving this comment just in case I ever end up in a similar situation. Very well explained!

[–] BaalInvoker@lemmy.eco.br 7 points 8 months ago (2 children)

It looks like your /boot partition was on Mint partition

You can create a new /boot partition and then install your bootloader there

It's not complicated

I don't remember the exact steps on the top of my mind right now, but it's something like

From a live USB (maybe it's necessary to chroot)

  1. Create a new /boot partition
  2. Install grub on it
  3. Check if your bios is starting from this new efi file. If not, make your bios boot from your new efi file by selecting it manually

I think that's it

[–] Jumuta@sh.itjust.works 1 points 8 months ago* (last edited 8 months ago)

it'd be a bit different on uefi though

the arch wiki on grub is really good

[–] KazuchijouNo@sh.itjust.works 2 points 8 months ago

You could try fixing grub from a live linux session. How to do the fixing is beyond my knowledge tho... Good luck!

[–] padook@feddit.nl 1 points 8 months ago (1 children)

Your problem may differ from mine, but whenever I've been greeted with the command line in grub the solution has actually been in bios. I'll leave you with my notes, which are a bit snarky after spending a lot of time trying to figure out hot to repair grub, when the solution was 3 clicks in bios:

"Inspiron won't boot

Goes to the grub command prompt

Don't fuck with that thing

Restart, F2 to get into bios

Change boot sequence to start the SSD first, not ubuntu

Reboot, itll do it a couple times, but should boot right into normal grub"

I hope your solution is the same

[–] merthyr1831@lemmy.world 1 points 8 months ago

Sadly not a boot order issue, every option is borked :/

[–] SinJab0n@mujico.org 0 points 8 months ago

Look out for a tutorial to install grub again.