Appendix A: GRUB Dual-Boot OS Switching

Installing Windows and then Linux operating systems on each node ensures that the GRUB is installed as the bootloader. Before continuing, verify that GRUB is able to manually boot both operating systems. Leave the Linux partition as the default. The partition table should appear as follows when finished:

  1. NTFS (Windows) (hd0,0)
  2. EXT3 (Linux) (hd0,1)
  3. Swap (Linux)

If your partition scheme is different, you can look up the partitions using a partition editor, or by reading GRUB's menu.lst file (usually located at /boot/grub/menu.lst).

Note For sites planning to redeploy frequently, consider installing GRUB to the Linux partition instead of the master boot record (MBR) because Windows overwrites the MBR (every subsequent deployment), which could cause you to lose access to an MBR-based GRUB configuration.

PXE booting is the recommended dual-boot method, but the following offers instructions for automating dual-boot OS switching using GRUB.

Instructions for automating dual-boot operating system switching assume that you are installing a Linux system that uses the GRand Unified Bootloader (GRUB). Note that you should set up dual-booting only on compute nodes. To automate dual-boot operating system switching, during the Linux installation, manually partition the drive. To do so:

  1. 1 (ext3) primary partition, right after the Windows partition, mounted at "/".
  2. 1 FAT32 partition (primary or extended) of at least 256 MB mounted at /boot/otheros.
  3. 1 extended partition for swap.
  4. Note which partition number the FAT32 partition is. If it is the third primary partition, it will usually be sda3, or if it is an extended partition, it will be greater than 4. You can look this up using the gparted partitioning utility.

Note After following these steps, there should be two grub.conf files, one at /boot/grub and one at /boot/otheros. The grub.conf file at /boot/otheros should not be a symlink to the grub.conf file at /boot/grub.

Post Linux Installation Steps for Dual-Boot Setup

  1. Copy all the files in /boot/grub to /boot/otheros:
  2. > cp /boot/grub/* /boot/otheros
  3. Create a symbolic link from /boot/grub/menu.lst to /boot/grub/grub.conf. To create the link, issue the following commands:
  4. > cd /boot/grub
    > rm menu.lst
    > ln -s grub.conf menu.lst
  5. Copy and paste the following text into the /boot/grub/grub.conf file, immediately preceding the first "title" line:
  6. title BOOT REDIRECT: PLEASE WAIT
    root (hd0,2)
    configfile /menu.lst
    boot

    Please note that the preceding text should be the first "title" entry in the list of boot options in /boot/grub/grub.conf. Also, make this title the default boot option (i.e. default 0); this will allow you to boot your system to a known partition if anything goes wrong during the boot redirect setup.

    Also note that in the preceding sample code, the numeral 2 in the line root (hd0,2) represents the FAT32 partition; you should replace the 2 in that line with your FAT32 partition number.

  7. Save and close the file.
  8. Copy the following sample code and save it in a file named switchos.pl and place it in /boot/otheros/.
  9. #Contents of the switchos.pl file (used by Moab to change the OS)
    #!/usr/bin/perl
    use strict;
    use warnings;
    my $default;
    my $file;
    my ($os) = @ARGV;
    $os = "" unless defined $os;
    $file    = 'menu.lst';
    if ( $os eq 'linux' )
      {
      $default = 0;
      }
    elsif ( $os eq 'windows' )
      {
      $default = 2;
      }
    else
      {
      die "Usage: switch.pl <windows|linux>";
      }
    my $menu = <<__END__;
    # grub.conf generated by anaconda
    #
    # Note that you do not have to rerun grub after making changes to this file 
    # NOTICE:  You have a /boot partition.  This means that
    #          all kernel and initrd paths are relative to /boot/, e.g..
    #          root (hd0,5)
    #          kernel /vmlinuz-version ro root=/dev/sda8
    #          initrd /initrd-version.img
    #boot=/dev/sda
    default=$default
    timeout=5
    splashimage=(hd0,5)/grub/splash.xpm.gz
    hiddenmenu
    title Red Hat Enterprise Linux AS (2.6.9-42.ELsmp)
            root (hd0,5)
            kernel /vmlinuz-2.6.9-42.ELsmp ro root=/dev/sda8 rhgb quiet
            initrd /initrd-2.6.9-42.ELsmp.img title Red Hat Enterprise Linux AS-up (2.6.9-42.EL)
            root (hd0,5)
            kernel /vmlinuz-2.6.9-42.EL ro root=LABEL=/dev/sda8 rhgb quiet
            initrd /initrd-2.6.9-42.EL.img
    title Windows HPC 2008
            rootnoverify (hd0,0)
            chainloader +1
    __END__
    open FILE, ">$file";
    print FILE $menu;
    close FILE;
  10. Edit /boot/otheros/switchos.pl to reflect your system configuration. That is, verify the specified disk and FAT32 partition values are correct. If you want, replace the in-line grub.conf (between the __END__ lines) in the file with your own grub.conf. Note the injection of the current boot OS via the Perl variable: default=$default.
  11. Create a file named bootlin.bat that includes the following:
  12. w:
    cd \
    perl switchos.pl linux
  13. Boot into the Windows partition and ensure that you have installed the latest version of Perl.
  14. Assign a drive letter to the FAT32 partition. (Note that w is used in the previous example.)
  15. To switch between the Windows and Linux environments, do the following:
    1. Boot into Windows using the following command (run from /boot/otheros):
    2. > ./switchos.pl windows
      > reboot
    3. Change the drive letter of the FAT32 partition to w.
    4. Switch back to Linux by running the following command (from w:\):
    5. > perl switchos.pl linux
      > shutdown /r /t 00 /f

Copyright © 2011 Adaptive Computing Enterprises, Inc.®