Linux磁盘分区详解

Linux磁盘分区详解文章目录预备知识磁道扇区柱面簇文件系统本地存储设备的识别设备的挂载和卸载设备名称设备挂载磁盘分区具体分区步骤swap分区管理概念新建swap分区删除swap分区磁盘配额quota配额概念quota如何设定配额quota的限额磁盘加密cryptsetup概念加密方法加密设备开机自动挂载删除加密后的虚拟设备预备知识在开始之前,先了解一些基础知识。磁道硬盘被一圈圈分成18等分的同心圆,这些同心…

大家好,又见面了,我是你们的朋友全栈君。

预备知识

在开始之前,先了解一些基础知识。

磁道

  • 硬盘被一圈圈分成18等分的同心圆,这些同心圆就是磁道。但打开硬盘,用户不能看到这些,它实际上是被磁头磁化的同心圆。这些磁道是有间隔的,因为磁化单元太近会产生干扰。

扇区

  • 每个磁道中被分成若干等份的区域。扇区是硬盘数据存储的最小单位。

柱面

  • 假如一个硬盘只有3个磁盘片,每一片中的磁道数是相等的。从外圈开始,这些磁道被分成了0磁道、1磁道、2磁道…具有相同磁道编号的同心圆组成面就称作柱面。为了便于理解,柱面可以看作没有底的铁桶。可以看出,柱面数就是磁盘上的磁道数。柱面是硬盘分区的最小单位。因此,一个硬盘的容量=柱面X磁头X扇区X512。

  • 扇区是硬盘数据存储的最小单位,但操作系统无法对数目众多的扇区进行寻址,所以操作系统就将相邻的扇区组合在一起,形成一个簇,然后再对簇进行管理.每个簇可以包括2、4、8、16、32、64个扇区

文件系统

在这里插入图片描述

常见的文件系统 作用
ext4 是 Red Hat Enterprise Linux 6 的标准文件系统。它非常强大可靠 , 具有多项可以提高现代工作量处理性能的功能。
ext3 最多只能支持32TB的文件系统和2TB的文件,实际只能容纳2TB的文件系统和16GB的文件
ext2 是常用于 Linux 中的较旧的文件系统。它简单可靠 ,非常适合小型存储设备,但是效率低。
vfat 支持包括一系列相关文件系统 ( VFAT/FAT16/FAT32 ), 这些文件系统针对较旧版本的 Microsoft Windows 开发 , 在大量的系统和设备上受支持。
xfs 在 Red Hat Enterprise Linux 7 的标准文件系统其具备数据完全、性能稳定、扩展性强 ( 8eb-1byte ) 、传输速率高 ( 7G/s )

本地存储设备的识别

我们先来了解一些如何查看本地存储设备呢?

命令 含义
fdisk -l 列出磁盘分区信息,系统中真实存在的硬盘,但是不一定能够识别
cat /proc/partitions 系统可以识别的,但是不一定能用
blkid 列出系统中可以使用的设备id,系统能够识别,也能够使用的
df 查看系统中正在使用的设备信息,系统正在挂载的设备
fdisk -l          列出磁盘分区信息,系统中真实存在的硬盘,但是不一定能够识别

cat /proc/partitions 		 系统可以识别的,但是不一定能用
blkid            	   列出系统中可以使用的设备id,系统能够识别,也能够使用的
df                  查看系统中正在使用的设备信息,系统正在挂载的设备

设备的挂载和卸载

设备名称

