9

I have a machine that used to dual-boot Ubuntu (16.04 currently) and Windows 7, with Ubuntu's GRUB as boot loader.

Now I just added Arch Linux as third OS, following the official installation instructions. I did not install GRUB from Arch because I wanted to use the one controlled by Ubuntu. The instructions contained a command mkinitcpio -p linux that probably generated some boot files which I ran as described.

Now when I try to boot Ubuntu from GRUB through its default entry, I get this unpleasant error (sorry for the screen photo):

error message

As the output of uname -a shows, it's trying to boot the Arch kernel, but /dev/sda6 is the Ubuntu root partition.

I have to navigate to Advanced options for Ubuntu and select one of the Ubuntu, with Linux 4.4.0-* entries to be able to load Ubuntu, I couldn't find an entry that would correctly load Arch though.

Running sudo update-grub from Ubuntu ("update-grub is a stub for running grub-mkconfig -o /boot/grub/grub.cfg to generate a grub2 config file.") does not change anything. The grub-customizer tool was also useless in fixing this so far.

What causes this confusion of GRUB and how do I fix it so that each Linux version boots with the correct kernel and from the correct partition?

It looks like I stupidly installed Arch with Ubuntu's /boot mounted, so it probably placed its boot files in there.

I'm fine with erasing all the Arch related stuff to get Ubuntu's boot loader straight again and do a clean install of Arch later.


Updates (thanks to @terdon for his support in the Ask Ubuntu chat):

Here is my /boot/grub/grub.cfg.

All Linux entries seem to point at my /dev/sda6 partition, which is Ubuntu's root:

$ grep ' linux /' /boot/grub/grub.cfg
    linux /vmlinuz-linux root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro
        linux /vmlinuz-linux root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro
        linux /vmlinuz-linux root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro
        linux /vmlinuz-linux root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro init=/sbin/upstart
        linux /vmlinuz-linux root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro recovery nomodeset
        linux /vmlinuz-4.4.0-21-generic root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro
        linux /vmlinuz-4.4.0-21-generic root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro init=/sbin/upstart
        linux /vmlinuz-4.4.0-21-generic root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro recovery nomodeset
        linux /vmlinuz-4.2.0-35-generic root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro
        linux /vmlinuz-4.2.0-35-generic root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro init=/sbin/upstart
        linux /vmlinuz-4.2.0-35-generic root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro recovery nomodeset

I tried to update GRUB config from Ubuntu:

$ sudo grub-mkconfig -o /boot/grub/grub.cfg 
Generating grub configuration file ...
dpkg: warning: version 'linux' has bad syntax: version number does not start with a digit
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found linux image: /boot/vmlinuz-4.4.0-21-generic
Found initrd image: /boot/initrd.img-4.4.0-21-generic
Found linux image: /boot/vmlinuz-4.2.0-35-generic
Found initrd image: /boot/initrd.img-4.2.0-35-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
Found Arch on /dev/sda8
done

I tried to reinstall GRUB to the MBR from Ubuntu:

$ sudo grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.

$ sudo grub-install --recheck /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.

Those are the installed Ubuntu kernel packages by the way, I did try to dpkg-reconfigure all of them, but without any effect on the issue:

$ dpkg -l linux-image* | grep ^ii
ii  linux-image-4.2.0-35-generic       4.2.0-35.40  amd64        Linux kernel image for version 4.2.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-21-generic       4.4.0-21.37  amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-extra-4.2.0-35-generic 4.2.0-35.40  amd64        Linux kernel extra modules for version 4.2.0 on 64 bit x86 SMP
ii  linux-image-extra-4.4.0-21-generic 4.4.0-21.37  amd64        Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP

I also tried to regenerate the Ubuntu initramfs:

$ sudo update-initramfs -u -k all
update-initramfs: Generating /boot/initrd.img-4.4.0-21-generic
update-initramfs: Generating /boot/initrd.img-4.2.0-35-generic

My partition layout:

Checked from the Ubuntu system. The labels should explain themselves.

