- 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 cryptsetup
Set the size of the encrypted container in megabytes.
SIZE=1024
Set the path to the encrypted container.
CONTAINER=/root/data.bin
Set the filesystem.
FILESYSTEM=ext3
Set the container ID.
MOUNT_ID=homedir
Set the mount directory.
MOUNT_DIR=/home/
This command can be executed for a long time.
dd if=/dev/urandom of=$CONTAINER bs=1M count=$SIZE
Answer the question and enter the encryption password.
cryptsetup -y luksFormat $CONTAINER
cryptsetup luksOpen $CONTAINER $MOUNT_ID
mkfs -t $FILESYSTEM -j /dev/mapper/$MOUNT_ID
cryptsetup luksClose $MOUNT_ID
echo "cryptsetup luksOpen $CONTAINER $MOUNT_ID && mount /dev/mapper/$MOUNT_ID $MOUNT_DIR"
echo "umount $MOUNT_DIR && cryptsetup luksClose $MOUNT_ID"