Edit grub file from live USB stick

I haven't quite figured out yet how to edit files on the internal drive from the live USB drive.

For example, some users have trouble accessing the GRUB menu. How can you edit your /etc/default/grub file from the live USB drive so that the GRUB menu appears when you subsequently boot Zorin normally?

Do you need chroot therefore, as described in this guide, to be able to run sudo update-grub as well?

In the guide are listed these commands:

Boot from live USB, then mount your system:

sudo mount /dev/sda2 /mnt 

(Replace the partition /dev/sda2 with your root partition. You can find it with lsblk -f )

For UEFI systems mount the EFI partition:

sudo mount /dev/sda1 /mnt/boot/efi 

For Legacy and UEFI systems then run:

sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

Chroot into the system:

sudo chroot /mnt

Edit /etc/default/grub and regenerate:

nano /etc/default/grub

Change the lines you want. Move the cursor down with the arrow keys. To display the grub menu during boot change that lines to the following (the timeout is the time in seconds how long the grub menu is displayed, 10 is a good value):
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
Press ctrl+o to save, enter to confirm and ctrl+x to quit nano editor.

update-grub
exit

Unmount and reboot:

sudo umount -R /mnt
sudo reboot

Once the computer flickers off, pull the USB Stick from the port.

Is that the right procedure?

I've never used chroot so I'm not sure.

Sure you need chroot and this guide explained well how to edit grub, chroot is included in live usb, so if you need to help someone you just follow the entire guide

2 Likes

Thank you very much!

2 Likes

the most important part is the beginning, Identify Your Partitions

# List all block devices and their mount points

lsblk -f

# Or get more detail including UUIDs
sudo fdisk -l

# Check filesystem types
sudo blkid
2 Likes

I tested it, and it worked perfectly! :grinning_face:

But how to adapt the line
sudo mount /dev/sda1 /mnt/boot/efi
for users with a legacy BIOS? It is not shown in the guide.

Generally, BIOS just uses a direct install of Grub.

sudo mount /dev/sda2 /mnt

sudo mount --bind /dev /mnt/dev

sudo mount --bind /proc /mnt/proc

sudo mount --bind /sys /mnt/sys

sudo chroot /mnt

nano /etc/default/grub

Make the needed changes to grub file, then tap ctl+o to overwrite, enter to save as current configuration, then ctl+x to exit the editor.
Now, you must run:

update-grub

The user does need to check that they do not have /boot on a separate partition, first, though.

If they are, you would mount:

sudo mount /dev/sda2 /mnt

sudo mount /dev/sda1 /mnt/boot

Then proceed to edit grub.

2 Likes

Can you please remove the line with sudo grub-install..., because it is not needed for editing /etc/default/grub, and replace it with nano /etc/default/grub, so that the thread can be used as a guide?

And what to do if /boot is on a separate partition with a legacy BIOS?

Ugh. I misunderstood you, again. LOL
Edit made.

1 Like

Here again the complete instructions if you have a legacy BIOS, in the correct order. It is very important to unmount the virtual filesystems at the end (with the umount command) to avoid problems.

List your partitions

lsblk -f
sudo mount /dev/sda2 /mnt 

(Replace the partition /dev/sda2 with your root partition)

If you have /boot on a separate partition, also mount the /boot partition:

sudo mount /dev/sda1 /mnt/boot

(replace /dev/sda1 with your boot partition)

Then run:

sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

Chroot into the system:

sudo chroot /mnt

Edit /etc/default/grub and regenerate:

nano /etc/default/grub

Change the lines you want. Move the cursor down with the arrow keys. To display the grub menu during boot change that lines to the following (the timeout is the time in seconds how long the grub menu is displayed, 10 is a good value):
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
Press ctrl+o to save, enter to confirm and ctrl+x to quit nano editor.

update-grub
exit

Unmount and reboot:

sudo umount -R /mnt
sudo reboot

Once the computer flickers off, pull the USB Stick from the port.

1 Like

In the second link of the first post is a good guide, if you need to repair grub and not just want to edit the file /etc/default/grub.
I read that this method sometimes helps when the app "boot repair" fails.

I read that it's important to unmount the mounted volumes in reverse order. This guide doesn't do that. Will that cause any damage, or is it safe to do so?

A post was merged into an existing topic: Kernel Panic Unable to mount root fs - also can't boot into Grub

Is it your plan to simplify the result of this thread and repost it in Tutorials & Guides or to fine tune and tweak this thread and then move it wholesale to Tutorials & Guides?

As it is in its current state, if a reference either here or as a tutorial - I think we might need to go Janitorial and clean the thread up for clarity...

Probably a new thread would be better for a tutorial.

But for me the question with unmounting the virtual filesystem is not solved, and I want to be sure that the guide is correctly. I did some research and noticed you sometimes used in forum the all-in-one command like here and sometimes you unmounted the filesystems separately in reverse order.

Does it matter how you unmount?

It doesn't.

How quickly I am trying to get a post out is a bigger factor.
Separating the commands is more clear and more instructive - and when I have time, I try to do this.

However, if in a hurry, a truncated all in one command works just as well. And sometimes, the end user clearly prefers a 'one paste' over ten.

For example:

sudo apt update

sudo apt full upgrade

Or:

sudo apt update && sudo apt full-upgrade

In the first, the end user might be looking at it and say. "Ah, I see. I update my sources to get fresh data.
Then, I upgrade the selected packages."

The second one, the end user says, "Ok, I paste that one command and move on to work I gotta do, got it. Thanks."

2 Likes

Thank you very much for your help! When it doesn't harm, then I prefer the shorter command because the list of commands to be executed before is already long enough. And the longer the list of commands, the more mistakes can happen when typing them in.

But you're right: With the more detailed version, you can see more quickly that you're undoing everything that came before - here, I first had to think about what the command would do.

Personally, I found the output of the first commands for the hard drives pretty hard to read. Could users also use gparted - which is already on the live USB drive anyway - and check the names of their hard drives and partitions there? For example, I wouldn't know how to tell from the terminal output whether a user with a legacy BIOS has a separate boot partition. The flags for root and boot were not shown in terminal.

1 Like

There is no right answer.

Users are diverse and varied. One might see a wall of separated terminal commands and the only effect it has is daunting. It looks overwhelming.
Yet, another, will see clear steps to be followed in bite sized pieces, creating a calming effect, instead of anxiety.

I can only offer up that if you write a guide, do what you want, include disclaimers for tricky bits - and be prepared to do a bit of hand-holding when you present it.

Don't stress over the finer details - Trust the rugged toughness in humans.