*BSD not detected by os-prober

Bug #432254 reported by Peter Belew on 2009-09-18
46
This bug affects 8 people
Affects Status Importance Assigned to Milestone
Bootloader Manager
Undecided
Unassigned
os-prober (Ubuntu)
Wishlist
Unassigned

Bug Description

Binary package hint: os-prober

I have a multiboot system with Windows XP, Ubuntu 9.10 alpha, and FreeBSD 7.2 installed. After Karmic Alpha-4 (upgrading with apt-get up to the time of the bug report) installing with Grub 2 in the MBR, the FreeBSD partition is not recognized.

Some system information:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu karmic (development branch)"
Linux lightning 2.6.31-10-generic #34-Ubuntu SMP Wed Sep 16 00:23:19 UTC 2009 i686 GNU/Linux
model name : VIA Samuel 2
cpu MHz : 798.000

General disk layout:

/dev/sda1 - Windows XP
/dev/sda2 - Ubuntu /boot partition
/dev/sda3 - FreeBSD 'slice' containing all BSD partitions
/dev/sda4 - subdivided into remaining partitions for Ubuntu

Previously (with Ubuntu 9.04 and Grub 1) the booting worked well for all 3 OSes.

There is an old Windows 95 drive on /dev/sdb - the OS on that is detected by os-prober. Currently, running os-prober gives me the results:

root@lightning:~# os-prober
/dev/sda1:Microsoft Windows XP Professional:Windows:chain
/dev/sdb1:Windows NT/2000/XP:Windows1:chain
root@lightning:~#

On a similar system runing XP, Ubuntu 9.04, and FreeBSD, the (Grub 1) menu.lst stanza for FreeBSD 7.1 is

# Choice 0: use 1st BSD subpartition in disk 1 partition 3
title FreeBSD 7.1
  root (hd0,2,a)
  kernel /boot/loader

ProblemType: Bug
Architecture: i386
Date: Thu Sep 17 21:13:00 2009
DistroRelease: Ubuntu 9.10
Package: os-prober 1.33
ProcEnviron:
 PATH=(custom, user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
ProcVersionSignature: Ubuntu 2.6.31-10.34-generic
SourcePackage: os-prober
Uname: Linux 2.6.31-10-generic i686

Peter Belew (peterbe) wrote :
Peter Belew (peterbe) wrote :

Note that I can boot into Ubuntu or FreeBSD by

1) use the Windows NT Pro tools to replace the Windows MBR
2) use Linux (Knoppix or another live CD) to make the desired partition bootable instead
    of /dev/sda1
3) reboot.

I have to make sure a boot loader is in the Ubuntu partition /dev/sda2 before doing that! That was the case yesterday under my inital installation of 9.10 alpha 4, when I installed grub in /dev/sda2
Since then, I have updated the system, and grub 2 is in the MBR.

Peter Belew (peterbe) wrote :

I would like to create an entry in grub.cfg by creating a file for that in /etc/grub.d and running ubdate-grub2

I have tried modifying /etc/grub.d/40_custom as follows:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
# This is an attempt to use the GRUB 1 stanza for FreeBSD on this system
menuentry "FreeBSD 7.2" {
        insmod ufs
        set root=(hd0,3,a)
# kernel /boot/loader
        drivemap -s (hd0) ${root}
        chainloader +1
}

But the resulting grub.cfg won't allow me to boot FreeBSD. Perhaps the volume should be identified as (hd0,8), which is what the FreeBSD boot partition looks like when mounted on Linux (I can mount the BSD volumes from Ubuntu all right).

Suggestions are welcome.

Peter Belew (peterbe) wrote :

Actually I have given up on this issue, for all practical purposes. I just installed 9.04 first, then did the online update with Update Manager - which is advertised NOT to replace the legacy GRUB with GRUB 2. The procedure is described here: http://www.ubuntu.com/testing/karmic/alpha5

I do intend to upgrade another system soon, using this procedure.

I would like to hear if the problem of booting FreeBSD (or NetBSD or OpenBSD etc.) from Linux's GRUB 2 has been solved. I have seen references online to a 10_freebsd script, presumably to be put in /etc/grub.d for rebuilding GRUB 2, but I have not actually seen such a file.

