Skip to contentSkip to conversation

Support FreeBSD in osdetect.lua

PATCH In review Vladimir 'phcoder' Serbinenko 3 participants 9 messages Jul 21, 2009 – Jul 25, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support FreeBSD in osdetect.lua

Support FreeBSD on both UFS and ZFS. Requires my zfs.mod for zfs and my ufs uuid patch for UFS

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
util/osdetect.lua +41 -4
index 38a9099..1d09500 100644
@@ -40,6 +40,28 @@ function enum_device (device, fs, uuid)
     b1, b2, b3, b4 = string.match (second, "(%d+)%.?(%d*).?(%d*)%-?(%d*)")
     return (a1 > b1) or (a2 > b2) or (a3 > b3) or (a4 < b4);
   end
+  local function freebsd_variants (title, header, footer)
+     normal = "\nset FreeBSD.acpi_load=YES" ..
+	"\nset FreeBSD.hint.acpi.0.disabled=0"
+     noacpi = "\nunset FreeBSD.acpi_load" ..
+	"\nset FreeBSD.hint.acpi.0.disabled=1" ..
+	"\nset FreeBSD.loader.acpi_disabled_by_user=1"
+     safe = "\nset FreeBSD.hint.apic.0.disabled=1" ..
+	"\nset FreeBSD.hw.ata.ata_dma=0" ..
+	"\nset FreeBSD.hw.ata.atapi_dma=0" ..
+	"\nset FreeBSD.hw.ata.wc=0" ..
+	"\nset FreeBSD.hw.eisa_slots=0" ..
+	"\nset FreeBSD.hint.kbdmux.0.disabled=1"
+     grub.add_menu (header .. normal .. footer, title)
+     grub.add_menu (header .. " single" .. normal .. footer,
+		    title .. " (single)")
+     grub.add_menu (header .. " verbose" .. normal .. footer,
+		    title .. " (verbose)")
+     grub.add_menu (header .. noacpi .. footer,
+		    title .. " (without ACPI)")
+     grub.add_menu (header .. noacpi .. safe .. footer,
+		    title .. " (safe mode)")
+  end
 
   root = "(" .. device .. ")/"
   source = "root (" .. device .. ")\nchainloader +1"
@@ -58,11 +80,26 @@ function enum_device (device, fs, uuid)
     title = "MS-DOS"
   elseif (grub.file_exist (root .. "kernel.sys")) then
     title = "FreeDOS"
