LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Need help fixing up Grub 2 on SD card with Win/Ubuntu on different drive. (https://www.linuxquestions.org/questions/linux-general-1/need-help-fixing-up-grub-2-on-sd-card-with-win-ubuntu-on-different-drive-4175548805/)

gtr33m 07-24-2015 03:01 AM

Need help fixing up Grub 2 on SD card with Win/Ubuntu on different drive.
 
I need some help getting Grub setup correctly on an admittedly peculiar setup.

I have a HP ML110 G7 which has some quirks. It has two sata contollers, the main one which is fixed to a 4 port HD cradle and a second that has 2 ports for other devices. In AHCI mode, only the first controller can be set as the boot device.

The server also has an internal USB socket and an Internal SD Card. The bios can be set to boot from USB, but then you must fix whether it's the SD Card, internal USB or external USB. This can't be selected at boot time.

My setup is a 1TB conventional HD on the first sata controller and a 128GB SSD on the second. I have Windows 10 and Ubuntu 15.04.

Because the BIOS won't boot from the second sata controller, and I want to keep the 1TB as removable data only, the only solution that I could come up with after many, may trials was to sacrifice an old 256 MB SD card as a boot device with grub installed manually which then boots the OS of choice from the SSD card. This way if the 1TB is missing or broken, then the system will still boot fine. Not the most elegant solution, but it works fine and boots quickly as the SD card does not contain any of the OS files.

This worked fine until the first time there was an update to the linux kernel and thus an update to grub, on the next boot Ubuntu would no longer boot. Windows boots fine.

I did manage to boot into linux by using the grub-recovery and using the find command to locate the vmlinuz and kernel files and then executing the boot manually, but this was not persistent and I couldn't seem to fix it permanently.

I'm quite certain that I've got it setup incorrectly as I have transferred the vmlinuz files to the SD card, and this does not seem to be the fastest or most reliable setup. I tried symlinking the /grub folder from the ssd to the /boot on the SD card, but this just ended up nesting grub as /boot/boot/grub.

What I'd like to achieve, is the SD card as the boot device, with all the necessary files outside of the config on the SSD. I especially want a setup that will update on Windows and Ubuntu which will not kill the grub boot. I'd also like to avoid a chain-loading of grubs in order to boot into linux (ie grub on sd to grub on ssd) unless it's a simple quick handover.

I'm sure there is an easy simple solution, but I'm stuck.

Thanks,

gtr33m

Keruskerfuerst 07-24-2015 12:12 PM

Then post fdisk -l.
Post /boot/grub2/grub.cfg.
Post the folder below /boot/*

fatmac 07-24-2015 01:29 PM

Maybe the use of labels or UUIDs would help.

gtr33m 07-25-2015 03:37 AM

Thanks for the quick response.

I can't access the computer at the moment, however I did have the grub ls entries written down:

hd0,msdos1 = SD card
hd1,msdos1 = Windows Data HDD
hd1,msdos2 = Linux Data HDD
hd2,msdos1 = SSD Persistent Boot
hd2,msdos2 = SSD Windows
hd2,msdos3 = SSD Linux

I'll get the rest as soon as I can access the system.

Thanks

gtr33m 07-25-2015 08:47 AM

I managed to get the system up and running using the grub command line. Not fixed, but at least I could get the info.

fdisk -l

Code:

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
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: 0x0006a750

Device    Boot      Start        End    Sectors  Size Id Type
/dev/sda1            2048 1743810559 1743808512 831.5G  7 HPFS/NTFS/exFAT
/dev/sda2      1743810560 1953523711  209713152  100G 83 Linux

Disk /dev/sdc: 119.2 GiB, 128035676160 bytes, 250069680 sectors
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: 0x0001d8fb

Device    Boot    Start      End  Sectors  Size Id Type
/dev/sdc1  *        2048    718847    716800  350M  7 HPFS/NTFS/exFAT
/dev/sdc2          718848 208125951 207407104 98.9G  7 HPFS/NTFS/exFAT
/dev/sdc3      208125952 250068991  41943040  20G 83 Linux

Disk /dev/sdb: 244 MiB, 255852544 bytes, 499712 sectors
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: 0x0005188a

Device    Boot Start    End Sectors  Size Id Type
/dev/sdb1  *    2048 499711  497664  243M 83 Linux

blkid
Code:

/dev/sda1: LABEL="WINDOWS" UUID="33FB730F257204EF" TYPE="ntfs" PARTUUID="0006a750-01"
/dev/sda2: LABEL="LINUX" UUID="a3e08f53-4860-403d-8266-9621e277c5b7" TYPE="ext4" PARTUUID="0006a750-02"
/dev/sdb1: UUID="b694f9b3-6312-45bb-ba99-c40c04ad9e69" TYPE="ext4" PARTUUID="0005188a-01"
/dev/sdc1: LABEL="System Reserved" UUID="46CA4022CA40111B" TYPE="ntfs" PARTUUID="0001d8fb-01"
/dev/sdc2: UUID="289643679643349A" TYPE="ntfs" PARTUUID="0001d8fb-02"

/boot/grub/grub.cfg from /dev/sdc3
Code:

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
  set default="${next_entry}"
  set next_entry=
  save_env next_entry
  set boot_once=true
else
  set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
  font=unicode
else
insmod part_msdos
insmod ext2
set root='hd2,msdos3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
else
  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_AU
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=0
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 0 ; then
    set timeout=0
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 44,0,30,0; then
  clear
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
        set gfxpayload="${1}"
        if [ "${1}" = "keep" ]; then
                set vt_handoff=vt.handoff=7
        else
                set vt_handoff=
        fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-bbd209f9-085b-4ffa-b928-b6919221f847' {
        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='hd2,msdos3'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
        else
          search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
        fi
        linux        /boot/vmlinuz-3.19.0-23-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro  quiet splash $vt_handoff
        initrd        /boot/initrd.img-3.19.0-23-generic
}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-bbd209f9-085b-4ffa-b928-b6919221f847' {
        menuentry 'Ubuntu, with Linux 3.19.0-23-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-23-generic-advanced-bbd209f9-085b-4ffa-b928-b6919221f847' {
                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='hd2,msdos3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
                else
                  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
                fi
                echo        'Loading Linux 3.19.0-23-generic ...'
                linux        /boot/vmlinuz-3.19.0-23-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro  quiet splash $vt_handoff
                echo        'Loading initial ramdisk ...'
                initrd        /boot/initrd.img-3.19.0-23-generic
        }
        menuentry 'Ubuntu, with Linux 3.19.0-23-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-23-generic-init-upstart-bbd209f9-085b-4ffa-b928-b6919221f847' {
                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='hd2,msdos3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
                else
                  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
                fi
                echo        'Loading Linux 3.19.0-23-generic ...'
                linux        /boot/vmlinuz-3.19.0-23-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro  quiet splash $vt_handoff init=/sbin/upstart
                echo        'Loading initial ramdisk ...'
                initrd        /boot/initrd.img-3.19.0-23-generic
        }
        menuentry 'Ubuntu, with Linux 3.19.0-23-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-23-generic-recovery-bbd209f9-085b-4ffa-b928-b6919221f847' {
                recordfail
                load_video
                insmod gzio
                if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
                insmod part_msdos
                insmod ext2
                set root='hd2,msdos3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
                else
                  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
                fi
                echo        'Loading Linux 3.19.0-23-generic ...'
                linux        /boot/vmlinuz-3.19.0-23-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro recovery nomodeset
                echo        'Loading initial ramdisk ...'
                initrd        /boot/initrd.img-3.19.0-23-generic
        }
        menuentry 'Ubuntu, with Linux 3.19.0-20-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-20-generic-advanced-bbd209f9-085b-4ffa-b928-b6919221f847' {
                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='hd2,msdos3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
                else
                  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
                fi
                echo        'Loading Linux 3.19.0-20-generic ...'
                linux        /boot/vmlinuz-3.19.0-20-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro  quiet splash $vt_handoff
                echo        'Loading initial ramdisk ...'
                initrd        /boot/initrd.img-3.19.0-20-generic
        }
        menuentry 'Ubuntu, with Linux 3.19.0-20-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-20-generic-init-upstart-bbd209f9-085b-4ffa-b928-b6919221f847' {
                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='hd2,msdos3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
                else
                  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
                fi
                echo        'Loading Linux 3.19.0-20-generic ...'
                linux        /boot/vmlinuz-3.19.0-20-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro  quiet splash $vt_handoff init=/sbin/upstart
                echo        'Loading initial ramdisk ...'
                initrd        /boot/initrd.img-3.19.0-20-generic
        }
        menuentry 'Ubuntu, with Linux 3.19.0-20-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.19.0-20-generic-recovery-bbd209f9-085b-4ffa-b928-b6919221f847' {
                recordfail
                load_video
                insmod gzio
                if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
                insmod part_msdos
                insmod ext2
                set root='hd2,msdos3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
                else
                  search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
                fi
                echo        'Loading Linux 3.19.0-20-generic ...'
                linux        /boot/vmlinuz-3.19.0-20-generic root=UUID=bbd209f9-085b-4ffa-b928-b6919221f847 ro recovery nomodeset
                echo        'Loading initial ramdisk ...'
                initrd        /boot/initrd.img-3.19.0-20-generic
        }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry 'Memory test (memtest86+)' {
        insmod part_msdos
        insmod ext2
        set root='hd2,msdos3'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
        else
          search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
        fi
        knetbsd        /boot/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
        insmod part_msdos
        insmod ext2
        set root='hd2,msdos3'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos3 --hint-efi=hd2,msdos3 --hint-baremetal=ahci2,msdos3  bbd209f9-085b-4ffa-b928-b6919221f847
        else
          search --no-floppy --fs-uuid --set=root bbd209f9-085b-4ffa-b928-b6919221f847
        fi
        linux16        /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Windows Recovery Environment (loader) (on /dev/sdc1)' --class windows --class os $menuentry_id_option 'osprober-chain-46CA4022CA40111B' {
        insmod part_msdos
        insmod ntfs
        set root='hd2,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd2,msdos1 --hint-efi=hd2,msdos1 --hint-baremetal=ahci2,msdos1  46CA4022CA40111B
        else
          search --no-floppy --fs-uuid --set=root 46CA4022CA40111B
        fi
        parttool ${root} hidden-
        drivemap -s (hd0) ${root}
        chainloader +1
}
set timeout_style=menu
if [ "${timeout}" = 0 ]; then
  set timeout=10
fi
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

I updated the system and re-ran update-grub, then copied the grub.cfg to /boot/grub/ on /dev/sdb1, which is the SD Card. I know this is not a solution, but it does allow me to boot without having to use the grub command line.

Perhaps the best solution would be to simply have the SD boot and immediately pass it off to grub on the SSD. This way if I move the SSD to a new system it will still be viable and boot into linux. Given that the SD card is only a work around for this hardware this seems logical. I would like to avoid a double grub menu if possible.

Thanks


All times are GMT -5. The time now is 03:26 PM.