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

Bug#995104: d-i: partman-basicfilesystems; swap



Package: partman-basicfilesystems
Version: 156
Tags: patch

Hello d-i team,

I am not happy with current swap management in manual partitioning.

1) All existing swaps are automatically marked as used and formatted.

Formatting an existing swap changes its UUID. On multiboot setups this breaks other installed systems such as Debian which use these swaps and rely on UUID to identify them. I have read multiple reports on Debian user forums from people which did not notice that all swaps were marked as used and to be formatted and broke already installed systems.

On the other hand, I cannot see any benefit in formatting an existing swap. The transition from old swap format v0 to current format v1 was 20 years ago, so I doubt that any v0 swap still exists on any disk in use. Is it to avoid on-disk format incompatibilities between architectures (endianness, page size...) ?

Also, activating a shared swap removes the hibernation image that may have been written by another system. This breaks suspending a system to disk and rebooting another system.

For these reasons I propose to disable this feature. I think it is better that people who use manual partitioning select swaps they want to use instead of deselecting swaps they do not want to use.

2) Partman forces used existing swaps to be formated.

As explained above, formatting an existing swap is useless and may break other installed systems which use it.

3) Partman does not allow the user to choose to format or not format an existing swap.

Actually most of the needed code is present but can never be reached due to improper checks.

The attached patch makes the following changes:

- disable automatic use and format of existing swaps
 init.d/autouse_swap

- do not format existing swap by default when manually selected
 choose_method/swap/do_option

- enable choice to format or not format an existing swap
 active_partition/basicfilesystems/choices
 active_partition/basicfilesystems/do_option

Caveat: I don't know how this is compatible with non-Linux architectures which may use different swap formats.
diff -ur a/active_partition/basicfilesystems/choices b/active_partition/basicfilesystems/choices
--- a/active_partition/basicfilesystems/choices	2021-07-23 19:14:05.000000000 +0200
+++ b/active_partition/basicfilesystems/choices	2021-09-26 01:08:03.102852685 +0200
@@ -10,19 +10,24 @@
 
 cd $dev
 
-[ -f $part/method -a -f $part/acting_filesystem ] || exit 0
+[ -f $part/method ] || exit 0
 
 method=$(cat $part/method)
-filesystem=$(cat $part/acting_filesystem)
 
-case "$filesystem" in
-    ext2|fat16|fat32|ntfs)
+if [ "$method" = swap ]; then
 	:
-	;;
-    *)
+elif [ -f $part/acting_filesystem ]; then
+	filesystem=$(cat $part/acting_filesystem)
+	case "$filesystem" in
+	    ext2|fat16|fat32|ntfs)
+		;;
+	    *)
+		exit 0
+		;;
+	esac
+else
 	exit 0
-	;;
-esac
+fi
 
 choice_mountpoint () {
 	case "$filesystem" in
@@ -40,6 +45,7 @@
 }
 
 choice_options () {
+	[ "$filesystem" ] || return 0
 	db_metaget partman-basicfilesystems/text/options description
 	printf "options\t%s\${!TAB}%.45s\n" "$RET" "$(get_mountoptions $dev $id)"
 }
@@ -51,11 +57,10 @@
 		description="$RET"
 		if [ -f $part/format ]; then
 			db_metaget partman-basicfilesystems/text/yes description
-			printf "dont_format_swap\t%s\${!TAB}%s\n" "$description" "${RET}"
 		else
 			db_metaget partman-basicfilesystems/text/no description
-			printf "format_swap\t%s\${!TAB}%s\n" "$description" "${RET}"
 		fi
+		printf "format_swap\t%s\${!TAB}%s\n" "$description" "${RET}"
 	fi
 }
 
diff -ur a/active_partition/basicfilesystems/do_option b/active_partition/basicfilesystems/do_option
--- a/active_partition/basicfilesystems/do_option	2021-07-23 19:14:05.000000000 +0200
+++ b/active_partition/basicfilesystems/do_option	2021-09-26 01:08:15.655006505 +0200
@@ -8,8 +8,11 @@
 
 cd $dev
 
-[ -f $part/method -a -f $part/acting_filesystem ] || exit 0
-filesystem=$(cat $part/acting_filesystem)
+[ -f $part/method ] || exit 0
+if [ "$(cat $part/method)" != swap ]; then
+	[ -f $part/acting_filesystem ] || exit 0
+	filesystem=$(cat $part/acting_filesystem)
+fi
 
 do_fatmountpoint () {
 	local noninteractive tpl
@@ -94,14 +97,12 @@
 	select_mountoptions $dev $id
 	;;
     format_swap)
-	>$part/format
-	update_partition $dev $id
-	;;
-    dont_format_swap)
 	if [ -f $part/format ]; then
 		rm $part/format
-		update_partition $dev $id
+	else
+		>$part/format
 	fi
+	update_partition $dev $id
 	;;
     label)
 	label=''
diff -ur a/choose_method/swap/do_option b/choose_method/swap/do_option
--- a/choose_method/swap/do_option	2021-07-23 19:14:05.000000000 +0200
+++ b/choose_method/swap/do_option	2021-09-26 01:09:39.976109430 +0200
@@ -11,6 +11,17 @@
 	old_method=do_not_use
 fi
 
+# keep settings if already selected as swap
+[ "$old_method" = swap ] && exit 0
+
 echo swap >$dev/$id/method
->$dev/$id/format
+
+# format only if does not already contain swap
+if [ -f $dev/$id/detected_filesystem ] &&
+   [ "$(cat $dev/$id/detected_filesystem)" = linux-swap ]; then
+	rm -f $dev/$id/format
+else
+	>$dev/$id/format
+fi
+
 rm -f $dev/$id/use_filesystem
diff -ur a/init.d/autouse_swap b/init.d/autouse_swap
--- a/init.d/autouse_swap	2021-07-23 19:14:05.000000000 +0200
+++ b/init.d/autouse_swap	2021-09-26 01:10:29.608810228 +0200
@@ -2,6 +2,9 @@
 
 . /lib/partman/lib/base.sh
 
+# disable automatic use of existing swap
+exit 0
+
 mkdir -p /var/lib/partman/autoused_swap
 
 partitions=

Reply to: