Genericize package grub-loopback-iso
authorRyan Finnie <ryan@finnie.org>
Sun, 1 Jun 2014 09:34:00 +0000 (09:34 +0000)
committerMichael Prokop <mika@grml.org>
Sun, 31 Aug 2014 17:30:30 +0000 (10:30 -0700)
Grml's grub loopback.cfg interface has become a de facto standard for Linux
distributions.  Because of that, the Debian grml-rescueboot package is
usable with more ISOs than just Grml, so this change renames the package
to grub-loopback-iso, genericizes it, and provides backwards compatibility
with grml-rescueboot.  It does the following:

  * Renames everything to grub-loopback-iso.
  * Changes default ISOs directory to /boot/isos.
  * Adds a transitional grml-rescueboot package.
  * Replaces README with a generic explanation.
  * Removes previous stock /etc/grub.d/42_grml instances.
  * Checks for and uses the "legacy" /etc/default/grml-rescueboot if
    it exists.
  * Even if /etc/default/grml-rescueboot is not customized, "legacy"
    /boot/grml will be checked for as well.
  * Allows $ISO_LOCATION to contain multiple search directories, mostly as
    a by-product of backwards compatibility.

Note that debian/changelog is not updated, though this change expects the
next release to be numbered 0.4.6.  If that is not the case, be sure to
update the Replaces: and Breaks: in debian/control.

Signed-off-by: Ryan Finnie <ryan@finnie.org>
15 files changed:
42_loopback-iso [moved from 42_grml with 79% similarity]
TODO
debian/README
debian/control
debian/dirs [deleted file]
debian/grml-rescueboot.lintian-overrides [deleted file]
debian/grub-loopback-iso.dirs [new file with mode: 0644]
debian/grub-loopback-iso.install [new file with mode: 0644]
debian/grub-loopback-iso.lintian-overrides [new file with mode: 0644]
debian/grub-loopback-iso.postinst [moved from debian/postinst with 65% similarity]
debian/grub-loopback-iso.postrm [moved from debian/postrm with 91% similarity]
debian/grub-loopback-iso.preinst [new file with mode: 0644]
debian/install [deleted file]
etc/default/grml-rescueboot [deleted file]
etc/default/grub-loopback-iso [new file with mode: 0644]

similarity index 79%
rename from 42_grml
rename to 42_loopback-iso
index 8cfdb3f..d458990 100755 (executable)
--- a/42_grml
@@ -1,6 +1,6 @@
 #!/bin/sh
-# Filename:      42_grml
-# Purpose:       grub-mkconfig helper script for Grml rescue systems
+# Filename:      42_loopback-iso
+# Purpose:       grub-mkconfig helper script for loopback.cfg-compatible ISOs
 # Authors:       Grml team (grml.org), (c) Andreas Gredler <jimmy@grml.org>, Michael Prokop <mika@grml.org>
 # License:       This file is licensed under the GPL v2+.
 ################################################################################
@@ -21,8 +21,18 @@ else
 fi
 
 # default unless configured otherwise:
-ISO_LOCATION="/boot/grml"
+ISO_LOCATION="/boot/isos"
 
+# grml-rescueboot backwards compatibility
+if [ -d /boot/grml ]; then
+  ISO_LOCATION="${ISO_LOCATION} /boot/grml"
+fi
+
+if [ -r /etc/default/grub-loopback-isos ] ; then
+  . /etc/default/grub-loopback-isos
+fi
+
+# grml-rescueboot backwards compatibility
 if [ -r /etc/default/grml-rescueboot ] ; then
   . /etc/default/grml-rescueboot
 fi
