存储设备的管理

这篇主要讲了

1.设备的基本信息,及基本使用 挂载 卸载等

2.设备的分区方法 ,及普通分区的管理(修改标签,开机自动化挂载等)

3.swap分区的管理 ,swap分区是直接被系统利用的分区不需要挂载

4.分区对不同用户设置配额

5.分区加密 对加密分区读写 破坏加密分区



(一)设备的基本信息及使用


一.设备的查看


1.发现系统中的设备

(1)fdisk -l

[root@server ~]# fdisk -l
Disk /dev/vda: 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: 0x00013f3e
Device Boot      Start         End      Blocks   Id  System                         ##第一块硬盘分区信息
/dev/vda1   *        2048    20970332    10484142+  83  Linux
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



(2)cat /proc/partitions     ##查看分区表

 [root@server ~]# cat /proc/partitions
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb

 

partprobe ##同步分区表 (看的系统中的)



2.系统发现的,但是没有投入使用 随时可以使用的设备

 (1)blkid    ##查看设备的id信息

【root@server ~]# blkid  
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs“

设备名字     uid                                                                              文件系统类型




3.被系统发现并正在使用的设备

(1)df  (看的硬盘中的)

     -h  ##单位为1g=2^n (更精确)

[root@server ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        10G  6.8G  3.3G  68% /
devtmpfs        482M     0  482M   0% /dev
tmpfs           498M   84K  497M   1% /dev/shm
tmpfs           498M   14M  485M   3% /run
tmpfs           498M     0  498M   0% /sys/fs/cgroup


      -H  ##单位为1g=10^n

[root@server ~]# df -H

Filesystem      Size  Used Avail Use% Mounted on

/dev/vda1        11G  7.3G  3.5G  68% /

devtmpfs        506M     0  506M   0% /dev

tmpfs           522M   87k  522M   1% /dev/shm

tmpfs           522M   14M  508M   3% /run

tmpfs           522M     0  522M   0% /sys/fs/cgroup






二.设备名称的读取

1./dev/xd*

x=s  /dev/sd*          ##sate硬盘,或者iscsi网络存储
x=v  /dev/vd*          ##虚拟硬盘,一般出现在虚拟机里
x=h  /dev/hd*          ##ide硬盘 ,一般出现在老式电脑里
*=a~...                ##/dev/vda, 系统中的第一块虚拟硬盘
/dev/sda1              ##系统中的第一块sate硬盘的第一个分区


2./dev/cdrom,/dev/sr[0-...]  ##系统中的光驱

3./dev/mapper/*              ##系统中的虚拟设备




三.设备的使用

设备必须用目录来对设备中的内容进行读取
所以设备使用时需要作挂载动作

 


1.blkid     ##识别设备

[root@really ~]# blkid
/dev/sda1: UUID="B01E51981E515904" TYPE="ntfs" 
/dev/sda2: UUID="d2f71dd0-0b65-4c28-b6b0-da684548456f" TYPE="xfs" 
/dev/sda3: UUID="373992f9-e6b5-4901-b734-8cfb74f61b0d" TYPE="swap" 
/dev/sda5: UUID="e39bbd52-0703-4015-819d-8664d40e7c4a" TYPE="xfs" 
/dev/sdb1: LABEL="M-gM-3M-;M-gM-;M-^_" UUID="0000678400004823" TYPE="ntfs" 
/dev/sdb5: LABEL="M-hM-=M-/M-dM-;M-6" UUID="0000678400004823" TYPE="ntfs" 
/dev/sdb6: LABEL="M-fM-^VM-^GM-fM-!M-#" UUID="0000678400004823" TYPE="ntfs" 
/dev/sdb7: LABEL="M-eM-(M-1M-dM-9M-^P" UUID="0000678400004823" TYPE="ntfs" 
/dev/loop0: UUID="2015-10-30-11-11-49-00" LABEL="RHEL-7.2 Server.x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/sdc1: LABEL="HP v285w" UUID="9B03-2CED" TYPE="vfat"        ##插入的u盘


[root@really ~]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda5       56237232 40605444  15631788  73% /
devtmpfs         3870272        0   3870272   0% /dev
tmpfs            3879028      568   3878460   1% /dev/shm
tmpfs            3879028     9256   3869772   1% /run
tmpfs            3879028        0   3879028   0% /sys/fs/cgroup
/dev/sda2         508588   120876    387712  24% /boot
/dev/loop0       3947824  3947824         0 100% /var/www/html/rh7.2
/dev/sdc1       31020992  2929920  28091072  10% /run/media/kiosk/HP v285w          ##u盘挂载位置




2.mount 设备 挂载点   ##挂载设备(挂载在一个目录后 可查看设备里的内容 不能查看原来目录里的东西)

(1)##默认不加参数为读写

(2)-o ro         ##-o 指定动作 ro表示read only

[root@really mnt]# mount -o ro /dev/sdc1 /mnt
[root@really mnt]# ls -lr /mnt
total 32
drwxr-xr-x. 8 root root 16384 Oct 30 15:31 ????
drwxr-xr-x. 4 root root 16384 Oct 28 11:34 ??
[root@really mnt]# touch file /mnt
touch: setting times of ‘/mnt’: Read-only file system


(3)-o remount,rw 设备或挂载点       ##热更改为读写 不需要解挂载(在设备使用时将参数改为rw)

[root@really mnt]# mount -o remount,rw /dev/sdc1
[root@really mnt]# touch /mnt/file
[root@really mnt]# ls -lr /mnt
total 32
-rwxr-xr-x. 1 root root     0 Nov  6 11:30 file
drwxr-xr-x. 8 root root 16384 Oct 30 15:31 ????
drwxr-xr-x. 4 root root 16384 Oct 28 11:34 ??





3.umount 设备|挂载点     ##卸载设备(可接设别或挂载点 任意

[root@really mnt]# umount /dev/sdc1                 ##卸载u盘挂载
[root@really mnt]# df                                          ##查看正在使用的设备
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda5       56237232 40606232  15631000  73% /
devtmpfs         3870272        0   3870272   0% /dev
tmpfs            3879028      568   3878460   1% /dev/shm
tmpfs            3879028     9252   3869776   1% /run
tmpfs            3879028        0   3879028   0% /sys/fs/cgroup
/dev/sda2         508588   120876    387712  24% /boot
/dev/loop0       3947824  3947824         0 100% /var/www/html/rh7.2


注意:当卸载设备时出现下列情况

[root@server zl]# umount /dev/vdb1
umount: /zl: target is busy.                                                           ##出现如下报错时
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))


表示设备正在被系统的某个程序使用的处理方法:

(1)进程发现的方式

   1.fuser -vm 设备

[root@foundation14 ~]# fuser -vm /dev/sdb1
                     USER        PID ACCESS COMMAND
/dev/sdb1:           root     kernel mount /mnt
                     root      20071 ..c.. bash
                     root      20720 F.c.. vim


  2.lsof 设备

[root@foundation14 ~]# lsof /dev/sdb1
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    20071 root  cwd    DIR   8,17    16384    1 /mnt
vim     20720 root  cwd    DIR   8,17    16384    1 /mnt
vim     20720 root    3u   REG   8,17    12288 3096 /mnt/.file.swo


(2)关闭进程的方法

   1.fuser -kvm 设备

[root@foundation14 ~]# fuser -kvm /dev/sdb1
                     USER        PID ACCESS COMMAND
/dev/sdb1:           root     kernel mount /mnt
                     root      15647 ..c.. bash
                     root      20021 F.c.. vim
[root@foundation14 ~]# umount /dev/sdb1
[root@foundation14 ~]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda5      266049616 23050820 242998796   9% /
devtmpfs         1868044        0   1868044   0% /dev
tmpfs            1881152      516   1880636   1% /dev/shm
tmpfs            1881152     9016   1872136   1% /run
tmpfs            1881152        0   1881152   0% /sys/fs/cgroup
/dev/sda2         505580   149488    356092  30% /boot
/dev/loop0       3947824  3947824         0 100% /var/www/html/rh7.2
/dev/loop1       3947824  3947824         0 100% /rh7.2
tmpfs             376232       20    376212   1% /run/user/1000


  2.kill -9  uid

[root@foundation14 ~]# kill -9 2007
-bash: kill: (2007) - No such process
[root@foundation14 ~]# kill -9 20071
[root@foundation14 ~]# umount /dev/sdb1 
[root@foundation14 ~]# df







(二)设备的分区


一.设备分区信息

1.mbr 主引导 446bit(字节) 磁头去找系统的启动分区

2.mbr + 55aa (2个字节 硬盘有效性标示类似于目录)+mpt (主分区表64字节)=512

3.一个主分区占用主分区表16个字节记录分区信息

4.一块硬盘上如果用mbr分区方式 最多可以存在四个主分区

5.『分区表记录的为主分区
扩展分区弥补分区表不足 记录逻辑分区』(mbr分区方式,一个分区最大2tb)




二.分区的划分


1.[root@node1 ~]# fdisk -l  ##发现系统中的设备

Disk /dev/vda: 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux  ##vda1 已经被全部使用

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors  ##vdb还没有分区
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes




2.[root@node1 ~]# fdisk /dev/vdb  ##进入/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 0x12a6a759.

Command (m for help): m     ##输入m 查看参数用法

Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition     ##删除分区
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition    ##新建分区
   o   create a new empty DOS partition table
   p   print the partition table          ##区分分区表信息
   q   quit without saving changes   ##推出
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit     ##将当前操作写入硬盘分区
   x   extra functionality (experts only)

Command (m for help): n               ##创建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)     ##主分区
   e   extended  ##拓展分区

Partition number (1-4, default 1): 1     ##确认主分区id
First sector (2048-20971519, default 2048):     ##分区起始快位置 用默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M      ##分区结束快位置 用+
Partition 1 of type Linux and of size 100 MiB is set

Command (m for help): wq            ##保存分区策略并退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.




3.[root@node1 ~]# cat /proc/partitions     ##查看新建分区有没有被系统识别

major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     102400 vdb1    ##被识别



[root@node1 ~]# mount /dev/vdb1 /mnt  ##可以识别但不能使用

mount: /dev/vdb1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'  ##没有识别硬盘信息的软件(文件系统)
##文件系统包括
#ext2-4 日志文件系统(可以支持数据32TB分区)
#fwt(4TB)
#wrfs(32TB)
#xfs (18EB 吞吐速度可达到7GB/s 硬盘达不到 大数据常用)



4.[root@node1 ~]# mkfs.xfs /dev/vdb1    ##格式化设备

meta-data=/dev/vdb1              isize=256    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=25600, 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@node1 ~]# blkid          ##查看可用设备
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="22987d47-c812-47b3-9fa1-af8436dec326" TYPE="xfs"      ##可以看到被格式化好的设备
[root@node1 ~]# mount /dev/vdb1 /mnt      ##挂载设备 使设备投入使用
[root@node1 ~]# cd /mnt
[root@node1 mnt]# ls
[root@node1 mnt]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3831836   6642064  37% /
devtmpfs          481120       0    481120   0% /dev
tmpfs             496708      84    496624   1% /dev/shm
tmpfs             496708   13064    483644   3% /run
tmpfs             496708       0    496708   0% /sys/fs/cgroup
/dev/vdb1          98988    5280     93708   6% /mnt                 ##挂载的设备




三.设备永久挂载

1.[root@node1 mnt]# vim /etc/fstab ##设备挂载配置文件

设备            挂载点     文件系统类型     挂载参数    是否备份设备     是否检测设备
/dev/vdb1      /zl            xfs               default           0                      0


2.[root@node1 mnt]# mount -a  ##让fstab中未生效的策略生效

[root@node1 mnt]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3831848   6642052  37% /
devtmpfs          481120       0    481120   0% /dev
tmpfs             496708      84    496624   1% /dev/shm
tmpfs             496708   13064    483644   3% /run
tmpfs             496708       0    496708   0% /sys/fs/cgroup
/dev/vdb1          98988    5280     93708   6% /zl


3.排错 如配置文件写错 会导致系统启动失败 用之前学习的重置root密码类似的方式 修改配置文件





四.删除分区

1.[root@node1 mnt]# vim /etc/fstab  ##删除永久挂载配置策略


2.[root@node1 mnt]# umount /dev/vdb1   ##卸载挂载

[root@node1 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3832384   6641516  37% /
devtmpfs          481120       0    481120   0% /dev
tmpfs             496708      84    496624   1% /dev/shm
tmpfs             496708   13064    483644   3% /run
tmpfs             496708       0    496708   0% /sys/fs/cgroup
 

3.[root@server ~]# 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
Selected partition 1
Partition 1 is deleted




五.分区方式修改

 

一.mbr----->gpt

1.[root@node1 mnt]# parted /dev/vdb  ##修改硬盘分区方式

GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel     ##修改分区方式                                                     
New disk label type? gpt     ##改为gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? y           ##是否更改                                       
(parted) quit   ##退出
Information: You may need to update /etc/fstab.  ##提示有新的更改 建议同步配置文件



2.[root@node1 mnt]# fdisk -l   ##查看

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: gpt      ##改为gpt了



3.[root@node1 mnt]# fdisk /dev/vdb   ##在gpt分区模式下新建立分区

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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): n
Partition number (1-128, default 1): 1  ##可以存在128个分区


 

二.gpt--------->mbr

1.[root@node1 mnt]# parted /dev/vdb

GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel                                                          
New disk label type? msdos                                                
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? y                                                                 
(parted) quit                                                             
Information: You may need to update /etc/fstab.



2.[root@node1 mnt]# fdisk -l

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: 0x00033857




(三)swap分区的管理

 

一.swap 分区的查看

[root@foundation14 ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/sda3                                  partition    3933180    0    -1



二.swap 分区的建立


1.[root@node1 ~]# 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): n     ##新建分区
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (206848-20971519, default 206848): 
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M
Partition 2 of type Linux and of size 100 MiB is set

Command (m for help): t      ##更改分区id
Partition number (1,2, default 2): 2   ##选择更改哪个分区
Hex code (type L to list all codes): l  ##列出所有分区id

Hex code (type L to list all codes): 82  ##更改id的编号
Changed type of partition 'Linux' to 'Linux swap / Solaris'  ##更改成功

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


2.[root@node1 ~]# mkswap /dev/vdb2  ##格式化新建分区

Setting up swapspace version 1, size = 102396 KiB
no label, UUID=0722a0b2-503c-43cb-aad1-a92b65284ec4
[root@node1 ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="cb24b1a8-b3b9-4e61-ab84-ef86c9df0903" TYPE="swap" 
/dev/vdb2: UUID="0722a0b2-503c-43cb-aad1-a92b65284ec4" TYPE="swap" 


3.[root@node1 ~]# swapon -a /dev/vdb2  ##激活swap 使系统利用此设备(swap是系统利用设备 不需要挂载)

[root@node1 ~]# fdisk -l
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   82  Linux swap / Solaris


4.[root@node1 ~]# vim /etc/fstab   ##开机自动激活swap

/dev/vdb2     swap     swap    defaults        0  0


5.[root@node1 ~]# swapoff /dev/vdb2  ##关闭






三.当磁盘全部被占用 不能创建新分区时 可以用文件来代替


1.[root@node1 ~]# dd if=/dev/zero of=/swapfile bs=1M count=1000  ##从/dev/zero(为空) 截取1M的片段1000个(1G) 新建为/swapfile文件

1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 14.8073 s, 70.8 MB/s
[root@node1 ~]# du -sh /swapfile ##查看新建文件大小
1000M    /swapfile



2.[root@node1 ~]# mkswap /swapfile  ##格式化文件

Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=5d6920f6-584e-48f4-a236-7c4ef31c911d
[root@node1 ~]# blkid    ##查看不到/swapfile 因为其表示设备是文件
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="cb24b1a8-b3b9-4e61-ab84-ef86c9df0903" TYPE="swap" 
/dev/vdb2: UUID="0722a0b2-503c-43cb-aad1-a92b65284ec4" TYPE="swap" 



3.[root@node1 ~]# vim /etc/fstab     ##编辑配置文件

/swapfile        swap      swap     defaults         0  0  



4.[root@node1 ~]# swapon -a    ##激活

swapon: /swapfile: insecure permissions 0644, 0600 suggested.
[root@node1 ~]# swapon -s       ##查看
Filename                Type        Size    Used    Priority
/dev/vdb2                                  partition    102396    0    -1
/swapfile                                  file    1023996    0    -2







(四)磁盘配额

为磁盘使用用户分配额度

分区配额针对设备


1.[root@node1 ~]# mount -o usrquota /dev/vdb1 /zl/   ##激活设置配额参数


2.[root@node1 ~]# chmod 777 /zl/  ##加权限 为下面实验做准备


3.[root@node1 ~]# edquota -u student /dev/vdb1   ##编辑对于/dev/vdb1硬盘的student用户的使用限额

Disk quotas for user student (uid 1000):

  Filesystem                   blocks       soft       hard     inodes     soft     hard

  /dev/vdb1                         0          0          204800          0        0        0



4.效果

(1)[student@node1 ~]$ dd if=/dev/zero of=/zl/fiel bs=1M count=20           ##在/zl中创建20M的文件

20+0 records in

20+0 records out

20971520 bytes (21 MB) copied, 0.0400231 s, 524 MB/s

[student@node1 ~]$ du -sh /zl/file                                                                    ##成功创建20M文件

20M    /zl/file


(2)[student@node1 ~]$ dd if=/dev/zero of=/zl/fiel bs=1M count=220      ##在/zl中创建220M的文件

dd: error writing ‘/zl/fiel’: Disk quota exceeded

201+0 records in

200+0 records out

209715200 bytes (210 MB) copied, 0.744319 s, 282 MB/s

[student@node1 ~]$ du -sh /zl/file                                                       ##只创建出200M文件 因为之前设置的student用户使用此设备的配额为200M

200M    /zl/file


5.开机自动激活配额

/dev/vdb1  /zl xfs defaults,usrquota 0 0







(五)分区加密


一.分区加密


1.[root@localhost ~]# fdisk /dev/vdb      ##新建分区

2.[root@localhost ~]# cryptsetup luksFormat /dev/vdb1   ##对设备加密

WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES  ##确认加密
Enter passphrase: 
Verify passphrase:

 


3.[root@localhost mapper]# cryptsetup open /dev/vdb1 zl  ##解密设备

Enter passphrase for /dev/vdb1: 


4.[root@localhost mapper]#  mkfs.xfs  /dev/mapper/zl   ####用管理文件格式化设备(/dev/mapper/zl 为设备加密时的形态)

meta-data=/dev/mapper/zl         isize=256    agcount=4, agsize=655168 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=2620672, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0



5.[root@localhost mapper]# mount /dev/mapper/zl  ##挂载设备 设备内容可读写

mount: can't find /dev/mapper/zl in /etc/fstab
[root@localhost mapper]# mount /dev/mapper/zl /mnt/
[root@localhost mapper]# touch /mnt/file{1..5}
[root@localhost mapper]# cd /mnt
[root@localhost mnt]# ls
file1  file2  file3  file4  file5



6.[root@localhost ~]# umount /mnt  ##卸载设备

7.[root@localhost ~]# cryptsetup close zl  ##关闭设备加密层

[root@localhost ~]# mount /dev/mapper/zl  /mnt/  ##无法使用设备
mount: special device /dev/mapper/zl does not exist
[root@localhost ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="eb723191-7d41-40b5-a06a-00fc027ad663" TYPE="crypto_LUKS" ##设备加密



二.开机自动加密

1.[root@localhost ~]# vim /etc/fstab

/dev/mapper/zl /mnt xfs defaults 0 0


2.[root@localhost ~]# vim /etc/crypttab

zl /dev/vdb1 /root/passfile


3.[root@localhost ~]# vim /root/passfile

19970214


4.root@localhost ~]# chmod 600 /root/passfile


5.[root@localhost ~]# cryptsetup luksAddKey /dev/vdb1 /root/passfile

Enter any passphrase: 




三.加密的清除

1.[root@localhost ~]# umount /dev/mapper/zl  ##卸载设备

2.[root@localhost ~]# cryptsetup close zl  ##关闭设备加密层

3.[root@localhost ~]# mkfs.xfs /dev/vdb1  ##格式化设备 破坏加密

mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (crypto_LUKS).
mkfs.xfs: Use the -f option to force overwrite.


4.[root@localhost ~]# mkfs.xfs /dev/vdb1 -f  ##强制执行3.

meta-data=/dev/vdb1              isize=256    agcount=4, agsize=655296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=2621184, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0



5.[root@localhost ~]# vim /etc/fstab  ##删除加密时修改的配置文件

[root@localhost ~]# cat /etc/fstab 
#
## /etc/fstab
## Created by anaconda on Wed May  7 01:22:57 2014
##
## Accessible filesystems, by reference, are maintained under '/dev/disk'
## See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
##
#UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /                       xfs     defaults        1 1



6.[root@localhost ~]# vim /etc/crypttab    ##删除加密时修改的配置文件

[root@localhost ~]# cat /etc/crypttab  ##内容为空


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值