$ lsblk -f /dev/sda
NAME    FSTYPE LABEL       UUID                                 MOUNTPOINT
sda                                                             
├─sda1  ntfs   win7-boot   90DCF3A5DCF3842E                     /win/boot
├─sda2  ntfs   windows7    482C7A572C7A3FCC                     /win/c
├─sda3  ext4   grub-boot   6dbb8633-dadd-4b5e-8d85-b0895fde9dfb /boot
├─sda5  ext4   images      81dc42c4-a161-4ccd-b704-6e5c09298943 /images
├─sda6  ext4   ubuntu-1604 eee18451-b607-4875-8a88-c9cb6c6544c8 /
├─sda7  ext4   ubuntu-home 485b3ef1-7216-4053-b25c-f656d529e8e6 /home
├─sda8  ext4   arch-root   8d281a0c-969c-44cf-ba6a-1d3c7b4be7ec 
├─sda9  ext4   arch-home   32522902-a53d-44c8-90f2-6bbf14c40f1f 
└─sda10 swap   linux-swap  8b05bd9b-bc42-46f6-8c18-50711a3c48b9 [SWAP]

My GRUB menu structure:

GRUB main page

Advanced options for Ubuntu:
GRUB advanced options for Ubuntu

Advanced options for Arch:
GRUB advanced options for Arch


My /boot directory:

$ ls -la /boot
total 118480
drwxr-xr-x  4 root root     4096 Apr 24 20:50 .
drwxr-xr-x 28 root root     4096 Apr 24 19:44 ..
-rw-r--r--  1 root root  1313029 Mär 16 01:45 abi-4.2.0-35-generic
-rw-r--r--  1 root root  1239577 Apr 19 00:21 abi-4.4.0-21-generic
-rw-r--r--  1 root root   184888 Mär 16 01:45 config-4.2.0-35-generic
-rw-r--r--  1 root root   189412 Apr 19 00:21 config-4.4.0-21-generic
drwxr-xr-x  6 root root     4096 Apr 26 19:58 grub
-rw-r--r--  1 root root 18598360 Apr 24 20:59 initramfs-linux-fallback.img
-rw-r--r--  1 root root  3516429 Apr 24 20:59 initramfs-linux.img
-rw-r--r--  1 root root 33642388 Apr 24 18:31 initrd.img-4.2.0-35-generic
-rw-r--r--  1 root root 36143341 Apr 24 19:51 initrd.img-4.4.0-21-generic
drwx------  2 root root    16384 Okt 28 17:43 lost+found
-rw-r--r--  1 root root   182704 Jan 28 13:44 memtest86+.bin
-rw-r--r--  1 root root   184380 Jan 28 13:44 memtest86+.elf
-rw-r--r--  1 root root   184840 Jan 28 13:44 memtest86+_multiboot.bin
-rw-------  1 root root  3745312 Mär 16 01:45 System.map-4.2.0-35-generic
-rw-------  1 root root  3853719 Apr 19 00:21 System.map-4.4.0-21-generic
-rw-------  1 root root  6829104 Mär 16 01:45 vmlinuz-4.2.0-35-generic
-rw-------  1 root root  7013968 Apr 19 00:21 vmlinuz-4.4.0-21-generic
-rw-r--r--  1 root root  4435552 Apr 14 19:20 vmlinuz-linux

The 4.4.0 and 4.2.0 kernels should be Ubuntu, Arch should have a 4.5.0 kernel. But how do I find out which file without kernel version in its name belongs to what?


My Ubuntu root directory (directories excluded):

$ ls -la / | grep ^[^d]
total 124
lrwxrwxrwx   1 root      root         32 Apr 24 19:44 initrd.img -> boot/initrd.img-4.4.0-21-generic
lrwxrwxrwx   1 root      root         32 Apr  5 17:45 initrd.img.old -> boot/initrd.img-4.2.0-35-generic
lrwxrwxrwx   1 root      root         29 Apr 24 19:44 vmlinuz -> boot/vmlinuz-4.4.0-21-generic
lrwxrwxrwx   1 root      root         29 Apr  5 17:45 vmlinuz.old -> boot/vmlinuz-4.2.0-35-generic

My Arch root directory does not contain any files or links.

  • I had same problem with triple boot of ubuntu, windows and arch linux. you need to fix grub manually if needed, boot into arch linux then rebuild grub from there, you might need to install os-prober. then run these sudo mkinitcpio -p linux then sudo grub-mkconfig -o /boot/grub/grub.cfg lastly sudo grub-install /dev/sda – Edward Torvalds May 2 '16 at 6:42
  • When I was installing various Linux distros on my laptop(while replacing older one, keeping windows untouched) I had similar problem.What I did is simply delete respective folder of older os from efi and do a grub-update. But in my case, 1. It was UEFI system 2. I did not keep multiple linux OS. – Registered User May 5 '16 at 6:15
  • While booting, can you dynamically modify the kernel and initrd to boot into Ubuntu ? If you have done so, then what is the error came ? – SHW May 5 '16 at 7:47
  • The screen you posted contains the error message: Root device mounted successfully, but /sbin/init does not exists. Did you investigate this? Is init really missing? If so, you should definitely install it, if instead it is present, any idea why it cannot be found? – MariusMatutiae May 6 '16 at 11:04
