• Liunx-05磁盘管理


    硬盘的基本知识

    硬盘的接口类型

    硬盘接口决定着硬盘与计算机之间的连接速度,所以硬盘是一个很重要的属性。

    从整体上,硬盘接口类型可分为IDE、SATA、SCSI 、SAS和光纤通道五种,IDE接口硬盘多用于家用产品中,也有部分应用于服务器,SCSI接口的硬盘则主要应用于服务器市场,而光纤通道只在高端服务器上,价格昂贵。SATA是种新生的硬盘接口类型,在家用市场中有着广泛的前景。

    IDE    ——>  SATA I/II/III		   个人pc机
    SCSI   ——>  SAS 				服务器上
    
    • IDE代表着硬盘的一种类型,但在实际的应用中,人们也习惯用IDE来称呼最早出现IDE类型硬盘ATA-1,这种类型的接口随着接口技术的发展已经被淘汰了,而其后发展分支出更多类型的硬盘接口,比如ATA、Ultra ATA、DMA、Ultra DMA等接口都属于IDE硬盘。其特点为:价格低廉,兼容性强,性价比高,数据传输慢,不支持热插拔等等。
    • SCSI并不是专门为硬盘设计的接口,是一种广泛应用于小型机上的高速数据传输技术。SCSI接口具有应用范围广、多任务、带宽大、CPU占用率低,以及热插拔等优点
    • 使用SATA(Serial ATA)口的硬盘又叫串口硬盘,是未来PC机硬盘的趋势。Serial ATA采用串行连接方式,串行ATA总线使用嵌入式时钟信号,具备了更强的纠错能力,与以往相比其最大的区别在于能对传输指令(不仅仅是数据)进行检查,如果发现错误会自动矫正,这在很大程度上提高了数据传输的可靠性。串行接口还具有结构简单、支持热插拔的优点。
    • SAS接口其可以向下兼容SATA。具体来说,二者的兼容性主要体现在物理层和协议层的兼容。在物理层,SAS接口和SATA接口完全兼容,SATA硬盘可以直接使用在SAS的环境中,从接口标准上而言,SATA是SAS的一个子标准,因此SAS控制器可以直接操控SATA硬盘,但是SAS却不能直接使用在SATA的环境中,因为SATA控制器并不能对SAS硬盘进行控制;在协议层,SAS由3种类型协议组成,根据连接的不同设备使用相应的协议进行数据传输。其中串行SCSI协议(SSP)用于传输SCSI命令;SCSI管理协议(SMP)用于对连接设备的维护和管理;SATA通道协议(STP)用于SAS和SATA之间数据的传输。因此在这3种协议的配合下,SAS可以和SATA以及部分SCSI设备无缝结合。其传输速率比SATA要快很多。
    • 光纤通道光纤通道的主要特性有:热插拔性、高速带宽、远程连接、连接设备数量大

    硬盘命名方式

    OSIDE(并口)SATA(串口)SCSI
    RHEL5/dev/hda/dev/sda/dev/sda
    RHEL6/dev/sda/dev/sda/dev/sda
    RHEL7/dev/sda/dev/sda/dev/sda

    /dev/sda2

    s=硬件接口类型(sata/scsi

    d=disk(硬盘)

    a=第1块硬盘(b,第二块),2=第几个分区
    /dev/hd h=IDE硬盘 /dev/hdd3
    /dev/vd v=虚拟硬盘 /dev/vdf7

    HP服务器硬盘

    /dev/cciss/c0d0
    /dev/cciss/c0d0p1 c0第一个控制器, d0第一块磁盘, p1分区1
    /dev/cciss/c0d0p2 c0第一个控制器, d0第一块磁盘, p2分区2

    硬盘的分区方式

    fdisk(小于2T)MBR

    MBR <2TB fdisk

    4个主分区或者3个主分区+1个扩展分区(N个逻辑分区)

    MBR(Master Boot Record)的缩写,由三部分组成,即:

    1. Bootloader(主引导程序)=446字节 硬盘第一个扇区=512字节
      • 引导操作系统的主程序
    2. DPT分区表(Disk Partition Table)=64字节
      • 分区表保存了硬盘的分区信息,操作系统通过读取分区表内的信息,就能够获得该硬盘的分区信息
      • 每个分区需要占用16个字节大小,保存有文件系统标识、起止柱面号、磁头号、扇区号、起始扇区位置(4个字节)、分区总扇区数目(4个字节)等内容
      • 分区表中保存的分区信息都是主分区与扩展分区的分区信息,扩展分区不能直接使用,需要在扩展分区内划分一个或多个逻辑分区后才能使用
      • 逻辑分区的分区信息保存在扩展分区内而不是保存在MBR分区表内,这样,就可以突破MBR分区表只能保存4个分区的限制
    3. 硬盘有效标志(校验位)=2个字节
    gdisk(大于2T)GPT

    GPT >2TB gdisk(parted) 128个主分区

    注意:从MBR转到GPT,或从GPT转换到MBR会导致数据全部丢失

    新建虚拟机

    克隆虚拟机

    之前我们安装了虚拟机,现在需要进行磁盘与分区的实验,现在需要进行克隆。

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    复制之后可以使用192.168.47.10进行连接(这个时候模板机器不要打开)

    初始化克隆机器

    修改IP地址

    [root@template-host ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33       
    IPADDR=192.168.47.11
    [root@template-host ~]# grep IPADDR /etc/sysconfig/network-scripts/ifcfg-ens33    
    IPADDR=192.168.47.11
    [root@template-host ~]# systemctl restart network
    

    后面就使用47.11进行连接

    修改主机名

    [root@template-host ~]# hostnamectl set-hostname cpgl
    [root@template-host ~]# bash
    [root@cpgl ~]# 
    

    添加一块磁盘

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    这里就可以看见的磁盘类型,就是上面说明的接口类型,在做一些需要磁盘直连的时候需要选择SATA,一般选择的就是SCSI,现在我们选择SCSI。

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    完成之后需要重启一下虚拟机

    查看磁盘设备

    fdisk命令

    • 格式:fdisk -l [磁盘设备] :列出分区类型
    # lsblk
    # df -h  查看正在挂载的设备情况
    # fdisk -l		查看当前系统的所有设备分区情况
    # fdisk  /dev/sdb
    #普通机械磁盘一般容量是  硬盘容量 = 柱面数(cylinders)× 盘面数(磁头数)(heads) × 扇区数(sectors) × 扇区大小(一般为512字节)(Sector size)
    由于我们这个是固态磁盘所以 硬盘容量 10G =  n * 1024 * 1024 * 1024 
    [root@cpgl ~]# fdisk -l
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e203e
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    
    Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors   #磁盘空间 # 这里是我们新加入的磁盘
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    #扇区大小(逻辑/物理)  都是512字节。
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    #I/O 大小(最小/最大) 都是512字节。
    
    Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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命令
      • 用途:在交互式的操作环境中管理磁盘分区
      • 格式:fdisk [磁盘设备]
    • 交互模式中的常用指令
      • a: 设置启动分区
      • b : 编辑分区标签
      • m:查看操作指令的帮助信息
      • p:列表查看分区信息
      • n:新建分区 类型:p主分区,e扩展分区,l逻辑分区
      • d:删除分区
      • t:变更分区类型
      • w:保存分区设置并退出
      • q:放弃分区设置并退出
      • s 创建一个新的空的SUN标示
      • t 改变分区的类型
      • u 改变显示的单位
      • v 检查验证分区表

    总结:

    1. 最多只能分4个主分区,主分区编号1-4
    2. 逻辑分区大小总和不能超过扩展分区大小,逻辑分区分区编号从5开始
    3. 如果删除扩展分区,下面的逻辑卷分区也被删除
    4. 扩展分区的分区编号(1-4)

    分区管理

    磁盘划分思路

    • 进入分区表 新建分区 fdisk /dev/sdb
    • 更新分区表<刷新分区表>
    • 格式化分区——>文件系统 mkfs.ext4 /dev/sdb1
    • 挂载使用——>mount【开机自动挂载|autofs自动挂载】

    磁盘分区例子

    磁盘划分分区

    本例将这个10G的硬盘分区,分区计划:分一个主分区 ,大小3G,文件格式ext4.三个逻辑分区,大小分别为2G,2G,3G。实际分区个数和大小可论情况所定。

    [root@cpgl ~]# fdisk -l
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e203e
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    
    Disk /dev/sdb: 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 /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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/sdb 然后回车,给硬盘进行分区。
    [root@cpgl ~]#  fdisk /dev/sdb 
    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 0x5d800ccc.
    #输入n回车新建分区
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    #再输入p回车新建主分区
    Select (default p): p
    #选择分区号在1-4间,输入1回车
    Partition number (1-4, default 1): 1
    #这里是设置分区起始的序列号,直接回车选择默认即可
    First sector (2048-20971519, default 2048): 
    Using default value 2048
    #设置分区大小为3G,输入+3G后回车
    Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +3G
    Partition 1 of type Linux and of size 3 GiB is set
    #划分扩展分区,按n回车
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    #输入e,表示创建扩展分区,输入e回车
    Select (default p): e
    Partition number (2-4, default 2): 
    First sector (6293504-20971519, default 6293504): 
    Using default value 6293504
    #直接回车选择默认,表示将划分第一个主分区后的磁盘全部划分个这个逻辑分区
    Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519): 
    Using default value 20971519
    Partition 2 of type Extended and of size 7 GiB is set
    #输入命令p查看当前分区状态
    Command (m for help): p
    
    Disk /dev/sdb: 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: 0x5d800ccc
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048     6293503     3145728   83  Linux
    /dev/sdb2         6293504    20971519     7339008    5  Extended
    #划分扩展分区sdb2下的逻辑分区
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 1 extended, 2 free)
       l   logical (numbered from 5)
    #输入l表示选择创建逻辑分区
    Select (default p): l
    Adding logical partition 5
    First sector (6295552-20971519, default 6295552): 
    Using default value 6295552
    #输入+2G,表示划分分区大小为2G
    Last sector, +sectors or +size{K,M,G} (6295552-20971519, default 20971519): +2G
    Partition 5 of type Linux and of size 2 GiB is set
    
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 1 extended, 2 free)
       l   logical (numbered from 5)
    Select (default p): l
    Adding logical partition 6
    First sector (10491904-20971519, default 10491904): 
    Using default value 10491904
    #输入+2G,表示划分分区大小为2G
    Last sector, +sectors or +size{K,M,G} (10491904-20971519, default 20971519): +2G
    Partition 6 of type Linux and of size 2 GiB is set
    
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 1 extended, 2 free)
       l   logical (numbered from 5)
    Select (default p): l
    Adding logical partition 7
    First sector (14688256-20971519, default 14688256): 
    Using default value 14688256
    #默认,表示划分分区大小为剩余的大小
    Last sector, +sectors or +size{K,M,G} (14688256-20971519, default 20971519): 
    Using default value 20971519
    Partition 7 of type Linux and of size 3 GiB is set
    #输入p查看当前分区状态
    Command (m for help): p
    
    Disk /dev/sdb: 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: 0x5d800ccc
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048     6293503     3145728   83  Linux
    /dev/sdb2         6293504    20971519     7339008    5  Extended
    /dev/sdb5         6295552    10489855     2097152   83  Linux
    /dev/sdb6        10491904    14686207     2097152   83  Linux
    /dev/sdb7        14688256    20971519     3141632   83  Linux
    #划分的空间与我们计划划分相同,最后输入w回车,进行保存退出。
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@cpgl ~]# 
    
    分区结束查看分区
    [root@cpgl ~]# fdisk -l
    
    Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000e203e
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    
    Disk /dev/sdb: 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: 0x5d800ccc
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048     6293503     3145728   83  Linux
    /dev/sdb2         6293504    20971519     7339008    5  Extended
    /dev/sdb5         6295552    10489855     2097152   83  Linux
    /dev/sdb6        10491904    14686207     2097152   83  Linux
    /dev/sdb7        14688256    20971519     3141632   83  Linux
    
    Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
    
    格式化分区

    文件系统 mkfs.ext4 /dev/sdb1

    #mkfs.ext4  /dev/sdb1
    #mkfs.ext4  /dev/sdb5
    #mkfs.ext4  /dev/sdb6
    #mkfs.ext4  /dev/sdb7
    [root@cpgl ~]# mkfs.ext4  /dev/sdb1
    mkfs.ext4  /dev/sdb5
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    196608 inodes, 786432 blocks
    39321 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=805306368
    24 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (16384 blocks): mkfs.ext4  /dev/sdb6
    mkfs.ext4  /dev/sdb7done
    Writing superblocks and filesystem accounting information: done 
    
    [root@cpgl ~]# mkfs.ext4  /dev/sdb5
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    131072 inodes, 524288 blocks
    26214 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=536870912
    16 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done 
    
    [root@cpgl ~]# mkfs.ext4  /dev/sdb6
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    131072 inodes, 524288 blocks
    26214 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=536870912
    16 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done 
    
    [root@cpgl ~]# mkfs.ext4  /dev/sdb7
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    196608 inodes, 785408 blocks
    39270 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=805306368
    24 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done 
    
    

    分别对磁盘进行格式化处理,格式化为ext4文件类型

    挂载使用

    mount【开机自动挂载|autofs自动挂载】

    mkdir /data1/
    mkdir /data5/
    mkdir /data6/
    mkdir /data7/
    mount /dev/sdb1 /data1/
    mount /dev/sdb5 /data5/
    mount /dev/sdb6 /data6/
    mount /dev/sdb7 /data7/
    

    查看挂载情况

    [root@cpgl ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 475M     0  475M   0% /dev
    tmpfs                    487M     0  487M   0% /dev/shm
    tmpfs                    487M  7.6M  479M   2% /run
    tmpfs                    487M     0  487M   0% /sys/fs/cgroup
    /dev/mapper/centos-root   17G  1.6G   16G  10% /
    /dev/sda1               1014M  137M  878M  14% /boot
    tmpfs                     98M     0   98M   0% /run/user/0
    /dev/sdb1                2.9G  9.0M  2.8G   1% /data1
    /dev/sdb5                2.0G  6.0M  1.8G   1% /data5
    /dev/sdb6                2.0G  6.0M  1.8G   1% /data6
    /dev/sdb7                2.9G  9.0M  2.8G   1% /data7
    

    配置/etc/fstab

    [root@cpgl ~]# vi /etc/fstab 
    /dev/sdb1                                       ext4    /data1/
    /dev/sdb5                                       ext4    /data5/
    /dev/sdb6                                       ext4    /data6/
    /dev/sdb7                                       ext4    /data7/
    

    其他磁盘相关知识

    扩展SWAP分区大小

    • mkswap命令 用途:Make Swap,创建交换文件系统
    [root@localhost ~]# mkswap /dev/sdb5  //格式化交换分区
    Setting up swapspace version 1, size = 2006929 kB 
    [root@localhost ~]# swapon /dev/sdb5  //启用交换分区
    [root@localhost ~]# free | grep -i swap
    Swap:      3008456          0    3008456
    [root@localhost ~]# swapoff /dev/sdb5  //停用交换分区
    [root@localhost ~]# free | grep -i swap   //查看交换空间
    Swap:      1048568          0    1048568
    

    SWAP的优先级设定

    • swap分区从高优先级到低优先级依次使用
    • 查看优先级: swapon –s
    • 用户可以给某个swap指定一个0到32767的优先级
    • 如果用户没有指定,那么核心会自动给swap指定一个优先级,这个优先级从-1开始,每加入一个新的没有用户指定优先级的swap,会给这个优先级减1
    • 通过设置priority把性能最好,速度最快的磁盘上的swap设置为最高的优先级
    • 修改/etc/fstab 指定一个大的pri值
    • /dev/sdd2 swap swap defaults,pri=1 0 0

    在这里插入图片描述

    磁盘配额

    • 实现磁盘限额的条件

      • 需要Linux内核支持
      • 安装quota软件包
    • Linux磁盘限额的特点

      • 作用范围:针对指定的文件系统(分区)
      • 限制对象:用户帐号、组帐号
      • 限制类型:
        • 磁盘容量(默认单位为KB)***
        • 文件数量 (or)
      • 限制方法:软限制、硬限制
    • 启用文件系统的配额支持

      • 添加usrquota、grpquota挂载参数
    [root@localhost ~]# vi /etc/fstab
    /dev/sdb1      /mailbox        ext3   default,usrquota,grpquota   0  0
    [root@localhost ~]# mount  /mailbox
    [root@localhost ~]# mount  | tail -1
    /dev/sdb1 on /mailbox type ext3 (rw,usrquota,grpquota)
    
    • 检测磁盘配额并创建配额文件
      • 使用quotacheck命令创建配额文件
        • quotacheck -ugcv 文件系统
        • quotacheck -augcv
        • -u、-g:检测用户、组配额
        • -c:创建配额数据文件
        • -v:显示执行过程信息
        • -a:检测所有可用的分区
    [root@localhost ~]# quotacheck  -ugcv  /dev/sdb1
    quotacheck: Scanning /dev/sdb1 [/mailbox] 
    ……
    done
    [root@localhost ~]# ls -l /mailbox/aquota.*
    -rw------- 1 root root 6144 09-14 12:04 /mailbox/aquota.group
    -rw------- 1 root root 6144 09-14 12:04 /mailbox/aquota.user
    
    
    • 编辑用户和组帐号的配额设置
      • 使用edquota命令编辑配额设置
        • edquota -u 用户名
        • edquota -g 组名
    [root@localhost ~]# edquota -u zhangsan
    Disk quotas for user zhangsan (uid 501):
      Filesystem    blocks   soft   hard    inodes    soft     hard
      /dev/sdb1       0      80000  100000     0        40         50
    第3列:磁盘容量软限制                                 第6列:文件个数软限制
    第4列:磁盘容量硬限制                                  第7列:文件个数硬限制
    [root@localhost ~]# edquota -g users
    Disk quotas for group users (gid 100):
      Filesystem     blocks    soft    hard     inodes     soft       hard
      /dev/sdb1      252       0     1024000    39         0           0
    
    • 启用、关闭文件系统的配额功能
      • 使用quotaon、quotaoff命令
    [root@localhost ~]# quotaon -ugv /mailbox
    /dev/sdb1 [/mailbox]: group quotas turned on
    /dev/sdb1 [/mailbox]: user quotas turned on
    [root@localhost ~]# quotaoff -ugv /mailbox
    /dev/sdb1 [/mailbox]: group quotas turned off
    /dev/sdb1 [/mailbox]: user quotas turned off
    
    • 验证磁盘配额功能
      • 必须切换到设置配额的分区(挂载目录)
      • 创建指定数量的文件:使用touch命令,或cp命令
      • 创建指定容量的文件:使用dd命令,或cp命令
    [zhangsan@mail ~]$ cd /mailbox
    [zhangsan@mail mailbox]$ dd if=/dev/zero of=myfile bs=1M count=120
    sdb1: warning, user block quota exceeded.
    sdb1: write failed, user block limit reached.
    dd: 写入 “myfile”: 超出磁盘限额
    ……
    
    • 查看配额使用情况
      • 侧重用户、组帐号角度:使用quota命令
        • quota -uv 用户名
        • quota -gv 组名
      • 侧重文件系统角度:使用repquota命令
        • repquota 文件系统
    [root@localhost ~]# quota -u zhangsan
    Disk quotas for user zhangsan (uid 515):
         Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
          /dev/sdb1  100000*  80000  100000               1      40      50
    [root@localhost ~]# quota -g users
    Disk quotas for group users (gid 10): none
    
    [root@localhost ~]# repquota -v /mailbox
    *** Report for user quotas on device /dev/sdb1
    Block grace time: 3days; Inode grace time: 3days
                            Block limits                File limits
    User            used    soft    hard  grace    used  soft  hard  grace
    
    
  • 相关阅读:
    哈希表简介
    Python 笔记(22)— 变量解析原则(LEGB)、浅拷贝、深拷贝
    [附源码]计算机毕业设计springboot汽车租赁管理系统
    关于web3营销的一切知识
    echarts静态饼图
    NC338 删除升序数组的重复元素
    Elastic Cloud v.s. Zilliz Cloud:性能大比拼
    内存CACHE同步引起OSD时间戳显示异常
    同花顺自动化交易股票下单接口API量化系统,别信那些外挂插件和软件,头部券商有现成的接口
    Shell脚本攻略:循环语句for
  • 原文地址:https://blog.csdn.net/a13554371686/article/details/126961753