LUKS是为Linux硬盘加密标准。通过提供一个标准的磁盘上的格式,它不仅方便之间分布的兼容性,而且还提供了多个用户密码的安全管理。必须首先对加密的卷进行解密,才能挂载其中的文件系统。
[root@desktop21 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 (还26G,够了吧,我只需要300M做实验)
VG UUID ZAGsPK-tIBO-08bd-RoMp-fPeC-Ei5l-x3asx6
[root@desktop21 Desktop]# lvcreate -L 300M -n testlv /dev/vol0
Rounding up size to full physical extent 320.00 MiB
Logical volume "testlv" created
[root@desktop21 Desktop]# cryptsetup luksFormat /dev/vol0/testlv WARNING! ======== This will overwrite data on /dev/vol0/testlv irrevocably. Are you sure? (Type uppercase yes): YES (注意,只能是大写字母) Enter LUKS passphrase: (输入密码) Verify passphrase: (确认密码)
1、[root@desktop21 Desktop]# cryptsetup luksOpen /dev/vol0/testlv testlv Enter passphrase for /dev/vol0/testlv: (输入密码进行验证!)
[root@desktop21 Desktop]# ll /dev/mapper/testlv /dev/vol0/testlv lrwxrwxrwx. 1 root root 7 Aug 4 15:17 /dev/mapper/testlv -> ../dm-7 lrwxrwxrwx. 1 root root 7 Aug 4 15:17 /dev/vol0/testlv -> ../dm-6
2、[root@desktop21 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, 24577, 40961, 57345, 73729, 204801, 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.
3、[root@desktop21 Desktop]# mkdir /testlv [root@desktop21 Desktop]# mount /dev/mapper/testlv /testlv/ [root@desktop21 Desktop]# df -h /testlv/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/testlv 308M 11M 283M 4% /testlv --->想要开机自动挂载?写道fstable里吧 [root@desktop21 Desktop]# vim /etc/fstab (加上这一行) /dev/mapper/testlv /testlv ext4 defaults 0 0
[root@desktop21 Desktop]# vim /etc/crypttab (加入这一行,具体分区自己改) testlv /dev/sda5
[root@desktop21 Desktop]# touch /root/passlv
[root@desktop21 Desktop]# vim /etc/crypttab (修改称这样,最后加入了密码文件的路径)
[root@desktop21 Desktop]# echo mypasswd >/root/passlv [root@desktop21 Desktop]# chown root /root/passlv [root@desktop21 Desktop]# chmod 600 /root/passlv [root@desktop21 Desktop]# cryptsetup luksAddKey /dev/vol0/testlv /root/passlv Enter any passphrase: (输入之前密码)
[root@desktop21 Desktop]# cat /root/passlv mypasswd
[root@desktop21 Desktop]# echo >/root/passlv [root@desktop21 Desktop]# cat /root/passlv
[root@desktop21 Desktop]# cryptsetup luksAddKey /dev/vol0/testlv /root/passlv Enter any passphrase: (还是输入之前的密码)
[root@desktop21 Desktop]# cat /root/passlv