Also, there needs to be a clear way to select the legacy GRUB when doing a fresh install of Karmic.

Peter Belew (peterbe) wrote :

I just updated the above Karmic installation (which uses the legacy GRUB 1) and noticed an update of os-prober. In this contact (without GRUB 2 installed) it produces no screen output when run. I would assume this program requires that GRUB 2 is installed, though.

os-prober doesn't require that GRUB 2 is installed - it's a standalone
program, in fact not originally written for use with GRUB 2 at all,
which just needs to be run as root. If it's producing no output, it's
probably because it didn't detect anything (there'll be verbose output
in syslog).

I don't think os-prober has any code to detect BSD systems at all right
now. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=234470 was filed
some time ago about this and I don't see any BSD-related code in the
source.

It would probably not be very hard to add this support, but I don't have
any BSD-based systems to hand. Could you provide technical details of
how to detect FreeBSD reliably? For example:

 * What partition types might it use?
 * What file names might we look for?
 * How could we distinguish FreeBSD from other BSD variants?
 * Any other gotchas you know about?

FreeBSD is installed in one or more primary partitions, which FreeBSD refers to as 'slices'. Then the slices are broken down into partitions, identified by lower-case letters. This subdivision is different from the usual DOS/Windows/IBM scheme of dividing extended partitions.

In Linux fdisk, a FreeBSD 'slice' is shown as type a5, OpenBSD as type a6, NetBSD as a9. You can see that by listing partition types in Linux fdisk. So on one of my systems, the fdisk 'p' command shows that I have

  /dev/sda2 * 19 3665 29294055 a5 FreeBSD

Those partition types will help distinguish FreeBSD from its relatives, but I don't have any experience with the others, so I don't know how they are subdivided in those systems. PC-BSD is derived from FreeBSD, so I assume its partitioning is the same.

Linux can mount FreeBSD partitions, at least read-only. I have the following /etc/fstab entries on the same system:

#bsd partition(s)
# bsd: /dev/ad0s2a
/dev/sda8 /mnt/bsdroot ufs ro,ufstype=ufs2 0 0
# bsd: /dev/ad0s2f
/dev/sda12 /mnt/bsdusr ufs ro,ufstype=ufs2 0 0
# bsd: /dev/ad0s2g
/dev/sda13 /mnt/bsdhome ufs ro,ufstype=ufs2 0 0

The comments show what FreeBSD calls those partitions. You can see how the names are mapped on Linux by looking at

root@lightning:~# cat /proc/partitions
major minor #blocks name

   8 0 78150744 sda
   8 1 144553 sda1
   8 2 29294055 sda2
   8 3 1 sda3
   8 5 11719386 sda5
   8 6 979933 sda6
   8 7 36009666 sda7
   8 8 524288 sda8 '/' on FreeBSD
   8 9 949064 sda9
   8 10 1522688 sda10
   8 11 524288 sda11
   8 12 10485760 sda12 'usr' on FreeBSD
   8 13 15287967 sda13 '/home' on FreeBSD

so they look somewhat like DOS logical partitions inside an extended partition.

For the legacy Grub 1 on the same system, this will boot FreeBSD:

title FreeBSD 7.1
root (hd0,1,a)
kernel /boot/loader

So grub and Linux are able to access the UFS file system on the FreeBSD partitions.

It would probably help to install a minimal FreeBSD on a primary partition on your HD - I'll follow with a bit of information about that.

Peter Belew (peterbe) wrote :

I would suggest downloading the boot-only mini-CD image from here:

ftp://ftp.freebsd.org/pub/FreeBSD/ISO-IMAGES-i386/7.2/

and doing a minimal install after booting from that (it will allow you to install from an FTP site, such as that one). That will take up a whole primary partition ('slice').

During installation, partitioning is done in two stages: first, a primary partition is created or selected to be a FreeBSD slice, then on the next screen you can set up the partitions within that. There's a default option for creating those partitions, which should work fine.

I'm not sure if the root directory (which includes /boot ) is necessarily in partition 'a' of the selected slice.

