this post was submitted on 25 Feb 2024
42 points (95.7% liked)

Linux

48413 readers
1268 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
 

I'm trying to update my grub boot order back to booting the first option instead of the second, so I run sudo nano /etc/default/grub, but it brings up this, which is not the file I want to edit.

I'm on fedora 38

all 26 comments
sorted by: hot top controversial new old
[–] [email protected] 29 points 9 months ago (1 children)

This should get you back to defaults:

sudo cp /usr/share/grub/default/grub /etc/default/grub && sudo update-grub

At some point you definitely did accidentally write to /etc/default/grub when you meant to write to /boot/grub/grub.cfg.

There's no shame in that; Grub's configuration process is very confusing and counter-intuitive.

Everybody who has used Linux long enough has stories of breaking their systems in sillier ways, and this didn't even really break your system 🙂.

[–] [email protected] 3 points 9 months ago (1 children)

THanks! but I'm getting the error cp: cannot stat '/usr/share/grub/default/grub': No such file or directory when running this.

[–] [email protected] 0 points 9 months ago* (last edited 9 months ago) (2 children)

What version of Ubuntu are you using?

What is the output of the following command?:

dpkg -l | grep grub

If you urgently want your grub menu to default to the first entry that can be done first, but unless that's needed I'd prefer to get to the root of the problem(s) and get a proper fix.

[–] [email protected] 3 points 9 months ago (1 children)
[–] [email protected] 2 points 9 months ago* (last edited 9 months ago) (1 children)

Ahh, sorry.

For Fedora it looks like the default /etc/default/grub looks like this:

GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="rhgb quiet" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true

( Taken from https://discussion.fedoraproject.org/t/how-to-regenerate-etc-default-grub/72677/9 )

If you're using LVM / LUKS you may need additional kernel parameters, like resume=... for suspend to disk to work properly.

Please, before doing anything else, post the output of the following:

cat /proc/cmdline

And make a backup of your existing grub.cfg with:

sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg-backup-$(date --iso-8601=s)

Also, be sure that you have a LiveUSB on hand. You don't want to be SOL if we break something and can't boot again without fixing it first.

[–] [email protected] 1 points 9 months ago

[email protected]

Sorry again. I wrote this last comment (and this one, TBH) from my phone and "--iso=s" should have been "--iso-8601=s" . I've edited my comment and the command should now work (Making a backup of your grub.cfg containing the date, to the second, in the filename. I did that to hopefully avoid you running the same command again after trying some fixes and accidentally clobbering your backup).

[–] [email protected] 0 points 9 months ago

This command doesn't work for me

[–] [email protected] 25 points 9 months ago

This looks like grub2-mkconfig was run with the output mistakenly set to /etc/default/grub. Someone ran

grub2-mkconfig -o /etc/default/grub

Instead of

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

[–] Throwaway1234 13 points 9 months ago* (last edited 9 months ago) (2 children)

so I run sudo nano /etc/default/grub

For improved security during file edits that require root access, it's highly advised to use sudoedit (or sudo -e). This method is considered the standard practice to avoid the security pitfalls associated with directly invoking editors with sudo. To ensure the use of nano with sudoedit, simply set the VISUAL environment variable with export VISUAL=nano before running sudoedit . Alternatively, for a one-off command: VISUAL=nano sudoedit /path/to/file.

Please note that while sudoedit is a safer starting point, it's not the only method available. Alternatives such as doas, doasedit, or leveraging polkit with pkexec can offer even more controlled and secure ways to manage file editing with elevated privileges. However, it's perfectly acceptable to stick with sudoedit, as it's a commonly trusted tool.

Be aware that direct usage of sudo nano or other editors is strongly discouraged. It bypasses important security mechanisms and can lead to inadvertent system-wide risks.

EDIT: changed VISUAL=nano sudoedit to VISUAL=nano sudoedit /path/to/file.

[–] [email protected] 11 points 9 months ago (1 children)

On shared systems with untrusted users, you're right. On your own system when you already have full admin rights, sudo nano is fine and doesn't have any security implications that I'm aware of.

[–] Throwaway1234 3 points 9 months ago* (last edited 9 months ago) (1 children)

I agree with the general sentiment. Thank you for mentioning that!

Though, the use of sudo nano might still pose a risk if any software found on the system is either vulnerable/exploitable, not trusted, or simply exploitative. In that case, like what's achieved through sandboxing i.e. not allow the software to go beyond their intended scope, it makes sense to put a limit on the capabilities of the software. And to that effect, the use of sudoedit still offers merit over sudo nano.

Though, if the user doesn't (already) rely on bubblejail, firejail, Flatpak etc for what they offer in sandboxing. And/or if said user simply doesn't care for the principle of least privilege, then the use of sudo nano is perfectly valid.

[–] [email protected] 1 points 9 months ago

This isn’t a scenario I’m familiar with. How can I learn more?

[–] [email protected] 2 points 9 months ago

Never heard of sudoedit. I want to experiment with a system where I alias sudo=pkexec, VanillaOS does that

[–] [email protected] 9 points 9 months ago

Somehow your /etc/default/grub file contents have been replaced with that of /boot/grub/grub.cfg

[–] [email protected] 6 points 9 months ago* (last edited 9 months ago)

That looks like the grub file that's put in /boot to make the menu to boot the system.

Are you sure you've never run "grub2-mkconfig -o /etc/default/grub"? Because making the grub file you may have overwritten the config file.

By the look of things I would reinstall grub with my package manager to forcing to overrun config files. Keep in mind this would return the file to your distribution defaults.

[–] [email protected] 5 points 9 months ago (1 children)

It says that's /etc/default/grub in the top right. You sure you didn't create a symlink or overwrite it?

[–] [email protected] 2 points 9 months ago

This is what it's supposed to look like

[–] [email protected] 1 points 9 months ago

Something has definitely been buggered seven ways from sunday here. If you need it I'm willing to provide you my config which you could then paste in. I haven't changed anything, just enabled OS prober. Take this as a last resort though.

[–] [email protected] 1 points 9 months ago (1 children)
[–] [email protected] 1 points 9 months ago (1 children)
[–] [email protected] 2 points 9 months ago* (last edited 9 months ago) (1 children)

Well, if you look at the file... and search the internet for "fedora edit grub entry not possible" that works.

You use grub2-mkconfig to create this file, and what you want to change it in another file that is used to create this one.

The thing is, what do you want to edit?

[–] [email protected] 1 points 9 months ago (1 children)

I want to edit the grub config, to change the default boot order

[–] [email protected] 1 points 9 months ago

Did you already do an internet search? Positive you will find that answer