5
+250

I finally solved it by nuking the Arch partition and its boot files in my Ubuntu's /boot directory from orbit. Ubuntu is fine again now, all remaining GRUB entries are working again.

Here's a list of what I did:

  • Delete Arch's initramfs files:

    sudo rm /boot/initramfs-linux*
    
  • Delete Arch's vmlinuz file:

    sudo rm vmlinuz-linux
    
  • Format the Arch partition (/dev/sda8) using GParted

  • Update GRUB's configuration:

    sudo update-grub
    
  • Reboot and enjoy!

  • I think the first coded line should contain initramfs-linux not ...ranfs... – Anwar Aug 11 '17 at 6:25
  • 1
    @Anwar Of course, thanks for paying attention. I fixed the typo. – Byte Commander Aug 11 '17 at 10:09
1

Fixing grub.cfg by hand (not recommended)

Looking at your grub.cfg

the Ubuntu entry is broken (and some of the following one as well)

menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-eee18451-b607-4875-8a88-c9cb6c6544c8' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos3'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos3 --hint-efi=hd0,msdos3 --hint-baremetal=ahci0,msdos3  6dbb8633-dadd-4b5e-8d85-b0895fde9dfb
    else
      search --no-floppy --fs-uuid --set=root 6dbb8633-dadd-4b5e-8d85-b0895fde9dfb
    fi
    linux   /vmlinuz-linux root=UUID=eee18451-b607-4875-8a88-c9cb6c6544c8 ro  
    initrd  /initramfs-linux.img
}

The last two lines are your grub-issued command to load kernel and initrd, and are currently looking for the ARCH kernel and initiramfs. Furthermore, it looks for them under the / in partition identified by uuid=eee18451-b607-4875-8a88-c9cb6c6544c8 which might or might not host the intended Ubuntu files.

You can fix this by:

sudo blkid

to get the uuid of your ubuntu root partition.

Then replace the last two lines with the simlink to your latest kernel and initrd images (since this is the way ubuntu expects it to be)

linux   /vmlinuz root=UUID=<correct-uuid-ubuntu-partition> ro  
initrd  /initrd.img

If this doesn't fix it right away, some other correction might be required. You can find them out by "copying" one of the tested and working entry, and I'd reccomend you use the most vanilla one (e.g. no upstart or other kernel parameter such as nomodeset being passed).

This should be a good candidate:

menuentry 'Ubuntu, with Linux 4.4.0-21-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-21-generic-advanced-eee18451-b607-4875-8a88-c9cb6c6544c8'

The Arch entry is similarly broken, in that it probably looks up for Arch initramfs and kernel under the Ubuntu root partition. The default location of those is under /boot. Adjust the final two lines of Arch entry by correcting the location and checking that the root partition uuid is the one containing the Arch root.

A (several) word(s) of warning:

It is in general NOT recommended to Ubuntu users to mess with grub.cfg by hand. Definetely make a copy of it and be careful in its editing. Be prepared to the off chance that your system becomes unbootable (but you will be able to resurrect it using the boot procedure outlined in my old answer).

Also, while this might fix your problem this time around, it might come back to bite you the next time you have to repopulate your grub menu. For some reason, the os probing of grub under ubuntu gets confused by the presence of Arch kernel under /boot. I would guess that an utility such as boot-repair should be able to correctly make all your distros bootable, but if I remember correctly it didn't work for you.

One permanent fix might consist in installing the arch kernel and images in a different directory than the default /boot. This is fiddly and you should consult Arch wiki's grub entry on how to do it properly.

OLD ANSWER (recommended if you plan to switch to Arch long term) Here is what I would do, and somehow have done a few months back.

Go to the arch wiki grub page and read out the relevant section for your partition table (you are likely UEFI, so read about ESP and so on).

Booting into Arch manually

