linux中的磁盤配額設置詳解

 

磁盤配額的設置

詳細步驟:

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超出磁盤限額

//超出硬限制

  

     

 

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章