출처 : http://verdetree.egloos.com/3452806 <디스크 장애 발생 및 복구> fsck : 파일시스템 체크 및 복구 명령어(file system checker) #fsck 만 적고 tab 키를 두 번 눌러 본다. fsck fsck.ext2 fsck.ext3 #df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 5.7G 2.8G 2.7G 52% / /dev/shm 125M 0 125M 0% /dev/shm /dev/sda3 1.6G 90M 1.5G 6% /home /dev/hda1 93M 5.6M 83M 7% /disk2 #fsck /dev/hda1 또는 fsck /dev/sda3 fsck 1.37 (21-Mar-2005) e2fsck 1.37 (21-Mar-2005) /dev/hda1 is mounted. WARNING!!! Running e2fsck on a mounted filesystem may cause SEVERE filesystem damage. Do you really want to continue (y/n)? no ---> 마운트된 파티션을 체크하면 손상을 줄 수 있으므로 n 을 입력한다. check aborted. # #umount /disk2 #df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 5.7G 2.8G 2.7G 52% / /dev/shm 125M 0 125M 0% /dev/shm /dev/sda3 1.6G 90M 1.5G 6% /home # #fsck.ext3 /dev/hda1 e2fsck 1.37 (21-Mar-2005) /dev/hda1: clean, 12/24576 files, 8774/98248 blocks # ---> 파일시스템(파티션)이 문제가 없는 상태(clean) (fsck 보다는 fsck.ext3 를 사용하는 것을 권장) -dumpe2fs : 파티션 논리적인 구조를 볼 수 있는 명령어- #dumpe2fs /dev/hda1 dumpe2fs 1.37 (21-Mar-2005) Filesystem volume name: Last mounted on: Filesystem UUID: 07c1a627-e65e-4f59-a49c-ee5bb93bae75 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal resize_inode filetype sparse_super Default mount options: (none) Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 24576 Block count: 98248 Reserved block count: 4912 Free blocks: 89474 Free inodes: 24564 First block: 1 Block size: 1024 Fragment size: 1024 Reserved GDT blocks: 256 Blocks per group: 8192 Fragments per group: 8192 Inodes per group: 2048 Inode blocks per group: 256 Filesystem created: Thu Aug 14 16:17:53 2008 Last mount time: Mon Aug 18 13:56:00 2008 Last write time: Mon Aug 18 14:19:25 2008 Mount count: 3 Maximum mount count: 21 Last checked: Thu Aug 14 16:17:53 2008 Check interval: 15552000 (6 months) Next check after: Tue Feb 10 16:17:53 2009 Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 128 Journal inode: 8 Default directory hash: tea Directory Hash Seed: 901f8482-3945-4c3f-9e5c-cb282816a591 Journal backup: inode blocks Group 0: (Blocks 1-8192) Primary superblock at 1, Group descriptors at 2-2 Reserved GDT blocks at 3-258 Block bitmap at 259 (+258), Inode bitmap at 260 (+259) Inode table at 261-516 (+260) 3547 free blocks, 2036 free inodes, 2 directories Free blocks: 4646-8192 Free inodes: 13-2048 Group 1: (Blocks 8193-16384) Backup superblock at 8193, Group descriptors at 8194-8194 Reserved GDT blocks at 8195-8450 Block bitmap at 8451 (+258), Inode bitmap at 8452 (+259) Inode table at 8453-8708 (+260) 7676 free blocks, 2048 free inodes, 0 directories Free blocks: 8709-16384 Free inodes: 2049-4096
dd - convert and copy a file The default ibs= and obs= sizes are specified as 512 bytes (dd 는 백업 명령어 중의 하나) if : input file /dev/zero : special file(지우개에 해당) of : output file count : 횟수 -dd 형식- dd 입력장치 출력장치 옵션 ---> 입력장치에서 일정 크기만큼(디폴트는 1블록,512bytes) 데이타를 읽은 후 출력장치에 그대로 써준다. #dd if=/dev/zero of=/dev/hda1 count=32 32+0 records in 32+0 records out count 옵션을 주지 않으면 파티션이 모두 삭제 된다. (dd 명령은 마운트 해제후 사용한다.) if : 입력 of : 출력 ---> /dev/zero 에서 읽은 후 /dev/hda1 에 쓰기 작업을 32번 반복하라는 의미 (즉, /dev/hda1 의 앞쪽 파티션 정보가 삭제된다.) #mount /dev/hda1 /disk2 mount: you must specify the filesystem type # ---> dd 명령으로 인해 파티션이 손상되서 마운트되지 않는다. #mount -t ext3 /dev/hda1 /disk2 mount: wrong fs type, bad option, bad superblock on /dev/hda1, or too many mounted file systems # 수퍼블록(super block) ext2 또는 ext3 파일 시스템에서 사용되는 주요 설정 정보들이 기록되어 있는 영역, 수퍼블록이 깨지면 마운트가 안되기 때문에 파티션 내부에 일정 간격(8192)으로 백업수퍼블록이 존재한다. #fsck.ext3 /dev/hda1 fsck.ext3 파일시스템 체크 및 수리 명령어 e2fsck 1.37 (21-Mar-2005) Couldn't find ext2 superblock, trying backup blocks... Resize inode not valid. Recreate? yes (질문이 나오면 y 를 입력) /dev/hda1 was not cleanly unmounted, check forced. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Free inodes count wrong for group #0 (2037, counted=2036). Fix? yes Free inodes count wrong (24565, counted=24564). Fix? yes /dev/hda1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/hda1: 12/24576 files (0.0% non-contiguous), 8774/98248 blocks # #mount /dev/hda1 /disk2 #cd /disk2 #ls lost+found test.txt #cat test.txt appple orange mango # #man fsck -y For some filesystem-specific checkers, the -y option will cause the fs-specific fsck to always attempt to fix any detected filesystem corruption automatically. #man mount defaults 다음과 같은 기본 옵션을 사용하게 한다: rw, suid, dev, exec, auto, nouser, and async. remount 이미 마운트된 화일 시스템을 다시 마운트한다. <디스크 쿼타(Quota)> 사용자별로 하드디스크 사용량을 제한하는 기능 ---> 쿼타를 지정하지 않으면 일반계정이 파티션의 남은 용량을 다 사용할 수도 있기 때문에 실제 서버에서는 하드디스크 사용량 제한 설정을 해 준다. 1. /etc/fstab 파일을 열고 쿼타를 지정할 파티션 라인의 defaults 다음에 ,usrquota 추가 --->defaults 와 usrquota 사이에 공백이 있으면 안 됨 --->/home 파티션이 없는 경우 / 파티션에 지정하기 usrquota : 사용자별 쿼타 grpquota : 그룹별 쿼타 (그룹별 쿼타를 지정하려면 grpquota 를 사용) ////////////////////////////////////////////////////// #vi /etc/fstab # This file is edited by fstab-sync - see 'man fstab-sync' for details LABEL=/ / ext3 defaults 1 1 /dev/devpts /dev/pts devpts gid=5,mode=620 0 0 /dev/shm /dev/shm tmpfs defaults 0 0 LABEL=/home /home ext3 defaults,usrquota 1 2 /dev/proc /proc proc defaults 0 0 /dev/sys /sys sysfs defaults 0 0 LABEL=SWAP-sda2 swap swap defaults 0 0 /dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0 /dev/hdc /media/cdrom auto pamconsole,exec,noauto,managed 0 0 ////////////////////////////////////////////////////// 2. 파티션을 리마운트 하거나 리부팅 하기 mount mount -o remount /home mount 로 확인 #mount (현재 마운트되어 있는 정보 출력) /dev/sda1 on / type ext3 (rw) /dev/proc on /proc type proc (rw) /dev/sys on /sys type sysfs (rw) /dev/devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/shm on /dev/shm type tmpfs (rw) /dev/sda3 on /home type ext3 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) automount(pid1602) on /misc type autofs (rw,fd=4,pgrp=1602,minproto=2,maxproto=4) automount(pid1649) on /net type autofs (rw,fd=4,pgrp=1649,minproto=2,maxproto=4) /dev/hdc on /media/cdrom type iso9660 (ro,nosuid,nodev,_netdev) # #mount -o remount /home (리부팅하지 않고 파티션을 재마운트하기) #mount /dev/sda1 on / type ext3 (rw) /dev/proc on /proc type proc (rw) /dev/sys on /sys type sysfs (rw) /dev/devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/shm on /dev/shm type tmpfs (rw) /dev/sda3 on /home type ext3 (rw,usrquota) ---> 확인 none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) automount(pid1602) on /misc type autofs (rw,fd=4,pgrp=1602,minproto=2,maxproto=4) automount(pid1649) on /net type autofs (rw,fd=4,pgrp=1649,minproto=2,maxproto=4) /dev/hdc on /media/cdrom type iso9660 (ro,nosuid,nodev,_netdev) # 3. 쿼타 설정파일 생성하기 cd /home touch aquota.user chmod 600 aquota.user quotacheck /home quotacheck : 사용자들이 파티션을 얼마만큼 사용하고 있는지 체크하는 명령어, 루트 파티션을 체크할 때는 -m 옵션을 지정해야 한다. (quotacheck -m /) 그룹별 쿼타는 aquota.group 로 파일 생성 man quotacheck quotacheck expects each filesystem to be checked to have quota files named [a]quota.user and [a]quota.group located at the root of the associated filesystem. -m Don’t try to remount filesystem read-only. aquota.user 사용자별로 디스크 사용량을 저장하고 있는 파일 #cd /home #touch aquota.user (쿼타를 적용할 파티션 디렉토리에 만들어야 함) #chmod 600 aquota.user #quotacheck /home #quotacheck /home ---> 다시 실행하면 warning 이 출력되지 않는다. 4. 사용자별 쿼타 설정 및 쿼타 On 시키기 edquota : 사용자별 쿼타 설정 명령어 quotaon : 쿼타를 on 시키는 명령어 quotaoff : 쿼타를 off 시키는 명령어 edquota -u apple 단위는 Kbyte(킬로바이트) 1024byte=1Kbyte 1024Kbyte=1Mbyte 5M : 5120(1024 * 5) 50M : 51200 quotaon /home (쿼타 활성화) edquota -p apple apple2 apple3 ---> apple 계정의 쿼타 설정을 apple2,apple3 에게 복사하는 명령 #edquota -u apple (apple 계정에 대한 쿼타 편집 명령) Disk quotas for user apple (uid 500): Filesystem blocks soft hard inodes soft hard /dev/sda3 28 0 0 7 0 0 blocks : 디스크 용량 제한 항목 inodes : 파일갯수 제한 항목 soft : 경고메시지 출력 용량 hard : 사용자가 이용할 수 있는 Maximum 용량 (soft 를 50M, hard 를 100M 로 주면 50메가를 넘어서면 경고메시지가 출력되지만 유예기간 동안에는 100메가 용량까지 사용할 수 있다.) 사이즈 0 은 쿼타 제한이 없다는 의미 blocks 의 28과 inodes 의 7은 계정추가시 자동으로 복사된 파일의 용량과 수가 출력된 것으로 관리자가 수정하면 안 된다. -apple 계정 디스크 사용량 5M 로 제한- edquota -u apple 이 실행된 화면에서 아래와 같이 설정 Disk quotas for user apple (uid 500): Filesystem blocks soft hard 28 0 5120 soft, hard 가 0 일 때는 제한없이 사용할 수 있다는 의미 blocks 의 hard 부분에 5120 을 입력하고 저장후 종료하기(esc :wq) #quotaon -v /home #quota (자신의 디스크 사용량 확인하는 명령) Disk quotas for user root (uid 0): none # #quota apple (apple 계정의 쿼타량 확인) Disk quotas for user apple (uid 500): Filesystem blocks quota limit grace files quota limit grace /dev/sda3 28 0 5120 7 0 0 # #repquota -av (report quota : 사용자별로 디스크 사용량 출력 명령) -av 모든계정에 대해 자세히 출력 /home 에 aquota.user 또는 quota.user 파일이 없다면 출력되지 않는다. *** Report for user quotas on device /dev/sda3 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ------------------------------------------------------ root -- 35332 0 0 7 0 0 apple -- 28 0 5120 7 0 0 banana -- 28 0 0 7 0 0 candy -- 24 0 0 6 0 0 cola -- 24 0 0 6 0 0 Statistics: Total blocks: 8 Data blocks: 1 Entries: 8 Used average: 8.000000 #adduser apple4 #adduser apple5 #quotaoff -v /home /dev/sda3 [/home]: user quotas turned off #quotaoff -v /home quotaoff: quotactl on /dev/sda3 [/home]: 그런 프로세스가 없음 # ---> 쿼타를 이미 off 했으므로 위와 같이 출력된다. #quotacheck /home #quotaon -v /home #quotaon -v /home quotaon: using /home/aquota.user on /dev/sda3 [/home]: 장치나 자원이 동작 중 # ---> 쿼타가 활성화 중일 때는 위와 같이 출력됨 #repquota -av
728x90

+ Recent posts