This is a highly formative experience that I recommend trying. Assuming your Arch Linux kernel is located somewhere on your disk, press c at grub prompt and type ls to see a list of device and partitions looking like (hd0,msdos1),(hd1,gpt1),.... You can ls each of them to see the content.

You need to find out three things:

  • Where is your Arch / root partition
  • Where is your Arch kernel vmlinuz
  • Where is your Arch intiramfs-linux.img

once possessing these three, you will run three commands in grub> prompt something similar to this.

grub> set root=(hd0,1)
grub> linux /vmlinuz root=/dev/sda1
grub> initrd /intiramfs-linux.img
grub> boot

Notice that grub can do find, e.g.

grub> find /sbin/init

(the one grub cannot find automagically and giving you a kernel panic ;) )

All of this I have learned here, a source which I highly recommend. If you can manage, skip to fixing grub! Otherwise...

Boot Arch from a live key! Get a live Arch environment and following the installation wiki chroot onto Arch in much the same way you did the first time.

Fixing grub

From inside Arch, install the relevant grub packages, and in particular os-prober to allow grub-install to detect your other system. Follow carefully the install guide there and you should be able to (at least) boot both arch and ubuntu from grub menu. Installing commands will end up looking like this.

** Warning ** Do not run these command, they are exemplification, you need to work out the ones appropriate to your system

# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub --recheck
# grub-mkconfig -o /boot/grub/grub.cfg

** If all else fails **

Unfortunately, this is as specific as it gets given the limited number of info and SE is not really a forum for such issues, hence my "generic" answer referring to useful resources.

If you can't figure it out, maybe drop by the Arch forums, and provided you have tried your best and read the docs before hand, you might find help.

Doing all this through Arch has been a fundamental learning experience for me.

  • 1
    Thanks for your response. First, it's a BIOS system with MBR partitioned disk. Second, I want to use the grub package and configuration from Ubuntu, reinstalling GRUB from Arch is not what I plan. I also doubt that this would make any change... And I can boot to Ubuntu through the GRUB entry somewhere in the Advanced options. The problem is that GRUB somehow seems not to be able to determine which kernel or initial ramdisk or whatever is belonging to which system on which partition. – Byte Commander Apr 27 '16 at 5:38
  • Essentially, the same steps apply. grub-install and grub-mkconfig (which makes you a new grub.cfg files) are grub command which are available under ubuntu as well. Check out if os-prober is also available or a similar thing ( this allows mkconfig to find other filesystems). This fixes it assuming kernel images are in the right place, rereading your post I am not quite sure that's the case. Inspect your /boot partition to ensure all kernels and .img are there. You might have overwritten your linux initrd.img with arch's initramfs. Hit up ubuntu forums or askubuntu. – Three Diag Apr 27 '16 at 6:48
  • As I wrote, I ran the grub-mkconfig already to no avail, but I'll check the available images in /boot when I'm back home. And there are some os-prober scripts. – Byte Commander Apr 27 '16 at 6:57
  • Sorry, missed that. Then you probably have overwritten your ubuntu kernel and initrd with arch ones. You can pop them in place by running your upgrade/update sequence from the ubuntu fallback kernel (I think) – Three Diag Apr 27 '16 at 7:08
  • The Ubuntu kernels should be fine as I can boot all of them from the "Advanced options for Ubuntu" menu. If anything is wrong there, it could be only the symlink to the default kernel... Going to check that this evening. – Byte Commander Apr 27 '16 at 7:13
0

My solution is simpler. I use the terminal and do the following:

sudo rm /boot/grub/grub.cfg
sudo update-grub

If you have further problems, just use boot-repair, which is a free download, small enough to burn to a CD disk.

  • The OP has already run update-grub. Boot-repair is very unlikely to help with this particular issue. – terdon May 2 '16 at 9:54
  • grub and some boot repair or update processes assume that what is in /boot/grub/grub.cfg is ctrrent and correct. But make changes, like a partition reformat, you get a new UUID, which puts you into grub-rescue> To deal with this, just do this: sudo rm /boot/grub/grub.cfg; sudo update-grub. All entries in grub.cfg will be new and current. – BAD-Boop May 7 '16 at 10:48
  • Yes, but again, the OP has already done this and it didn't help. I realize the question is big and it's easy to miss but sudo grub-mkconfig -o /boot/grub/grub.cfg is right there. update-grub is a very simple shell script that runs grub-mkconfig -o /boot/grub/grub.cfg . You can see this with cat /usr/sbin/update-grub. – terdon May 7 '16 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.