Linux operating technical documentation - disk and file system management

Disk and file system management

First, disk management and partition

1, to detect and confirm the new hard drive

Here Insert Picture Description

2, the hard disk partition plan

Interactive partitions into the management interface
Here Insert Picture Description
1, "p" instructions: List of the hard disk partition
Here Insert Picture Description
2, "n" command: New Partition
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
create an extended partition and two logical partitions
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
3, "d" commands: delete partition
Here Insert Picture Description
4, "t" command: change partition type
XFS, Swap file system corresponding to the ID number 83, 82, respectively, and for the Windows NTFS file system corresponding to the ID number is generally 86
to logical partitions "dev / sdb5" type change to Swap
Here Insert Picture Description
5, "w" and "q" command: exit fdisk partition tool
"w" command to save the partition operation, and "q" command will not be saved on the hard disk partitioning operations done
to re-detect / dev / sdb "disk the zoning changes
Here Insert Picture Description

Second, the file management system

1, create a file system

1, using the mkfs command
to create the XFS file system
Here Insert Picture Description
or
Here Insert Picture Description
2, use the command mkswap
partition / dev / sdb5 created as a swap partition (should be the target partition by fdisk tool ID number is set to 82)
Here Insert Picture Description
to enable, disable swap partition / dev / sdb5
Here Insert Picture Description

2, mounting and unmounting file systems

1、挂载文件系统
将光盘设备挂载到/media/cdrom目录
Here Insert Picture Description
将建立的/dev/sdb1分区挂载到新建的/mailbox目录下
Here Insert Picture Description
将下载的CentoOS 7 系统的DVD光盘镜像文件"CentOS-7-x86_64-DVD-1611.iso"挂载到/media/mnt目录下
Here Insert Picture Description
2、卸载文件系统
通过挂载点目录卸载对应的分区
Here Insert Picture Description
通过设备文件卸载光盘
Here Insert Picture Description
3、设置文件系统的自动挂载
查看当前系统内自动挂载的设备或分区
Here Insert Picture Description

第1字段:设备名或设备卷标名。
第2字段:文件系统的挂载点目录的位置。
第3字段:文件系统类型,如XFS、Swap等。
第4字段:挂载参数,即mount命令"-o"选项后可使用的参数。例如,defaults, rw、ro、noexec 分别表示默认参数、可写、只读、禁用执行程序。
第5字段:表示文件系统是否需要dump备份。一般设为1时表示 需要,设为0时将被dump忽略。
第6字段:该数字决定在系统启动时进行磁盘检查的顺序。0表示不进行检查,1表示优先检查,2表示其次检查。根分区应设为1 ,其他分区设为2。

添加自动挂载分区/dev/sdb1
Here Insert Picture Description
Here Insert Picture Description
4、查看磁盘使用情况
查看当前系统中挂载的各文件系统的磁盘使用情况
Here Insert Picture Description

三、LVM逻辑卷管理

1、LVM概述

1、PV (Physical Volume,物理卷)
物理卷是LVM机制的基本存储设备,通常对应为一个普通分区或整个硬盘。物理卷一般直接使用设备文件 名称,如/dev/sdb1、/dev/sdb2、/dev/sdd 等。对用于转换成物理卷的普通分区,建议先使用fdisk工具将分区类型的D标记号改为"8e"。
2、VG (Volume Group,卷组)
由一个或多个物理卷组成一个整体,即称为卷组,在卷组中可以动态地添加或移除物理卷。
3、LV ( Logical Volume,逻辑卷)
逻辑卷建立在卷组之上,与物理卷没有直接关系。

2、LVM的管理命令

常用的LVM管理命令

功能 PV管理命令 VG管理命令 LV管理命令
Scan(扫描) pvscan vgscan Ivscan
Create (建立) pvcreate vgcreate Ivcreate
Display (显示) pvdisplay vgdisplay Ivdisplay
Remove (移除) pvremove vgremove Ivremove
Extend (扩展) vgextend Ivextend
Reduce (减少) vgreduce Ivreduce

