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

Re: Bug#632627: Re[2]: Bug#632627: Re[2]: resume file



On Tue, 30 Jul 2013, Askar Safin escribió:

> >1. uswsusp will use the initramfs resume device. So, uswsusp should read the file included in the initrd image at "conf/conf.d/resume". Is ok?
> If you mean configure time (i. e. dpkg-reconfigure uswsusp) or suspending time, then, of course, no. Because this requires unpacking initramfs, and this is slow.
> Use /etc/initramfs-tools/conf.d/resume . Of course, at wake up time use /conf/conf.d/resume.
> 
> >6. What file should read s2disk and s2both to find the resume device when they save the image?
> They should use same device which used by early userspace when this userspace perform waking up (to be sure waking up is possible). So, we should read /etc/initramfs-tools/conf.d/resume .
> 
> >8a. I am not sure about this, because initramfs-tools is required by the kernel, but there are case that uswsusp doesn't depends on initramfs-tools and use the resume device in /etc/uswsusp.conf if initramfs-tools is not installed? Could be initramfs-tools not installed and uswsusp installed?
> Yes. Kernel depends on "initramfs-tools | linux-initramfs-tool" and linux-initramfs-tool is virtual package provided by initramfs-tools and dracut. So, this is possible if you using dracut instead of initramfs-tools. (This information is about sid.)
> 
> >8. debian/control file: uswsusp will depends on initramfs-tools?
> uswsusp triggers initramfs rebuilding. So, if you want initramfs-tools, add dependency "initramfs-tools". If you can work with both initramfs-tools and dracut, add dependency "initramfs-tools | linux-initramfs-tool".
> 
> > So, initramfs-tools should read /etc/uswsusp.conf and add the resume
> > device to the resume file?
> I think, yes.
> 
> > Then, when the user run dpkg-reconfigure uswsusp,
> > update-initramfs-tools will update the initrd resume file and then the
> > system know where find the resume file.
> Yes
> 
> Askar

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
diff -ur initramfs-tools-0.113.orig/debian/initramfs-tools.preinst initramfs-tools-0.113/debian/initramfs-tools.preinst
--- initramfs-tools-0.113.orig/debian/initramfs-tools.preinst	2013-07-30 01:46:30.000000000 +0200
+++ initramfs-tools-0.113/debian/initramfs-tools.preinst	2013-07-30 01:11:08.000000000 +0200
@@ -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 -ur initramfs-tools-0.113.orig/update-initramfs initramfs-tools-0.113/update-initramfs
--- initramfs-tools-0.113.orig/update-initramfs	2013-07-30 01:46:30.000000000 +0200
+++ initramfs-tools-0.113/update-initramfs	2013-07-30 01:48:19.000000000 +0200
@@ -68,7 +68,7 @@
 		# return false.
 		return 1
 	fi
-return 0
+	return 0
 }
 
 mild_panic()
@@ -161,6 +161,45 @@
 	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 @@
 		fi
 	fi
 
+	update_resume_device
+
 	generate_initramfs
 
 	run_bootloader
@@ -344,6 +385,8 @@
 
 	backup_initramfs
 
+	update_resume_device
+
 	generate_initramfs
 
 	run_bootloader

Reply to: