2011年1月5日 星期三

Debian Package Management - APT (Advanced Package Tool)

類別 : [TMLDP] [System Administration][Foundation]

1. Debian Package Manaement

        dpkg 是 Debian 最基礎的套件管理工具,其它的Debian 衍生發行版,如Ubuntu、
Knoppix都可以使用dpkg 來進行套件的管理。
但由於dpkg 並無法有效的處理套件相依性衝突的問題,故從Debian 2.1 Slink (1999)就出現了可以有效處理套件相依衝突的APT(Advanced Package Tool)供的工具來進行Debian 套件管理 。

        較常用的APT (Advanced Package Tool) 工具集工具如下 ,

  • apt-get : apt 所提供的套件安裝、移除、升級命令。
  • apt-cache : apt 所提供的套件查詢命令。
  • aptitude : Debian官方推薦的dpkg 套件管理前端工具程式,具有比apt更 好的套件相依衝突處理能力,除提供命令列操作介面外也提供了一個 文字視窗操作介面。
  • synaptic : Debian-Base 發行版最常見的圖形使用者介面視窗套件管理工具。


  2./etc/apt/apt.conf 

        APT的主設定檔是「/etc/apt/apt.conf」,主要是用來設定APT的相關屬性,例如設 定檔的所位置、主設定檔檔名、更新來源設定檔的檔名、下載的套件放置目錄...等。

3. /etc/apt/sources.list

『/etc/apt/source.list』是apt 系統的套件來源設定檔,部分內容如下,
#deb cdrom:[Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)]/ lucid main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.


deb http://tw.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid main restricted


## Major bug fix updates produced after the final release of the
## distribution.
deb http://tw.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid-updates main restricted


## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://tw.archive.ubuntu.com/ubuntu/ lucid universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid universe
….........

套件來源設定檔中的每一行都是用來描述一個套件來源,其語法如下,

<DebType> <AddressType://Hostaddress/> <Distribution> <Section1> <Section2> <Section3>...

DebType : deb套件類別,『deb』 表示是二進位套件檔,『deb-src』表示是原始碼套件 檔。
AddressType : 連線位址類別,常見的有 http、ftp、file、cdrom、ssh...等。

Distribution : 發行版名稱。

Section : 套件類別,如 stable 、testing、main、restricted、univers、multivers....等,可 時選擇一種以上的套件類別。

『/etc/apt/source.list』的內容變更後需重新執行一次『apt-get update』以更新套 件索引清單。

4.apt-get

        APT提供了一個在命令列用來進行套件的安裝、移除與更新的工具-「apt-get」其 語法如下,

        apt-get [Option] <command> [PackageName]

            常用選項如下,

            a. -y, --yes, --assume-yes : 當apt-get執行時提出詢問自動給與"YES"的答案。

        常用command:
        a. update : 更新本機有效套件索引清單

                變更『/etc/apt/source.list』的內容後或使用 APT 系列工具前,如
『apt-get』、  『apt-cache』都應該先更新本機有效套件索引清單。

root@lab5:~# apt-get update
Hit http://tw.archive.ubuntu.com lucid Release.gpg
Hit http://tw.archive.ubuntu.com lucid-updates Release.gpg
Hit http://security.ubuntu.com lucid-security Release.gpg
Hit http://security.ubuntu.com lucid-security Release
Hit http://tw.archive.ubuntu.com lucid Release
Hit http://security.ubuntu.com lucid-security/main Packages
Hit http://tw.archive.ubuntu.com lucid-updates Release
Hit http://security.ubuntu.com lucid-security/restricted Packages
Hit http://security.ubuntu.com lucid-security/main Sources
Hit http://security.ubuntu.com lucid-security/restricted Sources
Hit http://security.ubuntu.com lucid-security/universe Packages
Hit http://security.ubuntu.com lucid-security/universe Sources
Hit http://tw.archive.ubuntu.com lucid/main Packages
Hit http://security.ubuntu.com lucid-security/multiverse Packages
Hit http://security.ubuntu.com lucid-security/multiverse Sources
Hit http://tw.archive.ubuntu.com lucid/restricted Packages
….....
Hit http://tw.archive.ubuntu.com lucid-updates/universe Packages
Hit http://tw.archive.ubuntu.com lucid-updates/universe Sources
Hit http://tw.archive.ubuntu.com lucid-updates/multiverse Packages
Hit http://tw.archive.ubuntu.com lucid-updates/multiverse Sources
Reading package lists... Done

        b. 安裝套件

               
#apt-get install PackageName 



            
    
當需要下載套件時,apt-get 會詢問使用者是否要繼續執行。

        b. 移除套件

            與 dpkg 相同,apt-get 也提供了兩種不同的移除方式

              b-1.remove 移除套件,但保留設定檔

                   #apt-get remove PackageName

             b-2.purge 連同設定檔完整移除

                #apt-get purge PackageName

       c. upgrade : 更新系統所有已安裝套件到當前發行版版本最新狀態

          #apt-get upgrade
root@lab5:~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
acpi-support acpid app-install-data-partner apparmor apparmor-utils apt apt-transport-https
apt-utils aptdaemon at-spi avahi-autoipd avahi-daemon avahi-utils base-files bind9-host
binutils bogofilter bogofilter-bdb bogofilter-common brasero brasero-common byobu bzip2
capplets-data coreutils cups cups-bsd cups-client cups-common cups-driver-gutenprint
desktopcouch dmsetup dnsmasq-base dnsutils dpkg e2fslibs e2fsprogs empathy empathy-common
erlang-base erlang-crypto erlang-inets erlang-mnesia erlang-public-key erlang-runtime-tools
erlang-ssl erlang-syntax-tools erlang-xmerl evince evolution evolution-common
evolution-data-server evolution-data-server-common evolution-plugins f-spot fglrx-modaliases
file-roller firefox firefox-branding firefox-gnome-support gdebi gdebi-core gdm gedit
….......................
….......................
upstart ure ureadahead usb-creator-common usb-creator-gtk vinagre w3m wget xserver-common
xserver-xorg-core xulrunner-1.9.2
360 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 269MB of archives.
After this operation, 11.8MB of additional disk space will be used.
Do you want to continue [Y/n]?


        d.dist-upgrade : 發行版版本升級

           當發行版推出新版時,可以使用『apt-get dist-grade』將整個系統更新 到最新的發行版版本

              #apt-get dist-upgrade
root@lab5:~# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
linux-headers-2.6.32-27 linux-headers-2.6.32-27-generic linux-image-2.6.32-27-generic
The following packages will be upgraded:
acpi-support acpid app-install-data-partner apparmor apparmor-utils apt apt-transport-https
apt-utils aptdaemon at-spi avahi-autoipd avahi-daemon avahi-utils base-files bind9-host
…..............................
…..............................
ttf-thai-tlwg tzdata ubufox ubuntu-system-service ubuntuone-client ubuntuone-client-gnome
udev udisks unattended-upgrades uno-libs3 update-inetd update-manager update-manager-core
upstart ure ureadahead usb-creator-common usb-creator-gtk vinagre w3m wget xserver-common
xserver-xorg-core xulrunner-1.9.2
363 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 312MB of archives.
After this operation, 197MB of additional disk space will be used.
Do you want to continue [Y/n]?



5.apt-chche

『apt-cache 』可以用來查詢安裝套件名稱、套件相關訊息等資訊,其語法如下,

apt-cache [option] command [PackageName]

常用command如下,

a. showpkd : 顯示套件版本資訊及與其他套件的相依關係。
root@lab5:~# apt-cache showpkg joe
Package: joe
Versions:
3.7-1 (/var/lib/apt/lists/tw.archive.ubuntu.com_ubuntu_dists_lucid_universe_binary-i386_Packages)
Description Language:
File: /var/lib/apt/lists/tw.archive.ubuntu.com_ubuntu_dists_lucid_universe_binary-i386_Packages
MD5: 4d6bbc0d4cf8b71ec0b3dfa1ffb8ca46


