Lecture 8 Additional Storage
Linux上所有的儲存設備都需要有一個裝置檔案對應,這些裝置檔案位于/dev/目錄下。
USB,SCSI,SATA,iscsi裝置以sd開頭,IDE以hd開頭。表示方式:/dev/sd[a-z]N。
這些裝置檔案由udev建立,特殊檔案,沒有大小,有主裝置号和次裝置号。主裝置号用于描述這些裝置屬于哪個總線系統(哪類裝置)。屬于同一個總線的裝置屬于同一類裝置,一個總線上可以挂載不同的主裝置。次裝置号用于差別總線上不同的裝置。
mknod ,MAKEDEV 建立一個裝置
mknod /eev/mydevice [c|b] Major_num Minor_num
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608435EKLO.png"></a>
手動建立的裝置檔案在系統重新開機後會丢失。
/dev/null 黑洞(相當于一個垃圾桶)
/dev/zero 0 零裝置 初始化磁盤裝置
/dev/random /dev/urandom 随機數
所有字元裝置都是線性的。所有的塊裝置都是随機裝置。字元裝置和塊裝置沒有大小。
lsmod 顯示所有子產品的狀态資訊
modinfo 顯示一個子產品的摘要資訊
modprobe 裝載 解除安裝子產品
-r 解除安裝子產品
depmod 生成子產品間依賴關系的清單
insmod 需指定具體路徑
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608436PL0F.png"></a>
rmmod 從核心中移除子產品
-f 強行解除安裝
mkinitrd 自動生成一個initrd檔案。
--with 用于額外指定附加什麼樣的子產品
sfidsk 可以在腳本中使用的分區工具,可以儲存目前磁盤分區的分區表,能夠備份磁盤分區
sfidsk -d /dev/sdb &gt; /root/part_back/sdb.partitions 備份
sfidsk /dev/sdb &lt;/root/part_back/sdb.partitions 恢複
partprobe 通知核心更新一下分區資訊 ,存放位置:/proc/partitions。
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608436m6wt.png"></a>
格式化磁盤:
mkfs /dev/device 預設是格式化為ext2
mkfs -t ext3=mkfs.ext3
-L label 為磁盤添加卷标
mkfs -t -L MYDEV /dev/sda5
也可以為卷标指定一個UUID(随機數)
blkid 檢視id 和卷标
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_12986084374zRo.png"></a>
e2label /dev/sda5 檢視卷标
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608440aO2j.png"></a>
設定卷标
e2label /dev/sda5 DEV
mount LABEL=DEV /mnt/test 使用卷标挂載
mke2fs -L label 指定卷标
-j journal 有日志功能 (ext3)
-b 指定block塊大小 Specify the size of blocks in bytes。
-c 檢查壞塊(不常用) Check the device for bad blocks before creating the file system.。
-i bytes/inode 位元組和inode的比率。Specify the bytes/inode ratio.
-N 手動指定bytes/inode
overrides the default calculation of the number of inodes that should be reserved for the filesystem (which is based on the number of blocks and the bytes-per-inode ratio). This allows the user to specify the number of desired inodes directly.
-m 預留比例,為管理者所預留的磁盤分區的塊數占總數的比例。
Specify the percentage of the filesystem blocks reserved for the super-user.This avoids fragmentation, and allows root-owned daemons, such as sys-logd(8), to continue to function correctly after non-privileged processes are prevented from writing to the filesystem. The default percentage is 5%.
tune2fs 專門用于調整mke2fs建立的檔案裝置的資訊
adjust tunable filesystem parameters on ext2/ext3 filesystems
-L 改卷标
-j 把ext3檔案格式轉換為ext3格式
-c 指定最大挂載次數,超過指定次數後分區會自檢 0 禁用自檢。
Adjust the number of mounts after which the filesystem will be checked by e2fsck(8)
tun2fs -c0 /dev/sda5
-i 經過多長時間要自檢一次 ,預設180天。
Adjust the maximal time between two filesystem checks
-m 調整預留比例
-r 明确指定保留多少塊
-u 保留白間可以供誰用
-o 用于調整預設挂載選項
mount -o 調整預設選項
rw 可讀寫
suid 允許設定了suid和sgid的執行正常功能
dev 允許啟用裝置檔案
exec 允許執行上面的二進制檔案
auto 可以自動挂載
nouser 禁止普通使用者挂載此裝置
async 異步寫入,提高磁盤性能
acl 允許使用acl功能
-t 指定挂載的時候所使用的檔案系統類型
mount -o defaults,acl /dev/sda5 /mnt/test
預設顯示挂載屬性
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608440eJpb.png"></a>
loop 挂載本地回環裝置
mount -o loop /root/boot.iso /mnt/test
user_xattr 允許使用者使用檔案的擴充屬性
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608441m2CG.png"></a>
mount -o defaults 直接設定預設選項
dumpe2fs 顯示一個e2fs檔案裝置的詳細資訊
findsfs label 根據卷标來查找裝置
findfs LABLE=DEV
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608443kIo8.png"></a>
remount 重新挂載
/etc/mtab 保留了目前系統上挂載的所有的裝置,無論是自動挂載(/etc/fstab)的還是使用者手動挂載的
umount -a /etc/mtab
解除安裝mtab下的檔案,即解除安裝掉所有挂載的裝置
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608444cden.png"></a>
fuser -v 顯示哪個使用者正在通路挂載點
fuser -km 将通路使用者強行踢出
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608444iujq.png"></a>
再解除安裝
建立一個交換分區:
mkswap /dev/sda6 将某一個分區格式化為虛拟分區
swapon /dev/sda6 啟用虛拟分區
swapoff /dev/sda6 關閉虛拟分區
swapon -a 啟用所有交換分區
dd if=/dev/zero(資料來源) of=/var/local/swapfile(放到哪裡去) bs=1k(一次讀多大資料塊)count=1M(讀取多少個這樣的資料塊)
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_12986084450S5I.png"></a>
mkswap /tmp/swapfile
swapon /tmp/swapfile
free 檢視
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608446h5KB.png"></a>
RH131 Lecture 9 User Administration
vipw 編輯/etc/shadow檔案 在編輯的時候鎖定此檔案
vigr 編輯/etc/gshadow檔案 在編輯的時候鎖定此檔案
Quota 磁盤配額: 用于定義某個使用者在磁盤上或者某個分區上最多隻能使用的磁盤空間,或者最多隻能建立的檔案的個數。
磁盤配額在核心中實作,實際上是在檔案系統上實作的,跟檔案系統相關。隻能對一個分區來做。
兩種配額标準:空間配額:定義一個使用者最多隻能使用多少個磁盤塊,以k為機關。
檔案配額:定義一個使用者最多隻能使用多少個檔案。
兩種配額類型:軟限制:可以超出限定的配額數。
硬限制:無論如何不能超過。
二者可以結合起來使用。
磁盤配額對管理者無效。
在檔案系統上,使用磁盤配額時要在分區上指定特殊的挂載選項。
兩種政策:usrquota (針對使用者) grpquota(針對組) 各自實作,存儲在各自特定的檔案中。在某個分區啟用了配額功能之後,會在從磁盤分區的根目錄上建立兩個檔案:
aquota.user aquota.group,記錄使用者配額的定義。
實作過程:編輯/etc/fstab檔案,在defaults 後面加上使用的政策
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608447OORt.png"></a>
重新挂載,檢視:
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608448JyYs.png"></a>
quotacheck 預設建立aquota.user aquota.group兩個檔案
-c 檢查aquota.user aquota.group,無論檔案是否存在,均重新建立
-u 檢查使用者配額
-g 檢查組的配額
-m 無論如何,不要把此檔案系統挂載為隻讀檔案系統
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608449d96p.png"></a>
quotaon 打開某個檔案系統上磁盤配額功能 quotaoff 關閉
edquota -u(可省略) username 編輯某個使用者的磁盤配額
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608449ts8x.png"></a>
su 到student下進 行驗證:
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608450WHSh.png"></a>
使用dd指令驗證一下:
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608451EH8J.png"></a>
限定使用者使用的檔案數,使用edquota編輯
總結:1.啟用usrquota,grpquota
2.檢查對應分區所挂載目錄下是否存在aquota.user 或aquota.group兩個檔案,如果沒有,使用quotacheck -cugm來建立
3 quotaon 啟用此分區上配額
4 編輯使用者配額
edquota -p 把一個使用者的配額複制到另一個使用者上
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608454dftD.png"></a>
setquota 在腳本中以非互動的模式實作磁盤配額
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608457dJdo.png"></a>
edquota -t 改變預設軟限制和硬限制使用者所能夠使用的寬限期
<a href="http://lyp0909.blog.51cto.com/attachment/201102/25/508999_1298608458WOKN.png"></a>
warnquota /home 報告目前系統上使用磁盤配額的檔案系統上任何一個超出配額的使用者,向其發送郵件通知。
quotaoff /home 臨時性地關閉磁盤配額
本文轉自 490999122 51CTO部落格,原文連結:http://blog.51cto.com/lyp0909/500267,如需轉載請自行聯系原作者