磁盘配额的设置
详细步骤:
1、 虚拟机添加硬盘(分为两种类型IDE、 SCSI)
2、 fdisk 进行分区
#fdisk -l
查看新添加的硬盘的名称/dev/sdb
3、 mkfs 格式化
以下两种方法相同
#mkfs -t ext3 /dev/sdb1
或者
#mkfs.ext3 /dev/sdb1
4、 挂载
挂在分为用就挂载和临时挂载
1) 永久挂载(在fstab文件中进行设置)
#vi /etc/fstab
2) 临时挂载 直接在命令行的方式下执行下边的命令
用法:#mount –t ext3 外部设备名 挂载点
#mount /dev/sdb1 /mnt/u_po
//临时挂载 将/dev/sdb1挂在到 /mnt/u_po 此目录必须存在
-o 选项 defaults usrquota grpquota 永久挂载的参数选项
卸载的方式有两种:
第一种:表示卸载外部设备
#umount /dev/sdb1
第二种:卸载挂载点
#umount /mnt/u_po
#mount -t ext3 -o defaults,usrquota,grpquota /dev/sdb1 /var/zhy
或者
#vi /etc/fstab
/dev/sdb1 /var/zhy ext3 defaults,usrquota,grpquota 1 1
:wq
重启系统
或者
#mount -o remount /var/zhy
#quotacheck -cvuga
目的:检测当前设备的配额使用情况,并生成相应的配置文件
开启配额功能
#quotaon –avgu
Aquota.usr Aquota.group Lost+found
对用户zhy进行限制
#edquota –u zhy
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 100 200 0 4 8
Blocks:第一种方式 (B M k)限制空间大小
Soft:软限制----超出该限制会有提醒
Hard:硬限制---不允许超出
Innode:节点 文件的数量(个)
Soft:软限制8个
Hard:硬限制
//关闭配额功能
#quotaoff –avug
//开始重新分区
Disk /dev/hda doesn't contain a valid partition table
[root@localhost var]# fdisk /dev/sdb
//进入
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
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
Command action
e extended
p primary partition (1-4)
P//选择分区的类型
Partition number (1-4): 1
First cylinder (1-1024, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1024, default 1024): +500M
//保存分区的信息
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost var]# fdisk -l
Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1436 11430247+ 83 Linux
/dev/sda3 1437 1566 1044225 82 Linux swap
Disk /dev/sdb: 1073 MB, 1073741824 bytes
64 heads, 32 sectors/track, 1024 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 478 489456 83 Linux
Disk /dev/hda: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk /dev/hda doesn't contain a valid partition table
//格式化硬盘
[root@localhost var]# mkfs -t ext3 /dev/sdb1
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
122400 inodes, 489456 blocks
24472 blocks (5.00%) reserved for the super user
First data block=1
60 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost var]# fdisk -l
Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1436 11430247+ 83 Linux
/dev/sda3 1437 1566 1044225 82 Linux swap
Disk /dev/sdb: 1073 MB, 1073741824 bytes
64 heads, 32 sectors/track, 1024 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 478 489456 83 Linux
Disk /dev/hda: 1073 MB, 1073741824 bytes
16 heads, 63 sectors/track, 2080 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk /dev/hda doesn't contain a valid partition table
[root@localhost var]# rm -rf zhy
[root@localhost var]# clear
//创建目录
[root@localhost var]# mkdir zhy
//给zhy赋权限
[root@localhost var]# chmod 777 zhy
[root@localhost var]# mount -t ext3 -o defaults,usrquota,grpquota /dev/sdb1 /v
ar/zhy
[root@localhost var]# cd zhy
//检测
[root@localhost zhy]# quotacheck -cvuga
quotacheck: Scanning /dev/sdb1 [/var/zhy] done
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost zhy]# ls
aquota.group aquota.user lost+found
//开启服务
[root@localhost zhy]# quotaon -avug
/dev/sdb1 [/var/zhy]: group quotas turned on
/dev/sdb1 [/var/zhy]: user quotas turned on
[root@localhost zhy]# ls
aquota.group aquota.user lost+found
[root@localhost zhy]# edquota -u zhs
[root@localhost zhy]# su zhs
[zhs@localhost zhy]$ ls
aquota.group aquota.user lost+found
[zhs@localhost zhy]$ touch file1 file2 file3
[zhs@localhost zhy]$ touch file4
//超出软限制的警告
sd(8,17): warning, user file quota exceeded.
[zhs@localhost zhy]$ touch file5
[zhs@localhost zhy]$ touch file6
sd(8,17): write failed, user file limit reached.
touch: 正在创建目录 ‘file6’: 超出磁盘限额
//超出硬限制