2.9.8-1 (/var/lib/dpkg/status)
Description Language:
File: /var/lib/dpkg/status
MD5: 4d6bbc0d4cf8b71ec0b3dfa1ffb8ca46




Reverse Depends:
Dependencies:
3.7-1 - libc6 (2 2.4) libncurses5 (2 5.6+20071006-3)
2.9.8-1 - libc6 (2 2.3.2-1) libncurses5 (2 5.3.20030510-1)
Provides:
3.7-1 -
2.9.8-1 -
Reverse Provides:
b.show : 顯示套件完整資訊。
root@lab5:~# apt-cache show joe
Package: joe
Priority: optional
Section: universe/editors
Installed-Size: 1452
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Original-Maintainer: Josip Rodin <joy-packages@debian.org>
Architecture: i386
Version: 3.7-1
Depends: libc6 (>= 2.4), libncurses5 (>= 5.6+20071006-3)
Filename: pool/universe/j/joe/joe_3.7-1_i386.deb
Size: 480102
MD5sum: f6bf566629af078893eaf5dd64be042a
SHA1: 543e8b1f2343c02964b4357b7b66005662c5bf9e
SHA256: 7257bce2d680003e941b2eaa4516ee1376343512ab2702d27c10e62009bf2338
Description: user friendly full screen text editor
Joe, the Joe's Own Editor, has the feel of most PC text editors: the key
sequences are reminiscent of WordStar and Turbo C editors, but the feature
set is much larger than of those. Joe has all of the features a Unix
user should expect: full use of termcap/terminfo, complete VI-style Unix
integration, a powerful configuration file, and regular expression search
….....

c.stats : 顯示收集在cache 的套件相關統計
root@lab5:~# apt-cache status
E: Invalid operation status
root@lab5:~# apt-cache stats
Total package names: 39580 (1583k)
Normal packages: 30024
Pure virtual packages: 646
Single virtual packages: 2637
Mixed virtual packages: 296
Missing: 5977
Total distinct versions: 33064 (1852k)
Total distinct descriptions: 33064 (794k)
Total dependencies: 215836 (6043k)
Total ver/file relations: 35095 (562k)
Total Desc/File relations: 33064 (529k)
Total Provides mappings: 6127 (123k)
Total globbed strings: 150 (1992)
Total dependency version space: 1090k
Total slack space: 77.7k
Total space accounted for: 10.2M
d.search : 查詢安裝套件名稱

若需要確認安裝的套件名稱,可以使用
『apt-cache search <PATTERN>』查詢,不過通常你會得到相當多輸出,可 以適當利用 grep 過濾無關的資訊。
root@lab5:~# apt-cache search ssh | grep -w 'ssh'
python-paramiko - Make ssh v2 connections with Python
ssh-import - import SSH public keys from Launchpad.net
clusterssh - administer multiple ssh or rsh shells simultaneously
dpsyco-ssh - Automate administration of access via ssh
gtk-led-askpass - GTK+ password dialog suitable for use with ssh-add
jta - Java telnet/ssh applet - documentation
jta-doc - Java telnet/ssh applet
ksshaskpass - interactively prompt users for a passphrase for ssh-add
libnet-ssh-gateway-ruby - Ruby library for tunneling connections to servers with ssh
libnet-ssh-gateway-ruby1.8 - Ruby library for tunneling connections to servers with ssh
libnet-ssh-gateway-ruby1.9.1 - Ruby library for tunneling connections to servers with ssh
libnet-ssh-perl - Perl extension for secure shell
libnet-ssh-ruby1.8 - pure ruby module that emulates an SSH client
libpam-ssh - Single sign-on via private SSH key
ssh-askpass - under X, asks user for a passphrase for ssh-add
ssh-askpass-fullscreen - Under Gnome2, asks user for a passphrase for ssh-add
sshguard - Protects from brute force attacks against ssh
sshm - A command-line tool to manage your ssh servers
sshpass - Non-interactive ssh password authentication
sslh - ssl/ssh multiplexer
zssh - interactive file transfers over ssh
ssh - secure shell client and server (metapackage)
ssh-askpass-gnome - interactive X program to prompt users for a passphrase for ssh-add
erlang-ssh - Erlang/OTP implementation of SSH protocol
ssh-krb5 - secure shell client and server (transitional package)
root@lab5:~#

e.depends : 查詢指定檔案或指定套件的相依套件
root@lab5:~# apt-cache depends ssh
ssh
Depends: openssh-client
Depends: openssh-server
root@lab5:~# apt-cache depends joe
joe
Depends: libc6
Depends: libncurses5

root@lab5:~# apt-cache depends openssh-client
openssh-client
Depends: libc6
Depends: libedit2
Depends: libgssapi-krb5-2
Depends: libssl0.9.8
Depends: zlib1g
|Depends: debconf
Depends: <debconf-2.0>
cdebconf
debconf
Depends: adduser
Depends: dpkg
Depends: passwd
Suggests: ssh-askpass
gtk-led-askpass
ksshaskpass
ssh-askpass-fullscreen
ssh-askpass-gnome
Suggests: libpam-ssh
Suggests: keychain
Suggests: openssh-blacklist
Suggests: openssh-blacklist-extra
Recommends: xauth
Conflicts: rsh-client
Conflicts: <sftp>
Conflicts: ssh
Conflicts: ssh-krb5
Replaces: ssh
Replaces: ssh-krb5
root@lab5:~#
6.apt-cdrom

若需要將光碟當成更新來源,可以使用『apt-cdrom add 』將光碟的設定項加入 『/etc/apt/source.list』中,奇語法如下,

#apt-cdrom add
root@lab5:~# apt-cdrom add
Using CD-ROM mount point /media/apt/
Identifying.. [d00480f76f2d81dbf30817849c039fdc-2]
Scanning disc for index files..
Found 2 package indexes, 0 source indexes, 0 translation indexes and 1 signatures
This disc is called:
'Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)'
Copying package lists...gpgv: Signature made Thu Apr 29 20:56:05 2010 CST using DSA key ID FBB75451
gpgv: Good signature from "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>"
Reading Package Indexes... Done
Writing new source list
Source list entries for this disc are:
deb cdrom:[Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)]/ lucid main restricted
Repeat this process for the rest of the CDs in your set.
W: Skipping nonexistent file /media/apt/dists/lucid/main/binary-i386/Packages
W: Skipping nonexistent file /media/apt/dists/lucid/restricted/binary-i386/Packages
root@lab5:~#

完成後,在『/etc/apt/source.list』中就會多出一行以cd-rom 作為更新來源的設定 項。

root@lab5:~# cat /etc/apt/sources.list | grep cdrom | grep -v "^#"
deb cdrom:[Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)]/ lucid main restricted

若需確認光碟完整性可以使用『apt-cdrom ident』進行掃描。



            

2010年12月9日 星期四

設定GRUB 密碼(LAB)

  •  類別 : [TMLDP] [System Administrator] [Advance ] [LAB]
  • 主題 : 設定 GRUB 密碼

  • 適用發行版 : RedHat 系列發行版 ( RHEL、CentOS、Fedora...)、Ubuntu
    ※尚未實測其他發行版

  • LAB 環境 : CntOS 5.5

  • 要進行這個測試你需要知道,
  1. GRUB 設定檔管理
  2. 如何使用 vi Text Editr 進行文字檔編輯
  3. 如何進行串流重導
  • 相關主題 : [The GRUB Boot Loader] [Stream、Redirection、Filter and Pipes]                   [The vi Text Editor] 
  • 實驗要求 :

  1. 設定 GRUB 密碼為 PassWord
  2. 設定預設開機選項的密碼為PassWd

  • 操作步驟 :

    STEP 1. 使用grub-md5-crypt 命令產生 MD5加密密碼字串
