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.
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 usesudo su
to become root and run this commands without the use of sudo. – mook765 Aug 09 '22 at 12:36efibootmgr -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:57sudo 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