> For the complete documentation index, see [llms.txt](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/file-systems-cocepts/lpic2-201/dev-mapper.md).

# /dev/mapper/

The `/dev/mapper/` directory on Linux systems typically contains device mapper (DM) devices, which are virtual block devices created by the Linux kernel's device mapper subsystem. These devices are often used in conjunction with LVM (Logical Volume Manager) and encryption mechanisms like dm-crypt. Here’s an overview of its usage and contents:

### Understanding `/dev/mapper/`

1. **Logical Volumes (LVs)**:
   * When using LVM, logical volumes are represented as `/dev/mapper/<VG>-<LV>` where `<VG>` is the volume group name and `<LV>` is the logical volume name.
   * Example: `/dev/mapper/vg_name-lv_name`.
2. **Encrypted Devices**:
   * Encrypted volumes created with `dm-crypt` are typically found under `/dev/mapper/`.
   * Example: `/dev/mapper/crypt_name`.
3. **Software RAID**:
   * When using software RAID (e.g., Linux MD RAID), `/dev/mapper/` may also contain RAID devices.
   * Example: `/dev/mapper/md0`.

### Common Commands and Operations

* **Listing Device Mapper Devices**:

  ```bash
  ls /dev/mapper/
  ```

  Lists all device mapper devices currently available.
* **Displaying Device Information**:

  ```bash
  dmsetup ls --tree
  ```

  Provides a tree view of all device mapper devices and their relationships.
* **Activating LVM Logical Volumes**:

  ```bash
  vgchange -a y
  ```

  Activates all volume groups, making logical volumes accessible under `/dev/mapper/`.
* **Activating Encrypted Devices**:

  ```bash
  cryptsetup luksOpen /dev/sdX encrypted_name
  ```

  Opens an encrypted device `/dev/sdX` and creates a mapping under `/dev/mapper/`.

### Example Use Case: LVM Logical Volume

Assuming you have an LVM setup:

* **Create a Logical Volume**:

  ```bash
  lvcreate -L 1G -n lv_name vg_name
  ```

  Creates a logical volume named `lv_name` of size 1GB in the volume group `vg_name`.
* **Activate Volume Group**:

  ```bash
  vgchange -a y vg_name
  ```

  Activates the volume group `vg_name`, making `/dev/mapper/vg_name-lv_name` accessible.
* **Mounting the Logical Volume**:

  ```bash
  mkdir /mnt/lv_mount
  mount /dev/mapper/vg_name-lv_name /mnt/lv_mount
  ```

  Mounts the logical volume to `/mnt/lv_mount` for accessing files.

### Conclusion

The `/dev/mapper/` directory plays a crucial role in managing storage resources on Linux systems, especially when using LVM, software RAID, or encryption. It provides a unified interface for accessing logical volumes and encrypted devices, simplifying the management and utilization of storage resources. Understanding its usage is essential for effective storage management and data security on Linux servers and workstations. For detailed options and configurations, refer to respective man pages (`man lvcreate`, `man cryptsetup`, etc.) and official documentation.