-  elseif (grub.file_exist (root .. "boot/loader") and
+  elseif (fs == "ufs" and grub.file_exist (root .. "boot/kernel/kernel") and
 	  grub.file_exist (root .. "boot/device.hints")) then
-    source = "root (" .. device .. ")\nfreebsd /boot/loader" ..
-      "\nfreebsd_loadenv /boot/device.hints"
-    title = "FreeBSD"
+     header = "set root=" .. device .. "\nfreebsd /boot/kernel/kernel"
+     footer = "\nset FreeBSD.vfs.root.mountfrom=ufs:ufsid/" .. uuid ..
+	"\nfreebsd_loadenv /boot/device.hints"
+     title = "FreeBSD (on " .. fs .. " ".. device .. ")"
+     freebsd_variants (title, header, footer)
+     return 0
+  elseif (fs == "zfs" and grub.file_exist (root .. "@/boot/kernel/kernel") and
+      grub.file_exist (root .. "@/boot/device.hints")) then
+     header = "set root=" .. device .. "\nfreebsd /@/boot/kernel/kernel"
+     footer =  "\nfreebsd_module_elf /@/boot/kernel/opensolaris.ko" ..
+      "\nfreebsd_module_elf /@/boot/kernel/zfs.ko" ..
+      "\nfreebsd_module /@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache" ..
+      "\nprobe -l -s name $root" ..
+      "\nset FreeBSD.vfs.root.mountfrom=zfs:$name" ..
+      "\nfreebsd_loadenv /@/boot/device.hints"
+     title = "FreeBSD (on " .. fs .. " ".. device .. ")"
+     freebsd_variants (title, header, footer)
+     return 0
   else
     grub.enum_file (enum_file, root .. "boot")
     if kernel_num ~= 0 then
#1 lore raw

util/osdetect.lua function enum_device (device, fs, uuid) · line 63

Quoted 12 lines · Vladimir 'phcoder' Serbinenko

Support FreeBSD on both UFS and ZFS. Requires my zfs.mod for zfs and my ufs uuid patch for UFS

util/osdetect.lua +9 -0
+     grub.add_menu (header .. normal .. footer, title)
+     grub.add_menu (header .. " single" .. normal .. footer,
+                   title .. " (single)")
+     grub.add_menu (header .. " verbose" .. normal .. footer,
+                   title .. " (verbose)")
+     grub.add_menu (header .. noacpi .. footer,
+                   title .. " (without ACPI)")
+     grub.add_menu (header .. noacpi .. safe .. footer,
+                   title .. " (safe mode)")

I hate to be "Mister No", but I think this change is not suitable for the generic osdetect.lua. Most users don't have problems with FreeBSD not working on their hardware. Getting five menu entries for different options is too much. It may be OK for a FreeBSD installer, but not for the generic script that also detects other OSes.

A reasonable middle ground would be to have one entry called "safe mode" to would lead to a menu offering single mode, disabling ACPI, disabling whatever else is potentially problematic. I think all entries under "safe mode" can enable extra verbosity.

The implementation could remove the original menu, or it could insert entries immediately below "safe mode". I don't know if it's possible, but it could be useful.

Actually, I don't want osdetect.lua to be overengineered and overloaded with intimate knowledge of different OSes. It's an example for others to extend, not a complete solution.

Signature · 2 lines
Regards,
Pavel Roskin
#2 lore raw
Quoted 20 lines · Pavel Roskin
Quoted 12 lines · Vladimir 'phcoder' Serbinenko

Support FreeBSD on both UFS and ZFS. Requires my zfs.mod for zfs and my ufs uuid patch for UFS

+     grub.add_menu (header .. normal .. footer, title)
+     grub.add_menu (header .. " single" .. normal .. footer,
+                   title .. " (single)")
+     grub.add_menu (header .. " verbose" .. normal .. footer,
+                   title .. " (verbose)")
+     grub.add_menu (header .. noacpi .. footer,
+                   title .. " (without ACPI)")
+     grub.add_menu (header .. noacpi .. safe .. footer,
+                   title .. " (safe mode)")

I hate to be "Mister No", but I think this change is not suitable for the generic osdetect.lua.  Most users don't have problems with FreeBSD not working on their hardware.  Getting five menu entries for different options is too much.  It may be OK for a FreeBSD installer, but not for the generic script that also detects other OSes.

Quoted 5 lines

A reasonable middle ground would be to have one entry called "safe mode" to would lead to a menu offering single mode, disabling ACPI, disabling whatever else is potentially problematic.  I think all entries under "safe mode" can enable extra verbosity.

Actually this menu is done to match the default one of FreeBSD loader. I'm not a FreeBSD expert so I prefered to stick to the same menu as default bootloader.

Quoted 4 lines

The implementation could remove the original menu, or it could insert entries immediately below "safe mode".  I don't know if it's possible, but it could be useful.

Bean proposed something like this but I don't know his progress

Quoted 3 lines

Actually, I don't want osdetect.lua to be overengineered and overloaded with intimate knowledge of different OSes.  It's an example for others to extend, not a complete solution.

We put it into our repository this means that we accept improvements. I also think that there will be distributions similar to Super GRUB Disk and other recovery tools based on osdetect.lua. Unless we provide a good reference osdetect.lua there will be a bitrot between such distributions every one neglecting some OSes

Quoted 11 lines

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#3 lore raw
Quoted 3 lines · Vladimir 'phcoder' Serbinenko

Actually this menu is done to match the default one of FreeBSD loader. I'm not a FreeBSD expert so I prefered to stick to the same menu as default bootloader.

I see.

Quoted 5 lines
Quoted 4 lines

The implementation could remove the original menu, or it could insert entries immediately below "safe mode". I don't know if it's possible, but it could be useful.

Bean proposed something like this but I don't know his progress

Quoted 8 lines
Quoted 3 lines

Actually, I don't want osdetect.lua to be overengineered and overloaded with intimate knowledge of different OSes. It's an example for others to extend, not a complete solution.

We put it into our repository this means that we accept improvements. I also think that there will be distributions similar to Super GRUB Disk and other recovery tools based on osdetect.lua. Unless we provide a good reference osdetect.lua there will be a bitrot between such distributions every one neglecting some OSes

I don't fee strongly against your change. However, I would hate to see five lines for every Linux kernel (although it would be nice to have safe mode for Windows in the GRUB menu). So this should not be an example for other OSes.

Obviously, the zfs part shouldn't go in yet.

Signature · 2 lines
Regards,
Pavel Roskin
#4 lore raw
Quoted 9 lines
Quoted 5 lines

We put it into our repository this means that we accept improvements. I also think that there will be distributions similar to Super GRUB Disk and other recovery tools based on osdetect.lua. Unless we provide a good reference osdetect.lua there will be a bitrot between such distributions every one neglecting some OSes

I don't fee strongly against your change.  However, I would hate to see five lines for every Linux kernel (although it would be nice to have safe mode for Windows in the GRUB menu).

You can have a look at my sendkey branch

Quoted 2 lines

 So this should not be an
example for other OSes.

We need two-level menu. However I prefer to merge gfxmenu first.

Quoted 3 lines

Obviously, the zfs part shouldn't go in yet.

We discussed with Robert Millan the issue and decided that zfs.mod will go to grub-extras. Just I had no time to upload it yet. As zfs part of osdetect.lua is harmless and effectless if no zfs.mod is present I see no reason for it not to be in mainstream

Quoted 10 lines

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#5 lore raw
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 3 lines

Obviously, the zfs part shouldn't go in yet.

We discussed with Robert Millan the issue and decided that zfs.mod will go to grub-extras. Just I had no time to upload it yet. As zfs part of osdetect.lua is harmless and effectless if no zfs.mod is present I see no reason for it not to be in mainstream

Well, this gets a bit more complicated. grub-extras is not part of GNU GRUB, but osdetect.lua is (currently). I'm not sure if we should make GRUB components depend on grub-extras this way (I think this is Pavel's point).

