You are not logged in.

#1 2012-08-24 20:31:51

alphe
Member
Registered: 2009-03-30
Posts: 18

[solved] Upgrading to grub2 a system with a dedicated boot partition

I would like to have your help with the upgrade to grub2 cause even after some reading I am not sure that I have the correct plan

I have two disks in my computer

 Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63    31455269    15727603+  83  Linux
/dev/sda2        31457280    73410559    20976640   83  Linux
/dev/sda3       209712510  1953520064   871903777+  83  Linux

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1        71682030   625137344   276727657+  83  Linux
/dev/sdb2              63      208844      104391   83  Linux
/dev/sdb3        42186690    71682029    14747670    5  Extended
/dev/sdb4          208845    42186689    20988922+  83  Linux
/dev/sdb5        63247905    71682029     4217062+  82  Linux swap / Solaris
/dev/sdb6        42186816    63247904    10530544+  83  Linux

sdb1: /home
sdb2: a dedicated grub partition
sdb4: /root
sdb6: not used

sda1: a backup Arch partition in which occasionally I rsync my /root for failsafe reasons
sda2: a Debian partition
sda3: data partition

The menu.lst in the dedicated grub partition is this

# general configuration:
default   saved
timeout   10
#color light-blue/black light-cyan/blue

# (0) Arch Linux
title  Arch Linux
savedefault
root (hd0,3)
configfile /boot/grub/menu.lst

# (1) Arch Stable
title  Arch Stable
savedefault
root (hd1,0)
configfile /boot/grub/menu.lst

# (2) Debian
title  Debian
savedefault
root (hd1,1)
kernel /vmlinuz root=UUID=96cfd53f-4e32-4cde-bd5e-372a2dcaac9d ro quiet pci=noaer
initrd /initrd.img

Combining wiki instructions with some google search for dedicated grub2 partitions I conclude to the following plan

# Backup Important Data 
mv /boot/grub /boot/grub-legacy
dd if=/dev/sdb of=/home/data/Backup/mbr_backup bs=512 count=1
#Install grub-bios package
pacman -S grub-bios
modprobe dm-mod
grub-install --target=i386-pc --recheck --debug /dev/sdb
mkdir -p /boot/grub/locale
cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo
#Generate GRUB2 BIOS Config file 
grub-mkconfig -o /boot/grub/grub.cfg

# mount dedicated grub partition
mount /dev/sdb2 /media/grub
# install grub2 to the grub partition
grub-install --root-directory=/media/grub /dev/sdb
# convert menu.lst to grub.cfg
grub-menulst2cfg /media/grub/boot/grub/menu.lst /media/grub/boot/grub/grub.cfg
# make a prayer and reboot
# rsync /root to Arch stable (sda1)
# modify manually the sdb2 /grub/boot/grub.cfg (I will figure how)
# find out what I have to do with debian (sda2)

Could you please confirm that this plan seems correct because I do not want to play with my bootloader smile

Thanks in advance

Last edited by alphe (2012-08-25 20:45:31)

Offline

#2 2012-08-25 06:31:05

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

There's no need to reboot.

# pacman -S grub-bios os-prober
# grub-install --target=i386-pc --recheck --debug /dev/sdb
# grub-mkconfig -o /boot/grub/grub.cfg

Obviously, /dev/sdb (whatever brand and model) needs to be the first in the BIOS boot order.


Is there any particular reason why you'd want GRUB(2)? Syslinux is much easier to understand and converting your current menu.lst would be a piece of cake. Syslinux counts drives from zero and partitions from one, so "hd0 1" is the equivalent of GRUB Legacy's "(hd0,0)".

Personally I use UUID's. They're much more accurate.

https://wiki.archlinux.org/index.php/Be … bootloader

# pacman -S syslinux
# syslinux-install_update -iam
# nano /boot/syslinux/syslinux.cfg

"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#3 2012-08-25 07:51:26

ZekeSulastin
Member
Registered: 2010-09-20
Posts: 266

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