If you are setting up to run on a system with Windows XP on it, the file /boot/boot0 can be put in the Windows C:\ directory, and the NT/XP BOOT.INI file can be edited to load that in order to boot into FreeBSD (apparently that works if the FreeBSD partition is on the same drive - I've done that, myself).

BTW you can also mount Linux partitions from FreeBSD; one problem, at least in earlier versions, is that the inodes had to be 128 bytes in size - that may have been fixed in FreeBSD 7.2, but I haven't tried that yet (that's part of the reason I set up this test system, but I got sidetracked on the GRUB 2 issue, when I saw the Karmic alphas had come out and tried them!)

Jean.c.h (slug71) on 2009-09-25
Changed in os-prober (Ubuntu):
status: New → Confirmed
Jean.c.h (slug71) wrote :

I confirmed this and duplicated a bug i filed to this one. I have Karmic alpha 6 installed on a system that also has Kubuntu, PC-BSD and ReactOS installed with more OSs to come.

Grub2 or shall i say os-prober did not detect ReactOS nor PC-BSD.

Would be awesome if this can be fixed.

Jean.c.h (slug71) wrote :

I added Grub as affected by this too since im not really sure this is only os-prober related. As i understand it os-prober is only an interim solution for what Grub2 should be able to handle on its own.

Colin Watson (cjwatson) wrote :

Who said os-prober was an interim solution? I see no reason why grub2 should reimplement all the work os-prober has done so far.

(Also, I don't know what ubuntu-bootloader-manager is, but it's not how we manage bugs on the Ubuntu grub2 package ...)

Changed in ubuntu-bootloader-manager:
status: New → Invalid
Changed in os-prober (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → Wishlist
Jean.c.h (slug71) wrote :

This will boot FreeBSD. Add to grub.cfg

menuentry "freebsd" {
 set root=(hd0,x)
       chainloader +1
       boot
}

On my initial attempt to do this, I somehow made the system unbootable.

I have a working installation with the legacy GRUB, but I don't want
to touch that because I am in the middle of doing some work with the
FreeBSD on that system and don't want that to be unbootable.

So I've reinstalled Karmic alpha 6 on the original disk, and am now
updating it. Then I'll try changing the grub.cfg and see if I can boot
into BSD.

On Sat, Sep 26, 2009 at 10:33 AM, Slug71 <email address hidden> wrote:
> This will boot FreeBSD. Add to grub.cfg
>
> menuentry "freebsd" {
>        set root=(hd0,x)
>       chainloader +1
>       boot
> }
>
> --
> FreeBSD not detected by os-prober
> https://bugs.launchpad.net/bugs/432254
> You received this bug notification because you are a direct subscriber
> of the bug.
>

Peter Belew (peterbe) wrote :

I put the following in "40_custom" and then ran update-grub:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "freebsd" {
       set root=(hd0,8)
      chainloader +1
      boot
}

On rebooting, I selected the 'freebsd' entry in the grub menu.

The result was the message "error: no loaded kernel".

My fstab entry for BSD's root partition is

##bsd partition(s)
## bsd: /dev/ad0s2a
/dev/sda8 /mnt/bsdroot ufs ro,ufstype=ufs2 0 0

and that works well.

Perhaps I have to specify the FreeBSD loader as a kernel, or address
the root partition more like the way one does it in legacy GRUB?

On Sat, Sep 26, 2009 at 10:33 AM, Slug71 <email address hidden> wrote:
> This will boot FreeBSD. Add to grub.cfg
>
> menuentry "freebsd" {
>        set root=(hd0,x)
>       chainloader +1
>       boot
> }
>
> --
> FreeBSD not detected by os-prober
> https://bugs.launchpad.net/bugs/432254
> You received this bug notification because you are a direct subscriber
> of the bug.
>

I finally got the boot into FreeBSD to work. Here's what I put in 40_custom before running update-grub:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "freebsd" {
      set root=(hd0,2,a)
      chainloader +1
      boot
}

So the root specification is based on the FreeBSD slice (number) and partition (letter) method of specifying a partition, as in the legacy GRUB, except that the primary partition ("slice") numbering starts at 1 rather than 0.

