Encrypt the partition with cryptsetup

Warning: this is a private study note only. There is no guarantee of the correctness of the contents. 

1. prepare a USB pen drive
2. check its label with lsblk

[jerry@jerrycc_laptop ~]$ lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 465.8G  0 disk
├─sda1            8:1    0   200M  0 part
...
sdb               8:16   1   1.9G  0 disk 

3.  Create new partition with fdisk:
For example, you'll get a partition called /dev/sdb1

4. Format the partition with LUKS format:
> sudo cryptsetup -y luksFormat /dev/sdb1 

5. Open the partition and create the name for the mapper:
> sudo cryptsetup luksOpen /dev/sdb1 myEncryptDisk

6. Format the partition with regular file system formats:
Note that you have to find the partition in the device mapper directory

> ls -al /dev/mapper/
lrwxrwxrwx.  1 root root       7  1月 16 23:16 myEncryptDisk -> ../dm-3

Then you format the partition with specific file system chosen (ext4 for example)
> sudo mkfs.ext4 /dev/mapper/myEncryptDisk

7. Mount the mapper to the system with mount. and use it.
8. After you're done, umount it.

9.  Lock the partition:
> sudo cryptsetup luksClose myEncryptDisk

10. Unlock existing partition
go to step 5., create a new mapper name, and so on.

留言

這個網誌中的熱門文章

在 vimtutor 的 help 遇到 E434: Can't find tag pattern 問題ㄒ

Logical volume management LVM

Create a CentOS installation USB key with dd command