### LUKS Disk Encryption Setup Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/crypt.txt This is a basic shell script example for setting up LUKS disk encryption. Ensure 'cryptsetup' is installed and configured correctly. ```shell #!/bin/sh ``` -------------------------------- ### LVM Mirroring Metadata Layout Example Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/lvm2-raid.txt Provides an example of the metadata format for LVM mirroring, showing segment details and mirror configuration. ```text lv { id = "agL1vP-1B8Z-5vnB-41cS-lhBJ-Gcvz-dh3L3H" status = ["READ", "WRITE", "VISIBLE"] flags = [] segment_count = 1 segment1 { start_extent = 0 extent_count = 125 # 500 Megabytes type = "mirror" mirror_count = 2 mirror_log = "lv_mlog" region_size = 1024 mirrors = [ "lv_mimage_0", 0, "lv_mimage_1", 0 ] } } ``` -------------------------------- ### Creating and Populating a Test Suite Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt Creates a new test suite with specified fixture setup and teardown functions, then registers individual tests using the T macro. ```c void bitset_tests(struct dm_list *all_tests) { struct test_suite *ts = test_suite_create(_mem_init, _mem_exit); if (!ts) { fprintf(stderr, "out of memory\n"); exit(1); } T("get_next", "get next set bit", test_get_next); T("equal", "equality", test_equal); T("and", "and all bits", test_and); dm_list_add(all_tests, &ts->list); } ``` -------------------------------- ### Replaying Log Entries with replay-log Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/log-writes.txt This example demonstrates replaying log entries using the replay-log tool. It specifies the log device, the replay device, and an end mark. ```bash replay-log --log /dev/sdc --replay /dev/sdb --end-mark fsync ``` -------------------------------- ### Create Kcopyd Client Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/kcopyd.txt Initializes a kcopyd client, allocating memory pages for copy jobs. Call this before starting any copy operations. ```c int kcopyd_client_create(unsigned int num_pages, struct kcopyd_client **result); ``` -------------------------------- ### Uevent Example: Path Reinstated Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/uevent.txt This example demonstrates a uevent generated when a device-mapper path is reinstated, as observed with udevmonitor. It highlights the DM_ACTION variable indicating the path is back online. ```text 2.) Path reinstate. UEVENT[1192521132.989927] change@/block/dm-3 ACTION=change DEVPATH=/block/dm-3 SUBSYSTEM=block DM_TARGET=multipath DM_ACTION=PATH_REINSTATED DM_SEQNUM=2 DM_PATH=8:32 DM_NR_VALID_PATHS=1 DM_NAME=mpath2 DM_UUID=mpath-35333333000002328 MINOR=3 MAJOR=253 SEQNUM=1131 ``` -------------------------------- ### Uevent Example: Path Failure Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/uevent.txt This example shows a uevent generated when a device-mapper path fails, as captured by udevmonitor. It includes various device-mapper specific environment variables. ```text 1.) Path failure. UEVENT[1192521009.711215] change@/block/dm-3 ACTION=change DEVPATH=/block/dm-3 SUBSYSTEM=block DM_TARGET=multipath DM_ACTION=PATH_FAILED DM_SEQNUM=1 DM_PATH=8:32 DM_NR_VALID_PATHS=0 DM_NAME=mpath2 DM_UUID=mpath-35333333000002328 MINOR=3 MAJOR=253 SEQNUM=1130 ``` -------------------------------- ### RAID Status Output Example Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/raid.txt Illustrates the status output for a RAID array, showing RAID type, device health, and synchronization progress. ```text 1: raid \ 2: <#devices> \ 3: ``` ```text 0 1960893648 raid raid4 5 AAAAA 2/490221568 init 0 ``` -------------------------------- ### Create Striped Device with Perl Script Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/striped.txt This script automates the creation of a striped device using dmsetup. It calculates the optimal size and formats the table for the striped device based on the provided underlying devices and chunk size. Ensure you have Perl and dmsetup installed. ```perl #!/usr/bin/perl -w # Create a striped device across any number of underlying devices. The device # will be called "stripe_dev" and have a chunk-size of 128k. my $chunk_size = 128 * 2; my $dev_name = "stripe_dev"; my $num_devs = @ARGV; my @devs = @ARGV; my ($min_dev_size, $stripe_dev_size, $i); if (!$num_devs) { die("Specify at least one device\n"); } $min_dev_size = `blockdev --getsz $devs[0]` ; for ($i = 1; $i < $num_devs; $i++) { my $this_size = `blockdev --getsz $devs[$i]` ; $min_dev_size = ($min_dev_size < $this_size) ? $min_dev_size : $this_size; } $stripe_dev_size = $min_dev_size * $num_devs; $stripe_dev_size -= $stripe_dev_size % ($chunk_size * $num_devs); $table = "0 $stripe_dev_size striped $num_devs $chunk_size"; for ($i = 0; $i < $num_devs; $i++) { $table .= " $devs[$i] 0"; } `echo $table | dmsetup create $dev_name`; ``` -------------------------------- ### Fixture Setup Function Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt Defines a fixture for test suites. This function is responsible for initializing any common environment needed for the tests, such as creating a memory pool. ```c static void *_mem_init(void) { struct dm_pool *mem = dm_pool_create("bitset test", 1024); if (!mem) { fprintf(stderr, "out of memory\n"); exit(1); } return mem; } ``` -------------------------------- ### Create RAID5 Logical Volume Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/lvm2-raid.txt Example of creating a RAID5 logical volume with a specified size and stripe count. Alternatively, specify the devices directly. ```bash ~> lvcreate --type raid5 -L 30G -i 3 -n my_raid5 my_vg ``` ```bash ~> lvcreate --type raid5 -n my_raid5 my_vg /dev/sd[bcdef]1 ``` -------------------------------- ### LVM RAID1 Metadata Layout Example Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/lvm2-raid.txt Illustrates the metadata format for LVM RAID1, detailing device counts, region size, and paired meta/image devices. ```text lv { id = "EnpqAM-5PEg-i9wB-5amn-P116-1T8k-nS3GfD" status = ["READ", "WRITE", "VISIBLE"] flags = [] segment_count = 1 segment1 { start_extent = 0 extent_count = 125 # 500 Megabytes type = "raid1" device_count = 2 region_size = 1024 raids = [ "lv_rmeta_0", "lv_rimage_0", "lv_rmeta_1", "lv_rimage_1", ] } } ``` -------------------------------- ### Initiate Snapshot Merge Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/snapshot.txt Command to start the merging process for an LVM snapshot. Use the '-b' flag for background operation. ```bash # lvconvert --merge -b volumeGroup/snap Merging of volume snap started. ``` -------------------------------- ### Create RAID 4 Array Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/raid.txt Example of creating a RAID 4 array with specific parameters including minimum recovery rate. ```bash 0 1960893648 raid \ raid4 4 2048 sync min_recovery_rate 20 \ 5 8:17 8:18 8:33 8:34 8:49 8:50 8:65 8:66 8:81 8:82 ``` -------------------------------- ### Create LVM Cache Device with Basic Writeback Policy Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/cache.txt Creates an LVM cache device using the 'writeback' policy with default arguments. This is a common setup for general-purpose caching. ```bash dmsetup create my_cache --table '0 41943040 cache /dev/mapper/metadata \ /dev/mapper/ssd /dev/mapper/origin 512 1 writeback default 0' ``` -------------------------------- ### Expanded Repetitive Mapping Example Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/switch.txt Illustrates the expanded form of a repetitive mapping command, showing the equivalent explicit mapping for clarity. ```bash dmsetup message switch 0 set_region_mappings 1000:1 :2 :1 :2 :1 :2 :1 :2 \ :1 :2 :1 :2 :1 :2 :1 :2 :1 :2 ``` -------------------------------- ### Start Kcopyd Copy Job Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/kcopyd.txt Initiates an asynchronous sector copy operation. Requires a kcopyd client, source and destination regions, a completion callback, and context data. ```c int kcopyd_copy(struct kcopyd_client *kc, struct io_region *from, unsigned int num_dests, struct io_region *dests, unsigned int flags, kcopyd_notify_fn fn, void *context); ``` -------------------------------- ### Create dm-service-time multipath device with different throughput Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/service-time.txt This command demonstrates creating a multipath device with the 'service-time' selector, using different relative throughput values for the paths compared to the previous example. ```bash # echo "0 10 multipath 0 0 1 1 service-time 0 2 2 8:0 128 2 8:16 128 8" \ dmsetup create test ``` ```bash # dmsetup table test: 0 10 multipath 0 0 1 1 service-time 0 2 2 8:0 128 2 8:16 128 8 ``` ```bash # dmsetup status test: 0 10 multipath 2 0 0 0 1 1 E 0 2 2 8:0 A 0 0 2 8:16 A 0 0 8 ``` -------------------------------- ### Thin Pool Constructor with Feature Arguments Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/thin-provisioning.txt Example of using optional feature arguments with the 'thin-pool' constructor. 'skip_block_zeroing' is shown here, which skips zeroing of newly-provisioned blocks. ```bash skip_block_zeroing: Skip the zeroing of newly-provisioned blocks. ignore_discard: Disable discard support. no_discard_passdown: Don't pass discards down to the underlying data device, but just remove the mapping. ``` -------------------------------- ### Create a sparse device using dm-snapshot Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/zero.txt This command creates a 10TB sparse device named 'sparse1' with 10GB of actual storage. It uses the previously created 'zero1' device and a 10GB COW device (/dev/sdb1). Reads to unwritten areas return zeros. ```bash echo "0 $TEN_TERABYTES snapshot /dev/mapper/zero1 /dev/sdb1 p 128" | \ dmsetup create sparse1 ``` -------------------------------- ### Create Metadata Device Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/thin-provisioning.txt Initializes a metadata device by zeroing its first 4KB. This is a prerequisite for setting up a new pool device. ```bash dd if=/dev/zero of=$metadata_dev bs=4096 count=1 ``` -------------------------------- ### Print Statistics Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/statistics.txt Prints the collected statistics for a specified region, optionally from a starting line and for a number of lines. ```bash dmsetup message vol 0 @stats_print 0 ``` -------------------------------- ### Include Base Module Headers Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/refactoring.txt Demonstrates how to include headers from the 'base' module for memory pooling and data structures. ```c #include "base/mm/pool.h" #include "base/data-struct/list.h" ``` -------------------------------- ### Create Crypt Device with cryptsetup (LUKS) Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/crypt.txt Formats a block device with a LUKS header and then opens it as a crypt device named 'crypt1' using cryptsetup. This method uses standard LUKS encryption. Ensure the block device path is passed as an argument. ```bash #!/bin/sh cryptsetup luksFormat $1 cryptsetup luksOpen $1 crypt1 ``` -------------------------------- ### Build Unit Tests Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt Use this command to build the unit test executable. ```bash make unit-unit/unit-test ``` -------------------------------- ### Define IO Region Structure Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/kcopyd.txt Defines a structure to describe a region on a block device, including the starting sector and the number of sectors. ```c struct io_region { struct block_device *bdev; sector_t sector; sector_t count; }; ``` -------------------------------- ### Create Crypt Device with dmsetup (Keyring Service) Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/crypt.txt Creates a crypt device named 'crypt2' using dmsetup, retrieving the encryption key from a keyring service. The key is specified using a format that includes service details and a prefix. Ensure the block device path is passed as an argument. ```bash #!/bin/sh dmsetup create crypt2 --table "0 $(blockdev --getsize $1) crypt aes-cbc-essiv:sha256 :32:logon:my_prefix:my_key 0 $1 0" ``` -------------------------------- ### Create a 10TB dm-zero device Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/zero.txt This command creates a 10TB dm-zero device named 'zero1'. It's the first step in creating a sparse device. ```bash TEN_TERABYTES=`expr 10 \* 1024 \* 1024 \* 1024 \* 2` # 10 TB in sectors echo "0 $TEN_TERABYTES zero" | dmsetup create zero1 ``` -------------------------------- ### Creating a dm-log-writes Target Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/log-writes.txt This snippet shows how to create a dm-log-writes target using dmsetup. It specifies the main device, the log device, and the table parameters. ```bash TABLE="0 $(blockdev --getsz /dev/sdb) log-writes /dev/sdb /dev/sdc" dmsetup create log --table "$TABLE" ``` -------------------------------- ### Send Message to LVM Cache Device Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/cache.txt Sends a message to an LVM cache device to control its behavior. This example sets the 'sequential_threshold' tunable for the cache. ```bash dmsetup message my_cache 0 sequential_threshold 1024 ``` -------------------------------- ### Include Device Mapper Headers Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/refactoring.txt Shows how to include headers related to device mapper functionalities, specifically thin provisioning. ```c #include "dm/thin-provisioning.h" ``` -------------------------------- ### Activation Configuration with Tags Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/tagging.txt Specify which volumes to activate using a combination of volume names and tags. '@database' matches any tag set on the host. ```lvm.conf activation { volume_list = [ "vg1/lvol0", "@database" ] } ``` -------------------------------- ### Global Configuration for Tag-Based Activation Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/tagging.txt Sets up global LVM configuration to enable tag-based activation. 'volume_list = [ "@*" ]' activates volumes if any host tag matches a metadata tag. ```lvm.conf tags { hosttags = 1 } activation { # Only activate if host has a tag that matches a metadata tag volume_list = [ "@*" ] } ``` -------------------------------- ### Configure MQ Policy with Thresholds Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/cache-policies.txt Creates a 128GB mapped device using the MQ cache policy. Sets the sequential threshold to 1024 and the random threshold to 8. ```bash dmsetup create blah --table "0 268435456 cache /dev/sdb /dev/sdc \ /dev/sdd 512 0 mq 4 sequential_threshold 1024 random_threshold 8" ``` -------------------------------- ### Fixture Teardown Function Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt Defines the teardown logic for a test fixture. This function is called after all tests in a suite have completed to clean up any resources allocated during the fixture setup. ```c static void _mem_exit(void *mem) { dm_pool_destroy(mem); } ``` -------------------------------- ### List All Unit Tests Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt This command lists all available unit tests in a hierarchical tree structure, along with a brief description for each test. ```bash ./unit-test list ``` -------------------------------- ### Run All Unit Tests Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt Execute all unit tests by running 'make run-unit-test' from the top-level directory. ```bash make run-unit-test ``` -------------------------------- ### Create Crypt Device with dmsetup (Direct Key) Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/crypt.txt Creates a crypt device named 'crypt1' using dmsetup with a specified AES-CBC-ESSIV key. The key is provided directly in the command. Ensure the block device path is passed as an argument. ```bash #!/bin/sh dmsetup create crypt1 --table "0 $(blockdev --getsz $1) crypt aes-cbc-essiv:sha256 babebabebabebabebabebabebabebabe 0 $1 0" ``` -------------------------------- ### Invalidate Cache Blocks Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/cache.txt Invalidates specific cache blocks or ranges of blocks. The cache must be in passthrough mode when using this message. Ranges are inclusive of the start and exclusive of the end. ```bash dmsetup message my_cache 0 invalidate_cblocks 2345 3456-4567 5678-6789 ``` -------------------------------- ### Create Thin Pool Device Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/thin-provisioning.txt Creates a thin pool device using `dmsetup`. This command defines the mapping between metadata and data devices, block size, and a low water mark for free space. ```bash dmsetup create pool \ --table "0 20971520 thin-pool $metadata_dev $data_dev \ $data_block_size $low_water_mark" ``` -------------------------------- ### Include LVM Core Headers Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/refactoring.txt Illustrates including headers for LVM core functionalities, such as PV move operations. ```c #include "core/pvmove.h" ``` -------------------------------- ### Set up a DM-Verity Device with dmsetup Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/verity.txt This command sets up a read-only DM-Verity device. It specifies the device mapping, data device, metadata device, block sizes, number of blocks, hash algorithm, and the root hash. ```bash # dmsetup create vroot --readonly --table \ "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 \" 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 \" 1234000000000000000000000000000000000000000000000000000000000000" ``` -------------------------------- ### Create a Zoned Target with dmsetup Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/zoned.txt Create a zoned block device target using dmsetup after the device has been formatted. The zoned target requires the underlying zoned block device name as a parameter. ```bash echo "0 `blockdev --getsize ${dev}` zoned ${dev}" | dmsetup create dmz-`basename ${dev}` ``` -------------------------------- ### Create a New Thinly-Provisioned Volume Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/thin-provisioning.txt Use this command to create a new thinly-provisioned volume. The '0' is an identifier for the volume, which must be a 24-bit number. Ensure the identifier is not already in use. ```bash dmsetup message /dev/mapper/pool 0 "create_thin 0" ``` -------------------------------- ### Create LVM Cache Device with Tuned Writeback Policy Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/cache.txt Creates an LVM cache device with the 'writeback' policy and custom tunable arguments for sequential and random thresholds. Use this to fine-tune cache behavior based on access patterns. ```bash dmsetup create my_cache --table '0 41943040 cache /dev/mapper/metadata \ /dev/mapper/ssd /dev/mapper/origin 1024 1 writeback \ mq 4 sequential_threshold 1024 random_threshold 8' ``` -------------------------------- ### Display Device Mapper Table Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/queue-length.txt This command shows the current table configuration for the 'test' device, confirming the use of the multipath target with the queue-length selector and its associated paths and parameters. ```bash # dmsetup table test: 0 10 multipath 0 0 1 1 queue-length 0 2 1 8:0 128 8:16 128 ``` -------------------------------- ### Create an Internal Snapshot Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/thin-provisioning.txt To create an internal snapshot, suspend the origin device, send a message to the pool with the snapshot and origin identifiers, and then resume the origin device. The '1' is the snapshot identifier and '0' is the origin device identifier. ```bash dmsetup suspend /dev/mapper/thin dmsetup message /dev/mapper/pool 0 "create_snap 1 0" dmsetup resume /dev/mapper/thin ``` -------------------------------- ### Create Device Mapper Switch Table Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/switch.txt Creates a Device Mapper table for the 'switch' target, defining the initial mapping configuration for a logical volume. ```bash dmsetup create switch --table "0 `blockdev --getsz /dev/vg1/switch0` switch 3 128 0 /dev/vg1/switch0 0 /dev/vg1/switch1 0 /dev/vg1/switch2 0" ``` -------------------------------- ### Activate a DM-Verity Device with veritysetup Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/verity.txt This command activates a DM-Verity device using the veritysetup tool. It requires the device name, data device, metadata device, and the root hash. ```bash # veritysetup create vroot /dev/sda1 /dev/sda2 \ 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 ``` -------------------------------- ### Run Unit Tests Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/unit-tests.txt Execute the unit test runner. The first argument can be 'list' to show tests or 'run' to execute them. An optional regex pattern can filter the tests. ```bash ./unit-test [pattern] ``` -------------------------------- ### Device Mapper Snapshot Table Configuration Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/snapshot.txt Shows the device mapper table configuration for a base volume and its snapshot. This includes the real base device, the copy-on-write (COW) device for the snapshot, the snapshot device itself, and the snapshot-origin device. ```bash # dmsetup table|grep volumeGroup volumeGroup-base-real: 0 2097152 linear 8:19 384 volumeGroup-snap-cow: 0 204800 linear 8:19 2097536 volumeGroup-snap: 0 2097152 snapshot 254:11 254:12 P 16 volumeGroup-base: 0 2097152 snapshot-origin 254:11 ``` -------------------------------- ### Create Multipath Device with Queue-Length Selector Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/queue-length.txt This command creates a multipath device named 'test' using the queue-length path selector. It specifies two underlying paths (8:0 and 8:16) and sets a repeat_count of 128 for each. ```bash # echo "0 10 multipath 0 0 1 1 queue-length 0 2 1 8:0 128 8:16 128" \ dmsetup create test ``` -------------------------------- ### Use a Snapshot of an External Device Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/thin-provisioning.txt Activate a snapshot of an external device by appending an extra parameter to the 'thin' target, specifying the origin device. All descendants of this snapshot also require the same origin parameter. ```bash dmsetup create snap --table "0 2097152 thin /dev/mapper/pool 0 /dev/image" ``` -------------------------------- ### Backup Fileserver LVM Configuration Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/tagging.txt This configuration is for a backup fileserver. It is identical to the primary configuration and should be placed on the backup machine. ```ini lvm_fsb1.conf: activation { volume_list = [ "@fileserver" ] } ``` -------------------------------- ### Create Device Delaying Write Operations Separately Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/delay.txt This script sets up a device-mapper device that delays write operations by 500ms while reads are not delayed. It also demonstrates splitting read and write operations to different underlying devices ($1 for reads, $2 for writes). Ensure both target devices are available and unmounted. ```shell #!/bin/sh # Create device delaying only write operation for 500ms and # splitting reads and writes to different devices $1 $2 echo "0 `blockdev --getsz $1` delay $1 0 0 $2 0 500" | dmsetup create delayed ``` -------------------------------- ### Format a Device for DM-Verity Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/verity.txt This command formats a device to create the necessary hash tree structure for DM-Verity. It requires the data device and the metadata device as arguments. ```bash # veritysetup format /dev/sda1 /dev/sda2 ... Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 ``` -------------------------------- ### RAID4 Configuration (With Metadata Devices) Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/raid.txt Configures a RAID4 device with 4 data drives and 1 parity drive, including the specification of metadata devices. The chunk size is set to 1MiB, and RAID initialization is forced. ```bash # RAID4 - 4 data drives, 1 parity (with metadata devices) # Chunk size of 1MiB, force RAID initialization, ``` -------------------------------- ### Format a Zoned Block Device Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/zoned.txt Use the dmzadm tool to format a zoned block device. This analyzes the device's zone configuration and initializes the metadata sets. ```bash dmzadm --format /dev/sdxx ``` -------------------------------- ### Define Host Tags in Configuration Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/tagging.txt Configure LVM to use host tags for managing volume activation. The 'hosttags = 1' setting enables this feature. ```lvm.conf tags { # Set a tag with the hostname hosttags = 1 tag1 { } tag2 { # If no exact match, tag is not set. host_list = [ "hostname", "dbase" ] } } ``` -------------------------------- ### DM-IO Asynchronous I/O with Page List Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/io.txt Performs asynchronous I/O using a list of memory pages. Requires a callback function and context for completion notification. ```c int dm_io_async(unsigned int num_regions, struct io_region *where, int rw, struct page_list *pl, unsigned int offset, io_notify_fn fn, void *context); ``` -------------------------------- ### Device Mapper Snapshot File Listing Source: https://gitlab.com/lvmteam/lvm2/-/blob/main/doc/kernel/snapshot.txt Lists the device mapper files for a base volume and its snapshot, showing their major and minor device numbers and permissions. ```bash # ls -lL /dev/mapper/volumeGroup-* brw------- 1 root root 254, 11 29 ago 18:15 /dev/mapper/volumeGroup-base-real brw------- 1 root root 254, 12 29 ago 18:15 /dev/mapper/volumeGroup-snap-cow brw------- 1 root root 254, 13 29 ago 18:15 /dev/mapper/volumeGroup-snap brw------- 1 root root 254, 10 29 ago 18:14 /dev/mapper/volumeGroup-base ```