1、物理卷管理
(1)pvscan命令:用于扫描系统中所有的物理卷,并输出相关信息
Here Insert Picture Description
(2)pvcreate命令:用于将分区或整个硬盘转换成物理卷,主要是添加LVM属性信息并划分PE存储单位
pvcreate 设备名1 设备名2 (创建)
添加3块硬盘,先使用两块实现LVM逻辑卷,并格式化,挂载在/share上。
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
(3)pvdisplay命令:显示物理卷的详细信息,需要使用指定的物理卷作为命令参数,默认时将显示所有物理卷的信息
(4)pvremove命令:用于将物理卷还原成普通分区或磁盘,不再用于LVM体系,被移除的物理卷将无法被pvscan识别
2、卷组管理
(1)vgscan命令:用于扫描系统中已建立的LVM卷组及相关信息
(2)vgcreate命令:用于将一个或多个物理卷创建为一个卷组,第一个命令参数用于设置新卷组的名称,其后依次指定需要加入该卷组的物理卷作为参数
vgcreate 卷组名 物理卷名1 物理卷名2 (创建)
Here Insert Picture Description
(3)vgdisplay命令:用于显示系统中各卷组的详细信息,需要使用指定卷组名作为命令参数(未指定卷组时将显示所有卷组的信息)
(4)vgremove命令:用于删除指定的卷组,将指定卷组名称作为参数即可
(5)vgextend命令:用于扩展卷组的磁盘空间
vgextend 卷组名 物理卷名 (扩展vg)
再将第3块硬盘扩展到LVM卷中,并验证/share空间是否增加。
Here Insert Picture Description
Here Insert Picture Description
3、逻辑卷管理
(1) Ivscan命令:用于扫描系统中已建立的逻辑卷及相关信息
(2)Ivcreate命令:用于从指定的卷组中分割空间,以创建新的逻辑卷
lvcreate -L 容量大小 -n 逻辑卷名 卷组名 (创建)
(3)Ivdispla命令:用于显示逻辑卷的详细信息,可以指定逻辑卷的设备文件作为参数,也可以使用卷组名作为参数,以显示该卷组中所有逻辑卷的信息
(4)Ivextend命令:用于动态扩展逻辑卷的空间
lvextend -L +大小 /dev/卷组名/逻辑卷名 (扩展lv)
(5)Ivremove命令:用于删除指定的逻辑卷,直接使用逻辑卷的设备文件作为参数即可

3、LVM应用

创建lvm步骤:
pv–>vg–>lv–>格式化–>挂载
可以对分区或者整个磁盘实现LVM
如对分区实现(/dev/sdb1 20G,/dev/sdc1 20G)
1、创建PV pvcreate /dev/sdb1 /dev/sdc1
2、创建VG vgcreate benet /dev/sdb1 /dev/sdc1
3、创建LV lvcreate -L 20G -n test benet
4、格式化 mkfs -t xfs /dev/benet/test
5、挂载(备注:share目录需提前创建)
临时:mount /dev/benet/test /share
自动挂载:修改/etc/fstab文件即可
6、扩展lv卷
lvextend -L +10G /dev/benet/test
7、使用 xfs_growfs 命令更新文件系统大小
xfs_growfs /dev/benet/test

四、设置磁盘配额

1、磁盘配额管理

1、以支持配额功能的方式挂载文件系统
创建LVM逻辑卷并挂载
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
对share逻辑卷重新进行挂载(remount参数),并添加配额支持
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
每次开机后自动以支持配额功能的方式挂载该分区
Here Insert Picture Description
Here Insert Picture Description
2、编辑用户和组账号的配额设置

bsoft :: Set disk capacity of soft limit values.
bhard: a hard disk capacity limit value.
isoft: Set the hard limit value of the number of disk files.
ihard: Set the limit value of the number of disk files.
"-x" represents the start expert mode, allowing modification of all quota system management commands available in the current mode;
"-c" command represents a direct call management

Set user zhangsan disk quota: disk capacity soft limit 80MB, disk capacity hard limits 100MB File count soft limit of 40, the number of files a hard limit of 50.
Here Insert Picture Description
View user zhangsan disk capacity limit
Here Insert Picture Description
viewing zhangsan user of the number of disk files limit
Here Insert Picture Description
set group accounts caiwubu of disk quotas: disk capacity soft limit 1GB, disk capacity hard limits 2GB, the file number of the soft limit of 2000, the number of file hard limit 2500
Here Insert Picture Description
3, the view quota usage
view disk capacity quota of all available partitions usage
Here Insert Picture Description
reports to view disk capacities and file input
Here Insert Picture Description

Published 19 original articles · won praise 1 · views 636

Guess you like

Origin blog.csdn.net/g950904/article/details/103953497