Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the machine-id to persist #759

Merged
1 commit merged into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions meta-mender-core/classes/mender-setup.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ python() {

# Use PARTUUID to set fixed drive locations.
'mender-partuuid',

# Setup the systemd machine ID to be persistent across OTA updates.
'mender-persist-systemd-machine-id',
}

mfe = d.getVar('MENDER_FEATURES_ENABLE')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From c07ad477cd5715079a3bd086293e0adf91f15b88 Mon Sep 17 00:00:00 2001
From 8ecd3470f58cf8022e3188da3c2eb77448c244cb Mon Sep 17 00:00:00 2001
From: Drew Moseley <drew.moseley@northern.tech>
Date: Sun, 28 Jan 2018 17:44:32 -0500
Subject: [PATCH] Generic boot code for Mender.
Expand All @@ -7,15 +7,15 @@ Signed-off-by: Maciej Borzecki <maciej.borzecki@rndity.com>
Signed-off-by: Drew Moseley <drew.moseley@northern.tech>
Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
---
include/config_mender.h | 98 +++++++++++++++++++++++++++++++
include/env_mender.h | 152 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 250 insertions(+)
include/config_mender.h | 98 +++++++++++++++++++++++++
include/env_mender.h | 157 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 255 insertions(+)
create mode 100644 include/config_mender.h
create mode 100644 include/env_mender.h

diff --git a/include/config_mender.h b/include/config_mender.h
new file mode 100644
index 0000000..3836a6d
index 0000000000..3836a6ddd4
--- /dev/null
+++ b/include/config_mender.h
@@ -0,0 +1,98 @@
Expand Down Expand Up @@ -119,10 +119,10 @@ index 0000000..3836a6d
+#endif /* HEADER_CONFIG_MENDER_H */
diff --git a/include/env_mender.h b/include/env_mender.h
new file mode 100644
index 0000000..a1996ab
index 0000000000..0605f6a9fa
--- /dev/null
+++ b/include/env_mender.h
@@ -0,0 +1,152 @@
@@ -0,0 +1,157 @@
+/*
+ Copyright 2017 Northern.tech AS
+
Expand Down Expand Up @@ -205,6 +205,11 @@ index 0000000..a1996ab
+ "then " \
+ "run mender_pre_setup_commands; " \
+ "fi; " \
+ "if test \"${mender_systemd_machine_id}\" != \"\"; " \
+ "then " \
+ "setenv bootargs systemd.machine_id=${mender_systemd_machine_id} " \
+ "${bootargs}; " \
+ "fi; " \
+ "setenv mender_kernel_root " MENDER_STORAGE_DEVICE_BASE "${mender_boot_part}; " \
+ "if test ${mender_boot_part} = " __stringify(MENDER_ROOTFS_PART_A_NUMBER) "; " \
+ "then " \
Expand Down Expand Up @@ -276,5 +281,5 @@ index 0000000..a1996ab
+
+#endif /* HEADER_ENV_MENDER_H */
--
2.7.4
2.21.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
#
# Write the systemd machine-id to the bootloader environment
# so that it will persist between updates.
#

set -eu

CURRENT_BOOTLOADER_ID=$(fw_printenv mender_systemd_machine_id 2>/dev/null | cut -d= -f2)
CURRENT_SYSTEMD_ID=$(cat /etc/machine-id)

rc=0
if [ -z "${CURRENT_BOOTLOADER_ID}" ] && [ ! -z "${CURRENT_SYSTEMD_ID}" ]; then
fw_setenv "mender_systemd_machine_id" "${CURRENT_SYSTEMD_ID}"
rc=$?
elif [ "${CURRENT_BOOTLOADER_ID}" != "${CURRENT_SYSTEMD_ID}" ]; then
echo "Error; bootloader and systemd disagree on machine-id." >&2
rc=1
fi

exit $rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Mender persistent machine ID for systemd
ConditionPathExists=/etc/machine-id

[Service]
Type=oneshot
User=root
Group=root
ExecStart=/usr/bin/mender-set-systemd-machine-id.sh

[Install]
WantedBy=mender.service
13 changes: 13 additions & 0 deletions meta-mender-core/recipes-mender/mender/mender.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ FILES_${PN} += "${systemd_unitdir}/system/mender.service \
"

SRC_URI_append_mender-image_mender-systemd = " file://mender-data-dir.service"
SRC_URI_append_mender-persist-systemd-machine-id = " file://mender-systemd-machine-id.service \
file://mender-set-systemd-machine-id.sh"
FILES_${PN}_append_mender-image_mender-systemd = " ${systemd_unitdir}/system/mender-data-dir.service \
${systemd_unitdir}/system/mender.service.wants/mender-data-dir.service"
FILES_${PN}_append_mender-persist-systemd-machine-id = " ${systemd_unitdir}/system/mender-systemd-machine-id.service \
${systemd_unitdir}/system/mender.service.wants/mender-systemd-machine-id.service \
${bindir}/mender-set-systemd-machine-id.sh"

# Go binaries produce unexpected effects that the Yocto QA mechanism doesn't
# like. We disable those checks here.
Expand Down Expand Up @@ -236,3 +241,11 @@ do_install_append_mender-image_mender-systemd() {
install -d -m 755 ${D}${systemd_unitdir}/system/mender.service.wants
ln -sf ../mender-data-dir.service ${D}${systemd_unitdir}/system/mender.service.wants/
}

do_install_append_mender-persist-systemd-machine-id() {
install -m 644 ${WORKDIR}/mender-systemd-machine-id.service ${D}${systemd_unitdir}/system/
install -d -m 755 ${D}${systemd_unitdir}/system/mender.service.wants
ln -sf ../mender-systemd-machine-id.service ${D}${systemd_unitdir}/system/mender.service.wants/
install -d -m 755 ${D}${bindir}
install -m 755 ${WORKDIR}/mender-set-systemd-machine-id.sh ${D}${bindir}
}