Create encrypted FS in a file
#Create a file and allocate its size : here 1GB
dd if=/dev/zero of=encrypteddrive bs=1024 count=1048576
#Setup the encrypted file
cryptsetup -y luksFormat encrypteddrive
(enter passphrase and confirm)
#Open the Encrypted device
sudo cryptsetup luksOpen encrypteddrive secretdata
(enter password)
#Create an EXT4 filesystem inside the encrypted file
sudo mkfs.ext4 /dev/mapper/secretdata
#Create a directory to be the mountpoint
mkdir ../mp-encrypted
#Mount the encrypted FS
sudo mount /dev/mapper/secretdata ../mp-encrypted/
#After use, unmount the encrypted FS and close the encrypted file
sudo umount ../mp-encrypted/
sudo cryptsetup luksClose secretdata
Use:
#To access Data, open the file and mount it
sudo cryptsetup luksOpen encrypteddrive secretdata
sudo mount /dev/mapper/secretdata ../mp-encrypted/
#To close after use, unmount the partition and close the file
sudo umount ../mp-encrypted/
sudo cryptsetup luksClose secretdata
Resize the secret file filesystem example: add 2 GB
#Add 2 GB to the file (8 x 256M)
dd if=/dev/zero of=encrypteddrive bs=256M count=8 oflag=append conv=notrunc
#Open the Encrypted device
sudo cryptsetup luksOpen encrypteddrive secretdata
#resize the encrypted partition
sudo cryptsetup resize secretdata
#check the EXT4 filesystem inside the encrypted file
sudo e2fsck -f /dev/mapper/secretdata
#Resize the EXT filesystem
sudo resize2fs /dev/mapper/secretdata
Commentaires