[root@lab-2 ~]# grub-md5-crypt >> /boot/grub/grub.conf <<EOF
> PassWord
> PassWord
> EOF
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
[root@lab-2 ~]# grub-md5-crypt >> /boot/grub/grub.conf <<EOF
> PassWd
> PassWd
> EOF
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
[root@lab-2 ~]# cat /boot/grub/grub.conf | tail -6
Password:
Retype password:
$1$IrbRt/$k6kEGB8HK4bS8Q1TgIANu/
Password:
Retype password:
$1$bEcRt/$SSB74/27o5f0fnEONbjGW.
[root@lab-2 ~]#
STEP 2. 使用 vi 開啟 /boot/grub/grub.conf
[root@lab-2 ~]# vi /boot/grub/grub.conf
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hdb2
# initrd /initrd-version.img
#boot=/dev/hdb
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.26.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.26.1.el5.img
title CentOS (2.6.18-194.17.4.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.17.4.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.17.4.el5.img
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.el5.img
Password:
Retype password:
$1$IrbRt/$k6kEGB8HK4bS8Q1TgIANu/
Password:
Retype password:
$1$bEcRt/$SSB74/27o5f0fnEONbjGW.



STEP 3. 設定 GRUB 密碼為 PassWord
#boot=/dev/hdb
default=0
timeout=5
password --md5 $1$IrbRt/$k6kEGB8HK4bS8Q1TgIANu/ <--- 加這一行
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
          STEP 4. 設定預設開機選項密碼為 PassWd
hiddenmenu
title CentOS (2.6.18-194.26.1.el5)
lock <-- 加上這一行跟下一行
password --md5 $1$bEcRt/$SSB74/27o5f0fnEONbjGW.
root (hd0,0)
kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.26.1.el5.img

         ※修改後的/boot/grub/grub.conf 內容
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hdb2
# initrd /initrd-version.img
#boot=/dev/hdb
default=0
timeout=5
password --md5 $1$IrbRt/$k6kEGB8HK4bS8Q1TgIANu/
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.26.1.el5)
lock
password --md5 $1$bEcRt/$SSB74/27o5f0fnEONbjGW.
root (hd0,0)
kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.26.1.el5.img
title CentOS (2.6.18-194.17.4.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.17.4.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.17.4.el5.img
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.el5.img
STEP 5. 存檔後重啟系統

STEP 6. 驗證(一)



由於GRUB 已經設定了密碼保護,需先輸入 'p'

             


                     再輸入密碼後,才能進行其他作業



                      STEP 7. 驗證(二)

                                等待讀秒完畢,進入預設開機選項

                                 由於已經設定了GRUB 密碼,無法直接進入預設開機選項 

                               需先輸入'p',再輸入GRUB 密碼


                                 才能選取開機項目

                                由於這邊所選取的開機項目已設定個別開機選項密碼,
                                故需再輸入個別開機選項密碼才能進行後續開機作業






The GRUB Boot Loader - 設定 GRUB 密碼

類別 : [TMLDP] [Systm Administration] [Advance]

    若要避免惡意使用者於開機期間藉由修改核心啟動參數以單人模式免密碼登入系統,可以設定GRUB 密碼保護。

    設定GRUB 密碼後,當使用者於開機期間嘗試開啟GRUB 編輯器修改GRUB 開機選單內容,例如加上其他核心啟動參數時,就必須輸入密碼才可以進行變更。


    要設定GRUB 設定檔密碼需要使用『grub-md5-crypt』命令先產生一組經  MD5 (Messag-Difest algorithm 5) 雜湊加密演算法加密的密碼字串。


    於GRUB 的設定檔(/boot/grub/grub.conf)的主要設定區中加入下列設定,
#boot=/dev/hdb
default=0
timeout=5
passwd --md5 <加密密碼字串>

    若要針對個別開機選項設定密碼則除了要於個別開機選項設定區加上上述的『passwd --md5 <加密密碼字串>』外,還需要加上『lock』,

title CentOS (2.6.18-194.26.1.el5)
lock
passwd --md5 <加密密碼字串>

root (hd0,0)
kernel /vmlinuz-2.6.18-194.26.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.26.1.el5.img

      設定GRUB 密碼(LAB)

  

同時新增多組帳號及Disk Quota limit的實驗 (四)

  • LAB C :


    7. 在 /dev/hda5 啟動 Disk Quota limit。
    8. 實施Disk Quota limit 於usrer1 及 user2 兩個使用者帳號。
    9. /dev/hda5 的 soft limit 為20MB,hard limit 為 30 MB。
    10. usrer1 及 user2 兩個使用者帳號的家目錄Disk Quota limit 如下,soft limit 為10MB,hard limit 為 20 MB。
  • 操作步驟 :


    STEP 1. 於/home 所在檔案系統加上usrquota、grpquota 掛載選項  
    [root@lab-2 /]# mount -o remount,usrquota,grpquota /
    [root@lab-2 /]# mount | grep hdb2
    /dev/hdb2 on / type ext3 (rw,usrquota,grpquota)

STEP 2. 建立配額資料庫
[root@lab-2 ~]# quotacheck -ugvm /
quotacheck: Scanning /dev/hdb2 [/] done
quotacheck: Checked 15168 directories and 137285 files
[root@lab-2 ~]# quotacheck -ugvm /media/hdb5/
quotacheck: Scanning /dev/hdb5 [/media/hdb5] done
quotacheck: Checked 3 directories and 4 files
[root@lab-2 ~]#

          ※  第一次執行時因為 / 及 /media/hdb5 目錄中均無配額資料庫檔 aquota.user、
                 aquota.group 所以會出現錯誤訊息,然後系統會自動產生配額資料庫檔
[root@lab-2 ~]# quotacheck -ugvm /
quotacheck: Scanning /dev/hdb2 [/] done
quotacheck: Checked 15168 directories and 137285 files
[root@lab-2 ~]# quotacheck -ugvm /
quotacheck: Scanning /dev/hdb2 [/] 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 15168 directories and 137283 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@lab-2 ~]# quotacheck -ugvm /media/hdb5/
quotacheck: Scanning /dev/hdb5 [/media/hdb5] 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 3 directories and 2 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@lab-2 ~]# ls -l /aquota.* /media/hdb5/aquota.*
-rw------- 1 root root 8192 Dec 9 01:39 /aquota.group
-rw------- 1 root root 11264 Dec 9 01:39 /aquota.user
-rw------- 1 root root 6144 Dec 9 01:39 /media/hdb5/aquota.group
-rw------- 1 root root 6144 Dec 9 01:39 /media/hdb5/aquota.user

