linux新增硬碟並編輯配額

jhon_lee發表於2012-09-04
在vmware中實現給linux新增硬碟

實驗環境:Oracle linux5.2 ,vmware workstation 8.0

主機名:oel11g

 

一、新增虛擬磁碟

 “setting” --&gt”Add”à--&gt“Hard Disk” --&gt create a new virtual disk --&gtSCSI--? 磁碟大小20.0G(大小自定)--&gt“Disk file”保持預設finish--&gtOK

二、登陸到虛擬機器作業系統

[root@oel11g ~]# reboot

………….

 

重啟以後登陸

[root@oel11g ~]# fdisk -l

 

Disk /dev/sda: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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        2610    20860402+  8e  Linux LVM

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

Disk /dev/sdb doesn't contain a valid partition table

[root@oel11g ~]#

會出現一塊 /dev/sdb的磁碟,正是我們剛剛新增的磁碟資訊

三、建立分割槽

[root@oel11g ~]# fdisk /dev/sdb

 

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

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 2610.

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_ ······輸入n 建立一個新的分割槽

Command action

   e   extended

   p   primary partition (1-4)······ 一到四個主要分割槽

p  ······建立一個主要分割槽

Partition number (1-4): 1 ······建立一個新主分割槽,區號為1

First cylinder (1-2610, default 1): ___ ······柱面 預設1

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +2G ······指定分割槽大小

 

Command (m for help): w ······儲存

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

四、建立檔案系統並且使用mount掛載磁碟

檢視建立完成的磁碟資訊

[root@oel11g ~]# fdisk -l

 

Disk /dev/sda: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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        2610    20860402+  8e  Linux LVM

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         244     1959898+  83  Linux

[root@oel11g ~]#

[root@oel11g ~]# mkfs.

mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.msdos   mkfs.vfat

[root@oel11g ~]# 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)

245280 inodes, 489974 blocks

24498 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=503316480

15 block groups

32768 blocks per group, 32768 fragments per group

16352 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912

 

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 26 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@oel11g ~]# mkdir /disk   ·······建立一個目錄

[root@oel11g ~]# mount /dev/sdb1 /disk······ 掛載剛剛新增的硬碟

[root@oel11g ~]# df –l ······檢視掛載資訊

Filesystem         1K-blocks      Used Available Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

                 18219452  13335188   3943824  78% /

/dev/sda1          101086     11833     84034  13% /boot

tmpfs              517644         0    517644   0% /dev/shm

/dev/sdb1          1929068     35688   1795388   2% /disk

 

使用者同樣可以透過檢視mtab來檢視當前作業系統磁碟掛載情況

[root@oel11g disk]# cat /etc/mtab

/dev/mapper/VolGroup00-LogVol00 / ext3 rw 0 0

proc /proc proc rw 0 0

sysfs /sys sysfs rw 0 0

devpts /dev/pts devpts rw,gid=5,mode=620 0 0

/dev/sda1 /boot ext3 rw 0 0

tmpfs /dev/shm tmpfs rw 0 0

none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0

none /proc/fs/vmblock/mountPoint vmblock rw 0 0

sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0

/dev/sdb1 /disk ext3 rw 0 0

 

五、更改fstab檔案確保新新增的磁碟永久生效 1、編輯fstab檔案

?    /etc/fstab檔案每一行由空格分為六項,包括:

?    裝置檔案

?    掛載點

?    檔案系統型別

?    mount引數:包含defaults和auto的行會在開機時自動被載入。

?    dump引數:0表示永不備份。1表示每天備份,2表示每兩天備份一次,依次類推。

?    fsck順序:0表示忽略。1、2、3表示檢查順序。一般1被根檔案系統使用。網路檔案系統與光碟機軟碟機等裝置應該被忽略。

 

[root@oel11g disk]# vi /etc/fstab

/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

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/VolGroup00/LogVol01 swap                    swap    defaults        0 0

新增如下資訊

/dev/sdb1  /disk ext3  defaults,usrquota,grpquota 0 0

[root@oel11g disk]# mount -o remount /disk ······使用remount指令將修改資訊載入到/etc/mtab中

[root@oel11g disk]# cat /etc/mtab······檢視資訊

/dev/mapper/VolGroup00-LogVol00 / ext3 rw 0 0

proc /proc proc rw 0 0

sysfs /sys sysfs rw 0 0

devpts /dev/pts devpts rw,gid=5,mode=620 0 0

/dev/sda1 /boot ext3 rw 0 0

tmpfs /dev/shm tmpfs rw 0 0

none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0

none /proc/fs/vmblock/mountPoint vmblock rw 0 0

sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0

/dev/sdb1 /disk ext3 rw,usrquota,grpquota 0 0

[root@oel11g disk]#

2、生成配額檔案

[root@oel11g disk]# quotacheck -auvg

或者

[root@oel11g disk]# quotacheck -uvg /disk······檔案系統

在檔案系統的根目錄下建立aquota.user及aquota.group兩個檔案

[root@oel11g disk]# ls

aquota.group  aquota.user

3、編輯配額檔案

使用edquota 使用者名稱與edquota –g 組名編輯使用者與組的磁碟限額

[root@oel11g disk]# edquota oracle

Disk quotas for user oracle (uid 500):

  Filesyste    blocks   soft       hard     inodes     soft     hard

  /dev/sdb1      0          0          0          0        0        0

blocks: 只已經使用的塊大小

soft: 軟限制使用的大小

hard:硬限制使用的大小(當軟限制的大小到達後系統人允許擴長,直到到達硬限制數)

inodes:當前使用者在本檔案系統中可建立的目錄數

4、開啟配額功能

[root@oel11g ~]# quotaon -guvp /disk

group quota on /disk (/dev/sdb1) is on

user quota on /disk (/dev/sdb1) is on

開啟配額功能

 

[root@oel11g ~]# quotaoff -guvp /disk

group quota on /disk (/dev/sdb1) is on

user quota on /disk (/dev/sdb1) is on

關閉配額功能

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26474945/viewspace-742664/,如需轉載,請註明出處,否則將追究法律責任。

相關文章