首先检查硬盘,分区格式化
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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 78 522112+ 82 Linux swap / Solaris
/dev/sda3 79 1044 7759395 83 Linux
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab el
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):
Using default value 1044
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
检查系统内核对磁盘配额的支持
[root@localhost ~]# dmesg |grep quota
VFS: Disk quotas dquot_6.5.1
[root@localhost ~]# rpm -qa |grep quota
quota-3.13-1.2.3.2.el5
挂载磁盘并复制home 文件夹中的所有内容到磁盘内,查看,然后删除home 的内容
[root@localhost ~]# mount /dev/sdb1 /mnt/
[root@localhost ~]# cp -a /home/* /mnt/
[root@localhost ~]# ll /mnt
total 20
drwx------ 2 root root 16384 Feb 20 00:29 lost+found
drwx------ 2 redhat redhat 4096 Aug 17 2008 redhat
[root@localhost ~]# rm -rf /home/redhat
[root@localhost ~]# ll /home
total 0
编辑系统文件是之开机后自动挂载
[root@localhost ~]# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/sdb1 /home ext3 defaults,usrquota,grpquota 0 1
重启
[root@localhost ~]# reboot
重启后检查是否配置正确
[root@localhost ~]# mount
/dev/sda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sdb1 on /home type ext3 (rw,usrquota,grpquota)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
开始为用户创建磁盘配额
[root@localhost ~]# quotacheck -acugv
quotacheck: Scanning /dev/sdb1 [/home] quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
done
quotacheck: Checked 4 directories and 5 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# ll /home
total 36
-rw------- 1 root root 7168 Feb 20 01:04 aquota.group
-rw------- 1 root root 7168 Feb 20 01:04 aquota.user
drwx------ 2 root root 16384 Feb 20 00:29 lost+found
drwx------ 2 redhat redhat 4096 Aug 17 2008 redhat
[root@localhost ~]# quotaon -avug
/dev/sdb1 [/home]: group quotas turned on
/dev/sdb1 [/home]: user quotas turned on
[root@localhost ~]# edquota -u redhat
Disk quotas for user redhat (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 16 490000 5000000 4 4900 5000
创建一个用户,并将新用户的的配置信息与redhat 的相同
[root@localhost ~]# useradd hq
[root@localhost ~]# passwd hq
Changing password for user hq.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# edquota -p redhat hq
[root@localhost ~]# repquota -a
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 149628 0 0 4 0 0
redhat -- 16 490000 500000 4 4900 5000
hq -- 16 490000 500000 4 4900 5000
用户这里检查配置是否生效
login as: redhat
[email protected]'s password:
[redhat@localhost ~]$ quota
Disk quotas for user redhat (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 16 490000 500000 4 4900 5000
[redhat@localhost ~]$ dd if=/dev/zero of=./abc bs=1024 count=3
3+0 records in
3+0 records out
3072 bytes (3.1 kB) copied, 0.006562 seconds, 468 kB/s
[redhat@localhost ~]$ quota
Disk quotas for user redhat (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 20 490000 500000 5 4900 5000
配置成功