Linux之配额、lvm 逻辑卷

配额

配额是限定设备的容量

xfs操作系统,自动激活配额参数

一、激活配额参数(临时)
1、fdisk /dev/vdb #新建一个分区
2、cat /proc/partitions #查看分区信息,一般查看前要先同步分区信息
3、mkfs.xfs /dev/vdb1 #格式化
4、mount -o usrquota /dev/vdb1 /mnt/ #指定配额挂载,用mount看配额有没有激活
5、edquota -u student #给student设置配额,这里设置2M,内容如下:

Disk quotas for user student (uid 1000):
 Filesystem    blocks   soft    hard    inodes    soft    hard  
 /dev/vdb1     0        0       20480   0          0        0
blocks表示student在vdb1上的数据,这表示事实
soft表示软件
hard表示硬件,表示最大写入数据
这三个都表示容量
inodes表示用过的个数
soft表示了用多少次给予警告
hard表示最多可以用多少次
这三个表示个数

6、chmod 777 /mnt/ #给mnt权限,先挂载再修改权限,不然卸载后挂载,新设备会覆盖老的设备,权限会改变
7、su - student #切换到student
8、dd if=/dev/zero of=/mnt/studentfile bs=2M count=10 #测试从无限零字节设备中复制数据到/mnt/studentfile 中,大小为1M,个数为10

/dev/zero 无限零字节
dd 截取命令
if:inputfile,输入文件,如果不指定就会默认从stdin中读取输入
of:outfile,输出到文件,如果不指定就会默认输出到stdout中
bs代表以字节为大小的块大小
count表示被复制的快数

二、激活配额参数(开机自动激活)
1、vim /etc/fstab #内容如下

挂载设备     挂载点  文件系统类型   文件系统选项         是否备份  是否检测
/dev/vdb1   /mnt    xfs         defaults,usrquota   0        0

实验:

[root@localhost ~]# 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 (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): +1000M
Partition 1 of type Linux and of size 1000 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: 0xaafbd64a

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# cat /proc/partitions   查看分区
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17    1024000 vdb1
[root@localhost ~]# mkfs.xfs /dev/vdb1   格式化
mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (linux_raid_member).   提示设备已经存在
mkfs.xfs: Use the -f option to force overwrite.
[root@localhost ~]# mkfs.xfs /dev/vdb1 -f   强行格式化
meta-data=/dev/vdb1              isize=256    agcount=4, agsize=64000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=256000, 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@localhost ~]# mount -o usrquota /dev/vdb1 /mnt/  挂载在mnt目录上
[root@localhost ~]# mount   查看是否激活配额参数
/dev/vdb1 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)
这里只显示配额的设备,括号里面有usrquota则表示激活成功
[root@localhost ~]# edquota -u student  给student设置配额,大小为2M
Disk quotas for user student (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/vdb1                     0             0        20480          0        0        0
[root@localhost ~]# chmod 777 /mnt/  修改权限为777
[root@localhost ~]# su - student  切换到student
[student@localhost ~]$ dd if=/dev/zero of=/mnt/studentfile bs=2M count=10  测试从无限零字节设备中复制数据到/mnt/studentfile 中,大小为2M,个数为10,底下显示复制成功
10+0 records in
10+0 records out
20971520 bytes (21 MB) copied, 0.00895767 s, 2.3 GB/s
[student@localhost ~]$ rm -fr /mnt/studentfile  删除studentfile
[student@localhost ~]$ dd if=/dev/zero of=/mnt/studentfile bs=3M count=10 测试从无限零字节设备中复制数据到/mnt/studentfile 中,大小为3M,个数为10,因为复制大小大于配额的大小,故提示失败
dd: error writing ‘/mnt/studentfile’: Disk quota exceeded
7+0 records in
6+0 records
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值