二. 配额使用示例
2.1 创建分区并mount到目录
[root@rhce /]# fdisk /dev/sdc
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0x1e051117.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon't be recoverable.
Warning: invalid flag 0x0000 of partitiontable 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated.It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G}(1-652, default 652):
Using default value 652
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@rhce /]# fdisk -l
Disk /dev/sdc: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x1e051117
Device Boot Start End Blocks Id System
/dev/sdc1 1 652 5237158+ 83 Linux
[root@rhce /]# mkfs -t ext3 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1309289 blocks
65464 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@rhce /]#
[root@rhce /]# mount/dev/sdc1 /dave
[root@rhce /]# vim /etc/fstab
/dev/sdc1 /dave ext3 defaults 0 0
我们这里将/dev/sdc1 映射到了目录/dave.
2.2 创建2个测试用户
[root@rhce /]# groupadd grp01
[root@rhce /]# groupadd grp02
[root@rhce /]# cat /etc/group|grep grp0*
grp01:x:503:
grp02:x:504:
[root@rhce /]#
[root@rhce /]# useradd dave01 -g grp01
[root@rhce /]# useradd dave02 -g grp02
[root@rhce /]# passwd dave01
Changing password for user dave01.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updatedsuccessfully.
[root@rhce /]# passwd dave02
Changing password for user dave02.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updatedsuccessfully.
[root@rhce /]#
2.3 修改分区表启用配额限制
[root@rhce ~]# cat /etc/fstab
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sdc1 /dave ext3 defaults,usrquota,grpquot 0 0
[root@rhce ~]#
/etc/fstab 文件的第四个字段是装载文件系统是使用的选项:
(1)实现基于用户的磁盘配额,就加入usrquota关键字,
(2)实现基于组的磁盘配额,就加入grpqouta关键字,如果两者都需要,就全写入,中间可以用逗号分隔。
注意:请特别注意这里的拼写,是usrquota和grpquota,不要写成userquota和groupquota。
2.4 重新Remount 分区
[root@rhce ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs(rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
none on /sys/kernel/config type configfs(rw)
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
gvfs-fuse-daemon on /root/.gvfs typefuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdc1 on /dave typeext3 (rw)
分区是我们之前mount的,我们后来修改了mount的选项,增加了用户和组的配额,所以这里我们重新mount一次,使我们的修改生效。
[root@rhce ~]# mount -oremount /dave
[root@rhce ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts(rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs(rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
none on /sys/kernel/config type configfs(rw)
sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)
gvfs-fuse-daemon on /root/.gvfs typefuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdc1 on /dave typeext3 (rw,usrquota,grpquota)
[root@rhce ~]#