DSpider wrote:
# pacman -S syslinux
# syslinux-install_update -iam
# nano /boot/syslinux/syslinux.cfg
# grub-install --target=i386-pc --boot-directory=/media/ZSCruzer/boot --recheck --debug /dev/sde
$ vim /media/ZSCruzer/boot/grub/grub.cfg

Your point? Or could you just not miss the chance to add your little advert?

(Regarding using UUIDs: they're much more accurate because they aren't reliant on drives being loaded in the same order by the system every boot.  If you use hd(x,y), adding a new drive/odd thumbdrive interactions/etc can change the order the drives are seen thus breaking everything; UUIDs are unique to each partition and thus are not affected.  Labels could also be used, but the risk of a label collision is much higher than that of a UUID collision.  In that thumbdrive above, I referenced the FAT "UUID" as I really have no idea what drives would be in whatever I was booting from tongue)

Aside from that, DSpider is correct - just ensure /boot is mounted and writable when you go to do grub-install.  --boot-directory is only needed to specify a nonstandard boot directory.

Last edited by ZekeSulastin (2012-08-25 07:59:27)

Offline

#4 2012-08-25 11:43:28

Lennie
Member
From: Sweden
Registered: 2011-10-12
Posts: 146

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

alphe wrote:
# Backup Important Data 
mv /boot/grub /boot/grub-legacy
dd if=/dev/sdb of=/home/data/Backup/mbr_backup bs=512 count=1
#Install grub-bios package
pacman -S grub-bios
modprobe dm-mod
grub-install --target=i386-pc --recheck --debug /dev/sdb
mkdir -p /boot/grub/locale
cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo
#Generate GRUB2 BIOS Config file 
grub-mkconfig -o /boot/grub/grub.cfg

No need to install grub in mbr just to generate the grub files:

wiki wrote:

Generate core.img alone

To populate the /boot/grub directory and generate a /boot/grub/i386-pc/core.img file without embedding any grub-bios bootsector code in the MBR, post-MBR region, or the partition bootsector, add --grub-setup=/bin/true to grub-install:

# modprobe dm-mod
# grub-install --target=i386-pc --grub-setup=/bin/true --recheck --debug /dev/sda
alphe wrote:
# mount dedicated grub partition
mount /dev/sdb2 /media/grub
# install grub2 to the grub partition
grub-install --root-directory=/media/grub /dev/sdb
# convert menu.lst to grub.cfg
grub-menulst2cfg /media/grub/boot/grub/menu.lst /media/grub/boot/grub/grub.cfg
# make a prayer and reboot
# rsync /root to Arch stable (sda1)
# modify manually the sdb2 /grub/boot/grub.cfg (I will figure how)
# find out what I have to do with debian (sda2)

* After you've mounted your grub partition, copy the grub folder from /boot/grub to /media/grub.
* Rewrite your /media/grub/grub.cfg manually. You can boot all distros directly from that grub file. No need to use chainloading.

Here is an example (change it to your needs):

set timeout=10
set default=0

menuentry "Arch Linux" {
    set root=(hd1,4)
    linux /boot/vmlinuz-linux root=UUID=[...] ro
    initrd /boot/initramfs-linux.img
}

menuentry "Debian" {
    set root=(hd0,2)
    linux /vmlinuz root=UUID=96cfd53f-4e32-4cde-bd5e-372a2dcaac9d ro quiet pci=noaer
    initrd /initrd.img
}

* Install grub in mbr, pointing to your grub partition.

Offline

#5 2012-08-25 14:00:56

alphe
Member
Registered: 2009-03-30
Posts: 18

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

First of all thank you all for your time.

@Dspider, I am considering syslinux but I want first to give grub2 a try.

@Lennie, the reason that I am using a dedicated boor partition and chainloading is to have first a distribution menu and then a (sub)menu with options per distribution (ex Linux core, Linux-lts, boot in console etc).