Problem solved!

Peter Belew (peterbe) wrote :

Actually, the problem of *detection* of FreeBSD or other BSD systems is NOT solved yet, but at least we know how to set up a boot selection for FreeBSD manually.

Colin Watson (cjwatson) on 2010-02-04
summary: - FreeBSD not detected by os-prober
+ *BSD not detected by os-prober

My bug 502938 is essentially the same as this, but specifically for NetBSD.

I hope to be able to put some time in on this 'real soon now'. For the moment the most suitable way to boot NetBSD at least is via chainloader using an os-prober script as above. For NetBSD (doesn't seem to need the slice letter):

#!/bin/sh -e
echo "Adding NetBSD 5.0 on sdb4 to GRUB 2 menu"
cat << EOF
menuentry "NetBSD 5.0.3 on sdb4" {
insmod bsd
set root=(hd0,4)
chainloader (hd0,4)+1
}
EOF

Saved as 21_netbsd

Getting the various flavours of BSD auto-detected is not so simple since the BSDs differ quite a bit.

Is there a reason that the partition type flags shouldn't be used - every BSD has its own flag? Maybe easier than looking at the superblocks which don't seem too well documented - maybe I've not looked in the right place yet....

I've now got os-prober to detect and create chainloader menu stanzas for NetBSD and FreeBSD.
The key is to call blkid again with the -p option when a UFS partition is detected to return the ufs type and to mount the partition with the proper ufstype parameter to the mount commant.

To use the native GRUB commands will require more work. However since both NetBSD and FreeBSD provide their own boot menus when chainloaded to allow the user to do such things as boot single-user etc there may not be any mileage in using the native GRUB commands, certainly on FreeBSD where there doesn't seem to be any way of bypassing the FreeBSD boot menu.

Unfortunately blkid, on my test machine at least, intermittently finds two copies of FreeBSD, the second a duplicate of the real one but in a 'phantom' partition. And blkid doesn't recognise an OpenBSD partition at all - presumably because the ufs-magic numbers don't match.

So if a short term 'fix' is required then the best thing may be to have the 50-mounted script emit a suitable message when a UFS partition is detected, pointing the user to a set of example stanzas per Peter Belew's example for FreeBSD above.

I will continue to look at blkid as time permits.

The easy way to blkid doesn't recognise a

Peter Belew (peterbe) wrote :

I'm glad to see some progress is being made in this problem! - Peter Belew

Andrey Gavrilin (gaal-dev) wrote :

I did it.

50mouted-tests:

  if [ "$type" = ufs ]; then
   for ufstype in ufs2 44bsd; do
    if mount -o ro,ufstype=$ufstype -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
     mounted=1
     break
    fi
   done
  else
   if mount -o ro -t "$type" "$partition" "$tmpmnt" 2>/dev/null; then
    mounted=1
   fi
  fi

50linux-distro:

known_distro=(

90bsd-distro:

if [ "$type" = ufs ]; then
  pattern_disk='([[:alpha:][:punct:]]+)[[:digit:]]+'
  pattern_system="$partition[[:blank:]]+\*[[:blank:]]+.+[[:blank:]]+(.+)BSD"

  system=

  if [[ "$partition" =~ $pattern_disk ]]; then
    disk="${BASH_REMATCH[1]}"

    while read line; do
      if [[ "$line" =~ $pattern_system ]]; then
        system="${BASH_REMATCH[1]}BSD"
        break
      fi
    done< <( fdisk -l $disk )
  fi

  if [ ! -z $system ]; then
    if [ -f $dir/etc/motd ]; then
      pattern_version=

      case $system in
      FreeBSD | NetBSD | OpenBSD) pattern_version="$system[[:blank:]]+([[:graph:]]+)[[:blank:]]+(\([[:graph:]]+\))"
                                  ;;
      esac

      title="$system"

      if [ ! -z $pattern_version ]; then
        while read line; do
          if [[ "$line" =~ $pattern_version ]]; then
            title="$system ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}"
            break
          fi
        done< <( cat $dir/etc/motd )
      fi
    fi

    label="$(count_next_label "$system")"
    echo "$partition:$title:$label:chain"

    exit 0
  else
    exit 1
  fi
else
  exit 1
fi

Rafał Szkodziński (rafszk) wrote :

Try to install ufsutils, restart your computer, and then do the 'grub-mkconfig'. These steps helped me.

Peter Belew (peterbe) wrote :
Download full text (3.7 KiB)

This problem, at least for FreeBSD, seems to have been solved in 12.04 "Precise Pangolin":

I just upgraded a system from 11.04 to 11.10, then to 12.04 yesterday. It has Ubuntu, Windows XP, and FreeBSD 8.1 installed in it, similar to the configuration of the system I originally reported this bug on. (That system, with a C3 CPU, won't run recent versions of Ubuntu, and now has a recent 486 version of Debian on it).

Ubuntu version and kernel version
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
Linux billy 3.2.0-24-generic #37-Ubuntu SMP Wed Apr 25 08:43:52 UTC 2012 i686 i686 i386 GNU/Linux
model name : Intel(R) Celeron(R) CPU 1.70GHz
cpu MHz : 1691.571
MemTotal: 2029480 kB
SwapTotal: 522076 kB

Partitioning looks like:
# fdisk -l /dev/sda

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8f800000

   Device Boot Start End Blocks Id System
/dev/sda1 63 81915434 40957686 7 HPFS/NTFS/exFAT
/dev/sda2 81915435 82493774 289170 83 Linux
/dev/sda3 * 82493775 192715739 55110982+ a5 FreeBSD
/dev/sda4 192715740 312576704 59930482+ 5 Extended
/dev/sda5 192715803 217295189 12289693+ 83 Linux
/dev/sda6 217295253 218339414 522081 82 Linux swap / Solaris
/dev/sda7 218339478 312576704 47118613+ 83 Linux

/dev/sda2 is a /boot partition
/dev/sda5 is "/"
/dev/sda7 is "/home"

After running update-grub, the stanzas for Windows XP and FreeBSD in /boot/grub/grub.cfg now look like

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Microsoft Windows XP Professional (on /dev/sda1)" --class windows --class os {
        insmod part_msdos
        insmod ntfs
        set root='(hd0,msdos1)'
        search --no-floppy --fs-uuid --set=root 127855CF7855B1E9
        drivemap -s (hd0) ${root}
        chainloader +1
}
menuentry "FreeBSD 8.1-RELEASE (GENERIC) (on /dev/sda3)" --class windows --class os {
        insmod part_msdos
        insmod ufs2
        set root='(hd0,msdos3)'
        search --no-floppy --fs-uuid --set=root 4b2e8da4ae6a55e3
        drivemap -s (hd0) ${root}
        chainloader +1
}
### END /etc/grub.d/30_os-prober ###

I believe there is a FreeBSD bootloader in /dev/sda3. At any rate, when I select the FreeBSD entry in the Grub2 menu, it loads the FreeBSD bootloader, which displays the usual boot options.

Previously, I had this content in /etc/grub.d/40_custom:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
#
menuentry "FreeBSD 8.1" {
      set root=(hd0,3)
      chainloader +1
}

After upgrading to "precise", there were 2 entries for BSD in the Grub2 boot menu: the one produced automatically and the one produced by my 40_custom file. So I commented out the FreeBSD stuff ...

Read more...

Peter Belew (peterbe) wrote :

This should be checked for NetBSD, OpenBSD, PC-BSD, ReactOS, etc., especially the BSDs, by interested persons.

Peter Belew (peterbe) wrote :

I have just installed PC-BSD in the sda3 partition of a system with XP and Ubuntu 12.04 installed in it. Previously, update-grub detected FreeBSD and NetBSD installations in the same partition (BSD slice ada0s3).

However, update-grub failed to detect the PC-BSD partition. I tried creating a boot stanza in the 40_custom file, but update-grub failed to make that partition bootable.

This ('billy') is a different computer from my earlier comments - that system is pre-686 and won't run recent Ubuntus. However the disk is laid out similarly. I don't know if the PC-BSD installer installed a boot loader at the beginning of sda3.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.