STEP 3. 啟動Disk Quota

[root@lab-2 ~]# quotaon / /media/hdb5

STEP 4. 設定 user1 及 user2 的 Disk Quota limit
[root@lab-2 /]# edquota -u user1
Disk quotas for user user1 (uid 506):
Filesystem blocks soft hard inodes soft hard
/dev/hdb2 76 10240 20480 10 0 0
/dev/hdb5 0 30720 40960 0 0 0
[root@lab-2 /]# edquota -u user2
Disk quotas for user user2 (uid 507):
Filesystem blocks soft hard inodes soft hard
/dev/hdb2 76 10240 20480 10 0 0
/dev/hdb5 0 30720 40960 0 0 0


STEP 5. 變更 /media/hdb5 的目錄權限,使 user1 及 user2具檔案新增權限,並確認user1
及 user2 的家目錄權限
[root@lab-2 ~]# ls -ld /media/hdb5/
drwxr-xr-x 3 root root 1024 Dec 9 01:39 /media/hdb5/
[root@lab-2 ~]# chmod o+w /media/hdb5/
[root@lab-2 ~]# ls -ld /media/hdb5/
drwxr-xrwx 3 root root 1024 Dec 9 01:39 /media/hdb5/
[root@lab-2 /]# ls -ld /home/user1
drwx------ 3 user1 labuser 4096 Dec 6 14:40 /home/user1
[root@lab-2 /]# ls -ld /home/user2
drwx------ 3 user2 labuser 4096 Dec 6 14:39 /home/user2

