pavement

Category:Common Tasks

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
== How to Use Grub Bootloader on FreeBSD ==
 
<Jiafu He>jiafu_he at yahoo.com, 05/18/2004
 
This mini-howto is written as a dummy introduction on how to get,
 
install, setup and use GNU/Grub bootloader on FreeBSD. If you need
 
more detailed information, go read the Grub mannual at
 
http://www.gnu.org/manual/grub/html_mono/grub.html
 
Note: UFS2 is supported starting from the verion Grub-0.94_3.
 
1. Obtaining Grub files:
 
  To use Grub on FreeBSD UFS2, you need files "stage1", "stage2" and
 
  "ufs2_stage1_5". To handle other types of file systems, you need
 
  other stage 1.5 files like "ffs_stage1_5", "e2fs_stage1_5", or
 
  "fat_stage1_5" etc.
 
  You can obtain the files from either
 
  i. the GNU/Grub website http://www.gnu.org/software/grub/
 
  ii. or FreeBSD Grub port. Grub-0.94_3 requires freebsd 5.2.1 or
 
      current. To install Grub-0.94_3, do the following:
 
  -------------------------------
 
  #cd /usr/ports/sysutils/grub  /* go to the grub freebsd port dir */
 
  #make install clean    /* install it */
 
  -------------------------------
 
  If all goes well, the Grub files are generated in directory
 
  /usr/local/share/grub/i386-freebsd/ and the executable "grub" is
 
  installed under /usr/local/sbin/
 
2. Installing Grub on UFS2 partition:
 
  i. Create /boot/grub/ directory (or alternatively /grub/) on your HD
 
      and copy files in it:
 
  -----------------------------------------------
 
  #cd /boot;mkdir grub
 
  #cp -Rf /usr/local/share/grub/i386-freebsd grub
 
  -----------------------------------------------
 
  Make sure at least files "stage1" and "stage2" are under /boot/grub/. To be
 
  complete, the pertinent stage 1.5 file (here "ufs2_stage1_5") is also needed.
 
  ii. Create Grub boot floppy. You can either
 
    a. using "dd" (recommended):
 
    -----------------------------------------------
 
    #dd if=stage1 of=/dev/fd0 bs=512 count=1 /* stage1 to block #1 */
 
    1+0 records in
 
    1+0 records out
 
    #dd if=stage2 of=/dev/fd0 bs=512 seek=1 /* stage2 starting from block #2 */
 
    153+1 records in
 
    153+1 records out
 
    #
 
    -----------------------------------------------
 
    b. or alternatively using Grub "setup" under FreeBSD:
 
    -----------------------------------------------
 
    #fdformat -f1440 /dev/fd0  /* low level format the floppy if you want to */
 
    #newfs -LGrubBoot -O1 /dev/fd0 /* format into UFS1 */
 
    #mount /dev/fd0 /mnt
 
    #mkdir /mnt/boot
 
    #cp -Rf /usr/local/share/grub/i386-freebsd /mnt/boot/grub
 
    #touch /mnt/boot/grub/menu.lst /* touch and edit menu.lst, see step 3 */
 
    #umount /mnt
 
    #grub
 
    grub> device (fd0) /dev/fd0  /* set the device map */
 
    grub> root (fd0)
 
      Filesystem type is ffs, using whole disk
 
    grub> find /boot/grub/stage1 /* verify whether the required files are there */
 
      (fd0)
 
    grub> setup (fd0) /* setup the floppy */
 
      Checking if "/boot/grub/stage1" exists... yes
 
      Checking if "/boot/grub/stage2" exists... yes
 
      Checking if "/boot/grub/ffs_stage1_5" exists... yes
 
      Running "embed /boot/grub/ffs_stage1_5 (fd0)"... failed (this is not fatal)
 
      Running "embed /boot/grub/ffs_stage1_5 (fd0)"... failed (this is not fatal)
 
      Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.lst "
 
      ... succeeded
 
    Done.
 
    -----------------------------------------------
 
3. Touch and edit "/boot/grub/menu.lst". An example is given below, assuming that
 
    - partition 0: Windows XP;
 
    - partition 1: FreeBSD;
 
    - partition 2: Linux.
 
  -------------------------------------------
 
  default saved  # boot the last selection. Work together with savedefault below
 
  timeout 10  # timeout 10 seconds
 
  password --md5 $1$rEjBN0$0J06NigS.2ImTaipPOh0w/ # md5 passwd encryption: "testgrub"
 
  # Boot Windows XP. You have to chainloading.
 
  title Windows XP Professional  # display boot title on the Grub prompt
 
  root (hd0,0)  # set the root device or partition
 
  makeactive  # set the partition active so that next time it can be automatically
 
              # booted after timing-out
 
  chainloader +1  # Here we have to chainload
 
  savedefault  # save this selection as the default for next bootstrap
 
  # Boot FreeBSD
 
  title FreeBSD 5.1_p16
 
  root (hd0,1,a)
 
  kernel /boot/loader  # specify the kernel or kernel loader
 
  makeactive
 
  savedefault
 
  # Boot Redhat Linux
 
  title Redhat Linux
 
  root (hd0,2)
 
  kernel /boot/vmlinuz-2.4.18-14smp ro root=LABEL=/ hdc=ide-scsi
 
  initrd /boot/initrd-2.4.18-14smp.img
 
  makeactive
 
  savedefault
 
  # Install Grub on Slice 1 (the FreeBSD partition)
 
  title Install Grub on FreeBSD (Slice 1)
 
  root (hd0,1,a)
 
  setup (hd0)
 
  savedefault
 
  ---------------------------------------------
 
4. Install Grub to MBR on your hard disk (using grub native way):
 
  i. Boot the machine using the floppy just created;
 
  ii. on the Grub menu screen, you can either make use of the last menu entry
 
      (see menu.lst above) or do the following:
 
      -----------------------------------
 
            :
 
      (Grub menu screen)
 
            :
 
      p  # password is needed since the password line is in config file.
 
      password: testgrub
 
      c  # enter command prompt
 
      Then you enter the command prompt:
 
      grub> find /boot/grub/stage1  /* find which partition has Grub files */
 
      (hd0,1,a)  /* it will display the found parition */
 
      grub> root (hd0,1,a)
 
      Filesystem type is ufs2, partition type 0xa5
 
      grub> setup (hd0)  /* install Grub in MBR */
 
      Checking if "/boot/grub/stage1" exists ... yes
 
      Checking if "/boot/grub/stage2" exists ... yes
 
      Checking if "/boot/grub/ufs2_stage1_5" exists ... yes
 
      Running "embed /boot/grub/ufs2_stage1_5 (hd0)"... 16 sectors embeded.
 
      succeeded
 
      Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p
 
      (hd0,1,a)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
 
      ------------------------------------
 
5. Finally how to generate md5-encrypted password:
 
  Enter any Grub command prompt:
 
  grub> md5crypt  /* call the md5 password encryption utility */
 
    password: yourDesiredPassword  /* passwd are replaced by same number of "*" */
 
    EncryptedPassword  /* encrypted password is returned here, put it in config file */
 
  
[[Category: Common Tasks]]
 

Revision as of 13:22, 18 February 2008

Pages in category "Common Tasks"

The following 114 pages are in this category, out of 114 total.

A

B

C

D

E

F

G

H

I

K

L

M

N

O

P

Q

Q cont.

R

S

T

U

W

Personal tools