I have tried your instructions but when I am trying to install grub2 in mbr using

 grub-install --target=i386-pc --debug --recheck /dev/sdb2 

I am receiving the following error

 /usr/sbin/grub-bios-setup: warning: File system `ext2' doesn't support embedding.
/usr/sbin/grub-bios-setup: error: embedding is not possible, but this is required for RAID and LVM install.
+ exit 1 

but sdb2 is ext3 and not ext2

 Model: ATA ST3320620A (scsi)
Disk /dev/sdb: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system     Flags
 2      32,3kB  107MB   107MB   primary   ext3
 4      107MB   21,6GB  21,5GB  primary   ext3
 3      21,6GB  36,7GB  15,1GB  extended
 6      21,6GB  32,4GB  10,8GB  logical   ext3
 5      32,4GB  36,7GB  4318MB  logical   linux-swap(v1)
 1      36,7GB  320GB   283GB   primary   ext3 

Offline

#6 2012-08-25 14:25:44

Lennie
Member
From: Sweden
Registered: 2011-10-12
Posts: 146

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

alphe wrote:

@Lennie, the reason that I am using a dedicated boor partition and chainloading is to have first a distribution menu and then a (sub)menu with options per distribution (ex Linux core, Linux-lts, boot in console etc).

I have tried your instructions but when I am trying to install grub2 in mbr using

 grub-install --target=i386-pc --debug --recheck /dev/sdb2

I am receiving the following error

 /usr/sbin/grub-bios-setup: warning: File system `ext2' doesn't support embedding.
/usr/sbin/grub-bios-setup: error: embedding is not possible, but this is required for RAID and LVM install.
+ exit 1 

That is not installing in mbr, that is installing in a partition. Grub2 doesn't like to be installed in a partition so you need to use force for that. But I'm not sure it's needed... I think it's enough to generate the core.img (see the quote from wiki in my previous message) and chainload to that. (I hope you have something to boot with, if you screw up...)

Edit: Grub says 'ext2' for ext2/3/4.

Last edited by Lennie (2012-08-25 14:31:05)

Offline

#7 2012-08-25 14:48:20

alphe
Member
Registered: 2009-03-30
Posts: 18

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

I still don't get it (newbie here wink )

I was trying to "Install grub in mbr, pointing to your grub partition". What is the correct way to do it?

And also when you said "chainload to that" do you mean to leave grub-legacy into dedicated partition and chainload to grub2? If yes, then do I have other option cause I do not want to keep grub-legacy at all.

Thanks for your patience.

Edit comment: I found that it is possible to chainload grub to grub2.

Last edited by alphe (2012-08-25 15:01:16)

Offline

#8 2012-08-25 15:15:23

Lennie
Member
From: Sweden
Registered: 2011-10-12
Posts: 146

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

Sorry for that, I just realized I wasn't so clear as I thought... When I wrote "Install grub in mbr, pointing to your grub partition" I just mean install grub in mbr, but because you have grub on a separate partition you need to tell grub about that. That is done by the grub-install command, like you wrote in your first post: 'grub-install --root-directory=/media/grub /dev/sdb' (When I installed grub2 on a separate partition, to install it in mbr I temporarily mounted the grub partition as /boot and treated it as if it was a separate boot partition when I run the grub-install command.)

I don't know how to chainload from grub2, I just assume it's possible... And that's what you wrote you want to do. I know one can chainload from grub legacy to grub2 - that I have done for a long time, because I prefer to have grub legacy in mbr, and I just quite recently realized I can use that same menu.lst to boot all distros. From grub legacy you can chainload to any bootloader that is installed in a partition, and I guess you can do that from grub2 too.

When you have a separate partition for grub, that grub is not connected to any of the installed distros. Actually, if you want to only use one grub, you could even remove grub from all your installed distros... I wouldn't recommend it, it's easier to reinstall grub in mbr if its overwritten (or if you need to move the grub partition, or for whatever reason), if you have the same version of grub installed in one of the installed distros.

Last edited by Lennie (2012-08-25 15:18:22)

Offline

#9 2012-08-25 15:42:49

Lennie
Member
From: Sweden
Registered: 2011-10-12
Posts: 146

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

I found this

Another Bootloader

Chainloading other bootloader is fairly easy if there's support in GRUB2 for that specific bootloader. Otherwise, one could use a man in the middle or another bootloader in other words to do the task if necessary. In the latter case, one could use GRUB4DOS as it has functionalities similar to GRUB LEGACY. This is required when loading another bootloader like TrueCrypt become problematic in a single multiboot disk, otherwise something as simple as the following is enough to boot another disk with whatever bootloader.
Code

menuentry "WHATEVER" {
     insmod part_msdos
     insmod chain
     chainloader (hd1,1)+1

}

Offline

#10 2012-08-25 17:32:13

alphe
Member
Registered: 2009-03-30
Posts: 18

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

After I realized that I can chainload  from grub-legacy to grub2 at least I have finished with the half setup.

Now I have installed and configured grub2 in the Arch partition and I use grub-legacy in the dedicated grub partition. Just for future reference these are the lines in menu.lst for this

title  Arch Linux
savedefault
root (hd0,3)
kernel /boot/grub/i386-pc/core.img

But when I try to install grub2 in the dedicated grub partition using

grub-install --root-directory=/media/grub /dev/sdb

I get the following error

 /usr/sbin/grub-bios-setup: warning: this LDM has no Embedding Partition; embedding won't be possible.
/usr/sbin/grub-bios-setup: error: embedding is not possible, but this is required for RAID and LVM install.

Any idea?

And another question: suppose that I want to remove the dedicated grub partition and tell to MBR to boot to the Arch partition directly (sdb4). How can I do it?

Thanks.

Offline

#11 2012-08-25 18:22:53

Lennie
Member
From: Sweden
Registered: 2011-10-12
Posts: 146

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

Just to make it clear: You have grub legacy in your grub partition and grub legacy in mbr? And now you want to have grub2 in your arch partition and chainload to it?

Then you should not install grub2 in mbr (there you should have grub legacy), but in your arch partition. You need to use force to install grub2 to a partition.

About the error: If you want to have grub2 in mbr you need to have 2 mb gap before the first partition, because grub2 is too big for mbr. I guess the error you get is because you don't have that gap.

If you want to use Arch's grub from Arch's partition, instead of your grub partition, you need to install it's grub in mbr. (And make that 2 mb gap.)

To make it easier to understand, Grub sits in mbr and only knows about the exact sector where it's second file is (stage1.5 or stage2 for grub legacy and core.img for grub2), where it will get instructions of what to do next (what boot menu to show). If that file is moved, or if you want it to use another file on another partition, you need to reinstall it to tell it where that file is located.

Grub can also sit on a partition, and there it also only knows about either stage(1.5 or 2)  or core.img.

Last edited by Lennie (2012-08-25 18:33:37)

Offline

#12 2012-08-25 20:01:07

Lennie
Member
From: Sweden
Registered: 2011-10-12
Posts: 146

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

I really like the Boot Info Script. It's a great tool to diagnose boot problems, or to just get information about your boot loader(s).

Here's a snippet from my netbook:

=============== Boot Info Summary: ==============
 => Grub Legacy (v0.97) is installed in the MBR of /dev/sda and looks on the 
    same drive in partition #1 for /grub/stage2 and /grub/menu.lst.
 => Windows is installed in the MBR of /dev/sdb.

sda1: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        /grub/menu.lst

sda2: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  SYSLINUX 4.05 20120131
    Boot sector info:  Syslinux looks at sector 55149656 of /dev/sda2 for 
                       its second stage. SYSLINUX is installed in the 
                       /boot/extlinux directory. The integrity check of the 
                       ADV area failed.
    Operating System:  Ubuntu 12.04.1 LTS
    Boot files:        /boot/grub/grub.cfg /etc/fstab 
                       /boot/extlinux/extlinux.conf /boot/grub/core.img
<snip>
sda9: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  Grub2 (v1.97-1.98)
    Boot sector info:  Grub2 (v1.97-1.98) is installed in the boot sector of 
                       sda9 and looks at sector 296602923 of the same hard 
                       drive for core.img. core.img is at this location and 
                       looks in partition 12 for (,msdos12)/boot/grub.
    Operating System:  CrunchBang Linux statler
    Boot files:        /boot/grub/grub.cfg /etc/fstab /boot/grub/core.img

As you can see, I have grub legacy in mbr, and because I have a small gap after mbr, there is enough room for stage1_5. Therefore it  looks for stage2. (If there is no gap after mbr, it looks for stage1_5 at an exact sector.)

sda1 is my grub partition.
In sda2 I have installed syslinux (and grub2), but I don't use any of them.
In sda9 I have installed Grub2. As you can see it looks for core.img at an exact sector, and this script also shows that that file is there.

But there is a problem, core.img looks for files in sda12, which is not what it once was. Sda9 was once called sda12, but I deleted a few logical partitions, and all logical partitions with higher number got changed number. I think there must be 2 core.img, one residing at sector 296602923 which was embedded there when I installed grub to this partition, and another one in /boot/grub folder. I can't use "chainloader +1" (which should work if grub2 is installed in the partition, but it's not recommended...) then Grub2 says "file not find", but I can use "kernel /boot/grub/core.img" which finds grub.cfg and shows the boot menu.

I guess this means you don't need to install grub in Arch's partition, just  create core.img.

I hope you find this as interesting as I do... wink

Offline

#13 2012-08-25 20:42:45

alphe
Member
Registered: 2009-03-30
Posts: 18

Re: [solved] Upgrading to grub2 a system with a dedicated boot partition

Lennie, thank you very much for your valuable help.

I did not find what was the issue and the grub-install failed but I managed to solve it by converting the partition table to GPT. I assume that something was wrong with the msdos partition table. After the conversion the grub-install finished without errors.

Just for the record here is the output of bootinfoscript from my system as it is now

============================= Boot Info Summary: ===============================

 => Grub Legacy (v0.97) is installed in the MBR of /dev/sda and looks on the 
    same drive in partition #1 for /boot/grub/stage2 and /boot/grub/menu.lst.
 => Grub2 (v1.99) is installed in the MBR of /dev/sdb and looks at sector 2048 
    of the same hard drive for core.img. core.img is at this location and 
    looks in partition 99 for .

sda1: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info: 
    Operating System:  Arch Linux ()
    Boot files:        /boot/grub/menu.lst /etc/fstab

sda2: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info: 
    Operating System:  Debian GNU/Linux 6.0
    Boot files:        /boot/grub/grub.cfg /etc/fstab

sda3: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        

sdb1: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        

sdb2: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        /boot/grub/grub.cfg

sdb3: __________________________________________________________________________

    File system:       BIOS Boot partition
    Boot sector type:  Grub2's core.img
    Boot sector info: 

sdb4: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  Grub2 (v1.99)
    Boot sector info:  Grub2 (v1.99) is installed in the boot sector of sdb4 
                       and looks at sector 14853173 of the same hard drive 
                       for core.img. core.img is at this location and looks 
                       in partition 99 for .
    Operating System:  Arch Linux ()
    Boot files:        /boot/grub/grub.cfg /etc/fstab

sdb5: __________________________________________________________________________

    File system:       swap
    Boot sector type:  -
    Boot sector info: 

sdb6: __________________________________________________________________________

    File system:       ext3
    Boot sector type:  -
    Boot sector info: 
    Operating System:  Ubuntu 10.04.1 LTS
    Boot files:        /boot/grub/menu.lst /etc/fstab

Thanks again for your time smile

Offline

Board footer

Powered by FluxBB