github.com/containerd/Containerd@v1.4.13/snapshots/devmapper/README.md (about)

     1  ## Devmapper snapshotter
     2  
     3  Devmapper is a `containerd` snapshotter plugin that stores snapshots in ext4-formatted filesystem images
     4  in a devicemapper thin pool.
     5  
     6  ## Setup
     7  
     8  To make it work you need to prepare `thin-pool` in advance and update containerd's configuration file.
     9  This file is typically located at `/etc/containerd/config.toml`.
    10  
    11  Here's minimal sample entry that can be made in the configuration file:
    12  
    13  ```
    14  [plugins]
    15    ...
    16    [plugins.devmapper]
    17      pool_name = "containerd-pool"
    18      base_image_size = "8192MB"
    19    ...
    20  ```
    21  
    22  The following configuration flags are supported:
    23  * `root_path` - a directory where the metadata will be available (if empty
    24    default location for `containerd` plugins will be used)
    25  * `pool_name` - a name to use for the devicemapper thin pool. Pool name
    26    should be the same as in `/dev/mapper/` directory
    27  * `base_image_size` - defines how much space to allocate when creating the base device
    28  * `async_remove` - flag to async remove device using snapshot GC's cleanup callback
    29  
    30  Pool name and base image size are required snapshotter parameters.
    31  
    32  ## Run
    33  Give it a try with the following commands:
    34  
    35  ```bash
    36  ctr images pull --snapshotter devmapper docker.io/library/hello-world:latest
    37  ctr run --snapshotter devmapper docker.io/library/hello-world:latest test
    38  ```
    39  
    40  ## Requirements
    41  
    42  The devicemapper snapshotter requires `dmsetup` (>= 1.02.110) command line tool to be installed and
    43  available on your computer. On Ubuntu, it can be installed with `apt-get install dmsetup` command.
    44  
    45  ### How to setup device mapper thin-pool
    46  
    47  There are many ways how to configure a devmapper thin-pool depending on your requirements, disk configuration,
    48  and environment.
    49  
    50  On local dev environment you can utilize loopback devices. This type of configuration is simple and suits well for
    51  development and testing (please note that this configuration is slow and not recommended for production uses).
    52  Run the following script to create a thin-pool device:
    53  
    54  ```bash
    55  #!/bin/bash
    56  set -ex
    57  
    58  DATA_DIR=/var/lib/containerd/devmapper
    59  POOL_NAME=devpool
    60  
    61  mkdir -p ${DATA_DIR}
    62  
    63  # Create data file
    64  sudo touch "${DATA_DIR}/data"
    65  sudo truncate -s 100G "${DATA_DIR}/data"
    66  
    67  # Create metadata file
    68  sudo touch "${DATA_DIR}/meta"
    69  sudo truncate -s 10G "${DATA_DIR}/meta"
    70  
    71  # Allocate loop devices
    72  DATA_DEV=$(sudo losetup --find --show "${DATA_DIR}/data")
    73  META_DEV=$(sudo losetup --find --show "${DATA_DIR}/meta")
    74  
    75  # Define thin-pool parameters.
    76  # See https://www.kernel.org/doc/Documentation/device-mapper/thin-provisioning.txt for details.
    77  SECTOR_SIZE=512
    78  DATA_SIZE="$(sudo blockdev --getsize64 -q ${DATA_DEV})"
    79  LENGTH_IN_SECTORS=$(bc <<< "${DATA_SIZE}/${SECTOR_SIZE}")
    80  DATA_BLOCK_SIZE=128
    81  LOW_WATER_MARK=32768
    82  
    83  # Create a thin-pool device
    84  sudo dmsetup create "${POOL_NAME}" \
    85      --table "0 ${LENGTH_IN_SECTORS} thin-pool ${META_DEV} ${DATA_DEV} ${DATA_BLOCK_SIZE} ${LOW_WATER_MARK}"
    86  
    87  cat << EOF
    88  #
    89  # Add this to your config.toml configuration file and restart containerd daemon
    90  #
    91  [plugins]
    92    [plugins.devmapper]
    93      pool_name = "${POOL_NAME}"
    94      root_path = "${DATA_DIR}"
    95      base_image_size = "10GB"
    96  EOF
    97  ```
    98  
    99  Use `dmsetup` to verify that the thin-pool created successfully:
   100  ```bash
   101  sudo dmsetup ls
   102  devpool	(253:0)
   103  ```
   104  
   105  Once configured and restarted `containerd`, you'll see the following output:
   106  ```
   107  INFO[2020-03-17T20:24:45.532604888Z] loading plugin "io.containerd.snapshotter.v1.devmapper"...  type=io.containerd.snapshotter.v1
   108  INFO[2020-03-17T20:24:45.532672738Z] initializing pool device "dev-pool"
   109  ```
   110  
   111  Another way to setup a thin-pool is via [container-storage-setup](https://github.com/projectatomic/container-storage-setup)
   112  tool (formerly known as `docker-storage-setup`). It is a script to configure CoW file systems like devicemapper:
   113  
   114  ```bash
   115  #!/bin/bash
   116  set -ex
   117  
   118  # Block device to use for devmapper thin-pool
   119  BLOCK_DEV=/dev/sdf
   120  POOL_NAME=devpool
   121  VG_NAME=containerd
   122  
   123  # Install container-storage-setup tool
   124  git clone https://github.com/projectatomic/container-storage-setup.git
   125  cd container-storage-setup/
   126  sudo make install-core
   127  echo "Using version $(container-storage-setup -v)"
   128  
   129  # Create configuration file
   130  # Refer to `man container-storage-setup` to see available options
   131  sudo tee /etc/sysconfig/docker-storage-setup <<EOF
   132  DEVS=${BLOCK_DEV}
   133  VG=${VG_NAME}
   134  CONTAINER_THINPOOL=${POOL_NAME}
   135  EOF
   136  
   137  # Run the script
   138  sudo container-storage-setup
   139  
   140  cat << EOF
   141  #
   142  # Add this to your config.toml configuration file and restart containerd daemon
   143  #
   144  [plugins]
   145    [plugins.devmapper]
   146      pool_name = "${VG_NAME}-${POOL_NAME}"
   147      base_image_size = "10GB"
   148  EOF
   149  ```
   150  
   151  If successful `container-storage-setup` will output:
   152  ```
   153  + echo VG=containerd
   154  + sudo container-storage-setup
   155  INFO: Volume group backing root filesystem could not be determined
   156  INFO: Writing zeros to first 4MB of device /dev/xvdf
   157  4+0 records in
   158  4+0 records out
   159  4194304 bytes (4.2 MB) copied, 0.0162906 s, 257 MB/s
   160  INFO: Device node /dev/xvdf1 exists.
   161    Physical volume "/dev/xvdf1" successfully created.
   162    Volume group "containerd" successfully created
   163    Rounding up size to full physical extent 12.00 MiB
   164    Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
   165    Logical volume "devpool" created.
   166    Logical volume containerd/devpool changed.
   167  ...
   168  ```
   169  
   170  And `dmsetup` will produce the following output:
   171  ```bash
   172  sudo dmsetup ls
   173  containerd-devpool          (253:2)
   174  containerd-devpool_tdata    (253:1)
   175  containerd-devpool_tmeta    (253:0)
   176  ```