From d5911445a141e4c56cef1a77ab30cd2fe2aa8bb3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 17 May 2023 10:54:38 -0400 Subject: [PATCH] 64-gce-disk-removal.rules: delete This rule tries to clean up mount points after their backing block devices have been detached. However, it does not actually work on any recent systemd-based distro. It's been almost ten years now since `systemd-udevd` has been set up to run in a mount namespace[[1]]. (This has been replaced by `PrivateMounts=yes` in more recent versions.) This means that the `umount` done here will have no effect on the system. I've verified this is the case in a Debian 11 instance on GCP where I detached a device that was mounted. (It's worth noting that the initial addition of this rule, which AFAICT is this commit[[2]], predates the systemd patch by a year which means that this rule did work in the beginning.) Nowadays, mounting and unmounting should be done via systemd mount units. systemd knows to clean up stale mount entries if their underlying devices go away. If it really must be done from a udev rule, the `systemd-mount` command is recommended, but unmounting with this tool will not work for our purposes here since it assumes the device is still present. Using `mount` interactively is fine, but then it's reasonable to expect users to also manually `umount` once they're done with it. Also, note that the logic here is not quite correct. If `umount` fails (e.g. because the device wasn't actually mounted), the overall exit code of the shell command is nonzero, which systemd will log as a udev error like: (udev-worker)[534]: vda2: Process '/bin/sh -c '/bin/umount -fl /dev/vda2 && /usr/bin/logger -p daemon.warn -s WARNING: hot-removed /dev/vda2 that was still mounted, data may have been corrupted'' failed with exit code 32. For all the above reasons, drop this rule. [1]: https://github.com/systemd/systemd/commit/c2c13f2df42e0691aecabe3979ea81cd7faa35c7 [2]: https://github.com/GoogleCloudPlatform/compute-image-packages/commit/502f06e6d438d30d5cc632f37bb8256fa4ec65c8 --- src/lib/udev/rules.d/64-gce-disk-removal.rules | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/lib/udev/rules.d/64-gce-disk-removal.rules diff --git a/src/lib/udev/rules.d/64-gce-disk-removal.rules b/src/lib/udev/rules.d/64-gce-disk-removal.rules deleted file mode 100644 index dee719a..0000000 --- a/src/lib/udev/rules.d/64-gce-disk-removal.rules +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# When a disk is removed, unmount any remaining attached volumes. - -ACTION=="remove", SUBSYSTEM=="block", KERNEL=="sd*|vd*|nvme*", RUN+="/bin/sh -c '/bin/umount -fl /dev/$name && /usr/bin/logger -p daemon.warn -s WARNING: hot-removed /dev/$name that was still mounted, data may have been corrupted'" -- 2.40.0