Merge ~aciba/ubuntu/+source/hibagent:lp1896638-path-to-swapfile-by-uuid-jammy into ubuntu/+source/hibagent:ubuntu/jammy-devel

Proposed by Alberto Contreras
Status: Merged
Merge reported by: Alberto Contreras
Merged at revision: 7aa580cc27d7f72594fe63db8ec10da3eb0e8b54
Proposed branch: ~aciba/ubuntu/+source/hibagent:lp1896638-path-to-swapfile-by-uuid-jammy
Merge into: ubuntu/+source/hibagent:ubuntu/jammy-devel
Diff against target: 149 lines (+121/-0)
4 files modified
debian/changelog (+11/-0)
debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch (+33/-0)
debian/patches/lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems.patch (+75/-0)
debian/patches/series (+2/-0)
Reviewer Review Type Date Requested Status
Simon Chopin (community) Approve
Review via email: mp+440121@code.launchpad.net

Description of the change

Cherry-picked upstream fixes 43636fcf and 0f995e80 in pkg/ubuntu/kinetic-devel:

  * d/p/lp1896638-set-resume-device-by-partition-uuid: Set resume device
    by PARTUUID instead of by name. Thanks to Tony Nie <email address hidden>.
    (LP: #1896638)
  * d/p/lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems: Do not attempt to
    modify non existent GRUB config file. Thanks to Robert Schweikert
    <email address hidden>. (LP: #2013336)

Please tag & sponsor.

PPA: ppa:aciba/hibagent-sru-lp1896638-swapfile

Steps to test:

* Launch an EC2 instance
# sudo /usr/bin/enable-ec2-spot-hibernation
# journalctl -xeu hibagent.service | grep Errno
Failed to initialize swap, reason: [Errno 2] No such file or directory: '/boot/grub/menu.lst'

# sudo apt-add-repository -ys ppa:aciba/hibagent-sru-lp1896638-swapfile
# sudo apt install -y hibagent
# sudo /usr/bin/enable-ec2-spot-hibernation

* Make sure the agent is active and running:
# systemctl status hibagent

* Make sure the swap is correctly configured:
$ swapon --show
NAME TYPE SIZE USED PRIO
/swap file 3.9G 512K -2

* Make sure the resume partition is defined by uuid:
$ grep no_console /boot/grub/grub.cfg
... no_console_suspend=1 resume_offset=780288 resume=PARTUUID=14aaf7d8-41e2-43b2-b149-a402305a5136 ...

To post a comment you must log in.
7aa580c... by Alberto Contreras

changelog

Revision history for this message
Simon Chopin (schopin) wrote :

UPloaded, with a slight adjustment to the version number.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index ff27dd5..f7ab6b4 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,14 @@
6+hibagent (1.0.1-0ubuntu3.22.04.1) jammy; urgency=medium
7+
8+ * d/p/lp1896638-set-resume-device-by-partition-uuid: Set resume device
9+ by PARTUUID instead of by name. Thanks to Tony Nie <zirann@amazon.com>.
10+ (LP: #1896638)
11+ * d/p/lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems: Do not attempt to
12+ modify non existent GRUB config file. Thanks to Robert Schweikert
13+ <rjschwei@suse.com>. (LP: #2013336)
14+
15+ -- Alberto Contreras <alberto.contreras@canonical.com> Tue, 04 Apr 2023 18:22:05 +0200
16+
17 hibagent (1.0.1-0ubuntu2) hirsute; urgency=medium
18
19 * debian/copyright: Set Source to public upstream GitHub repository
20diff --git a/debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch b/debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch
21new file mode 100644
22index 0000000..39ef202
23--- /dev/null
24+++ b/debian/patches/lp1896638-set-resume-device-by-partition-uuid.patch
25@@ -0,0 +1,33 @@
26+From: Tony Nie <zirann@amazon.com>
27+Subject: Set resume device by PARTUUID instead of by device name
28+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/ec2-hibinit-agent/+bug/1896638
29+Origin: upstream, https://github.com/aws/ec2-hibernate-linux-agent/commit/43636fcf
30+---
31+ agent/hibagent | 7 +++++++
32+ 1 file changed, 7 insertions(+)
33+
34+Index: b/agent/hibagent
35+===================================================================
36+--- a/agent/hibagent 2023-03-24 13:12:50.192981414 +0100
37++++ b/agent/hibagent 2023-03-24 13:17:13.151025129 +0100
38+@@ -99,6 +99,11 @@ def get_swap_space():
39+ return int(lines[0].split()[2]) * 1024
40+
41+
42++def get_partuuid(device):
43++ return check_output(
44++ ['lsblk', '-dno', 'PARTUUID', device]).decode('ascii').strip()
45++
46++
47+ def patch_grub_config(swap_device, offset, grub_file, grub2_dir):
48+ log("Updating GRUB to use the device %s with offset %d for resume" % (swap_device, offset))
49+ lines = []
50+@@ -128,6 +133,8 @@ def patch_grub_config(swap_device, offse
51+ # Do GRUB2 update as well
52+ if grub2_dir and os.path.exists(grub2_dir):
53+ offset_file = os.path.join(grub2_dir, '99-set-swap.cfg')
54++ if swap_device.startswith("/dev"):
55++ swap_device = "PARTUUID=%s" % get_partuuid(swap_device)
56+ if not os.path.exists(offset_file):
57+ with open(offset_file, 'w') as fl:
58+ fl.write('GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT no_console_suspend=1 '
59diff --git a/debian/patches/lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems.patch b/debian/patches/lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems.patch
60new file mode 100644
61index 0000000..737b401
62--- /dev/null
63+++ b/debian/patches/lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems.patch
64@@ -0,0 +1,75 @@
65+From: Robert Schweikert <rjschwei@suse.com>
66+Subject: Do not attempt to modify non existent GRUB config file
67+
68+Distributions either use GRUB or GRUB2, we need to guard against attempts
69+to modify menu.lst on GRUB2 distributions
70+
71+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/hibagent/+bug/2013336
72+Origin: upstream, https://github.com/aws/ec2-hibernate-linux-agent/commit/0f995e80
73+---
74+ agent/hibagent | 48 +++++++++++++++++++++++++-----------------------
75+ 1 file changed, 25 insertions(+), 23 deletions(-)
76+
77+diff --git a/agent/hibagent b/agent/hibagent
78+index 02e2b03..f076220 100755
79+--- a/agent/hibagent
80++++ b/agent/hibagent
81+@@ -100,30 +100,32 @@ def get_swap_space():
82+
83+
84+ def patch_grub_config(swap_device, offset, grub_file, grub2_dir):
85+- log("Updating GRUB to use the device %s with offset %d for resume" % (swap_device, offset))
86+- lines = []
87+- with open(grub_file) as fl:
88+- for ln in fl.readlines():
89+- params = ln.split()
90+- if not params or params[0] != 'kernel':
91+- lines.append(ln)
92+- continue
93+-
94+- new_params = []
95+- for param in params:
96+- if "resume_offset=" in param or "resume=" in param:
97++ log("Updating GRUB to use the device %s with offset %d for resume"
98++ % (swap_device, offset))
99++ if grub_file and os.path.exists(grub_file):
100++ lines = []
101++ with open(grub_file) as fl:
102++ for ln in fl.readlines():
103++ params = ln.split()
104++ if not params or params[0] != 'kernel':
105++ lines.append(ln)
106+ continue
107+- new_params.append(param)
108+-
109+- if "no_console_suspend=" not in ln:
110+- new_params.append("no_console_suspend=1")
111+- new_params.append("resume_offset=%d" % offset)
112+- new_params.append("resume=%s" % swap_device)
113+-
114+- lines.append(" ".join(new_params)+"\n")
115+-
116+- with open(grub_file, "w") as fl:
117+- fl.write("".join(lines))
118++
119++ new_params = []
120++ for param in params:
121++ if "resume_offset=" in param or "resume=" in param:
122++ continue
123++ new_params.append(param)
124++
125++ if "no_console_suspend=" not in ln:
126++ new_params.append("no_console_suspend=1")
127++ new_params.append("resume_offset=%d" % offset)
128++ new_params.append("resume=%s" % swap_device)
129++
130++ lines.append(" ".join(new_params)+"\n")
131++
132++ with open(grub_file, "w") as fl:
133++ fl.write("".join(lines))
134+
135+ # Do GRUB2 update as well
136+ if grub2_dir and os.path.exists(grub2_dir):
137+--
138+2.37.2
139+
140diff --git a/debian/patches/series b/debian/patches/series
141index 7dc0cd8..3174b35 100644
142--- a/debian/patches/series
143+++ b/debian/patches/series
144@@ -7,3 +7,5 @@ use-sh-for-init-scripts.patch
145 add-lsb-init-info.patch
146 fix-enable-ec2-spot-hibernation.patch
147 0009-Use-Thread.is_alive-for-Python-3.9-compatibility.patch
148+lp1896638-set-resume-device-by-partition-uuid.patch
149+lp2013336-do-not-modify-GRUB-config-on-GRUB2-systems.patch

Subscribers

People subscribed via source and target branches