From 5200096c4e59e37139d097d0e2ec618086160268 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 15 Mar 2023 14:16:11 +0100 Subject: [PATCH] Deactivate any external data disk device on first boot (#2390) (#2410) * Deactivate any external data disk device on first boot (#2390) * Use lsblk to determine the underlying device file Comparing major number is not reliable, e.g. virtio disks have the same major number despite being different devices. Use lsblk to find the underlying device, and compare the device name instead. --- .../system/haos-data-disk-detach.service | 16 +++++++++++++ .../usr/libexec/haos-data-disk-detach | 23 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-data-disk-detach.service create mode 100755 buildroot-external/rootfs-overlay/usr/libexec/haos-data-disk-detach diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-data-disk-detach.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-data-disk-detach.service new file mode 100644 index 000000000..16495b302 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/haos-data-disk-detach.service @@ -0,0 +1,16 @@ +[Unit] +Description=HAOS data disk detach +DefaultDependencies=no +Before=mnt-data.mount +RefuseManualStart=true +RefuseManualStop=true +Requires=dev-disk-by\x2dlabel-hassos\x2ddata.device +After=dev-disk-by\x2dlabel-hassos\x2ddata.device systemd-fsck@dev-disk-by\x2dlabel-hassos\x2ddata.service +ConditionFirstBoot=yes + +[Service] +Type=oneshot +ExecStart=/usr/libexec/haos-data-disk-detach + +[Install] +WantedBy=local-fs.target diff --git a/buildroot-external/rootfs-overlay/usr/libexec/haos-data-disk-detach b/buildroot-external/rootfs-overlay/usr/libexec/haos-data-disk-detach new file mode 100755 index 000000000..361a6745e --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/libexec/haos-data-disk-detach @@ -0,0 +1,23 @@ +#!/bin/sh + +# Find root using rdev command +rootpart=$(rdev | cut -f 1 -d ' ') +rootdev=$(lsblk -no pkname "${rootpart}") + +# Wait up to 10s for devices to enumerate +sleep 10s + +datapartitions=$(blkid --match-token LABEL="hassos-data" --output device) + +for datapart in ${datapartitions} +do + datadev=$(lsblk -no pkname "${datapart}") + + # If major does not match our root device major, it is an external data + # disk. Rename to make sure it gets ignored. + if [ "$rootdev" != "$datadev" ] + then + echo "Found external data disk device on ${datapart}, mark it disabled..." + e2label "${datapart}" hassos-data-dis + fi +done