1

Hello dear programmers and users. This is going to be a long and descriptive question with a series of smaller questions leading up to the main question so please read with some patience. I have a dualbooted laptop with Windows 10 and Ubuntu 20.04 installed on it. I have been following these answers (the second answer is basically an improved version of the first answer) - Failed to get canonical path of /cow, Failed to get canonical path of /cow to try to chroot into the partition on which Ubuntu is installed so that I can modify /etc/default/grub and then run update-grub after it.

My overarching problem is that after installing Ubuntu the Grub menu which should show Ubuntu and Windows is not appearing and the laptop is booting directly into Windows 10. I have tried doing running the command -

bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi

from the Windows 10 command prompt as administrator but it is not clear whether it worked or not. This is because the other, more pressing problem, is that the configuration options in /etc/default/grub are set so as to not show the Grub Menu on startup. I have changed the configuration options -

GRUB_TIMEOUT_STYLE=menu #changed from hidden
GRUB_TERMINAL=console #uncommented this line

So far so good. I have recorded these steps in this answer to help future souls. Now coming to my problem, I am trying to chroot into the partition where Ubuntu is installed from a Live Ubuntu USB because I cannot access the installed Ubuntu system because of the Grub menu not showing up. I aim to run update-grub on the changed /etc/default/grub file so that the new configuration options reflect in the system and the GRUB menu starts showing up.

Now, I am very new to Linux terminal commands so I need a good list of commands from an experienced person. I can provide you all the information you need about my system.

The partition on which Ubuntu is installed is /dev/sdb6. The partition on which /boot/ exists is /dev/sdb1.

The list of commands I have run so far, and that were working save for one error are -

sudo mkdir /mnt/chrootdir
sudo mkdir /mnt/chrootdir/boot
sudo mount /dev/sdb6 /mnt/chrootdir/
sudo mount /dev/sdb1 /mnt/chrootdir/boot/

The last command, mounting the /dev/sdb1 /boot/ partition, produces an error -

Mount is denied because the NTFS volume is already exclusively opened. The volume may be already mounted, or another software may use it which could be identified for example by the help of the 'fuser' command.

So, is /dev/sdb1 not the boot partition of Ubuntu and is instead the boot partition of Windows 10? It is talking about NTFS so I am guessing in that direction. Here is the output of 'sudo fdisk -l' -

Disk /dev/sda: 223.58 GiB, 240057409536 bytes, 468862128 sectors
Disk model: KINGSTON SA400S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0385685f

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 466750024 466747977 222.6G 7 HPFS/NTFS/exFAT /dev/sda2 466751488 467804159 1052672 514M 27 Hidden NTFS WinRE /dev/sda3 467806208 468856831 1050624 513M 27 Hidden NTFS WinRE

Disk /dev/sdb: 298.9 GiB, 320072933376 bytes, 625142448 sectors Disk model: TOSHIBA MK3265GS Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x405647f3

Device Boot Start End Sectors Size Id Type /dev/sdb1 * 2048 206847 204800 100M 7 HPFS/NTFS/exFAT /dev/sdb2 206848 204802047 204595200 97.6G 7 HPFS/NTFS/exFAT /dev/sdb3 204802048 231920606 27118559 13G 7 HPFS/NTFS/exFAT /dev/sdb4 231921662 625141759 393220098 187.5G 5 Extended /dev/sdb5 231921664 232972287 1050624 513M b W95 FAT32 /dev/sdb6 232974336 625141759 392167424 187G 83 Linux

Disk /dev/sdc: 14.33 GiB, 15376318464 bytes, 30031872 sectors Disk model: Cruzer Blade
Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x2cf4ba3a

Device Boot Start End Sectors Size Id Type /dev/sdc1 * 0 5999871 5999872 2.9G 0 Empty /dev/sdc2 5271500 5279499 8000 3.9M ef EFI (FAT-12/16/32) /dev/sdc3 6000640 30031871 24031232 11.5G 83 Linux

