LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 12-31-2011, 05:09 PM   #1
snmcdonald
Member
 
Registered: Jul 2011
Location: Canada
Distribution: Debian, Arch
Posts: 55

Rep: Reputation: 0
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

Last edited by snmcdonald; 12-31-2011 at 05:14 PM. Reason: additional details
 
Old 12-31-2011, 05:56 PM   #2
snmcdonald
Member
 
Registered: Jul 2011
Location: Canada
Distribution: Debian, Arch
Posts: 55

Original Poster
Rep: Reputation: 0
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
 
Old 01-04-2012, 04:21 PM   #3
snmcdonald
Member
 
Registered: Jul 2011
Location: Canada
Distribution: Debian, Arch
Posts: 55

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
grub2


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to start Grub2-bootloader from extlinux-bootloader? floppy_stuttgart Linux - Newbie 13 11-13-2011 07:43 PM
[SOLVED] Grub2, moving /boot to separate partition qrange Linux - Software 8 10-25-2011 12:33 PM
[SOLVED] GRUB2 after a minor update of GRUB2 /boot prefix no longer needed?? wikapuki Linux - Software 1 10-24-2010 03:39 PM
openSUSE won't boot after I resized its partition - grub2 related Mountain Linux - General 18 11-09-2009 02:42 PM
Stuck at Grub2 prompt after deleting Linux partition of dual boot alcorta Linux - Software 3 07-09-2005 12:12 AM


All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration