Multi-Booting with Legacy Grub and Grub2

Summary: When Ubuntu changed to Grub 2 a couple of releases ago, it became significantly more difficult to set up multi-boot Linux systems. Most if not all Ubuntu derivatives are also using Grub2, and now the latest Debian release also uses it.

When Ubuntu changed to Grub 2 a couple of releases ago, it became significantly more difficult to set up multi-boot Linux systems. Most if not all Ubuntu derivatives are also using Grub2, and now the latest Debian release also uses it. There are probably a lot of ways to set up multi-booting between these two; I will detail here what I do, which I think is reasonably simple and doesn't impose too many limits or inconveniences.

First, if you are willing to let a Grub2 system be the primary bootloader, everything will be pretty simple because the update-grub utility will generally figure out the other installed systems. But if you want a Legacy Grub system to be the primary bootloader, you'll have some work to do to get it to work with Grub2 partitions. The simplest solution that I have found is to install Grub2 to the root partition of the other installations, and then "chainload" from Legacy Grub to those, so Grub2 will still take care of actually booting them.

Of course, there are several routes that you might take to get to this final configuration, depending on what order you install the distributions. Let's suppose that you have a Grub2 system already installed (such as Ubuntu), and you want to install a Legacy Grub system (such as openSuSE) and set up multi-booting. What you need to do, before installing the new system, is set up Grub2 in the root partition of the existing installation. That is done with the command:

sudo grub-install --force /dev/sda1

You have to replace sda1 in this command with whatever your root partition might be. This will install the Grub2 bootloader, and will caution you that this is not a particularly good idea. Once this is done, you can go ahead and install the additional distribution, and let it install Legacy Grub to the MBR of the disk, thus making itself the primary bootloader. When that is done, you need to add three lines to /boot/grub/menu.lst:

title Ubuntu 10.10 root (hd0,0) chainloader +1

This again assumes that Ubuntu was already installed in /dev/sda1, so you might have to adjust the partition number to match your installation. Remember that Legacy Grub counts partitions from zero, so the number here will be one less than the /dev/sdaX number.

When you reboot after this, you will see Ubuntu in the boot menu, and if you select it the system will actually reload with the Grub2 bootloader, and you will get the Ubuntu boot menu.

If you start from the opposite end, with a Legacy Grub distribution already installed, the procedure is pretty much the same. In fact, when installing most Grub2 distributions you will usually have the opportunity to tell it to install the bootloader to the root partition rather than the MBR, but since this option is often buried in some obscure place, or it works in some way that I don't quite understand or expect, I always choose to just let it install itself normally and take over as the primary bootloader - it will see the existing Linux installation, and will add it to the Grub2 configuration. Once the installation is done, I log in and run grub-install as described above, then reboot again. When the boot menu comes up, this time I select the original (Legacy Grub) installation. I then login to that, edit the menu.lst file as desribed above to add the new Grub2 installation, and then restore Legacy Grub as the primary bootloader with these commands:

# grub root (hd0,2) setup (hd0)

Once again, this assumes that the Grub2 distribution is on /dev/sda3, you should adjust the partition number as necessary.

As I said at the beginning, this is just the way that I handle Grub co-existance. There are certainly other ways to do it, I pretty much figured this out on my own. It works pretty well for me, although it can get fouled up and require repair if another distribution is installed. If there are better, simpler or easier solutions, I would be happy to hear about it.

jw 26/3/2011

Topic: Linux

About

I started working with what we called "analog computers" in aircraft maintenance with the United States Air Force in 1970. After finishing military service and returning to university, I was introduced to microprocessors and machine language programming on Intel 4040 processors. After that I also worked on, operated and programmed Digital Equipment Corporation PDP-8, PDP-11 (/45 and /70) and VAX minicomputers. I was involved with the first wave of Unix-based microcomputers, in the early '80s. I have been working in software development, operation, installation and support since then.

Kick off your day with ZDNet's daily email newsletter. It's the freshest tech news and opinion, served hot. Get it.

Talkback

13 comments
Log in or register to join the discussion
  • @jamie,
    The idea of a Grub menu, which then boots into another Grub menu is a tad confusing. I prefer Acronis OS Selector, which boots to Grub on the individual primary linux partition (Ubuntu in my case)

    A handy tip using Acronis OS Selector, is to make all primary partitions unhidden/visible when editing the partition table using Acronis Disk Director, with the Acronis Boot Partition (usually installed under WinXP primary partition as 'active' & unhidden/visible.
    This is not the normal Master Boot Record (MBR) Partition Table layout - which should have 1 primary partition active and the other 3 (max) primary partitions hidden, to form a 'proper MBR Partition Table layout' - only one partition should be visible and active at any one time.
    But this is then 'corrected' on the fly by Acronis OS Selector on boot. (Additionally with Win7-I remove the separate Win7 Boot loader, but this does remove recovery menu option)

    The key here to getting this right, is to then use Acronis OS Selector software Advanced setting to hide the partitions not required, based on each bootable OS, as each partition boots.
    This method prevents an OS from staying hidden after selecting a different OS from Acronis - and getting 'No operating system found' etc, which has the appearance of losing your OS.

    Another handy tip, recently encountered regards Windows 7 SP1, this often fails on systems running any boot loader management/multiple operating systems. You have to disable Acronis OS Selector, and setup the MBR Record in its proper format temporarily, ie. Win7 Active, unhidden - all other primary partitions hidden. Windows 7 SP1 then installs without error.

    Anyway, I'm not sure WinXP/Win7 is permitted anywhere near your partitions, but others might find it useful. Unrelated, but I currently find it impossible to mention IE9 & 'Windows Phone 7' without yawning, I probably need a few zzz's or is that Zunes.

    Most people now work 'across platform', whether that be phone/mac/win etc - so I find the idea of a 'latest technology' browser that only works in one environment about 10 year out of date, but have to admit, ie9 its a lot nicer than ie6-ie8, buggy? we'll see, well someone else will, because haven't any intention of using it.
    adamjarvis
  • @Jamie. Thanks for this very full explanation which seems to be the most plausible way of dealing with the situation, i.e. multiple Linux installations in constant flux.

    Unfortunately, in the meantime, I tried something else and have temporarily, I hope, locked myself out of my nice shiny new netbook which was just taking shape as my primary device.

    @ Adam. I'll study Acronis, which is a Linux/Unix based product, but I'm not clear how it copes with frequent changes to one's Linux installations. Since my Netbook comes with 3 primary partitions I do have to work with extended partitions for all my Linux installations.
    The Former Moley
  • @adam - Thanks for the excellent comment. I understand what you mean about the multiple-nested-chainloaded Grubs getting confusing, that is one reason why I didn't bother trying to figure out how to set up chainloading from Grub2 back to Legacy Grub as well. When I am trying to boot and end up in a position I don't want to be in, I hit ctl-alt-del and start over. I can only please laziness as an excuse for all of this... However, to be honest, my head was spinning a bit after reading your Acronis solution as well. Maybe there just isn't a really "simple" way to handle this not-necessarily-simple situation.

    In fact I do still have a few Windows partitions around, primarily for reference when friends ask questions or need help. In fact I believe that I currently have one of each XP/Vista/Win7, distributed across three different computers. But I also always have extended partitions, as I create a total of 15 partitions on each system to hold the various Linux distributions I install, and whatever partitions are necessary for Windows, Recovery and the like.

    @Moley - Ugh, I hope you don't have too much trouble getting it fixed. I suspect that you have run into the situation I was referring to above when I said "it can get fouled up and require repair...". If I happen to end up with no bootable partition, I generally fall back on a LiveCD image of a Legacy Grub distribution (openSuSE most times), and then configure and copy Grub to the MBR as described above. Good luck.

    jw
    j.a.watson@...
  • This is what I do using legacy grub. The strategy also worked with grub2 while I had the latest ubuntu running for a few days to try it out. (I normally use fedora, but was trying alternatives, including Arch and Ubuntu for a while because fedora could not handle the Intel graphic card on my Dell Latitude E6410. That changed with Fedora 15Alpha)

    For the multi-OS strategy I duplicate what happens with a kernel upgrade: the old kernel and associated files are kept n /boot providing a fallback kernel, and the entries for booting old and new kernels go in /boot/grub/grub.conf
    To allow the boot directory and grub stuff to be shared between different versions of linux I use a separate partition for /boot (currently 300MB in /dev/sda6 for historical reasons). Before installing a new version of linux I use 'cp -au /boot /home/oldboot' to keep the old boot stuff in the /home partition which I share across versions of linux (or it could be /usr/local/boot since I share /usr/local across versions). I then install the new linux using the boot partition, a new root partition (so far 15-20GB has been more than enough for each root), and also sharing the old swap partition (8GB on a machine with 4GB main memory). After installing a new linux, and booting it up. using the old /home and /usr/local, I copy back the previously saved kernel and startup files to /boot and carefully copy the required portions of the old /boot/grub/grub.conf file into the new one, choosing an order that corresponds to my likely use of the various systems. I also remove or comment out 'hiddenmenu' to make sure that grub actually shows me the available options at boot time. I usually increase the 'timeout' value to 6 or 8 seconds to give me more time to choose what to do when the menu comes up. My current grub.conf is: http://www.cs.bham.ac.uk/~axs/laptop/grub-conf.txt

    Note: I did try the latest Ubuntu for a short time but have now removed it since Fedora suits me much better. I keep arch out of interest, and the fedora 13 as a fallback. I did once make the machine unbootable because of a careless edit of grub.conf, but I find that the Arch 'live' CD makes a wonderful rescue CD. It starts up quickly with no graphical nonsense and allow me to log in as root to give whatever commands I need, providing 'nano' as a very simple but adequate editor for fixing startup files (e.g. /etc/fstab). So I did not have to reinstall.

    See also: http://www.cs.bham.ac.uk/~axs/laptop
    A.Sloman@...
  • I'm a little puzzled. /home contains many hidden files and folders which are, presumably, distribution specific.

    The only time I tried to share /home I ended up with an unworkable computer. I think it was Mandrake and SuSe - a long time ago. I never tried again, I just navigate the file manager as necessary
    The Former Moley
  • @Moley - Sharing /home between different distributions is tricky, and can be dangerous, but it can be done. The first criteria is that you have to have the game uid and gid both of (or all of) the distributions, which is often not the default case. It is also best if you use the same desktop, all the way down to the same version, on all of the systems, so that programs don't get confused over missing or invalid config file options. There are more such things, I think you can get the idea. Another alternative that I have tried once or twice to get around these kinds of problems is to share /home, but use different login names for each different distribution. This works, but it loses a lot of the benefits of the sharing to begin with. It will be interesting to hear how aaron.sloman handles this.

    @aaron.sloman - Thanks for the very interesting information. There are several things you mention that I hadn't thought about, I'll be trying them soon. I don't see, however, how your configuration works when you need to have both Legacy Grub and Grub2 on the same system - as far as I know, they are two totally different bootloaders, in particular with totally different configuration files, and neither can read the other's files. Do you allow for this, or do you just choose one version or the other to be used for booting everything?

    jw
    j.a.watson@...
  • Personally, if I want to install a number of operating systems on one computer, I install the GAG boot manager on the MBR then put individual grub, grub2 or lilo bootloaders in each OS partition. GAG even allows me to install other OSs such as Solaris and BSDs alongside Linux and Windows on the same system.
    anonymous
  • Thanks for feedback. Not everyone's mode of work would allow what I do.
    Moley wrote: "I'm a little puzzled. /home contains many hidden files and folders which are, presumably, distribution specific."
    I start with a "test" user before I install my standard uid, gid in /etc/passwd /etc/group, I always boot into console mode (runlevel 3) and after logging in go into graphic mode using 'startx'. That runs openbox (launched in ~/.xinitrc). I use the same OB config and startup files no matter which version of linux is running. In principle the contents of .config or some other file could cause problems but so far not for me. Maybe that's because I don't use gnome or kde or other heavy-weight tools that tend to be distribution specific. I somehow discovered that I needed these two commands in my ~/.xinitrc file:
    dbus-launch gnome-session
    pulseaudio --start

    Apart from that I start a clock, a couple of xterm windows, and openbox, and I have 10 virtual desktops in which I keep various things going -- not rebooting for weeks or months, just using hibernate (preferably with tuxonice kernel -- not yet available packaged for Fedora 15).

    My firefox and similar config files just work as expected across the distributions (now using firefox 4).

    If I am ever forced to separate out .home files for different OS versions I'll simply move most of /home/me into another partition that is shared, leaving only the top level directory and config files OS specific. (I already make heavy use of symbolic links for sharing things across partitions.)

    J.A.W wrote: "I don't see, however, how your configuration works when you need to have both Legacy Grub and Grub2 on the same system - as far as I know, they are two totally different bootloaders, in particular with totally different configuration files, and neither can read the other's files."

    At present I use only legacy grub (installed by Fedora15). When I played with Ubuntu, it installed grub2, with menu.lst in a new format. But that boot menu had two sub-menus, one in new format one in old so it was easy to copy the relevant booting information from an old grub config file into the relevant fields. in fact grub2 did that for me with some stuff I left in /boot when I installed ubuntu. I found grub2 distinctly slower to start, and was glad to go back to the old grub when I removed Ubuntu and installed F15.
    I have not studied the changes in the new features of grub2, and don't know whether they could have caused me trouble.
    A.Sloman@...
  • I am looking for something very related to that:
    -BIOS boots from HDD0 MBR, then Grub2 takes control and present a menu
    -Depending on what i select i boot Windows (i hate it because i still need it) or other Grub2

    Just to clarify a little:
    /dev/sda -> MBR (Grub2 for first menu)
    /dev/sda1 -> FAT32 xGB BootSector and all for one Windows bla bla bla, exp: W9X
    /dev/sda2 -> NTFS yGB BootSector and all for other Windows bla bla bla, exp: WXP
    /dev/sda3 -> NTFS zGB BootSector and all for another one Windows bla bla bla, exp: W7
    /dev/sda4 -> Extended partition
    /dev/sda5 -> FAT32 4GB for Windows Pagefile (shared for all Windows)
    /dev/sda6 -> EXT4 Linux 32Bits with its own Grub2 menu where i can select kernel, debug, etc
    /dev/sda7 -> EXT4 Linux 64Bits with its own Grub2 menu where i can select kernel, debug, etc
    /dev/sda8 -> Linux SWAP 4GB (Shared for all Linux)
    /dev/sda9 -> EXT4 for /boot for first Grub2 files, where main manu grub.cfg file goes

    It goes all correct if i use old Grub2 versions, but with the new one (latest one when i tried) i got allways the same problem.

    As i said the problem is that i am testing the new Grub2 version (with old versions i did not have any problem)...

    The boot process goes like this:
    -BIOS, then MBR, then Grub2 read file on /dev/sda9 - /boot/grub2/grub.cfg (old versions the file where was on /boot/grub/grub.cfg)
    -Then the menu i manually configure and edit is presented on screen
    -If I select to load any Windows, it goes perfect... cahinloader works well
    -If i select to load the other Grub2 that is on /dev/sda6 or /dev/sda7 it puts the screen on black, put on screen the word GRUB and halts... chainloader fails

    I have seen that new Grub2 can not be fitted onto a Partition Boot sector and it must reside onto Master Boot Record...
    ...continue...
    z666zz666z
  • ...

    Just for people not knowing... MBR can be bigger than 512 bytes... there are some extra sectors just after it that are not been used by partitions, but inside partitions the second sector can not be used for such.

    If i use old Grub2 or Grub1 (originally called only Grub) as Bootloaders on /dev/sda6 and /dev/sda7 there is no problem, works perfect.

    To archive this scheme:
    -I use fdisk /dev/sda to create empty partittions (without any system), just to ensure boot will go correct before installing all Systems
    -I use mount /dev/sda6 /mnt/MyDir
    -Then i use grub-install --root-directory=/mnt/MyDir /dev/sda6
    -Then i use vim /mnt/MyDir/boot/grub/menu.lst to put my personalized boot menu for /dev/sda6
    -Then i use unmount /dev/sda6
    -Same for /dev/sda7
    -Then i use mount /dev/sda9 /boot
    -Then i use grub2-install /dev/sda
    -Then i use vim /boot/grub2/gub.cfg to put my own first boot menu
    -Then i use umount /boot

    That way works perfectly, i can boot with menu on /dev/sda9 - /boot/grub2/grub.cfg then select one option and boot with menu on /dev/sda6 - /boot/grub/menu.lst

    Also it works great with old Grub2 doing like this:
    -I use fdisk /dev/sda to create empty partittions (without any system), just to ensure boot will go correct before installing all Systems
    -I use mount /dev/sda6 /mnt/MyDir
    -Then i use (with old Grub2 version, with new one will fail) grub2-install --root-directory=/mnt/MyDir /dev/sda6
    -Then i use vim /mnt/MyDir/boot/grub/grub.cfg to put my personalized boot menu for /dev/sda6
    -Then i use unmount /dev/sda6
    -Same for /dev/sda7
    -Then i use mount /dev/sda9 /boot
    -Then i use (no matter old Grub2 or new Grub2) grub2-install /dev/sda
    -Then i use vim /boot/grub2/gub.cfg to put my own first boot menu
    -Then i use umount /boot

    That way also works perfectly, i can boot with menu on /dev/sda9 - /boot/grub2/grub.cfg then select one option and boot with menu on /dev/sda6 - /boot/grub/grub.cfg
    ...continues...
    z666zz666z
  • ...

    The problem cames when such /dev/sda6 and /dev/sda7 i want them to use the new Grub2, just when booting the MBR Grub2 loads, shows the menu, let me select, i select one of them... then black screen with only text GRUB on it and hangs!!!

    I need to be able to install and chainload two or three or more Grub2, so i can have a chain of menus at boot.

    For simplifing, try to make this only using new Grub2:
    -Present one menu with two or more options
    -When selecting any of such options... chainload to another partition where is another Grub2 with its own menu

    I could not get that to work... if i use for such second Grub menu the old version of Grub2 or also Grub i can do it perfectly.

    More, what i can do with such old Grub2 and Grub is to add onto that second menu a "Back" option, so it chainloads to MBR and previous menu loads again (without rebooting), so if select wrong option on first menu i can go back.

    With new Grub2 i am getting mad... i can not make it lo be loaded correctly from a partition.

    New Grub2 olny loads correctly from MBR, but there i have my own menu.

    I mean:
    -I want a menu prior to Linux own Boot menu that let you select kernel or recovery, etc...

    Just an example:
    MBR boot will show:
    -Boot Windows 9x
    -Boot Windows XP
    -Boot Windows 7
    -Show boot menu of Linux 32Bits (*Note1)
    -Show boot menu of Linux 64Bits (*Note2)
    -Boot from SystemRescueCD.iso on console [Note: it is possible thanks to Grub2 loop trick]
    -Boot from SystemRescueCD.iso with GUI [Note: it is possible thanks to Grub2 loop trick]
    -Run memetest32
    -Boot from Floppy
    -...etc...
    -Reboot the PC
    -PowerOff the PC (this one i still do not get it to work)

    When option (*Note1) is selected a menu will appear (it is under Linux control, imagine i do not edit it, i just edit it to only add the GoBack option):
    -Kernel bla bla bla
    -Kernel bla bla bla
    -Kernel bla bla bla
    -recovery
    -...etc---
    -GoBak to main menu

    Also the same for (*Note2).
    ...continues...
    z666zz666z
  • Hope it is enough clear what i am trying... but in case it is not... i want a full tree of menus... the main on a /boot dedicated partition not seen by any system, i only edit it by using SystemRescueCD and is only for having the Grub2 main menu and SystemRescueCD.iso file, another one onto each root linux partition (the one that the distro will install, by now only for testing purposes the new Grub2).

    I repeat i can do all with old Grub2 versions (and Grub), is the new one that is making me mad!!!

    Any help?

    How dare can i install Grub2 onto a partition?

    In other words, i need this to work, very, very simplified:
    -fdisk /dev/sda
    -create one partition /dev/sda1
    -create just one more /dev/sda2
    -mkfs.ext4 /dev/sda1
    -mkfs.ext4 /dev/sda2
    (Yes all ext4, no ext3, no ext2, no ntfs, no FAT32, no SWAP, etc... as i said very simplified)
    -mkdir /mnt/MyDir
    -mount /dev/sda2 /boot
    -grub2-install /dev/sda
    -vim /boot/grub2/grub.cfg so i create the main menu that will show another menu on /dev/sda1 - /boot/grub2/grub.cfg
    -umount /dev/sda2
    -mount /dev/sda1 /mnt/MyDir

    What must i do just to let Grub2 install onto /dev/sda1 boot sector?
    -grub2-install --forced --root-directory=/mnt/MyDir /dev/sda1
    That works, put Grub2 there... but when i try to boot, it hangs

    I mean main MBR load GRUB2 from /dev/sda2 and shows main menu, but then when i select to load the other Grub2 from /dev/sda1 it hang, only appears GRUB word.

    I do a lot of test under VirtualBOX just to figure out how to solve it... no succedd!!!

    If i do such second menu using old Grub2 works perfect, loads perfect, etc...

    New one that uses /boot/grub2/grub.cfg not works... Grub2 that uses /boot/grub/grug.cfg work perfect (it cames for example on Ubuntu distros).

    You can try it by your own... use VirtualBOX and SystemRescueCD.iso 2.6.0 (Grub2.00_beta3) ... then use 2.5.1 (Grub2.00_beta2) and it works... it is just Grub2.00_beta3 the one getting me mad!!!

    Thanks in advance for any help.
    z666zz666z
  • Just to that one telling about GAG... for such i preffer XOSL!!!

    The problem is not the first Boot Manager... that works perfect!!!

    The problem is how to install Grub2.00Beta3 onto a partition!!! without touching the MBR.

    As i said i had no problem using Grub2.00Beta2, it is just the last release Grub2.00Beta3 the one getting me mad.

    If i use for first menu GAG, XOSL, Grub, Grub2, Lilo... it does not matter it is just a choice... the problem is that second one (the one on the partition hangs)... and that must be Grub2.00beta3... that is the one i am trying with!!!

    I do not know any serious distro using it (except SystemRescueCD) and hope they did not use it... it is not enough tested... i think there is a serious BUG on Grub2.00Beta3 that was not on Grub2.00Beta2... since i can make Grub2.00Beta2 load from partition but not with Grub2.00Beta3.
    z666zz666z