STEP 6. 測試 user1 Disk Quota limit 是否生效
[user1@lab-2 ~]$ dd if=/dev/zero of=file-1 bs=1M count=11
hdb2: warning, user block quota exceeded.
11+0 records in
11+0 records out
11534336 bytes (12 MB) copied, 0.0448105 seconds, 257 MB/s
[user1@lab-2 ~]$ dd if=/dev/zero of=file-2 bs=1M count=11
hdb2: write failed, user block limit reached.
dd: writing `file-2': Disk quota exceeded
9+0 records in
8+0 records out
9318400 bytes (9.3 MB) copied, 0.0372815 seconds, 250 MB/s

[user1@lab-2 ~]$ dd if=/dev/zero of=/media/hdb5/file-user1-1 bs=1M count=21
21+0 records in
21+0 records out
22020096 bytes (22 MB) copied, 0.156971 seconds, 140 MB/s
[user1@lab-2 ~]$ dd if=/dev/zero of=/media/hdb5/file-user1-2 bs=1M count=11
hdb5: warning, user block quota exceeded.
11+0 records in
11+0 records out
11534336 bytes (12 MB) copied, 0.0659443 seconds, 175 MB/s
[user1@lab-2 ~]$ quota
Disk quotas for user user1 (uid 506):
Filesystem blocks quota limit grace files quota limit grace
/dev/hdb2 20480* 10240 20480 12 0 0
/dev/hdb5 32900* 30720 40960 7days 2 0 0

STEP 7. 測試 user2 Disk Quota limit 是否生效
[user2@lab-2 ~]$ dd if=/dev/zero of=file-1 bs=1M count=11
hdb2: warning, user block quota exceeded.
11+0 records in
11+0 records out
11534336 bytes (12 MB) copied, 0.0328104 seconds, 352 MB/s
[user2@lab-2 ~]$ dd if=/dev/zero of=file-2 bs=1M count=11
hdb2: write failed, user block limit reached.
dd: writing `file-2': Disk quota exceeded
9+0 records in
8+0 records out
9318400 bytes (9.3 MB) copied, 0.0291954 seconds, 319 MB/s
[user2@lab-2 ~]$ dd if=/dev/zero of=/media/hdb5/file-user2-1 bs=1M count=21
21+0 records in
21+0 records out
22020096 bytes (22 MB) copied, 0.101413 seconds, 217 MB/s
[user2@lab-2 ~]$ dd if=/dev/zero of=/media/hdb5/file-user2-2 bs=1M count=11
hdb5: warning, user block quota exceeded.
11+0 records in
11+0 records out
11534336 bytes (12 MB) copied, 0.0535639 seconds, 215 MB/s
[user2@lab-2 ~]$ dd if=/dev/zero of=/media/hdb5/file-user2-3 bs=1M count=11
hdb5: write failed, user block limit reached.
hdb5: write failed, user block limit reached.
dd: writing `/media/hdb5/file-user2-3': Disk quota exceeded
8+0 records in
7+0 records out
8216576 bytes (8.2 MB) copied, 0.0546072 seconds, 150 MB/s
[user2@lab-2 ~]$ quota
Disk quotas for user user2 (uid 507):
Filesystem blocks quota limit grace files quota limit grace
/dev/hdb2 20480* 10240 20480 12 0 0
/dev/hdb5 40958* 30720 40960 6days 3 0 0
Powered By Blogger