I have verified by mounting on a file manager and checking the various file system folders such as /etc/, /dev/, /run/ et cetera, that /dev/sdb6 is the 200 GB Ubuntu partition. I am completely sure of this. So I suppose that the /dev/sdb1 present on the same hard drive and being 100MB in size, with the * mark on it under the Boot column... is the /boot/ partition for the installed Ubuntu system. Am I right? Please ask for any other information you need to determine this.

I was also trying to chroot into the system without mounting the /boot/ partition because the first answer didn't mount it. While running the commands -

sudo mkdir /mnt/chrootdir
sudo mount /dev/sdb6 /mnt/chrootdir/
sudo for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do mkdir /mnt/chrootdir/$dir && mount --bind /$dir /mnt/chrootdir/$dir; done

The last command gives me the error -

bash: syntax error near unexpected token `do'.

So does the above command have an error? It seems unlikely because the answer where I took it from has 45 upvotes and noone has commented with this error. It might be because of CRLF on Windows and LF on Linux. This refers to the line endings. I read this in an answer, not really sure about the details. If someone could make this mount command work without syntax errors, it would be a great help.

I am getting stuck here, otherwise I am really close to running update-grub through the live USB and to the GRUB menu being displayed at bootup. Please help. I will provide whatever information you require to give me the correct mounting commands. Again, the boot partition is /dev/sdb1 and the partition where Ubuntu is installed is /dev/sdb6.

EDIT 1 : The commands are running after doing 'sudo su' and then running them.

Now, when I run -

sudo su
mkdir /mnt/chrootdir/
mount /dev/sdb6 /mnt/chrootdir/

I get the following error message -

mkdir: cannot create directory ‘/mnt/chrootdir/proc’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/dev’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/sys’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/etc’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/bin’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/sbin’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/var’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/usr’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/lib’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/lib64’: File exists
mkdir: cannot create directory ‘/mnt/chrootdir/tmp’: File exists

So should I do mount --bind of each directory in /dev/sdb6 to these already existing directories?

One user asked the goal. The goal, in one line, is to run update-grub2 for the installed Ubuntu system from within the live usb so that the changed /etc/default/grub configuration options reflect in the installed Ubuntu system and the GRUB menu starts appearing at startup. I doubt that I need boot-repair for that because the answer which accomplished this task has 45 upvotes and it doesn't mention boot-repair. It simply chrooted into the installed Ubuntu partition and ran update-grub2.

EDIT 2 : Here is my bootinfo summary generated by boot-repair - https://paste.ubuntu.com/p/3csmQVFqTT/

EDIT 3 : Chrooting into /dev/sdb6 worked after using -

for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do mount --bind /$dir /mnt/chrootdir/$dir; done

Then I chrooted into /mnt/chrootdir/ and ran update-grub but oddly it showed only Windows 10 on sda as well as /dev/sdb after it finished running. It should show Ubuntu on /dev/sdb. Maybe the description in Grub is 'Windows 10' by mistake for the installed Ubuntu?

After rebooting, the Grub menu did not appear but I have discovered a shortcut for Legacy BIOS/MBR and that is pressing and holding the shift key during startup (before the BIOS menu is going to appear and throughout it). That makes the GRUB menu appear and I am going to use this workaround. I still don't understand why the GRUB menu is not appearing automatically. I have tried editing /etc/default/grub as well using the bcdedit command in the Windows command prompt. It is quite mysterious.

  • 1
    sudo for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do mkdir ... ; done is a chain of commands, separated by semicolons. The first command is used with sudo, the following commands are not, that's not going to work. Better to use sudo su to become root and run this commands without the use of sudo. – mook765 Aug 09 '22 at 12:36
  • 2
    This may be that your bios is picking windows instead of grub – lnee Aug 09 '22 at 13:51
  • Can you run efibootmgr -v (while booted in to ubuntu be it a the install or live cd or usb) and edit it in. – lnee Aug 09 '22 at 13:57
  • are you runing wsl if you are don't.Instead use a live cd or usb – lnee Aug 09 '22 at 14:02
  • You have old BIOS/MBR installs. It does not look like you have a separate /boot partition and do not need that for most installs. Is Windows fast start up off? Since two drives and BIOS, you will want Windows boot loader in MBR of one drive and grub in MBR of other drive to avoid boot issues with BIOS. Please copy & paste the pastebin link to the Bootinfo summary report ( do not post report), do not run the auto fix till reviewed.Lets see details, use ppa version with your USB installer (2nd option) or any working install, not Boot-Repair ISO https://help.ubuntu.com/community/Boot-Repair – oldfred Aug 09 '22 at 14:25
  • @lnee I doubt that is the case. I think it is simply a matter of the GRUB menu not showing up at startup because of incorrect /etc/default/grub configuration options. Even if it were the case, I have already ran bcdedit from the Windows administrator command prompt and Ubuntu is still not loading. I think the boot order is set to Windows first and then Ubuntu so I need to see the GRUB menu so that I can select Ubuntu at startup. – Aditya Raj Bhatt Aug 09 '22 at 16:08
  • @lnee I don't know what WSL is. I am using Ubuntu 20.04 Live USB. – Aditya Raj Bhatt Aug 09 '22 at 16:10
  • @lnee I installed efibootmgr and ran the command 'efibootmgr -v' but the application didn't run. Terminal gave the message - 'EFI variables are not supported on this system.' I have a legacy BIOS system, not UEFI. – Aditya Raj Bhatt Aug 09 '22 at 16:13
  • @mook765 Thanks for the suggestion to use 'Sudo su.' Now the commands are giving different error messages. – Aditya Raj Bhatt Aug 09 '22 at 16:16
  • @Rinzwind See question edit. – Aditya Raj Bhatt Aug 09 '22 at 16:17
  • @oldfred Yes, I have old BIOS/MBR. I hope I do not have a separate /boot partition because I didn't create one during Ubuntu installation. Thanks for the tip, I have turned WIndows fast startup off. I am installing boot-repair right now but to my (inexperienced) eyes, it doesn't seem like I should need it. There is nothing to repair. I just need to chroot into the partition which has Ubuntu installed. Please see my question edit. Do you agree? – Aditya Raj Bhatt Aug 09 '22 at 16:20
  • @oldfred - I have pasted the bootinfo summary in the question edit. Pasting it here too - https://paste.ubuntu.com/p/3csmQVFqTT/ . Please guide on how to chroot into the installed Ubuntu system. I am sure running update-grub2 successfully will do the job as I have already changed all the relevant /etc/default/grub configuration options. – Aditya Raj Bhatt Aug 09 '22 at 16:31
  • @AdityaRajBhatt That looks indeed like a mistake in the answer you tried. You don't need to create this directories since they exist already, just the bind mounts are needed. – mook765 Aug 09 '22 at 16:34
  • @mook765 Could you give me the exact commands? I am very new. Will they be -

    sudo su mkdir /mnt/chrootdir/ mount /dev/sdb6 /mnt/chrootdir/ for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do mount --bind /$dir /mnt/chrootdir/$dir; done

    I think the last line needs some modification because it will bind the Live USB's directories to the directories in chrootdir. Please tell me the exact command.

    – Aditya Raj Bhatt Aug 09 '22 at 16:40
  • Boot-Repair walks you thru a minimal chroot to totally reinstall grub. But install looks ok, cannot you not choose sdb drive in BIOS boot menu? Old BIOS chroot: http://ubuntuforums.org/showthread.php?t=1581099 & https://ubuntuforums.org/showthread.php?t=1285089&p=8068512#post8068512 where your install is sdb6. – oldfred Aug 09 '22 at 16:49
  • My BIOS boot menu is legacy. I only see the options to set the boot order as the external hard drive or an external device. I don't see the option to choose between different hard drives. I think the solution is in running the mkdir and mount --bind commands. If someone could give me the way to chroot into the existing system, my problem would be solved. I am just one or two commands away from running update-grub2 on the installed system through chroot. – Aditya Raj Bhatt Aug 09 '22 at 17:14

0 Answers0