All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Reimplement 10_freebsd.in using 10_linux.in
@ 2009-08-07 12:12 Robert Millan
  2009-08-16 19:29 ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Millan @ 2009-08-07 12:12 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]


This patch reimplements 10_freebsd.in using 10_linux.in as a base, with
the kFreeBSD-specific parts of 10_freebsd.in.

The new version brings in support for multiple kernel versions (the reason
for the rewrite) and also handling of acpi.ko.

It is diffed against 10_linux.in, since the old code structure is no longer
used.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."

[-- Attachment #2: kfreebsd-gnu.diff --]
[-- Type: text/x-diff, Size: 4194 bytes --]

--- util/grub.d/10_linux.in	2009-08-07 14:04:34.000000000 +0200
+++ util/grub.d/10_freebsd.in	2009-08-07 14:09:05.000000000 +0200
@@ -21,82 +21,79 @@
 libdir=@libdir@
 . ${libdir}/grub/grub-mkconfig_lib
 
-if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
-  OS=GNU/Linux
-else
-  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
-fi
-
-# loop-AES arranges things so that /dev/loop/X can be our root device, but
-# the initrds that Linux uses don't like that.
-case ${GRUB_DEVICE} in
-  /dev/loop/*|/dev/loop[0-9])
-    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
-  ;;
+case "${GRUB_DISTRIBUTOR}" in
+  Debian)	OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" ;;
+  *)		OS="FreeBSD" ;;
 esac
 
-if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
-    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ; then
-  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
-else
-  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
-fi
-
-linux_entry ()
+kfreebsd_entry ()
 {
   cat << EOF
 menuentry "$1" {
 EOF
   prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
   cat << EOF
-	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro $2
+	freebsd			${rel_dirname}/${basename}
+EOF
+
+  if test -n "${devices}" ; then
+    cat << EOF
+	freebsd_loadenv		${devices_rel_dirname}/${devices_basename}
 EOF
-  if test -n "${initrd}" ; then
+  fi
+
+  if test -n "${acpi_ko}" ; then
     cat << EOF
-	initrd	${rel_dirname}/${initrd}
+	freebsd_module_elf	${acpi_ko_rel_dirname}/${acpi_ko_basename}
 EOF
   fi
+
   cat << EOF
+	set FreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${GRUB_DEVICE}
+	set FreeBSD.vfs.root.mountfrom.options=rw
 }
 EOF
 }
 
-list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
+list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
         if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
       done`
 
 while [ "x$list" != "x" ] ; do
-  linux=`version_find_latest $list`
-  echo "Found linux image: $linux" >&2
-  basename=`basename $linux`
-  dirname=`dirname $linux`
+  kfreebsd=`version_find_latest $list`
+  echo "Found kernel of FreeBSD: $kfreebsd" >&2
+  basename=`basename $kfreebsd`
+  dirname=`dirname $kfreebsd`
   rel_dirname=`make_system_path_relative_to_its_root $dirname`
-  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
+
+  if [ x"$devices" != "x" ] ; then
+    devices_basename=`basename $devices`
+    devices_dirname=`dirname $devices`
+    devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
+  fi
+
+  # For "ufs" it's the same.  Do we care about the others?
+  kfreebsd_fs=${GRUB_FS}
+
+  version=`echo $basename | sed -e "s,^[^0-9]*-,,g;s/\.gz$//g"`
   alt_version=`echo $version | sed -e "s,\.old$,,g"`
-  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
 
-  initrd=
-  for i in "initrd.img-${version}" "initrd-${version}.img" \
-	   "initrd-${version}" "initrd.img-${alt_version}" \
-	   "initrd-${alt_version}.img" "initrd-${alt_version}"; do
-    if test -e "${dirname}/${i}" ; then
-      initrd="$i"
+  acpi_ko=
+  for i in "/lib/modules/${version}/acpi.ko" "/lib/modules/${alt_version}/acpi.ko" \
+      "/boot/kernel/acpi.ko"; do
+    if test -e "$i" ; then
+      acpi_ko="$i"
       break
     fi
   done
-  if test -n "${initrd}" ; then
-    echo "Found initrd image: ${dirname}/${initrd}" >&2
-  else
-    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
-    linux_root_device_thisversion=${GRUB_DEVICE}
+  if test -n "${acpi_ko}" ; then
+    echo "Found ACPI module: ${acpi_ko}" >&2
+    acpi_ko_basename=`basename ${acpi_ko}`
+    acpi_ko_dirname=`dirname ${acpi_ko}`
+    acpi_ko_rel_dirname=`make_system_path_relative_to_its_root $acpi_ko_dirname`
   fi
 
-  linux_entry "${OS}, Linux ${version}" \
-      "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
-  if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
-    linux_entry "${OS}, Linux ${version} (recovery mode)" \
-	"single ${GRUB_CMDLINE_LINUX}"
-  fi
+  kfreebsd_entry "${OS}, kFreeBSD ${version}"
 
-  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
+  list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '`
 done

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Reimplement 10_freebsd.in using 10_linux.in
  2009-08-07 12:12 [PATCH] Reimplement 10_freebsd.in using 10_linux.in Robert Millan
@ 2009-08-16 19:29 ` Vladimir 'phcoder' Serbinenko
  2009-08-17 14:01   ` Robert Millan
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-16 19:29 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]

On Fri, Aug 7, 2009 at 2:12 PM, Robert Millan<rmh@aybabtu.com> wrote:
>
> This patch reimplements 10_freebsd.in using 10_linux.in as a base, with
> the kFreeBSD-specific parts of 10_freebsd.in.
>
> The new version brings in support for multiple kernel versions (the reason
> for the rewrite) and also handling of acpi.ko.
>
> It is diffed against 10_linux.in, since the old code structure is no longer
> used.
As discussed on IRC this patch has problems on FreeBSD.
Among them
1) stat and readlink are different. Does anyone have an idea how to
make scripts always use right syntax?
2) "FreeBSD, kFreeBSD ..." isn't what FreeBSD user expects.
3) Version isn't detected correctly.
4) Doesn't use UUID
5) device.hints are forgotten
6) Doesn't support ZFS
Attached patch fixes 1 (breaking linux), 2,4 and 5
1,3 and 6 remain
>
> --
> Robert Millan
>
>  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
>  how) you may access your data; but nobody's threatening your freedom: we
>  still allow you to remove your data and not access it at all."
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git

[-- Attachment #2: 10_freebsdfix.diff --]
[-- Type: text/plain, Size: 2259 bytes --]

diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in
index 3585a68..cc6065f 100644
--- a/util/grub-mkconfig_lib.in
+++ b/util/grub-mkconfig_lib.in
@@ -39,7 +39,7 @@ make_system_path_relative_to_its_root ()
   fi
 
   # canonicalize
-  if path=`readlink -f $path` ; then : ; else
+  if path=`realpath $path` ; then : ; else
     return 1
   fi
 
@@ -50,12 +50,12 @@ make_system_path_relative_to_its_root ()
     dir=`echo $path | sed -e "s,/[^/]*$,,g"`
   fi
 
-  num=`stat -c %d $dir`
+  num=`stat -f %d $dir`
 
   # this loop sets $dir to the root directory of the filesystem we're inspecting
   while : ; do
-    parent=`readlink -f $dir/..`
-    if [ "x`stat -c %d $parent`" = "x$num" ] ; then : ; else
+    parent=`realpath $dir/..`
+    if [ "x`stat -f %d $parent`" = "x$num" ] ; then : ; else
       # $parent is another filesystem; we found it.
       break
     fi
diff --git a/util/grub.d/10_freebsd.in b/util/grub.d/10_freebsd.in
index 891a20f..ce0a9a1 100644
--- a/util/grub.d/10_freebsd.in
+++ b/util/grub.d/10_freebsd.in
@@ -22,7 +22,7 @@ libdir=@libdir@
 . ${libdir}/grub/grub-mkconfig_lib
 
 case "${GRUB_DISTRIBUTOR}" in
-  Debian)	OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD" ;;
+  Debian)	OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD, kFreeBSD " ;;
   *)		OS="FreeBSD" ;;
 esac
 
@@ -49,7 +49,7 @@ EOF
   fi
 
   cat << EOF
-	set FreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${GRUB_DEVICE}
+	set FreeBSD.vfs.root.mountfrom=${kfreebsd_fs}:${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
 	set FreeBSD.vfs.root.mountfrom.options=rw
 }
 EOF
@@ -66,7 +66,8 @@ while [ "x$list" != "x" ] ; do
   dirname=`dirname $kfreebsd`
   rel_dirname=`make_system_path_relative_to_its_root $dirname`
 
-  if [ x"$devices" != "x" ] ; then
+  if [ -f /boot/device.hints ] ; then
+    devices=/boot/device.hints
     devices_basename=`basename $devices`
     devices_dirname=`dirname $devices`
     devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
@@ -93,7 +94,7 @@ while [ "x$list" != "x" ] ; do
     acpi_ko_rel_dirname=`make_system_path_relative_to_its_root $acpi_ko_dirname`
   fi
 
-  kfreebsd_entry "${OS}, kFreeBSD ${version}"
+  kfreebsd_entry "${OS} ${version}"
 
   list=`echo $list | tr ' ' '\n' | grep -vx $kfreebsd | tr '\n' ' '`
 done

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Reimplement 10_freebsd.in using 10_linux.in
  2009-08-16 19:29 ` Vladimir 'phcoder' Serbinenko
@ 2009-08-17 14:01   ` Robert Millan
  2009-08-17 14:27     ` Vladimir 'phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Robert Millan @ 2009-08-17 14:01 UTC (permalink / raw)
  To: The development of GRUB 2

On Sun, Aug 16, 2009 at 09:29:08PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> As discussed on IRC this patch has problems on FreeBSD.
> Among them
> 1) stat and readlink are different. Does anyone have an idea how to
> make scripts always use right syntax?

AFAIK a custom autoconf snippet is the only way.  Do you know how to reliably
identify GNU-incompatible readlink?  I'm not sure what "readlink -f /" will do
on FreeBSD.

> -  if path=`readlink -f $path` ; then : ; else
> +  if path=`realpath $path` ; then : ; else

Note that this introduces an external dependency on GNU systems (readlink is
part of coreutils), which better be avoided (specially since the version of
realpath commonly used there has a problematic license).

> 2) "FreeBSD, kFreeBSD ..." isn't what FreeBSD user expects.

Ok.

> 3) Version isn't detected correctly.

Since this part is not in your patch, can you explain the problem?

> 5) device.hints are forgotten

Ok.

> 4) Doesn't use UUID
> 6) Doesn't support ZFS

These two are in the previous version too, so I'd fix/merge them separately
(increasing commit granularity is a good thing).

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Reimplement 10_freebsd.in using 10_linux.in
  2009-08-17 14:01   ` Robert Millan
@ 2009-08-17 14:27     ` Vladimir 'phcoder' Serbinenko
  2009-08-19 15:31       ` Robert Millan
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-08-17 14:27 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, Aug 17, 2009 at 4:01 PM, Robert Millan<rmh@aybabtu.com> wrote:
> On Sun, Aug 16, 2009 at 09:29:08PM +0200, Vladimir 'phcoder' Serbinenko wrote:
>> As discussed on IRC this patch has problems on FreeBSD.
>> Among them
>> 1) stat and readlink are different. Does anyone have an idea how to
>> make scripts always use right syntax?
>
> AFAIK a custom autoconf snippet is the only way.
I would prefer it to be done on runtime if possible.
>  Do you know how to reliably
> identify GNU-incompatible readlink?
Perhaps "readlink --version | head -n 1 |grep GNU" ?
> I'm not sure what "readlink -f /" will do
> on FreeBSD.
>
It complains about unknown option.
>> -  if path=`readlink -f $path` ; then : ; else
>> +  if path=`realpath $path` ; then : ; else
>
> Note that this introduces an external dependency on GNU systems (readlink is
> part of coreutils), which better be avoided (specially since the version of
> realpath commonly used there has a problematic license).
>
On FreeBSD it's a part of base system AFAIR. GNU readlink is available
through ports but is named greadlink. Perhaps we should try in script
first realpath and if it's not found try readlink?
>> 2) "FreeBSD, kFreeBSD ..." isn't what FreeBSD user expects.
>
> Ok.
>
>> 3) Version isn't detected correctly.
>
> Since this part is not in your patch, can you explain the problem?
>
I haven't looked in it but I guess the problem is that the kernel is
named just "kernel" with no version string.
>> 5) device.hints are forgotten
>
> Ok.
>
>> 4) Doesn't use UUID
>> 6) Doesn't support ZFS
>
> These two are in the previous version too, so I'd fix/merge them separately
> (increasing commit granularity is a good thing).
>
ZFS in mkconfig isn't ready at all. I think it can be postponed
without any problems
> --
> Robert Millan
>
>  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
>  how) you may access your data; but nobody's threatening your freedom: we
>  still allow you to remove your data and not access it at all."
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>



-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Reimplement 10_freebsd.in using 10_linux.in
  2009-08-17 14:27     ` Vladimir 'phcoder' Serbinenko
@ 2009-08-19 15:31       ` Robert Millan
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Millan @ 2009-08-19 15:31 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, Aug 17, 2009 at 04:27:51PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> >> 1) stat and readlink are different. Does anyone have an idea how to
> >> make scripts always use right syntax?
> >
> > AFAIK a custom autoconf snippet is the only way.
> I would prefer it to be done on runtime if possible.

Why?

> >  Do you know how to reliably
> > identify GNU-incompatible readlink?
> Perhaps "readlink --version | head -n 1 |grep GNU" ?

It's better to check for features, but if we have to check for vendor, there's
_AC_PATH_PROG_FLAVOR_GNU.

> > I'm not sure what "readlink -f /" will do
> > on FreeBSD.
> >
> It complains about unknown option.

Does it exit non-zero?  Then the check is simple.

> >> -  if path=`readlink -f $path` ; then : ; else
> >> +  if path=`realpath $path` ; then : ; else
> >
> > Note that this introduces an external dependency on GNU systems (readlink is
> > part of coreutils), which better be avoided (specially since the version of
> > realpath commonly used there has a problematic license).
> >
> On FreeBSD it's a part of base system AFAIR. GNU readlink is available
> through ports but is named greadlink. Perhaps we should try in script
> first realpath and if it's not found try readlink?

I was concerned about the other realpath, usually found in GNU/Linux
distributions.  Anyway, we could check greadlink, then readlink and
then realpath.

> >> 3) Version isn't detected correctly.
> >
> > Since this part is not in your patch, can you explain the problem?
> >
> I haven't looked in it but I guess the problem is that the kernel is
> named just "kernel" with no version string.

Oh, right.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-19 15:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07 12:12 [PATCH] Reimplement 10_freebsd.in using 10_linux.in Robert Millan
2009-08-16 19:29 ` Vladimir 'phcoder' Serbinenko
2009-08-17 14:01   ` Robert Millan
2009-08-17 14:27     ` Vladimir 'phcoder' Serbinenko
2009-08-19 15:31       ` Robert Millan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.