On Tue, 30 Jul 2013, Rodolfo García Peñas escribió:

[snip]

> Hi Askar,
> 
> thanks a lot for your reply. Could this initramfs-tools patch solve the 
> problem?
> 
> Some tips:
> 
> 1. The patch reads the /etc/uswsusp.conf, and check if the file exists. The 
> value is not changed to UUID.
> 2. I check if uswsusp is installed if the s2disk binary exists. Checking the 
> config file only could be an error if the package was removed (not purged).
> 3. The resume device is created always, not only when initramfs-tools is 
> installed. Because the user can change the device.
> 
> Comments are welcome.
> 
> Cheers,
> kix

Hi,

I am attaching the git patches for the initramfs-tools git. Is only a proposal. 
Ben, what do you think? Please, apply them only if you agree with this 
behaviour (and code).

If you agree, I will forward the bug report to initramfs-tools and I will tag 
it with +patch. Then, uswsusp package doesn't need changes.

Cheers,
kix
>From c92b6c76542baf254afe875d7fbc608460a3178a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <k...@debian.org>
Date: Tue, 30 Jul 2013 19:49:29 +0200
Subject: [PATCH 1/2] code style: Extra tab

This patch only adds an extra tab.
---
 update-initramfs |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/update-initramfs b/update-initramfs
index 998eaf0..251fb6b 100755
--- a/update-initramfs
+++ b/update-initramfs
@@ -68,7 +68,7 @@ chrooted()
 		# return false.
 		return 1
 	fi
-return 0
+	return 0
 }
 
 mild_panic()
-- 
1.7.10.4

>From 47c8558cf3ae7b0918c96ae983d9738acfef8159 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <k...@debian.org>
Date: Tue, 30 Jul 2013 19:54:43 +0200
Subject: [PATCH 2/2] resume using uswsusp configuration

This patch reads the uswsusp configuration file (/etc/uswsusp.conf)
to get the resume device. If the file exists and uswsusp package is
installed, it save the value in the /etc/initramfs-tools/conf.d/resume
file. When the initrd image is created, this value is stored in the
conf/conf.d/resume file.

If the uswsusp package is not installed, if the configuration file
doesn't exists, or the file included in the configuration file doesn't
exist, the value is not used, and the previous scheme is used.

The main difference between this patch and the previous behaviour is
the resume file is now created when the user run update-initramfs not
when the user install the initramfs-tools package. The reason is because
the user run 'dpkg-reconfigure uswsusp' can change the swap device, so
the swap included in the configuration file could be wrong. The code
to update the configuration file is moved from debian/initramfs-tools.preinst
file to update-initramfs file. The function chrooted() was previously
included in the file update-initramfs.
---
 debian/initramfs-tools.preinst |   34 -------------------------------
 update-initramfs               |   43 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/debian/initramfs-tools.preinst b/debian/initramfs-tools.preinst
index b0216a1..01ff9df 100644
--- a/debian/initramfs-tools.preinst
+++ b/debian/initramfs-tools.preinst
@@ -2,43 +2,9 @@
 
 set -e
 
-chrooted() {
-	# borrowed from udev's postinst
-	if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
-		# the devicenumber/inode pair of / is the same as that of
-		# /sbin/init's root, so we're *not* in a chroot and hence
-		# return false.
-		return 1
-	fi
-	return 0
-}
-
 case "$1" in
 	install)
 		mkdir -p /etc/initramfs-tools/conf.d
-
-		# First time install.  Can we autodetect the RESUME partition?
-		if [ -r /proc/swaps ]; then
-			RESUME=$(grep ^/dev/ /proc/swaps | sort -rk3 \
-				| head -n 1 | cut -d " " -f 1)
-			if command -v blkid >/dev/null 2>&1; then
-				UUID=$(blkid -s UUID -o value "$RESUME" || true)
-			# FIXME: post-Wheezy remove vol_id invocations
-			elif command -v vol_id >/dev/null 2>&1; then
-				UUID=$(vol_id -u "$RESUME" || true)
-			elif [ -x /lib/udev/vol_id ]; then
-				UUID=$(/lib/udev/vol_id -u "$RESUME" || true)
-			fi
-			if [ -n "$UUID" ]; then
-				RESUME="UUID=$UUID"
-			fi
-		fi
-
-		# write conf.d/resume if not in a chroot
-		if [ -n "${RESUME}" ] && ! chrooted; then
-			echo "RESUME=${RESUME}" > /etc/initramfs-tools/conf.d/resume
-		fi
-
 	;;
 esac
 
diff --git a/update-initramfs b/update-initramfs
index 251fb6b..285e5c1 100755
--- a/update-initramfs
+++ b/update-initramfs
@@ -161,6 +161,45 @@ remove_initramfs_bak()
 	verbose "Removing ${initramfs_bak}"
 }
 
+# Update the resume device
+update_resume_device()
+{
+	USWSUSPCFG=/etc/uswsusp.conf
+	S2DISK=/usr/sbin/s2disk
+
+	# If uswsusp installed, use that swap device
+	if [ -r ${USWSUSPCFG} ] && [ -x ${S2DISK} ]; then
+		RESUME=`sed -n 's/^[[:space:]]*'"resume device"'[[:space:]]*[=:][[:space:]]*\([^[:space:]]*\)/\1/ p' $USWSUSPCFG`
+
+		if [ ! -e ${RESUME} ]; then
+			RESUME=""
+		fi
+	fi
+
+	# If not found in uswsusp config, get from running system
+	if [ -z "${RESUME}" ]; then
+		if [ -r /proc/swaps ]; then
+			RESUME=$(grep ^/dev/ /proc/swaps | sort -rk3 \
+				| head -n 1 | cut -d " " -f 1)
+			if command -v blkid >/dev/null 2>&1; then
+				UUID=$(blkid -s UUID -o value "$RESUME" || true)
+			# FIXME: post-Wheezy remove vol_id invocations
+			elif command -v vol_id >/dev/null 2>&1; then
+				UUID=$(vol_id -u "$RESUME" || true)
+			elif [ -x /lib/udev/vol_id ]; then
+				UUID=$(/lib/udev/vol_id -u "$RESUME" || true)
+			fi
+			if [ -n "$UUID" ]; then
+				RESUME="UUID=$UUID"
+			fi
+		fi
+	fi
+
+	# write conf.d/resume if not in a chroot
+	if [ -n "${RESUME}" ] && ! chrooted; then
+		echo "RESUME=${RESUME}" > /etc/initramfs-tools/conf.d/resume
+	fi
+}
 
 generate_initramfs()
 {
@@ -307,6 +346,8 @@ create()
 		fi
 	fi
 
+	update_resume_device
+
 	generate_initramfs
 
 	run_bootloader
@@ -344,6 +385,8 @@ update()
 
 	backup_initramfs
 
+	update_resume_device
+
 	generate_initramfs
 
 	run_bootloader
-- 
1.7.10.4

Reply via email to