- System environment
- System preparation
- Parameters
- Create a container
- Encrypt the container
- Make a file system in the container
- Commands for mounting and umounting
- CentOS 8.1
yum install cryptsetupSet the size of the encrypted container in megabytes.
SIZE=1024Set the path to the encrypted container.
CONTAINER=/root/data.binSet the filesystem.
FILESYSTEM=ext3Set the container ID.
MOUNT_ID=homedirSet the mount directory.
MOUNT_DIR=/home/This command can be executed for a long time.
dd if=/dev/urandom of=$CONTAINER bs=1M count=$SIZEAnswer the question and enter the encryption password.
cryptsetup -y luksFormat $CONTAINERcryptsetup luksOpen $CONTAINER $MOUNT_IDmkfs -t $FILESYSTEM -j /dev/mapper/$MOUNT_IDcryptsetup luksClose $MOUNT_IDecho "cryptsetup luksOpen $CONTAINER $MOUNT_ID && mount /dev/mapper/$MOUNT_ID $MOUNT_DIR"echo "umount $MOUNT_DIR && cryptsetup luksClose $MOUNT_ID"