LUKS is the standard for Linux hard disk encryption. By providing a standard disk format, it not only facilitates the compatibility between distributions, but also provides security management for multiple user passwords. You must decrypt the encrypted volume before mounting the file system. System encryption: [Tool: cryptsetup; common parameters: luksFormat, luksOpen, luksClose, luksAddKey] [involved files:/etc/crypttab; self-created password files] Note: The above parameters are large
LUKS is the standard for Linux hard disk encryption. By providing a standard disk format, it not only facilitates the compatibility between distributions, but also provides security management for multiple user passwords. You must decrypt the encrypted volume before mounting the file system.
System encryption: [Tool: cryptsetup; common parameters: luksFormat, luksOpen, luksClose, luksAddKey] [file involved:/etc/crypttab; Create password file by yourself]
Note: The above parameters cannot be case-insensitive.
Okay. Let's try this powerful tool ~
1. Draw a partition for testing (fdisk)
---> Here we use my machine as an example. Because I have made all the space into lvm, the partitions are different. Let's take a m experiment.
[Root@www.linuxidc.com Desktop] # vgdisplay
--- Volume group ---
VG Name vol0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 27
VG Access read/write
VG Status resizable
Max lv 0
Cur LV 4
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 55.22 GiB
PE Size 32.00 MiB
Total PE 1767
Alloc PE/Size 928/29 .00 GiB
Free PE/Size 839/26 .22 GiB (still 26 GB, enough, I only need m for the experiment)
Vg uuid ZAGsPK-tIBO-08bd-RoMp-fPeC-Ei5l-x3asx6
[Root@www.linuxidc.com Desktop] # lvcreate-L 300 M-n testlv/dev/vol0
Rounding up size to full physical extent 320.00 MiB
Logical volume "testlv" created
---> OK, generate the testlv partition, 320 M (related to PE)
Ii. Partition encryption (cryptsetup luksFormat. Do not format the partition first !)
[Root@www.linuxidc.com Desktop] # cryptsetup luksFormat/dev/vol0/testlv
WARNING!
==========
This will overwrite data on/dev/vol0/testlv irrevocably.
Are you sure? (Type uppercase yes): YES (Note: Only uppercase letters are allowed)
Enter LUKS passphrase: (Enter the password)
Verify passphrase: (confirm the password)
3. Okay. The password has been created. We decrypted it and formatted it for mounting. (If it is not decrypted, it cannot be operated on)
1. [root@www.linuxidc.com Desktop] # cryptsetup luksOpen/dev/vol0/testlv
Enter passphrase for/dev/vol0/testlv: (Enter the password for verification !) ---> Note: the command finally writes a ing device name "testlv". Let's take a look.
[Root@www.linuxidc.com Desktop] # ll/dev/mapper/testlv/dev/vol0/testlv
Lrwxrwxrwx. 1 root 7 Aug 4/dev/mapper/testlv-> ../dm-7
Lrwxrwxrwx. 1 root 7 Aug 4/dev/vol0/testlv-> ../dm-6 ---> the two are actually the same. The ing name must be added to the command. You can use the cryptsetup command by yourself.
2. [root@www.linuxidc.com Desktop] # mkfs. ext4/dev/mapper/testlv
Mke2fs 1.41.12 (17-May-2010)
Filesystem label =
OS type: Linux
Block size = 1024 (log = 0)
Fragment size = 1024 (log = 0)
Stride = 0 blocks, Stripe width = 0 blocks
81600 inodes, 325632 blocks
16281 blocks (5.00%) reserved for the super user
First data block = 1
Maximum filesystem blocks = 67633152
40 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
8193,245 77, 40961,573 45, 73729,204 221185
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override. ---> OK. It will be formatted soon. Create a new directory for mounting!
3. [root@www.linuxidc.com Desktop] # mkdir/testlv
[Root@www.linuxidc.com Desktop] # mount/dev/mapper/testlv/
[Root@www.linuxidc.com Desktop] # df-h/testlv/
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/testlv 308 M 11 M 283 M 4%/testlv
---> Want to enable automatic mounting? Write in fstable
[Root@www.linuxidc.com Desktop] # vim/etc/fstab (add this line)
/Dev/mapper/testlv ext4 defaults 0 0 [the restart won't be mounted. Why? The configuration file is not written to inform the system that I have encrypted partitions. OK. Continue the test]