LinuxCommandLibrary

lckdo

Lock and execute a command

TLDR

View documentation for the recommended replacement

$ tldr flock
copy

SYNOPSIS

lckdo [-f] [-u] name

PARAMETERS

-f
    Force unlock by killing processes holding the lock file (use only with -u).

-u
    Release the lock on the device-mapper device.

DESCRIPTION

lckdo is a Linux utility from the device-mapper suite, used to acquire or release exclusive locks on device-mapper (dm) devices. This prevents concurrent access by multiple processes, ensuring safe operations like resizing filesystems, snapshot creation, or device detachment in scripts.

By default, running lckdo <name> creates a lock file in /var/lock/lckdo/<name>, blocking other invocations until unlocked. The command checks if the dm device exists via /sys/block/<name> and requires root privileges.

Common use cases include initramfs scripts for ordered device activation, LVM operations, or loop device management with dm targets (e.g., dm-crypt). It integrates with tools like dmsetup for atomic operations.

Locking fails if already held, unless forcing unlock. This simple flock-based mechanism avoids complex kernel coordination, making it lightweight for user-space control.

CAVEATS

Requires root privileges. Lock directory /var/lock/lckdo/ must exist and be writable. Force option (-f) terminates processes abruptly, risking data corruption. Does not lock kernel-side access, only user-space coordination.

EXAMPLES

lckdo mydm
Acquire lock on dm device 'mydm'.

lckdo -u mydm
Release lock.

lckdo -u -f mydm
Force unlock by killing holders.

LOCK FILES

Locks stored as /var/lock/lckdo/<name>. Manual removal possible but not recommended; use -u instead.

HISTORY

Introduced around 2013 in device-mapper 1.02.90 as part of persistent data tools for LVM Thin and snapshots. Maintained in device-mapper-persistent-data package.

SEE ALSO

dmsetup(8), losetup(8), lvchange(8)

Copied to clipboard