@@ -80,16 +90,18 @@ get_dependencies() {
 
 
 iso_list=""
-for file in "${ISO_LOCATION}"/*.iso ; do
+for dir in $ISO_LOCATION; do
+  for file in "$dir"/*.iso ; do
      if grub_file_is_not_garbage "$file" ; then
        iso_list="$iso_list $file "
      fi
+  done
 done
 
-for grmliso in $iso_list ; do
-  rel_dirname="$(make_system_path_relative_to_its_root $(dirname $grmliso))"
-  grml="$(basename $grmliso)"
-  device="$(${grub_probe} -t device ${grmliso})"
+for iso in $iso_list ; do
+  rel_dirname="$(make_system_path_relative_to_its_root $(dirname $iso))"
+  isofn="$(basename $iso)"
+  device="$(${grub_probe} -t device ${iso})"
 
   additional_param=""
 
@@ -105,18 +117,18 @@ for grmliso in $iso_list ; do
     ;;
   esac
 
-  echo "Found Grml ISO image: $grmliso" >&2
-  title="Grml Rescue System ($grml)"
+  echo "Found Loopback ISO image: $iso" >&2
+  title="Bootable ISO ($isofn)"
   grub_prep=$(prepare_grub_to_access_device "$device" | sed -e "s/^/        /")
 
   cat << EOF
 menuentry "${title}" {
 ${grub_prep}
-        iso_path="${rel_dirname}/${grml}"
+        iso_path="${rel_dirname}/${isofn}"
         export iso_path
         kernelopts=" $CUSTOM_BOOTOPTIONS $additional_param "
         export kernelopts
-        loopback loop "${rel_dirname}/$grml"
+        loopback loop "${rel_dirname}/$isofn"
         set root=(loop)
         configfile /boot/grub/loopback.cfg
 }
diff --git a/TODO b/TODO
index 66c748b..26d6c46 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,2 +1 @@
 * standarized support for custom options (so it works e.g. with Ubuntu as well)
-* set bootentry title within GRUB based on ISO (so e.g. "Grml" becomes "Ubuntu")
index ddde17d..6a9105f 100644 (file)
@@ -1,38 +1,20 @@
-The Debian Package grml-rescueboot
-==================================
-
-Usually systems are rescued with CD or USB stick. grml-rescueboot makes
-it possible to simply copy an Grml ISO image to the harddisk and boot the
-rescue image. This eliminates the need to carry around a USB stick
-to rescue a system as long as the hard disk and the boot manager still
-work.
-
-grml-rescueboot includes the script 42_grml which is installed in
-/etc/grub.d and run when update-grub is executed. The script looks for
-ISO images in /boot/grml/ and adds an entry for each image found.
-
-Howto
------
-
-- Get a recent Grml image from http://grml.org/download/
-- Copy the image to /boot/grml
-- Run update-grub
-- Reboot and enjoy your new rescue system
-
-Limitations
------------
-
-grml-rescueboot uses the loopback feature of GRUB2, so it won't work
-with legacy GRUB. Furthermore the ISO image needs to support
-loopback.cfg, a file which is placed in /boot/grub/. Grml supports
-loopback.cfg beginning with release version 2010.04.
-
-More technical details can be found here:
-http://www.supergrubdisk.org/wiki/Loopback.cfg
-
-Create your own ISO
--------------------
-
-You can make your own Grml Live ISO image using the grml-live
-build framework. Visit http://grml.org/grml-live/ and
-http://grml.org/ for more information.
+== About ==
+
+grub-loopback-iso is a GRUB 2 configuration hook to boot compatible
+ISOs stored on the host filesystem. The stanzas built utilize GRUB
+2's loopback mount support to chain a /boot/grub/loopback.cfg file on
+an ISO.
+
+== Installation ==
+
+Place compatible ISOs in a suitable location.  By default, this is
+/boot/isos, but may be changed by editing /etc/default/grub-loopback-iso
+(for example, if the /boot partition is too small).  However, keep in
+mind that the ISO's operating system may have restrictions on what type
+of partition the ISO may be placed on; it is the ISO's operating system
+(initrd most likely) which is responsible for finding the ISO by
+scanning partitions, so the partition and filesystem must be known to
+the ISO operating system.
+
+Then simply run "update-grub", and verify the correct stanzas have been
+created in /boot/grub/grub.cfg .
index 3d105de..8f6a8df 100644 (file)
@@ -1,4 +1,4 @@
-Source: grml-rescueboot
+Source: grub-loopback-iso
 Section: admin
 Priority: extra
 Maintainer: Grml Team <team@grml.org>
@@ -12,13 +12,22 @@ Homepage: http://git.grml.org/?p=grml-rescueboot.git
 Vcs-git: git://git.grml.org/grml-rescueboot.git
 Vcs-Browser: http://git.grml.org/?p=grml-rescueboot.git
 
-Package: grml-rescueboot
+Package: grub-loopback-iso
 Architecture: all
 Depends: grub-pc | grub-efi-amd64,
          ${misc:Depends},
          ${shlibs:Depends}
-Description: Integrates Grml ISO booting into GRUB
- This package provides a script for update-grub which looks for
- Grml ISO images in /boot/grml and automatically adds an entry
- for each image. The purpose is to use one of those images to
- boot a Grml rescue system without using a CD or USB stick.
+Replaces: grml-rescueboot (<< 0.4.6~)
+Breaks: grml-rescueboot (<< 0.4.6~)
+Description: Boot a compatible loopback ISO from GRUB 2
+ grub-loopback-iso is a GRUB 2 configuration hook to boot compatible
+ ISOs stored on the host filesystem. The stanzas built utilize GRUB
+ 2's loopback mount support to chain a /boot/grub/loopback.cfg file on
+ an ISO.
+
+Package: grml-rescueboot
+Depends: grub-loopback-iso, ${misc:Depends}
+Architecture: all
+Section: oldlibs
+Description: transitional dummy package
+ This is a transitional dummy package. It can safely be removed.
diff --git a/debian/dirs b/debian/dirs
deleted file mode 100644 (file)
index 820b9dc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/boot/grml
diff --git a/debian/grml-rescueboot.lintian-overrides b/debian/grml-rescueboot.lintian-overrides
deleted file mode 100644 (file)
index 2e3476f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-# Shipping /boot/grml (empty) is intentional.
-grml-rescueboot binary: package-contains-empty-directory boot/grml/
diff --git a/debian/grub-loopback-iso.dirs b/debian/grub-loopback-iso.dirs
new file mode 100644 (file)
index 0000000..c312318
--- /dev/null
@@ -0,0 +1 @@
+/boot/isos
diff --git a/debian/grub-loopback-iso.install b/debian/grub-loopback-iso.install
new file mode 100644 (file)
index 0000000..41e7928
--- /dev/null
@@ -0,0 +1,3 @@
+42_loopback-iso etc/grub.d/
+debian/README usr/share/doc/grub-loopback-iso/
+etc/default etc/
diff --git a/debian/grub-loopback-iso.lintian-overrides b/debian/grub-loopback-iso.lintian-overrides
new file mode 100644 (file)
index 0000000..5e8ad9f
--- /dev/null
@@ -0,0 +1,2 @@
+# Shipping /boot/isos (empty) is intentional.
+grub-loopback-iso binary: package-contains-empty-directory boot/isos/
similarity index 65%
rename from debian/postinst
rename to debian/grub-loopback-iso.postinst
index d5f9b75..9312804 100644 (file)
@@ -1,17 +1,35 @@
 #!/bin/sh
-# postinst script for grml-rescueboot
+# postinst script for grub-loopback-iso
 
 set -e
 
 update_grub_wrapper() {
-  # default, unless configured otherwise:
-  ISO_LOCATION=/boot/grml
+  # default unless configured otherwise:
+  ISO_LOCATION="/boot/isos"
 
+  # grml-rescueboot backwards compatibility
+  if [ -d /boot/grml ]; then
+    ISO_LOCATION="${ISO_LOCATION} /boot/grml"
+  fi
+
+  if [ -r /etc/default/grub-loopback-isos ] ; then
+    . /etc/default/grub-loopback-isos
+  fi
+
+  # grml-rescueboot backwards compatibility
   if [ -r /etc/default/grml-rescueboot ] ; then
     . /etc/default/grml-rescueboot
   fi
 
-  if ! ls "${ISO_LOCATION}"/*iso >/dev/null 2>&1 ; then
+  iso_list=""
+  for dir in $ISO_LOCATION; do
+    for file in "$dir"/*.iso ; do
+      [ -e "$file" ] || continue
+      iso_list="$iso_list $file"
+    done
+  done
+
+  if [ -z "$iso_list" ]; then
     echo "INFO: No *.iso files found inside ${ISO_LOCATION}."
     echo "INFO: Please create ${ISO_LOCATION} and place rescue ISO(s) there."
     echo "INFO: Finally invoke update-grub and enjoy your rescue system."
similarity index 91%
rename from debian/postrm
rename to debian/grub-loopback-iso.postrm
index dc1ef1d..71bb5f9 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# postrm script for grml-rescueboot
+# postrm script for grub-loopback-iso
 
 set -e
 
diff --git a/debian/grub-loopback-iso.preinst b/debian/grub-loopback-iso.preinst
new file mode 100644 (file)
index 0000000..4b98e52
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+# preinst script for grub-loopback-iso
+
+set -e
+
+remove_old_grubd() {
+  # Old grml-rescueboot 42_grml is saved upon upgrade as a conffile.
+  # Remove it if it matches known default hashes; otherwise warn.
+  [ -e /etc/grub.d/42_grml ] || return
+
+  default_grubd=""
+  case "$(md5sum /etc/grub.d/42_grml | cut -d' ' -f1)" in
+    1db35de0d6dddb149bd609689ef98b30) # 0.4.2
+      default_grubd=yes
+      ;;
+    c1afca4d42c494a7421c27ad9fb731fd) # 0.4.4
+      default_grubd=yes
+      ;;
+    ecc549965cc4b4d0d762a3ba6dfe7cb5) # 0.4.5
+      default_grubd=yes
+      ;;
+  esac
+
+  if [ -n "$default_grubd" ]; then
+    rm -f /etc/grub.d/42_grml
+    return
+  else
+    echo >&2
+    echo "WARNING: /etc/grub.d/42_grml appears to have been modified." >&2
+    echo "Please remove it and/or purge the transitional grml-rescueboot package." >&2
+    echo >&2
+  fi
+}
+
+case "$1" in
+  install|upgrade)
+    remove_old_grubd
+    ;;
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/install b/debian/install
deleted file mode 100644 (file)
index 37b732f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-42_grml etc/grub.d/
-debian/README usr/share/doc/grml-rescueboot/
-etc/default etc/
diff --git a/etc/default/grml-rescueboot b/etc/default/grml-rescueboot
deleted file mode 100644 (file)
index d2154de..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-## Configuration file for Debian package grml-rescueboot.
-
-# Location of ISOs:
-# ISO_LOCATION="/boot/grml/"
-
-# To set any specific bootoptions for rescue images
-# present in /boot/grml just set and enable the following option:
-# CUSTOM_BOOTOPTIONS="ssh=password lang=de"
diff --git a/etc/default/grub-loopback-iso b/etc/default/grub-loopback-iso
new file mode 100644 (file)
index 0000000..443ab2b
--- /dev/null
@@ -0,0 +1,8 @@
+## Configuration file for Debian package grub-loopback-iso.
+
+# Location of ISOs:
+# ISO_LOCATION="/boot/isos"
+
+# To set any specific bootoptions for loopback ISOs
+# present in /boot/isos just set and enable the following option:
+# CUSTOM_BOOTOPTIONS="ssh=password lang=de"