LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   GRUB2 - Boot to Partition with Custom Bootloader (https://www.linuxquestions.org/questions/linux-general-1/grub2-boot-to-partition-with-custom-bootloader-921418/)

snmcdonald 12-31-2011 04:09 PM

GRUB2 - Boot to Partition with Custom Bootloader
 
I am a programmer hobbyist. I currently got a hold of an old Intel 386 Manual and I thought it would be fun to see if I could make a custom boot loader. Nothing professional, just something fun.

I do not want delete everything on my computer and write directly on my MBR. I would like to leave GRUB2 as well as all my other partitions. I have set up a small partition to experiment with.

Is there a way to set GRUB2 to boot to a partition as if it was the computers MBR?

Currently /etc/grub.d/40_custom looks like

Code:

#!/bin/sh
exec tail -n +3 #0
#
#
#

menuentry "mybootloader" {
set root=(hd0,8)
chainloader +1
}


fdisk -l gives me:
Quote:

Device Boot Start End Blocks Id System
/dev/sda1 2048 206847 102400 7 HPFS/NTFS/exFAT
/dev/sda2 206848 842250239 421021696 7 HPFS/NTFS/exFAT
/dev/sda3 * 842250240 842444799 97280 83 Linux
/dev/sda4 842446846 1953525167 555539161 5 Extended
/dev/sda5 842446848 874475519 16014336 82 Linux swap / Solaris
/dev/sda6 874477568 1069787135 97654784 83 Linux
/dev/sda7 1069789184 1265098751 97654784 83 Linux
/dev/sda8 1265098815 1267058681 979933+ 60 Unknown

I update-grub and reboot. When I execute my partition from the GRUB menu I get:

Quote:

error: invalid signature

snmcdonald 12-31-2011 04:56 PM

I have added a force flag to ignore the file signature. It boots successfully.

Code:

#!/bin/sh
exec tail -n +3 #0
#
#
#

menuentry "mybootloader" {
set root=(hd0,8)
chainloader --force +1
}


Quote:

14.3.6 chainloader

— Command: chainloader [--force] file
Load file as a chain-loader. Like any other file loaded by the filesystem code, it can use the blocklist notation (see Block list syntax) to grab the first sector of the current partition with ‘+1’. If you specify the option --force, then load file forcibly, whether it has a correct signature or not. This is required when you want to load a defective boot loader, such as SCO UnixWare 7.1.
- Grub1.99 Documentation

snmcdonald 01-04-2012 03:21 PM

You can remove the --force flag if you have the appropriate boot loader signature.

An empty bootloader could simply be used by typing"

Code:

echo -ne '\x55\xAA' | sudo dd obs=1 seek=510 of=/dev/sda8
sudo hd /dev/sd8 -n512



All times are GMT -5. The time now is 05:51 AM.