[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH v2 3/5] Handle HFS file systems (format, mount, unmount, fstab entry)



v1 -> v2:

  - fixed changelog entry and commit message

---
 debian/changelog |  1 +
 grub-installer   | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/debian/changelog b/debian/changelog
index c19f183..bc21995 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ grub-installer (1.147) UNRELEASED; urgency=medium
   * Query force-efi-extra-removable only when installing grub-efi*
   * Install hfsutils in-target for powerpc/ppc64 newworld targets
   * Detect and select newworld bootstrap partitions
+  * Handle HFS file systems (format, mount, unmount, fstab entry)
 
  -- Frank Scheiner <frank.scheiner@web.de>  Thu, 16 Nov 2017 07:20:38 +0100
 
diff --git a/grub-installer b/grub-installer
index 10cce04..63e4a03 100755
--- a/grub-installer
+++ b/grub-installer
@@ -19,6 +19,8 @@ fi
 newline="
 "
 
+NW_OFFS_MOUNT_POINT="/boot/grub"
+
 db_capb backup
 
 log() {
@@ -139,6 +141,84 @@ nw_select_offs_part()
 	echo "$boot"
 	return 0
 }
+
+# adapted from ybin's mkoffs()
+nw_format_offs()
+{
+	local nw_boot_partition="$1"
+
+	local self="nw_format_offs"
+
+	mount | grep "^$nw_boot_partition\>" > /dev/null
+	if [ $? = 0 ] ; then
+		error "$self: $nw_boot_partition appears to be mounted! Aborting." 1>&2
+		return 1
+	fi
+
+	info "$self: Creating HFS filesystem on $nw_boot_partition..."
+	in-target hformat -l bootstrap "$nw_boot_partition" > /dev/null
+	if [ $? != 0 ] ; then
+		error "$self: HFS filesystem creation failed!" 1>&2
+		return 1
+	fi
+	in-target humount "$nw_boot_partition" ## otherwise we might get confused.
+
+	return 0
+}
+
+nw_include_offs_in_fstab()
+{
+	local nw_boot_partition="$1"
+	local fstab="$2"
+
+	local self="nw_include_offs_in_fstab"
+	local mount_point="$NW_OFFS_MOUNT_POINT"
+
+	if ! grep "$nw_boot_partition $mount_point hfs defaults 0 0" "$fstab" 1>/dev/null 2>&1; then
+		if echo "$nw_boot_partition $mount_point hfs defaults 0 0" >> $fstab; then
+			info "$self: In-target mount of $nw_boot_partition on $mount_point is now permanent."
+			return 0
+		else
+			error "$self: Problem accessing in-target $fstab." 1>&2
+			return 1
+		fi
+	else
+		info "$self: In-target mount of $nw_boot_partition on $mount_point was already permanent."
+	fi
+}
+
+nw_mount_offs()
+{
+	local nw_boot_partition="$1"
+
+	local self="nw_mount_offs"
+	local mount_point="$NW_OFFS_MOUNT_POINT"
+
+	in-target mkdir -p "$mount_point"
+
+	if mount -t hfs "$nw_boot_partition" "${ROOT}${mount_point}" 1>/dev/null 2>&1; then
+		info "$self: Mount of $nw_boot_partition on ${ROOT}${mount_point} succeeded."
+		return 0
+	else
+		error "$self: Mount of $nw_boot_partition on ${ROOT}${mount_point} failed." 1>&2
+		return 1
+	fi
+}
+
+nw_unmount_offs()
+{
+	local nw_boot_partition="$1"
+
+	local self="nw_unmount_offs"
+
+	if umount "$nw_boot_partition" 1>/dev/null 2>&1; then
+		info "$self: Unmount of $nw_boot_partition succeeded."
+		return 0
+	else
+		error "$self: Unmount of $nw_boot_partition failed." 1>&2
+		return 1
+	fi
+}
 ARCH="$(archdetect)"
 info "architecture: $ARCH"
 
@@ -357,8 +437,16 @@ case $ARCH in
 		fi
 	fi
 	offs_part=$( nw_select_offs_part )
+	nw_format_offs "$offs_part" || exit 1
+	nw_mount_offs "$offs_part" || exit 1
+	nw_include_offs_in_fstab "$offs_part" "$ROOT/etc/fstab" || exit 1
 	offs=$(findfs /boot/grub)
-	[ -n "$offs" ] || error "GRUB requires that the OF partition is mounted in /boot/grub" 1>&2
+	if [ -n "$offs" ]; then
+		bootfs=$offs
+		bootfstype=$(findfstype /boot/grub)
+	else
+		error "GRUB requires that the OF partition is mounted in /boot/grub" 1>&2
+	fi
 	;;
 esac
 
@@ -771,6 +859,10 @@ case $ARCH:$grub_package in
 	bootdev="$wipe_bootdev"
 	state=3
 	;;
+    powerpc/powermac_newworld:grub-ieee1275|ppc64/powermac_newworld:grub-ieee1275)
+	bootdev="$bootfs"
+	state=3
+	;;
     *)
 	# No need for install device selection on other platforms.
 	bootdev=dummy
-- 
1.9.1


Reply to: