From ae61c53c3b1e8c36662c623309bb8e0c249e4593 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 28 Mar 2022 15:10:56 +0200 Subject: man: document new udevadm lock tool --- man/udevadm.xml | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'man/udevadm.xml') diff --git a/man/udevadm.xml b/man/udevadm.xml index e299a75879..3248cfd256 100644 --- a/man/udevadm.xml +++ b/man/udevadm.xml @@ -51,6 +51,9 @@ udevadm wait options device|syspath + + udevadm lock options command + Description @@ -747,6 +750,87 @@ + + + udevadm lock + <arg choice="opt"><replaceable>options</replaceable></arg> + <arg choice="opt"><replaceable>command</replaceable></arg> + … + + + udevadm lock takes an (advisory) exclusive lock(s) on a block device (or + multiple therof), as per Locking Block Device + Access and invokes a program with the lock(s) taken. When the invoked program exits the lock(s) + are automatically released. + + This tool is in particular useful to ensure that + systemd-udevd.service8 + does not probe a block device while changes are made to it, for example partitions created or file + systems formatted. Note that many tools that interface with block devices natively support taking + relevant locks, see for example + sfdisk8's + switch. + + The command expects at least one block device specified via or + , and a command line to execute as arguments. + + + + + + + Takes a path to a device node of the device to lock. This switch may be used + multiple times (and in combination with ) in order to lock multiple + devices. If a partition block device node is specified the containing "whole" block device is + automatically determined and used for the lock, as per the specification. If multiple devices are + specified, they are deduplicated, sorted by the major/minor of their device nodes and then locked + in order. + + This switch must be used at least once, to specify at least one device to + lock. (Alternatively, use , see below.) + + + + + + + If a path to a device node is specified, identical to + . However, this switch alternatively accepts a path to a regular file or + directory, in which case the block device of the file system the file/directory resides on is + automatically determined and used as if it was specified with + . + + + + + + + Specifies how long to wait at most until all locks can be taken. Takes a value in + seconds, or in the usual supported time units, see + systemd.time7. If + specified as zero the lock is attempted and if not successful the invocation will immediately + fail. If passed as infinity (the default) the invocation will wait indefinitely + until the lock can be acquired. If the lock cannot be taken in the specified time the specified + command will not be executed and the invocation will fail. + + + + + + + Instead of locking the specified device(s) and executing a command, just print the + device path(s) that would be locked, and execute no command. This command is useful to determine + the "whole" block device in case a partition block device is specified. The devices will be sorted + by their device node major number as primary ordering key and the minor number as secondary + ordering key (i.e. they are shown in the order they'd be locked). Note that the number of lines + printed here can be less than the the number of and + switches specified in case these resolve to the same "whole" + devices. + + + + + @@ -760,6 +844,38 @@ still be announced via the sd-device API (or similar). + + Example + + + Format a File System + + Take a lock on the backing block device while creating a file system, to ensure that + systemd-udevd doesn't probe or announce the new superblock before it is + comprehensively written: + + # udevadm lock --device=/dev/sda1 mkfs.ext4 /dev/sda1 + + + + Format a RAID File System + + Similar, but take locks on multiple devices at once: + + # udevadm lock --device=/dev/sda1 --device=/dev/sdb1 mkfs.btrfs /dev/sda1 /dev/sdb1 + + + + Copy in a File System + + Take a lock on the backing block device while copying in a prepared file system image, to ensure + that systemd-udevd doesn't probe or announce the new superblock before it is fully + written: + + # udevadm lock -d /dev/sda1 dd if=fs.raw of=/dev/sda1 + + + See Also -- cgit v1.2.1