source: src-sh/pc-extractoverlay/ports-overlay/usr/local/etc/grub.d/30_os-prober @ 8a9837c

9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 8a9837c was 8a9837c, checked in by Kris Moore <kris@…>, 10 months ago

Improve BE description at GRUB menu
Add detection for Microsoft Windows to GRUB menu

  • Property mode set to 100755
File size: 2.4 KB
Line 
1#!/bin/sh
2#
3# Copyright 2013 iXsystems (Kris Moore)
4# All rights reserved
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted providing that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26
27# Script to detect other NON BSD OS's and add to grub.cfg
28
29check_ntfs_part()
30{
31   if [ "$3" = "MBR" ] ; then
32     cDisk="${1}s${2}" 
33   else
34     cDisk="${1}p${2}" 
35   fi
36   # Check the partition for a boot sector
37   glabel status ${cDisk} 2>/dev/null | grep -q "System Reserved"
38   if [ $? -ne 0 ] ; then return ; fi
39   cat << EOF
40menuentry "Microsoft Windows ($cDisk)" {
41   insmod ntfs
42   set root(hd${dNum},$2)
43   chainloader +1
44}
45EOF
46}
47
48dFile="/tmp/.disk-probe.$$"
49dNum="0"
50
51# Start by looking for disks
52for disk in `cd /dev/ && ls ada[0-9] da[0-9] 2>/dev/null`
53do
54   if [ -e "$dFile" ] ; then rm $dFile; fi
55   gpart show $disk 2>/dev/null >${dFile}
56   pType=""
57   while read dLine
58   do
59     echo "$dLine" | grep -q '=>' 
60     if [ $? -eq 0 ] ; then
61        pType=`echo $dLine | awk '{print $5}'`
62        continue
63     fi
64     fsType=`echo $dLine | awk '{print $4}'`
65     fsPart=`echo $dLine | awk '{print $3}'`
66     case $fsType in
67          ntfs) check_ntfs_part "$disk" "$fsPart" "$pType" ;;
68             *) ;; # Unknown / unsupported FS - Add more here!
69     esac
70
71   done < $dFile
72
73   # Increment our disk counter
74   dNum="`expr $dNum + 1`"
75done
76
77rm $dFile
Note: See TracBrowser for help on using the repository browser.