Mini Howto Subject: การกำหนด Quota ให้กับ User ใน Linux By: Kiti Sripalakit Date: Jun 27, 1998 Update from: - License: สงวนลิขสิทธิ์เอกสารนี้ โดย กิตติ ศรีปลกิต การเผยแพร่เอกสารนี้จะต้องอยู่ภายไต้ เงื่อนไขของ GNU General Public License เวอร์ชั่น 2.0 ที่ออกโดย Free Sofware Foundation กรุฒาอ่านรายละเอียดของ GPL ที่ Introduction: Quota ทำให้เราสามารถกำหนดคุณลักษณะของ Disk Storage สองอย่างคือ จำนวนของ inode ที่ User เป็นเจ้าของ และจำนวน Disk Block ที่กำหนดให้กับ User หลักการณ์ของ Quota คือ User จะถูกจำกัดการใช้เนื้อที่บน Disk ตลอดเวลา Quota สนับสนุนการทำงานตังแต่ Kernel Version 1.3.8x และสามารถทำงานได้ดีใน Kernel Version 2.0 release ปัจจุบัน Quota จะออกแบบให้ทำงานกับไฟล์ ext2 เท่านั้น Prerequirement 1. Kernel สามารถ Download ได้จาก ftp://tsx-11.mit.edu/pub/linux/sources/system/v2.0/ 2. Quota Software สามารถ Download ได้จาก ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/all.tar.gz การติดตั้ง Quota บน Linux 1. กำหนด Config ของ Kernel ใหม่ โดยเพิ่ม Quota support ในส่วน File System พิมพ์ y ในบรรทัด Quota support (CONFIG_QUOTA) [n] y 2. Compile และ Install quota software ต้อง Compile บน linux 2.x Kernels และอาจเกิดปัหาตอน Compile C-Compiler อาจแสดงข้อความเกี่ยวกับ undefined MNTOPT constants หากเกิดปัหานี้เราต้องทำการ Copy mntent.h ไปไว้ใน Directory /usr/include/mntent.h ก่อนแล้วจึง Compile 3. แก้ไข System init script เพื่อเช็ค Quota และ ให้ Run Quota เมื่อ Boot เครื่อง ตัวอย่าง # Check quota and then turn quota on. if [ -x /usr/sbin/quotacheck ] then echo Checking quotas. This may take some time. /usr/sbin/quotacheck -avug echo Done. fi if [ -x /usr/sbin/quotaon ] then echo Turning on quota. /usr/sbin/quotaon -avug fi ***เราจะต้อง Mount file system ใน /etc/fstab ก่อน ที่จะ Run Quota จึงควร Run Quota ในส่วนท้ายสุดของ System init script เช่นถ้าเป็น Slackware Linux ก็เอาไปไว้ใน rc.loca เป็นต้น *** 4. แก้ไข /etc/fstab ตัวอย่าง /dev/hda1 / ext2 defaults 1 1 /dev/hda2 /usr ext2 defaults 1 1 เพิ่ม usrquota ต่อจาก defaults โดยคั่นด้วย , เพื่อ Add Quota ใน File System /dev/hda1 / ext2 defaults 1 1 /dev/hda2 /usr ext2 defaults,usrquota 1 1 5. สร้าง Quota Record quota.user quota.user ต้องสร้างโดย root และ Read/Write โดย root เท่านั้น สร้างโดย Login เป๊น root แล้ว Enable Quota แล้วใช้คำสั่งใน partition /etc/fstab ดังนี้ touch /partition/quota.user chmod 600 /partition/quota.user 6. Reboot การกำหนด Quota ให้ User การกำหนดนี้ใช้ edquota command เช่น edquota bob คำสั่งนี้จะเข้า vi เพื่อกำหนด Quota สำหรับ User ชื่อ bob ต้อง Enable Quota ด้วย Quotas for user bob: /dev/hda2: blocks in use: 2594, limits (soft = 5120, hard = 6400) inodes in use: 356, limits (soft = 1000, hard = 1500) blocks in use is the total number of blocks (in kilobytes) a user has comsumed on a partition. inodes in use is the total number of files a user has on a partition. edquota ยังมีส่วนเสริมอีก 3 ส่วนที่ควรศึกษาคือ Soft Limit, Hard Limit, และ Grace Period Soft Limit ปกติ Soft Limit จะแสดง จำนวนการใช้ Disk มากที่สุด quota user อยู่ในส่วนนี้ แต่เมื่อรวมกับ Grace Period จะเป็นเส้นแบ่งเขต ซึ่ง Quota จะมี Warning ว่าใกล้จะมีการฝ่าฝ์น Quotaที่ตั้งไว้ Hard Limit Hard Limit จะทำงานเมื่อมีการ Set Grace Period มันจะกำหนด absolute limit ในการใช้ Disk ซึ่ง Quota User ไม่สามารถใช้ Disk มากกว่า Hard Limit ได้ Grace Period Grace Period คือ Time Limit ก่อนที่ Soft Limit จะถูกใช้สำหรับ Quota User (ใช้คำสั่ง edquota -t ) ตัวอย่าง เมื่อใช้คำสั่ง edquota -t Time units may be: days, hours, minutes, or seconds Grace period before enforcing soft limits for users: /dev/hda2: block grace period: 0 days, file grace period: 0 days ***สามารถแก้ไขโดยเปลี่ยน 0 เป็นอย่างอื่น แนะนำให้เป็น 7 *** Quota Command อื่นๆ Quotacheck ใช้ Scan file system ในการใช้ Disk และ updates quota record file quota.user ควร Run ทุกครั้งเมื่อ Boot เครื่อง หรือ ผ่านทาง Cronjob ทุก 1 สัปดาห์ Repquota ใช้ในการสร้าง Quota Information สรุปของ File System ตัวอย่าง # repquota -a Block limits File limits User used soft hard grace used soft hard grace root -- 175419 0 0 14679 0 0 bin -- 18000 0 0 735 0 0 uucp -- 729 0 0 23 0 0 man -- 57 0 0 10 0 0 user1 -- 13046 15360 19200 806 1500 2250 user2 -- 2838 5120 6400 377 1000 1500 Quotaon and Quotaoff ใช้ในการ turn on quota accouting และ turn off quota accouting มันจะถูกเรียกใช้งานเมื่อ System ถูก Startup และ System ถูก Shutdown