cryptsetup-close - Linux


Overview

cryptsetup-close is a command used to detach a previously mapped LUKS encrypted block device. It unlinks the mapping so the device can no longer be accessed until it is remapped using cryptsetup open.

Syntax

cryptsetup close [options] <device>

Required Arguments

  • <device>: Specifies the path to the mapped device to close.

Options/Flags

  • -h, –help: Display the help message.
  • –verbose, -v: Enable verbose mode.
  • –trace, -t: Enable tracing mode.
  • –force, -f: Force the close operation even if the device is still in use.
  • –trigger=TRIGGER_EVENT: Execute the specified action when a user-defined trigger event occurs. Possible events include:
    • close: Trigger the close action.
    • resume: Trigger the resume action.
    • suspend: Trigger the suspend action.

Examples

Close a Mapped Device

cryptsetup close /dev/mapper/my_encrypted_device

Force Close a Device Even if In Use (NOT Recommended)

cryptsetup --force close /dev/mapper/my_encrypted_device

Close a Device Using a Trigger Event

cryptsetup --trigger=close /dev/mapper/my_encrypted_device

Common Issues

Device Not Found

  • Ensure that the specified device is mapped and accessible.

Device Still in Use

  • Close all processes that may be using the device before attempting to close it with cryptsetup close. Alternatively, use the --force option to force the close operation.

Integration

cryptsetup-close can be combined with other commands for various tasks, such as automating the closing of encrypted devices:

#!/bin/bash
# Script to automatically close all mapped LUKS devices on system shutdown

# Get a list of all mapped LUKS devices
devices=$(cryptsetup status | awk -F: '/ luks/ {print $1}')

# Close each device in sequence
for device in $devices; do
    cryptsetup close $device
done

Related Commands

  • cryptsetup-open: Map a LUKS encrypted block device.
  • cryptsetup: The main command for managing LUKS encrypted devices.
  • dmsetup: The device mapper command used for managing device mappings.