/dev/xdx         
##/dev/hd0  /dev/hd1 (并口硬盘)/dev/sda  /dev/sdb  (串口硬盘SATA)/dev/vda  /dev/vdb  系统中的虚拟硬盘
/dev/mapper/*    		##虚拟设备
/sda          	  	    ##系统第一块串口硬盘,a代表第一块
/cdrom,/dev/sr0 		##代表光驱

设备挂载

mount  设备  挂载点            #挂载
umount /mnt                   #卸载挂载到/mnt下,可能会挂载到别的目录下
umount /dev/sdb1              #卸载/dev/sdb1s上的挂载
mount  -o ro /dev/sdb1   /mnt/                #只读挂载
mount  -o  remount,rw  /dev/sdb1 或者 /mnt/      #重新读写挂载
mount    #查看挂载信息
  • 解决设备正忙的情况
    方法1:
fuser -kvm /mnt
umount /mnt

方法2:

lsof /mnt/		查看/mnt上使用的情况
kill -9  进程号
umount /mnt

磁盘分区

  • 硬盘0磁道1扇区的512个字节中记录的信息如下:
512 = 446   +64   +2  字节
      mbr   dpt   55AA
 
mbr      硬盘主引导程序
dpt      硬盘分区表(DPT)
55AA     两个字节(55 AA)属于分区结束标志
  • 硬盘分区表 64字节,一块分区占16个字节,所以一块硬盘上最多划分4个主分区。
主分区:用主分区表记录的分区
扩展分区:主分区表记录的容器,不能直接使用
逻辑分区:容器中的分区,我们后面会提到的LVM

具体分区步骤

  • 第一步:fdisk -l
[root@localhost Desktop]# 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
  • 第二步:fdisk /dev/vdb 进入相关分区界面
command (m for help): 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                     ##查询分区id
   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                 ##修改分区id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit                    ##保存分区标信息到硬盘
   x   extra functionality (experts only)
  • 第三步:建立主分区
[root@localhost 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 0x312c67f3.
 
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): +100M  		##100M大小
Partition 1 of type Linux and of size 100 MiB 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
 
Command (m for help): wq                                         ##保存并退出
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
  • 第四步:格式化分区 mkfs.xfs /dev/vdb1 我们需要对分区格式化成想要的文件系统才可以进行文件的操作。
[root@localhost Desktop]# 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

查看是否成功,就是查看可用设备blkid,此时/dev/vdb1为可用设备

[root@localhost Desktop]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="0168a321-bdd9-4ef5-b476-83de5ecd8b63" TYPE="xfs" 
  • 第五步:挂载,设备挂载之后才能使用
[root@localhost Desktop]# mount /dev/vdb1 /mnt/
[root@localhost Desktop]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3165192   7308708  31% /
devtmpfs          469344       0    469344   0% /dev
tmpfs             484932     140    484792   1% /dev/shm
tmpfs             484932   12736    472196   3% /run
tmpfs             484932       0    484932   0% /sys/fs/cgroup
/dev/vdb1          98988    5280     93708   6% /mnt

成功啦!

  • 第六步:继续添加分区
  • 注意:主分区+扩展分区+逻辑分区最多16个,再多系统也不识别。
[root@localhost 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): 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): 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
 
 
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 
First sector (411648-20971519, default 411648): 
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +100M
Partition 3 of type Linux and of size 100 MiB 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
/dev/vdb3          411648      616447      102400   83  Linux
 
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e):                             	####当添加到第四个分区,默认分区为扩展分区e
Using default response e
Selected partition 4
First sector (616448-20971519, default 616448): 
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-20971519, default 20971519): ##默认大小全部给扩展分区,否则剩下的就浪费了
Using default value 20971519
Partition 4 of type Extended and of size 9.7 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
/dev/vdb3          411648      616447      102400   83  Linux
/dev/vdb4          616448    20971519    10177536    5  Extended
 
Command (m for help): wq
The partition table has been altered!
 
Calling ioctl() to re-read partition table. 

当出现warning:

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

我们需要手动同步分区表:

[root@localhost Desktop]# partprobe
[root@localhost Desktop]# cat /proc/partitions 		##查看系统可以识别的分区,发现成功
major minor  #blocks  name
 
 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     102400 vdb1
 253       18     102400 vdb2
 253       19     102400 vdb3
 253       20          1 vdb4
  • 永久挂载:
    vim /etc/fatab 开机自动挂载策略文件
/dev/vdb5   /mnt 	 xfs  	defaults              0   		 0  
 分区        挂载点 	格式     挂载参数        		是否备份 	是否检测

swap分区管理

概念

  • Swap分区在系统的物理内存(这里应该是运行内存)不够用的时候,把物理内存中的一部分空间释放出来,以供当前运行的程序使用。那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被释放的空间被临时保存到Swap分区中,等到那些程序要运行时,再从Swap分区中恢复保存的数据到内存中。

新建swap分区

  • 第一步:使用 fdisk 创建新分区。 在用 fdisk 保存更改之前 , 将分区类型更改为 “ Linux Swap”。
[root@localhost Desktop]# swapon -s
[root@localhost 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
/dev/vdb3          411648      616447      102400   83  Linux
/dev/vdb4          616448    20971519    10177536    5  Extended
/dev/vdb5          618496      823295      102400   83  Linux
 
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (825344-20971519, default 825344): 
Using default value 825344
Last sector, +sectors or +size{K,M,G} (825344-20971519, default 20971519): +100M
Partition 6 of type Linux and of size 100 MiB 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
/dev/vdb3          411648      616447      102400   83  Linux
/dev/vdb4          616448    20971519    10177536    5  Extended
/dev/vdb5          618496      823295      102400   83  Linux
/dev/vdb6          825344     1030143      102400   83  Linux
 
Command (m for help): t                                       ####更改类型
Partition number (1-6, default 6): 6
Hex code (type L to list all codes): l
 
 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 82                             ##改换分区
Changed type of partition 'Linux' to 'Linux swap / Solaris'
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: 0x312c67f3
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
/dev/vdb3          411648      616447      102400   83  Linux
/dev/vdb4          616448    20971519    10177536    5  Extended
/dev/vdb5          618496      823295      102400   83  Linux
/dev/vdb6          825344     1030143      102400   82  Linux swap / Solaris
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
  • 第二步:将刚刚swap分区用作交换区格式
mkswap	/dev/vdb6 
  • 第三步:永久挂载,将新swap添加到 /etc/fstab
    在这里插入图片描述
  • 第四步:swapon -a /dev/vdb6 将激活新交换区
  • 第五步:swapon -s 查看当前交换去状态
 [root@localhost Desktop]# swapon -a /dev/vdb6
 [root@localhost Desktop]# swapon -s
Filename                Type        Size    Used    Priority
/dev/vdb6                                  partition    102396    0    -1

删除swap分区

  • 第一步:编辑 /etc/fstab文件,取消永久挂载
  • 第二步:swapoff /dev/vda6 停用特定交换区
swapoff /dev/vdb6
  • 第三步:删除相关设备,fdisk /dev/vdb,进入编辑界面,删除设备
[root@localhost 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-6, default 6): 6
Partition 6 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: 0x312c67f3
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848      411647      102400   83  Linux
/dev/vdb3          411648      616447      102400   83  Linux
/dev/vdb4          616448    20971519    10177536    5  Extended
/dev/vdb5          618496      823295      102400   83  Linux
 
Command (m for help): wq
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
  • 第四步:删除设备后,同步分区表
partprobe

磁盘配额quota

配额概念quota

  • 就是限制用户对磁盘空间的使用量。

  • 原因:因为Linux是多用户多任务的操作系统,用户共用磁盘空间,为了合理的分配磁盘空间,于是就有了quota的出现。

  • quota的用途:显示磁盘使用情况和配额

  • quota的一般作用对象
    (1)针对Web server
    (2)针对mail server
    (3)针对file server

  • quota的限制
    (1)仅能针对整个文件系统
    (2)需要kernel的支持
    (3)只对一般用户有效

如何设定配额quota的限额

  • 第一步:开启quota功能
mount -o usrquota /dev/vdb5  /westos 
chmod  777 /westos
  • 第二步:设定student用户对磁盘/dev/vdb5的配额,使用edquota -u student命令编辑文件
filesystem blocks    soft  hard   inodes   soft   hard
  1         2         3     4      5        6      7
1:文件系统,说明该限制值时针对哪个文件系统
2:磁盘容量,这个值由quota计算,不要更改
3:磁盘容量的soft限制值
4:磁盘容量的hard限制值
5:文件数量,这个值由quota计算,不要改动
6:inode的soft值
7:inode的hard值
 
soft/hard为0时,表示没有限制,我们需要的是设置blocks的soft/hard值,inode的不要更改

在这里插入图片描述

  • 第三步:配额自动挂载
/dev/vdb5  /pub  xfs   defauits,usrquota  0  0

此时,student用户就只有2M的磁盘配额空间,也就是不能放入超过2M的文件,否则就会报错。

磁盘加密cryptsetup

概念

  • LUKS ( Linux 统一密钥设置 ) 是标准的设备加密格式。
    LUKS 可以对分区或卷进行加密,必须首先对加密的卷进行解密 ,才能挂载其中的文件系统。

加密方法

  • 第一步:cryptsetup luksFormat /dev/vdb5 ##加密设备
    在这里插入图片描述
  • 第二步:将设备加密,并将加密后的虚拟设备命名mac
    在这里插入图片描述
  • 第三步:虚拟设备格式化
    在这里插入图片描述
  • 第四步:挂载设备到挂载点
    在这里插入图片描述
  • 第五步:卸载并关闭虚拟设备,自关闭开始,这个虚拟设备失效,之前的文件无法查看。
umount /mac
cryptsetup close mac

在这里插入图片描述
在这里插入图片描述

加密设备开机自动挂载

  • 第一步:一样的,也是编辑/etc/fstab,将虚拟文件自动挂载
    在这里插入图片描述

  • 第二步:编辑/root/newpasswd密码文件,写入密码,并修改其权限chmod 600 /root/newpasswd
    在这里插入图片描述

  • 第三步:编辑/etc/crypttab文件,将加密后的虚拟设备和其密码文件写入
    在这里插入图片描述

  • 第四步:将设备/dev/vdb1和密码文件/root/newpasswd关联到一起
    在这里插入图片描述
    成功!
    在这里插入图片描述

删除加密后的虚拟设备

  • 第一步:编辑/etc/fstab文件,删除文件中的内容
  • 第二步:编辑/etc/crypttab文件,删除文件内容
  • 第三步:解除加密关系
    在这里插入图片描述
  • 第三步:解挂设备
umount /mac
  • 第四步:关闭虚拟设备
cryptsetup  close  mac
  • 第五步:格式化设备
mkfs.xfs /dev/vdb1 -f   ##强制格式化设备
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/143797.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号