I think we should contemplate to put LUA scripting in grub-extras too. Like other components of grub-extras, we don't have copyright assignment for it, so it would fit well the purpose of grub-extras. This would render the question about zfs moot.

Signature · 5 lines
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."
#6 lore raw
Quoted 3 lines

Well, this gets a bit more complicated.  grub-extras is not part of GNU GRUB, but osdetect.lua is (currently).  I'm not sure if we should make GRUB components depend on grub-extras this way (I think this is Pavel's point).

Well this part is just inactive if zfs.mod isn't present

Quoted 5 lines

I think we should contemplate to put LUA scripting in grub-extras too.  Like other components of grub-extras, we don't have copyright assignment for it, so it would fit well the purpose of grub-extras.  This would render the question about zfs moot.

LUA will probably be important for graphics. If we put LUA in grub-extras we will have 2 distinct videosystems and we're already short on ressources to maintain one

Quoted 14 lines

--
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
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#7 lore raw
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 4 lines

I think we should contemplate to put LUA scripting in grub-extras too.  Like other components of grub-extras, we don't have copyright assignment for it, so it would fit well the purpose of grub-extras.  This would render the question about zfs moot.

LUA will probably be important for graphics.

It can be useful, yes, but not essential. Native scripting should continue to be supported, since the whole grub-mkconfig stack relies on it.

Signature · 5 lines
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."
#8 lore raw
Quoted 4 lines
Quoted 1 line

LUA will probably be important for graphics.

It can be useful, yes, but not essential.  Native scripting should continue to be supported, since the whole grub-mkconfig stack relies on it.

Yes, but graphics itself isn't essential either. And I also agree that sh should be privelegied. But sh is inappropriate for handling graphics especially advanced ones. What I want to avoid is the maintainance burden if video subsystem has to work both with and without lua present. Anyway standard menus even graphical ones will be available without LUA too.

Quoted 14 lines

--
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
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

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