1:磁盘加密
临时加密
fdisk /dev/vdb #创建设备
cryptsetup luksFormat /dev/vdb1 #安装加密层
cryptsetup open /dev/vdb1 westos #打开加密层
mkfs.xfs /dev/mapper/westos #格式化揭秘后设备
mount /dev/mapper/westos /mnt/ #挂载设备
umount /mnt #解除挂载
cryptsetup close westos #退出加密层
[root@foundation164 Desktop]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6793b4f9.
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6793b4f9
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20
971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6793b4f9
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@foundation164 Desktop]# partprobe
[root@foundation164 Desktop]# cryptsetup luksFormat /dev/vdb1
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
[root@foundation164 Desktop]# cryptsetup open /dev/vdb1 westos
Enter passphrase for /dev/vdb1:
[root@foundation164 Desktop]# mkfs.xfs /dev/mapper/westos
meta-data=/dev/mapper/westos isize=256 agcount=4, agsize=65408 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=261632, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@foundation164 Desktop]# mount /dev/mapper/westos /mnt/
[root@foundation164 Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3124812 7349088 30% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17004 925656 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/westos 1043116 32928 1010188 4% /mnt
[root@foundation164 Desktop]# umount /mnt
[root@foundation164 Desktop]# cryptsetup close westos
[root@foundation164 Desktop]#
永久挂载
vim /etc/crypttab
#################################################
解密后设备管理文件 设备 加密字符存放文件
redhat /dev/vdb1 /root/lukspsfile
#################################################
vim /root/lukspsfile ##编辑密码
chmod 600 /root/lukspsfile ##设置权限
cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile
vim /etc/fstab
################################################
/dev/mapper/redhat /mnt xfs defaults 0 0
################################################
[root@foundation164 Desktop]# vim /etc/crypttab
[root@foundation164 Desktop]# vim /root/lukspsfile
[root@foundation164 Desktop]# chmod 600 /root/lukspsfile
[root@foundation164 Desktop]# cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile
Enter any passphrase:
[root@foundation164 Desktop]# vim /etc/fstab
[root@foundation164 Desktop]#reboot
加密清除
vim /etc/fstab
/etc/crypttab
rm -fr /root/lukspsfile
[root@foundation164 Desktop]# vim /etc/fstab
[root@foundation164 Desktop]# > /etc/crypttab
[root@foundation164 Desktop]# rm -fr /root/lukspsfile
2:磁盘阵列
fdisk /dev/vdb #创建三个分区
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3} #制作双磁盘一个闲置 a 添加 l 级别 n 数量 x 闲置
mkfs.xfs /dev/md0 #分区
mount /dev/md0 /mnt/ #挂载
watch -n 1 'cat /proc/mdstat; df -h /mnt' #监控
mdadm -D /dev/md0 #查看
mdadm /dev/md0 -f /dev/vdb2 #破坏
mdadm /dev/md0 -r /dev/vdb2 #删除
mdadm /dev/md0 -a /dev/vdb2 #添加
umount /dev/md0 #取消挂载
mdadm -S /dev/md0 #停止使用
fdisk /dev/vdb #删除磁盘
partprobe #同步分区表
[root@foundation164 Desktop]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6793b4f9
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1g
Unsupported suffix: 'g'.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
2^N: K (KibiByte), M (MebiByte), G (GibiByte)
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (2099200-20971519, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (4196352-20971519, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +1G
Partition 3 of type Linux and of size 1 GiB is set
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6793b4f9
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux
/dev/vdb2 2099200 4196351 1048576 83 Linux
/dev/vdb3 4196352 6293503 1048576 83 Linux
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@foundation164 Desktop]# partprobe
[root@foundation164 Desktop]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array?
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@foundation164 Desktop]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize=256 agcount=4, agsize=65500 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=262000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@foundation164 Desktop]# mount /dev/md0 /mnt
[root@foundation164 Desktop]#
[root@foundation164 Desktop]# watch -n 1 'cat /proc/mdstat;df -h /mnt'
[root@foundation164 Desktop]# mdadm /dev/md0
/dev/md0: 1023.44MiB raid1 2 devices, 1 spare. Use mdadm --detail for more detail.
[root@foundation164 Desktop]# mdadm /dev/md0 -f /dev/vdb2
mdadm: set /dev/vdb2 faulty in /dev/md0
[root@foundation164 Desktop]# mdadm /dev/md0 -r /dev/vdb2
mdadm: hot removed /dev/vdb2 from /dev/md0
[root@foundation164 Desktop]# mdadm /dev/md0 -a /dev/vdb2
mdadm: added /dev/vdb2
[root@foundation164 Desktop]# umount /mnt
[root@foundation164 Desktop]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@foundation164 Desktop]#
[root@foundation164 Desktop]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1-3, default 3): 1
Partition 1 is deleted
Command (m for help): d
Partition number (2,3, default 3): 2
Partition 2 is deleted
Command (m for help): d
Selected partition 3
Partition 3 is deleted
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6793b4f9
Device Boot Start End Blocks Id System
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@foundation164 Desktop]# partprobe
[root@foundation164 Desktop]#