[AIX 운영 체제와 장치 관리 41] 디스크 넘침과 마운트 — 폭주 프로세스, 공간 회수, 루트·/var 넘침 해결, 마운트 지점, 자동 마운트, 디스크 없는 워크스테이션 마운트 보안
https://archive.horanglab.com/posts/aix-osdev-41
핵심 정리
- 디스크 넘침은 대개 불필요한 파일을 쏟아내는 폭주 프로세스 때문입니다.
ps -ef,ps -u로 찾아kill -9로 끝내며, 지운 파일도 열고 있는 프로세스가 끝날 때까지 블록이 풀리지 않으므로 다른 명령 출력으로 덮어써(잘라) 회수할 수 있습니다. - 루트(
/)가 차면 failedlogin,/dev의 오타 장치 파일(예: rmto),/audit, 1MB가 넘는 파일을 확인하고, 지우기 전에 fuser로 사용 중인지 봅니다. /var가 차면 큰 파일,/var/tmp, wtmp(fwtmp로 편집), errlog(errstop 뒤 지우고 errdemon, cp /dev/null 금지), trcfile, vmcore, 스풀, 계정 레코드, preserve, sulog, snmpd.log를 확인합니다.- 마운트한 파일 시스템 루트의 권한이 마운트 지점보다 우선하지만
..을 위해 덮인 디렉터리에도 검색 권한(최소 111)이 있어야 pwd 등이 실패하지 않습니다./etc/filesystems의mount = automatic은 부팅 과정이,mount = true는/etc/rc의 mount all이 마운트합니다. - 디스크 없는 클라이언트용으로 내보낸 파일 시스템은 서버 사용자가 클라이언트의 setuid 프로그램이나 장치 특수 파일을 쓰지 못하도록
nosuid,nodev로 마운트합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 6.1 (5.3판과 거의 같음) |
| 원문 | Operating system and device management — 5.3판 101115쪽 일부, 6.1판 435444쪽 |
| 관련 명령어 | ps -ef, kill -9, find -xdev -size, fuser, fwtmp, errstop, errdemon, errclear, stopsrc -s qdaemon, touch, mount, ln -s |
| 관련 파일 | /etc/security/failedlogin, /var/adm/wtmp, /var/adm/ras/errlog, /var/adm/sulog, /var/tmp/snmpd.log, /etc/filesystems |
디스크 넘침은 너무 많은 파일이 할당된 공간을 채울 때 생깁니다. 불필요한 파일을 많이 만드는 폭주 프로세스가 원인일 수 있습니다.
다음 절차로 문제를 바로잡을 수 있습니다.
참고: 자기 것이 아닌 프로세스를 없애려면 root 사용자 권한이 있어야 합니다.
관련 개념
- 파일 시스템을 자동으로 정리하는 명령 — skulker 명령으로 원치 않는 파일을 지워 파일 시스템을 정리합니다.
문제 프로세스 찾기
다음 절차로 문제 프로세스를 가려냅니다.
- 프로세스 상태를 확인하고 문제를 일으킬 만한 프로세스를 찾으려면 다음을 입력합니다.
ps -ef | pg
ps 명령은 프로세스 상태를 보여 줍니다. -e 플래그는 (커널 프로세스를 뺀) 모든 프로세스 정보를 쓰고, -f 플래그는 프로세스를 만들 때의 명령 이름과 매개변수를 포함한 전체 목록을 만듭니다. pg 명령은 출력을 한 페이지씩 끊어 정보가 화면에서 너무 빨리 밀려나지 않게 합니다. CPU 시간 같은 시스템 자원을 지나치게 쓰는 시스템이나 사용자 프로세스를 확인합니다. sendmail, routed, lpd 같은 시스템 프로세스가 가장 폭주하기 쉬운 것으로 보입니다.
2. 예상보다 CPU를 많이 쓰는 사용자 프로세스를 확인하려면 다음을 입력합니다.
ps -u
- 각 문제 프로세스의 프로세스 ID(PID)를 적어 둡니다.
프로세스 끝내기
문제 프로세스를 끝낼 수 있습니다.
다음 절차로 문제 프로세스를 끝냅니다.
- 다음을 입력해 문제를 일으키는 프로세스를 끝냅니다.
kill -9 PID
PID는 문제 프로세스의 ID입니다. 2. 다음을 입력해 프로세스가 만든 파일을 지웁니다.
rm file1 file2 file3
file1 file2 file3은 프로세스 관련 파일 이름입니다.
프로세스를 끝내지 않고 파일 공간 회수
프로세스를 끝내지 않고 활성 파일에 할당된 블록을 회수하려면 다른 명령의 출력을 그 파일로 보냅니다. 데이터 방향 바꾸기가 파일을 잘라 블록을 회수합니다.
활성 파일을 파일 시스템에서 지워도, 프로세스가 파일을 닫거나 파일을 연 프로세스가 끝나 마지막 열린 참조가 사라질 때까지 파일에 할당된 블록은 할당된 채로 남습니다. 폭주 프로세스가 파일에 쓰고 있는데 파일을 지우면 프로세스가 끝날 때까지 파일에 할당된 블록이 풀리지 않습니다.
예:
$ ls -l
total 1248
-rwxrwxr-x 1 web staff 1274770 Jul 20 11:19 datafile
$ date > datafile
$ ls -l
total 4
-rwxrwxr-x 1 web staff 29 Jul 20 11:20 datafile
date 명령의 출력이 datafile 파일의 이전 내용을 대체했습니다. 잘린 파일에 보고된 블록은 1248에서 4로 크기가 줄었음을 보여 줍니다. 폭주 프로세스가 새로 잘린 이 파일에 계속 정보를 덧붙이면 다음 ls 명령은 다음 결과를 냅니다.
$ ls -l
total 8
-rxrwxr-x 1 web staff 1278866 Jul 20 11:21 datefile
datafile 파일 크기는 폭주 프로세스의 덧붙이기를 반영하지만 할당된 블록 수는 적습니다. 이제 datafile 파일에는 구멍이 있습니다. 파일 구멍은 디스크 블록이 할당되지 않은 파일 영역입니다.
/ (루트) 넘침
루트 파일 시스템(/)이 가득 찼을 때 다음을 확인합니다.
- 다음 명령으로
/etc/security/failedlogin파일 내용을 읽습니다.
who /etc/security/failedlogin
TTY가 너무 빨리 다시 만들어지는 상황이 실패한 로그인 항목을 만들 수 있습니다. 출력을 읽거나 저장한 뒤 파일을 비우려면 다음 명령을 실행합니다.
cp /dev/null /etc/security/failedlogin
/dev디렉터리에서 잘못 입력한 장치 이름을 확인합니다.rmt0대신rmto처럼 장치 이름을 잘못 입력하면/dev에rmto라는 파일이 만들어집니다. 명령은 보통 루트 파일 시스템 전체를 채울 때까지 진행한 뒤 실패합니다./dev는 루트(/) 파일 시스템의 일부입니다. 장치가 아닌(주·부 번호가 없는) 항목을 찾습니다. 이 상황을 확인하려면 다음 명령을 씁니다.
cd /dev
ls -l | pg
일반 파일이라면 파일 크기를 나타낼 자리에 장치 파일은 쉼표로 구분한 숫자 둘이 있습니다. 예:
crw-rw-rw- 1 root system 12,0 Oct 25 10:19 rmt0
다음 예처럼 파일 이름이나 크기 자리가 잘못된 장치를 나타내면 해당 파일을 지웁니다.
crw-rw-rw- 1 root system 9375473 Oct 25 10:19 rmto
참고
/dev디렉터리의 유효한 장치 이름은 지우지 않습니다. 잘못된 장치의 한 지표는 연결된 파일 크기가 500바이트보다 큰 것입니다.- 시스템 감사가 실행 중이면 기본
/audit디렉터리가 빨리 찰 수 있어 살펴봐야 합니다. - find 명령으로 지울 수 있는 아주 큰 파일을 확인합니다. 예를 들어 루트(
/) 디렉터리에서 1MB보다 큰 파일을 모두 찾으려면 다음 명령을 씁니다.
find / -xdev -size +2048 -ls |sort -r -n +6
이 명령은 1MB보다 큰 파일을 모두 찾아 가장 큰 것부터 역순으로 정렬합니다. find 명령의 -newer 같은 다른 플래그도 이 검색에 쓸모 있을 수 있습니다. 자세한 내용은 find 명령 설명을 봅니다.
참고: 루트 디렉터리를 확인할 때 /dev 디렉터리 장치의 주·부 번호가 실제 파일과 파일 크기 사이에 섞여 나옵니다. 쉼표로 구분한 주·부 번호는 무시해도 됩니다. 파일을 지우기 전에 다음 명령으로 사용자 프로세스가 지금 그 파일을 쓰고 있지 않은지 확인합니다.
fuser filename
filename은 의심되는 큰 파일 이름입니다. 지울 때 파일이 열려 있으면 디렉터리 목록에서만 지워집니다. 그 파일에 할당된 블록은 파일을 열고 있는 프로세스를 죽일 때까지 풀리지 않습니다.
/var 파일 시스템 넘침 해결
/var 파일 시스템이 가득 찼을 때 다음을 확인합니다.
- find 명령으로
/var디렉터리의 큰 파일을 찾을 수 있습니다. 예:
find /var -xdev -size +2048 -ls| sort -r +6
자세한 내용은 find 명령 설명을 봅니다.
/var/tmp에 낡았거나 남은 파일이 있는지 확인합니다.- 모든 로그인, rlogin, telnet 세션을 기록하는
/var/adm/wtmp파일 크기를 확인합니다. 시스템 계정이 실행 중이 아니면 이 로그는 끝없이 커집니다. 시스템 계정은 밤마다 이 파일을 비웁니다./var/adm/wtmp파일은 비우거나 편집해 오래되고 원치 않는 정보를 지울 수 있습니다. 비우려면 다음 명령을 씁니다.
cp /dev/null /var/adm/wtmp
/var/adm/wtmp 파일을 편집하려면 먼저 다음 명령으로 파일을 임시로 복사합니다.
/usr/sbin/acct/fwtmp < /var/adm/wtmp >/tmp/out
/tmp/out 파일을 편집해 원치 않는 항목을 지운 뒤 다음 명령으로 원래 파일을 대체합니다.
/usr/sbin/acct/fwtmp -ic < /tmp/out > /var/adm/wtmp
다음 절차로
/var/adm/ras디렉터리의 오류 로그를 비웁니다. 오류 로그는 직접 비우지 않으면 비워지지 않습니다.참고: 오류 로그를 비울 때
cp /dev/null명령을 절대 쓰지 않습니다. 길이가 0인errlog파일은 운영 체제의 오류 기록 기능을 끄며 백업에서 바꿔 넣어야 합니다.- 다음 명령으로 오류 데몬을 멈춥니다.
/usr/lib/errstop
- 다음 명령 가운데 하나로 오류 로그 파일을 지우거나 다른 파일 시스템으로 옮깁니다.
rm /var/adm/ras/errlog
또는
mv /var/adm/ras/errlog filename
filename은 옮긴 errlog 파일 이름입니다.
참고: 오류 로그 파일을 지우면 과거 오류 데이터가 지워집니다.
- 다음 명령으로 오류 데몬을 다시 시작합니다.
/usr/lib/errdemon
참고: cron에서 다음 항목을 실행해 errlog를 제한하는 것을 고려합니다.
0 11 * * * /usr/bin/errclear -d S,O 30
0 12 * * * /usr/bin/errclear -d H 90
- 이 디렉터리의
trcfile파일이 큰지 확인합니다. 크고 지금 추적을 실행하고 있지 않으면 다음 명령으로 지울 수 있습니다.
rm /var/adm/ras/trcfile
- 덤프 장치가 hd6(기본값)이면
/var/adm/ras디렉터리에vmcore*파일이 여럿 있을 수 있습니다. 파일 날짜가 오래됐거나 남길 필요가 없으면 rm 명령으로 지울 수 있습니다. - 큐 하위 시스템 파일이 든
/var/spool디렉터리를 확인합니다. 다음 명령으로 큐 하위 시스템을 비웁니다.
stopsrc -s qdaemon
rm /var/spool/lpd/qdir/*
rm /var/spool/lpd/stat/*
rm /var/spool/qdaemon/*
startsrc -s qdaemon
계정 레코드가 든
/var/adm/acct디렉터리를 확인합니다. 계정이 실행 중이면 이 디렉터리에 큰 파일이 여럿 있을 수 있습니다.끝난 vi 세션이 남은
/var/preserve디렉터리를 확인합니다. 대개 이 파일은 지워도 안전합니다. 사용자가 세션을 되살리고 싶어 하면vi -r명령으로 되살릴 수 있는 모든 세션을 나열할 수 있습니다. 특정 세션을 되살리려면vi -r filename을 씁니다.su 명령 사용 시도 횟수와 성공 여부를 기록하는
/var/adm/sulog파일을 고칩니다. 일반 파일이므로 편집기로 보고 고칠 수 있습니다. 지우면 다음 su 명령 시도 때 다시 만들어집니다. snmpd 데몬의 이벤트를 기록하는/var/tmp/snmpd.log도 고칩니다. 지우면 snmpd 데몬이 다시 만듭니다.참고:
/var/tmp/snmpd.log파일이 끝없이 커지지 않도록 크기를 제한할 수 있습니다./etc/snmpd.conf파일의 크기 관련 항목에서 숫자(바이트)를 바꿉니다.
관련 개념
- 시스템 계정
다른 파일 시스템 고치기와 일반 검색 기법
find 명령에 -size 플래그를 써서 큰 파일을 찾거나, 파일 시스템이 최근에 넘쳤으면 -newer 플래그로 최근에 바뀐 파일을 찾습니다.
-newer 플래그가 비교할 파일을 만들려면 다음 touch 명령을 씁니다.
touch mmddhhmm filename
mm은 월, dd는 일, hh는 24시간제 시, mm은 분, filename은 touch 명령으로 만들 파일 이름입니다.
touch로 파일을 만든 뒤 다음 명령으로 더 새로운 큰 파일을 찾을 수 있습니다.
find / filesystem_name -xdev -newer touch_filename -ls
다음 예처럼 find 명령으로 지난 24시간 안에 바뀐 파일도 찾을 수 있습니다.
find / filesystem_name -xdev -mtime 0 -ls
영어 원문
Disk overflows
A disk overflow occurs when too many files fill up the allotted space. This can be caused by a runaway process that creates many unnecessary files.
You can use the following procedures to correct the problem:
Note: You must have root user authority to remove processes other than your own.
Related concepts
Command for cleaning up file systems automatically Use the skulker command to clean up file systems by removing unwanted files.
Identifying problem processes
Use this procedure to isolate problem processes.
- To check the process status and identify processes that might be causing the problem, type:
ps -ef | pg
The ps command shows the process status. The -e flag writes information about all processes (except kernel processes), and the -f flag generates a full listing of processes including what the command name and parameters were when the process was created. The pg command limits output to a single page at a time, so information does not scroll too quickly off the screen. Check for system or user processes that are using excessive amounts of a system resource, such as CPU time. System processes such as sendmail, routed, and lpd seem to be the system processes most prone to becoming runaways.
- To check for user processes that use more CPU than expected, type:
ps -u
- Note the process ID (PID) of each problem process.
Terminating a process
You can terminate problem processes.
Use the following procedure to terminate a problem process:
- Terminate the process that is causing the problem by typing:
kill -9 PID
Where PID is the ID of the problem process.
- Remove the files the process has been making by typing:
rm file1 file2 file3
Where file1 file2 file3 represents names of process-related files.
Reclamation of file space without terminating a process
To reclaim the blocks allocated to an active file without terminating the process, redirect the output of another command to the file. The data redirection truncates the file and reclaims the blocks of memory.
When the active file is removed from the file system, the blocks allocated to the file remain allocated until the last open reference is removed, either as a result of the process closing the file or because of the termination of the processes that have the file open. If a runaway process is writing to a file and the file is removed, the blocks allocated to the file are not freed until the process terminates.
For example:
$ ls -l
total 1248
-rwxrwxr-x 1 web staff 1274770 Jul 20 11:19 datafile
$ date > datafile
$ ls -l
total 4
-rwxrwxr-x 1 web staff 29 Jul 20 11:20 datafile
The output of the date command replaced the previous contents of the datafile file. The blocks reported for the truncated file reflect the size difference from 1248> to 4. If the runaway process continues to append information to this newly truncated file, the next ls command produces the following results:
$ ls -l
total 8
-rxrwxr-x 1 web staff 1278866 Jul 20 11:21 datefile
The size of the datafile file reflects the append done by the runaway process, but the number of blocks allocated is small. The datafile file now has a hole in it. File holes are regions of the file that do not have disk blocks allocated to them.
/ (root) overflow
Check the following when the root file system (/) has become full.
- Use the following command to read the contents of the
/etc/security/failedloginfile:
who /etc/security/failedlogin
The condition of TTYs recreating too rapidly can create failed login entries. To clear the file after reading or saving the output, execute the following command:
cp /dev/null /etc/security/failedlogin
- Check the
/devdirectory for a device name that is typed incorrectly. If a device name is typed incorrectly, such asrmtoinstead ofrmt0, a file will be created in/devcalledrmto. The command will normally proceed until the entire root file system is filled before failing./devis part of the root (/) file system. Look for entries that are not devices (that do not have a major or minor number). To check for this situation, use the following command:
cd /dev
ls -l | pg
In the same location that would indicate a file size for an ordinary file, a device file has two numbers separated by a comma. For example:
crw-rw-rw- 1 root system 12,0 Oct 25 10:19 rmt0
If the file name or size location indicates an invalid device, as shown in the following example, remove the associated file:
crw-rw-rw- 1 root system 9375473 Oct 25 10:19 rmto
Note
– Do not remove valid device names in the /dev directory. One indicator of an invalid device is an associated file size that is larger than 500 bytes. – If system auditing is running, the default /audit directory can rapidly fill up and require attention.
- Check for very large files that might be removed using the find command. For example, to find all files in the root (
/) directory larger than 1 MB, use the following command:
find / -xdev -size +2048 -ls |sort -r -n +6
This command finds all files greater than 1 MB and sorts them in reverse order with the largest files first. Other flags for the find command, such as -newer, might be useful in this search. For detailed information, see the command description for the find command.
Note: When checking the root directory, major and minor numbers for devices in the /dev directory will be interspersed with real files and file sizes. Major and minor numbers, which are separated by a comma, can be ignored. Before removing any files, use the following command to ensure a file is not currently in use by a user process:
fuser filename
Where filename is the name of the suspect large file. If a file is open at the time of removal, it is only removed from the directory listing. The blocks allocated to that file are not freed until the process holding the file open is killed.
Resolving overflows in the /var file system
Check the following when the /var file system has become full.
- You can use the find command to look for large files in the
/vardirectory. For example:
find /var -xdev -size +2048 -ls| sort -r +6
For detailed information, see the command description for the find command.
Check for obsolete or leftover files in
/var/tmp.Check the size of the
/var/adm/wtmpfile, which logs all logins, rlogins and telnet sessions. The log will grow indefinitely unless system accounting is running. System accounting clears it out nightly. The/var/adm/wtmpfile can be cleared out or edited to remove old and unwanted information. To clear it, use the following command:
cp /dev/null /var/adm/wtmp
To edit the /var/adm/wtmp file, first copy the file temporarily with the following command:
/usr/sbin/acct/fwtmp < /var/adm/wtmp >/tmp/out
Edit the /tmp/out file to remove unwanted entries then replace the original file with the following command:
/usr/sbin/acct/fwtmp -ic < /tmp/out > /var/adm/wtmp
- Clear the error log in the
/var/adm/rasdirectory using the following procedure. The error log is never cleared unless it is manually cleared.
Note: Never use the cp /dev/null command to clear the error log. A zero-length errlog file disables the error logging functions of the operating system and must be replaced from a backup.
- Stop the error daemon using the following command:
/usr/lib/errstop
- Remove or move to a different filesystem the error log file by using one of the following commands:
rm /var/adm/ras/errlog
or
mv /var/adm/ras/errlog filename
Where filename is the name of the moved errlog file.
Note: The historical error data is deleted if you remove the error log file.
- Restart the error daemon using the following command:
/usr/lib/errdemon
Note: Consider limiting the errlog by running the following entries in cron:
0 11 * * * /usr/bin/errclear -d S,O 30
0 12 * * * /usr/bin/errclear -d H 90
- Check whether the
trcfilefile in this directory is large. If it is large and a trace is not currently being run, you can remove the file using the following command:
rm /var/adm/ras/trcfile
If your dump device is set to hd6 (which is the default), there might be a number of
vmcore*files in the/var/adm/rasdirectory. If their file dates are old or you do not want to retain them, you can remove them with the rm command.Check the
/var/spooldirectory, which contains the queueing subsystem files. Clear the queueing subsystem using the following commands:
stopsrc -s qdaemon
rm /var/spool/lpd/qdir/*
rm /var/spool/lpd/stat/*
rm /var/spool/qdaemon/*
startsrc -s qdaemon
Check the
/var/adm/acctdirectory, which contains accounting records. If accounting is running, this directory may contain several large files.Check the
/var/preservedirectory for terminated vi sessions. Generally, it is safe to remove these files. If a user wants to recover a session, you can use the vi -r command to list all recoverable sessions. To recover a specific session, usevi -r filename.Modify the
/var/adm/sulogfile, which records the number of attempted uses of the su command and whether each was successful. This is a flat file and can be viewed and modified with a favorite editor.
If it is removed, it will be recreated by the next attempted su command. Modify the /var/tmp/snmpd.log, which records events from the snmpd daemon. If the file is removed it will be recreated by the snmpd daemon.
Note: The size of the /var/tmp/snmpd.log file can be limited so that it does not grow indefinitely. Edit the /etc/snmpd.conf file to change the number (in bytes) in the appropriate section for size.
Related concepts
System accounting The system accounting utility allows you to collect and report on individual and group use of various system resources.
Fix other file systems and general search techniques
Use the find command with the -size flag to locate large files or, if the file system recently overflowed, use the -newer flag to find recently modified files.
To produce a file for the -newer flag to find against, use the following touch command:
touch mmddhhmm filename
Where mm is the month, dd is the date, hh is the hour in 24–hour format, mm is the minute, and filename is the name of the file you are creating with the touch command.
After you have created the touched file, you can use the following command to find newer large files:
find / filesystem_name -xdev -newer touch_filename -ls
You can also use the find command to locate files that have been changed in the last 24 hours, as shown in the following example:
find / filesystem_name -xdev -mtime 0 -ls
마운트
마운트는 파일 시스템, 파일, 디렉터리, 장치, 특수 파일을 특정 위치에서 쓸 수 있게 합니다. 파일 시스템에 접근하게 하는 유일한 방법입니다.
mount 명령은 운영 체제에 지정한 디렉터리에 파일 시스템을 붙이라고 지시합니다.
마운트하려는 파일이나 디렉터리에 접근할 수 있고 마운트 지점에 쓰기 권한이 있으면 파일이나 디렉터리를 마운트할 수 있습니다. system 그룹 구성원은 장치 마운트(장치나 파일 시스템을 디렉터리 위에 마운트)와 /etc/filesystems 파일에 설명한 마운트도 할 수 있습니다. root 사용자 권한으로 동작하는 사용자는 명령행에 장치와 디렉터리를 모두 지정해 파일 시스템을 마음대로 마운트할 수 있습니다. /etc/filesystems 파일은 시스템 초기화 때 자동으로 할 마운트를 정의하는 데 씁니다. mount 명령은 시스템 시작 뒤 마운트하는 데 씁니다.
마운트 지점
마운트 지점은 새 파일 시스템, 디렉터리, 파일에 접근하게 되는 디렉터리나 파일입니다. 파일 시스템이나 디렉터리를 마운트하려면 마운트 지점이 디렉터리여야 하고, 파일을 마운트하려면 파일이어야 합니다.
보통 파일 시스템, 디렉터리, 파일은 빈 마운트 지점 위에 마운트하지만 반드시 그럴 필요는 없습니다. 마운트 지점인 파일이나 디렉터리에 데이터가 있으면 다른 파일이나 디렉터리가 그 위에 마운트된 동안에는 그 데이터에 접근할 수 없습니다. 사실상 마운트한 파일이나 디렉터리가 원래 내용을 덮습니다. 그 위의 마운트를 풀면 원래 디렉터리나 파일에 다시 접근할 수 있습니다.
파일 시스템을 디렉터리 위에 마운트하면 마운트한 파일 시스템 루트 디렉터리의 권한이 마운트 지점 권한보다 우선합니다. 한 가지 예외는 덮인 디렉터리의 ..(점 둘) 부모 디렉터리 항목입니다. 운영 체제가 새 파일 시스템에 접근하려면 마운트 지점의 부모 디렉터리 정보를 쓸 수 있어야 합니다.
예를 들어 현재 작업 디렉터리가 /home/frank이면 cd .. 명령은 작업 디렉터리를 /home으로 바꿉니다. /home/frank 디렉터리가 마운트된 파일 시스템의 루트이면 cd .. 명령이 성공하려면 운영 체제가 /home/frank 디렉터리에서 부모 디렉터리 정보를 찾아야 합니다.
성공하려면 부모 디렉터리 정보가 필요한 명령은 사용자에게 덮인 디렉터리의 검색 권한이 있어야 합니다. 덮인 디렉터리가 검색 권한을 주지 않으면 예측할 수 없는 결과가 생길 수 있으며, 덮인 디렉터리 권한은 보이지 않으므로 더욱 그렇습니다. 흔한 문제는 pwd 명령 실패입니다. 덮인 디렉터리에 검색 권한이 없으면 pwd 명령은 다음 메시지를 돌려줍니다.
pwd: Permission denied
덮인 디렉터리 권한을 늘 적어도 111로 설정하면 이 문제를 피할 수 있습니다.
파일 시스템, 디렉터리, 파일 마운트
마운트에는 원격 마운트와 로컬 마운트 두 종류가 있습니다. 원격 마운트는 통신 회선으로 데이터를 보내는 원격 시스템에서 합니다. NFS(Network File System) 같은 원격 파일 시스템은 마운트하기 전에 파일을 내보내야 합니다. 로컬 마운트는 로컬 시스템에서 하는 마운트입니다.
각 파일 시스템은 서로 다른 장치(논리 볼륨)와 연결됩니다. 파일 시스템을 쓰려면 먼저 기존 디렉터리 구조(루트 파일 시스템이나 이미 연결된 다른 파일 시스템)에 연결해야 합니다. mount 명령이 이 연결을 합니다.
같은 파일 시스템, 디렉터리, 파일에 여러 경로로 접근할 수 있습니다. 예를 들어 데이터베이스 하나를 여러 사용자가 쓰면 같은 데이터베이스를 여러 번 마운트하는 것이 쓸모 있을 수 있습니다. 추적과 작업 구분을 위해 마운트마다 이름과 암호가 있어야 합니다. 같은 파일 시스템을 서로 다른 마운트 지점에 마운트해 이렇게 합니다. 예를 들어 /home/server/database를 /home/user1, /home/user2, /home/user3으로 지정한 마운트 지점에 마운트할 수 있습니다.
/home/server/database /home/user1
/home/server/database /home/user2
/home/server/database /home/user3
심볼릭 링크로 파일 시스템, 디렉터리, 파일을 여러 사용자에게 제공할 수 있습니다. 심볼릭 링크는 ln -s 명령으로 만듭니다. 여러 사용자를 중앙 파일에 링크하면 사용자가 파일에 접근할 때마다 파일의 모든 변경이 반영됩니다.
자동 마운트 제어
시스템 초기화 때 자동으로 마운트하도록 설정할 수 있습니다.
자동 마운트에는 두 종류가 있습니다. 첫째는 시스템을 부팅하고 실행하는 데 필요한 마운트입니다. 이 파일 시스템은 부팅 과정이 명시적으로 마운트합니다. /etc/filesystems 파일에서 이런 파일 시스템 스탠자는 mount = automatic입니다. 둘째는 사용자가 제어하는 자동 마운트입니다. 이 파일 시스템은 /etc/rc 스크립트가 mount all 명령을 내릴 때 마운트합니다. 사용자가 제어하는 자동 마운트 스탠자는 /etc/filesystems에서 mount = true입니다.
/etc/filesystems 파일이 자동 마운트를 제어하며, 마운트는 계층적으로 마운트 지점 하나씩 합니다. 특정 순서로 둘 수도 있고 순서를 바꾸고 재배열할 수도 있습니다. /etc/filesystems 파일에 관한 자세한 내용은 /etc/filesystems를 봅니다.
/etc/filesystems 파일은 마운트마다 하나씩 스탠자로 짜입니다. 스탠자는 해당 파일 시스템의 속성과 마운트 방법을 설명합니다. 시스템은 /etc/filesystems 파일에 나온 순서대로 파일 시스템을 마운트합니다. 다음은 /etc/filesystems 파일 안 스탠자의 예입니다.
/:
dev=/dev/hd4
vol="root"
mount=automatic
check=false
free=true
vfs=jfs
log=/dev/hd8
type-bootfs
/home:
dev=/dev/hd1
vfs=jfs
log=/dev/hd8
mount=true
check=true
vol="/home"
free=false
/usr:
/dev=/dev/hd2
vfs=jfs
log=/dev/hd8
mount=automatic
check=false
type=bootfs
vol="/usr"
free=false
/etc/filesystems 파일을 편집해 마운트 순서를 제어할 수 있습니다. 마운트가 실패해도 /etc/filesystems 파일에 정의한 이후 마운트는 계속됩니다. 예를 들어 /home 파일 시스템 마운트가 실패해도 /usr 파일 시스템 마운트는 계속돼 마운트됩니다. 마운트는 오타, 의존 관계, 시스템 문제 같은 이유로 실패할 수 있습니다.
디스크 없는 워크스테이션의 마운트 보안
디스크 없는 워크스테이션은 서버에서 /dev 디렉터리를 마운트하려면 원격 기계에서 장치 특수 파일을 만들고 접근할 수 있어야 합니다. 서버는 클라이언트용 장치 특수 파일과 서버용을 구분할 수 없으므로, 서버 사용자가 클라이언트 장치의 특수 파일로 서버의 물리 장치에 접근할 수 있습니다.
예를 들어 tty의 소유권은 그 tty를 쓰는 사용자로 자동 설정됩니다. 클라이언트와 서버의 사용자 ID가 같지 않으면 서버의 특권 없는 사용자가 서버의 다른 사용자가 쓰는 tty에 접근할 수 있습니다.
클라이언트에서 특권이 있는 사용자는 서버의 물리 장치와 맞는 장치 특수 파일을 만들어 접근에 특권이 필요 없게 할 수 있습니다. 그러면 그 사용자는 서버의 특권 없는 계정으로 새 장치 특수 파일을 써서 보통은 보호되는 장치에 접근할 수 있습니다.
비슷한 보안 문제가 클라이언트와 서버의 setuid와 setgid 프로그램에도 있습니다. 디스크 없는 클라이언트는 정상 운영을 위해 서버에서 setuid와 setgid 프로그램을 만들고 실행할 수 있어야 합니다. 이번에도 서버는 서버용 프로그램과 클라이언트용 프로그램을 구분할 수 없습니다.
또 서버와 클라이언트의 사용자 ID와 그룹 ID가 맞지 않을 수 있어, 서버 사용자가 자기에게 주지 않은 능력으로 프로그램을 실행할 수 있습니다.
문제는 setuid·setgid 프로그램과 장치 특수 파일이 그것을 만든 기계에서만 쓸 수 있어야 하기 때문에 생깁니다.
해결책은 이런 객체 사용을 제한하는 mount 명령의 보안 옵션을 쓰는 것입니다. 이 옵션은 /etc/filesystems 파일의 스탠자에도 쓸 수 있습니다.
mount 명령의 nosuid 옵션은 마운트한 파일 시스템으로 접근하는 setuid와 setgid 프로그램의 실행을 막습니다. 이 옵션은 특정 호스트에 마운트하지만 다른 호스트만 쓰는 파일 시스템(예: 디스크 없는 클라이언트용으로 내보낸 것)에 씁니다.
mount 명령의 nodev 옵션은 마운트한 파일 시스템으로 접근하는 장치 특수 파일로 장치를 여는 것을 막습니다. 이 옵션도 다른 호스트만 쓰려고 마운트하는 파일 시스템(예: 디스크 없는 클라이언트용으로 내보낸 것)에 씁니다.
일반적으로 서버 사용자는 /export 디렉터리에 접근할 수 없습니다.
/export/root 디렉터리 내보내기
/export/root 디렉터리는 읽기·쓰기 권한으로 내보내야 하며 서버의 root 사용자가 접근할 수 있어야 합니다. 그러나 이 디렉터리는 다음 mount 명령 옵션으로 마운트하고 싶을 수 있습니다.
- nosuid — 서버 사용자가 클라이언트의 setuid 프로그램을 실행하지 못하게 합니다.
- nodev — 사용자가 클라이언트의 장치 특수 파일로 서버 장치에 접근하지 못하게 합니다.
이 옵션으로 /export/root 디렉터리를 마운트하는 대신 서버에서 실행하는 사용자에게 /export/root 디렉터리 접근을 아예 주지 않을 수도 있습니다.
/export/exec 디렉터리 내보내기
/export/exec 디렉터리는 읽기 전용으로 내보내며 root 접근을 제공해야 합니다. 그러나 다음 mount 명령 옵션으로 마운트하고 싶을 수 있습니다.
- nosuid — 서버 사용자가 클라이언트의 setuid 프로그램을 실행하지 못하게 합니다. 서버의
/usr디렉터리를 내보낸다면 nosuid 옵션을 쓸 수 없습니다. - nodev — 사용자가 클라이언트의 장치 특수 파일로 서버 장치에 접근하지 못하게 합니다.
/export/share 디렉터리 내보내기
/export/share 디렉터리는 읽기 전용으로 내보내며 root 접근을 제공해야 합니다. 이 디렉터리에는 보통 데이터만(실행 파일이나 장치 없음) 있으므로 마운트 보안 옵션을 쓸 필요가 없습니다.
/export/home 디렉터리 내보내기
사용자 /home 디렉터리를 마운트하는 방법은 여러 가지입니다.
- 클라이언트
/home디렉터리 위에/export/home/Clienthostname디렉터리를 마운트할 수 있습니다. 이 경우 클라이언트는 읽기·쓰기 권한이 있고 root 사용자가 접근할 수 있습니다. 시스템 보안을 위해/export/home디렉터리를 다음 mount 명령 옵션으로 마운트합니다.- nosuid — 서버 사용자가 클라이언트의 setuid 프로그램을 실행하지 못하게 합니다.
- nodev — 사용자가 클라이언트의 장치 특수 파일로 서버 장치에 접근하지 못하게 합니다.
- 서버의
/home디렉터리를 클라이언트의/home디렉터리 위에 마운트할 수 있습니다. 이 경우/home디렉터리는 읽기·쓰기 권한으로, root 접근 없이 내보냅니다. 시스템 보안을 위해 서버와 클라이언트 모두에서/home디렉터리를 mount 명령의nosuid와nodev옵션으로 마운트합니다. - 아니면 사용자가 다른 기계에 로그인해도 홈 디렉터리에 접근할 수 있도록, 클라이언트에서 서버의 각
/home/UserName디렉터리를 클라이언트의/home/UserName디렉터리 위에 마운트할 수 있습니다. 이 경우 서버와 클라이언트의/home/UserName디렉터리를 모두 mount 명령의nosuid와nodev옵션으로 마운트합니다.
/export/dump 디렉터리 내보내기
/export/dump/Clienthostname 디렉터리를 읽기·쓰기 권한과 root 접근으로 내보냅니다. 서버 사용자는 /export/dump/Clienthostname 파일에 접근할 수 없습니다.
/export/swap 디렉터리 내보내기
/export/swap/Clienthostname 파일을 읽기·쓰기 권한과 root 접근으로 내보냅니다. 보안 조치는 필요 없습니다. 서버 사용자는 /export/swap/Clienthostname 파일에 접근할 수 없습니다.
디스크 없는 마운트
디스크 없는 워크스테이션의 파일 시스템은 서버의 /export 디렉터리에서 마운트하지만, 디스크 없는 기계에게는 독립 실행형 기계의 파일 시스템과 똑같아 보입니다.
다음은 서버가 내보낸 것과 디스크 없는 워크스테이션 마운트 지점의 관계입니다.
| 서버가 내보낸 것 | 클라이언트 마운트 지점 |
|---|---|
/export/root/HostName |
/(루트) |
/export/exec/SPOTName |
/usr |
/export/home/HostName |
/home |
/export/share |
/usr/share |
/export/dump |
디스크 없는 클라이언트가 덤프 공간으로 씀 |
/export/swap |
디스크 없는 클라이언트가 원격 페이징 공간으로 씀 |
/export 디렉터리에 관한 자세한 내용은 /export 디렉터리를 봅니다.
(원문에는 이 뒤에 /export/root·exec·share·home 내보내기 절이 한 번 더 거듭 실리고 /export/dump 절이 더해져 있으며, 위에 합쳐 옮겼습니다.)
영어 원문
Mounting
Mounting makes file systems, files, directories, devices, and special files available for use at a particular location. It is the only way a file system is made accessible.
The mount command instructs the operating system to attach a file system at a specified directory.
You can mount a file or directory if you have access to the file or directory being mounted and write permission for the mount point. Members of the system group can also perform device mounts (in which devices or file systems are mounted over directories) and the mounts described in the /etc/filesystems file. A user operating with root user authority can mount a file system arbitrarily by naming both the device and the directory on the command line. The /etc/filesystems file is used to define mounts to be automatic at system initialization. The mount command is used to mount after system startup.
Mount points
A mount point is a directory or file at which a new file system, directory, or file is made accessible. To mount a file system or a directory, the mount point must be a directory; and to mount a file, the mount point must be a file.
Typically, a file system, directory, or file is mounted over an empty mount point, but that is not required. If the file or directory that serves as the mount point contains any data, that data is not accessible while it is mounted over by another file or directory. In effect, the mounted file or directory covers what was previously in that directory. The original directory or file that has been mounted over is accessible again once the mount over it is undone.
When a file system is mounted over a directory, the permissions of the root directory of the mounted file system take precedence over the permissions of the mount point. The one exception involves the .. (dot dot) parent directory entry in the mounted-over directory. In order for the operating system to access the new file system, the mount point parent directory information must be available.
For example, if the current working directory is /home/frank, the command cd .. changes the working directory to /home. If /home/frank directory is the root of a mounted file system, the operating system must find the parent directory information in the /home/frank directory in order for the cd .. command to succeed.
For any command that requires parent directory information in order to succeed, users must have search permission in the mounted-over directory. Failure of the mounted-over directory to grant search permission can have unpredictable results, especially since the mounted-over directory permissions are not visible. A common problem is failure of the pwd command. Without search permission in the mounted-over directory, the pwd command returns this message:
pwd: Permission denied
This problem can be avoided by always setting the permissions of the mounted-over directory to at least 111.
Mounting file systems, directories, and files
There are two types of mounts, a remote mount and a local mount. Remote mounts are done on a remote system on which data is transmitted over a telecommunication line. Remote file systems, such as Network File System (NFS), require that the files be exported before they can be mounted. Local mounts are mounts done on your local system.
Each file system is associated with a different device (logical volume). Before you can use a file system, it must be connected to the existing directory structure (either the root file system or to another file system that is already connected). The mount command makes this connection.
The same file system, directory, or file can be accessed by multiple paths. For example, if you have one database and several users using this database, it can be useful to have several mounts of the same database. Each mount should have its own name and password for tracking and job-separating purposes. This is accomplished by mounting the same file system on different mount points. For example, you can mount from /home/server/database to the mount point specified as /home/user1, /home/user2, and /home/user3:
/home/server/database /home/user1
/home/server/database /home/user2
/home/server/database /home/user3
A file system, directory, or file can be made available to various users through the use of symbolic links. Symbolic links are created with the ln -s command. Linking multiple users to a central file ensures that all changes to the file are reflected each time a user accesses the file.
Automatic mount control
Mounts can be set to occur automatically during system initialization.
There are two types of automatic mounts. The first type consists of those mounts that are required to boot and run the system. These file systems are explicitly mounted by the boot process. The stanzas of such file systems in the /etc/filesystems file have mount = automatic. The second type of automatic mount is user-controlled. These file systems are mounted by the /etc/rc script when it issues the mount all command. The stanzas of user-controlled automatic mounts have mount = true in /etc/filesystems.
The /etc/filesystems file controls automatic mounts; they are done hierarchically, one mount point at a time. They can also be placed in a specific order that can be changed and rearranged. For more information about the /etc/filesystems file, see /etc/filesystems.
The /etc/filesystems file is organized into stanzas, one for each mount. A stanza describes the attributes of the corresponding file system and how it is mounted. The system mounts file systems in the order they appear in the /etc/filesystems file. The following is an example of stanzas within the /etc/filesystems file:
(26줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
You can edit the /etc/filesystems file to control the order in which mounts occur. If a mount is unsuccessful, any of the following mounts defined in the /etc/filesystems file continue to mount. For example, if the mount of the /home file system is unsuccessful, the mount for the /usr file system continues and be mounted. Mounts can be unsuccessful for reasons such as typographical errors, dependency, or a system problem.
Mount security for diskless workstations
Diskless workstations must have the ability to create and access device-special files on remote machines to have their /dev directories mounted from a server. Because servers cannot distinguish device-special files intended for a client from those intended for the server, a user on the server might be able to access the physical devices of the server using the special files of the client device.
For example, the ownership for a tty is automatically set to the user using the tty. If the user IDs are not the same on both the client and server, a nonprivileged user on the server can access a tty that is being used by a different user on the server.
A user who is privileged on a client can create device-special files to match physical devices on the server and have them not require privilege for access. The user can then use an unprivileged account on the server to access the normally protected devices using the new device-special files.
A similar security problem involves the use of setuid and setgid programs on the client and server. Diskless clients must be able to create and runsetuid and setgid programs on the server for normal operation. Again, the server cannot distinguish between those programs intended for the server and those intended for the client.
In addition, the user IDs and group IDs might not match between the server and client, so users on the server might be able to run programs with capabilities that were not intended for them.
The problem exists because the setuid and setgid programs and device-special files should only be usable on the machine that created them.
The solution is to use security options to the mount command that restrict the ability to use these objects. These options can also be used in stanzas in the /etc/filesystems file.
The nosuid option in the mount command prevents the execution of setuid and setgid programs that are accessed via the resulting mounted file system. This option is used for any file system that is being mounted on a particular host for use only by a different host (for example, exported for diskless clients).
The nodev option in the mount command prevents the opening of devices using device special files that are accessed via the resulting mounted file system. This option is also used for any file system that is being mounted for use only by a different host (for example, exported for diskless clients).
In general, users on a server do not have any access to the /export directory.
Exporting the /export/root Directory
The /export/root directory must be exported with read/write permissions, and the root user on the server must have access. However, you might want to mount this directory with the following options of the mount command:
- nosuid — Prevents a user on the server from running the setuid programs of the client
- nodev — Prevents a user from accessing the server devices using a device-special file of the client.
An alternative to mounting the /export/root directory with these options is to avoid giving users running on the server any access to the /export/root directory.
Exporting the /export/exec Directory
The /export/exec directory is exported with read-only permissions and must provide root access. However, you might want to mount this directory with the following options of the mount command:
- nosuid — Prevents a user on the server from running the setuid programs of the client. If you are exporting the server
/usrdirectory, you cannot use the nousid option. - nodev — Prevents a user from accessing the server devices using a device-special file of the client.
Exporting the /export/share Directory
The /export/share directory is exported with read-only permissions and must provide root access. Because this directory generally contains only data (no executables or devices), you do not need to use the mount security options.
Exporting the /export/home Directory
There are several ways to mount a user /home directory:
You can mount the
/export/home/Clienthostname directory over the client/homedirectory. In this case, the client has read/write permissions and the root user has access. To ensure system security, mount the/export/homedirectory with the following options to the mount command:nosuid — Prevents a user on the server from running the setuid programs of the client.
nodev — Prevents a user from accessing the server devices using a device-special file of the client.
You can mount the
/homedirectory on the server over the/homedirectory of the client. In this case, the/homedirectory is exported with read/write permissions and without root access. To ensure system security, mount the/homedirectory on both the server and client with thenosuidandnodevoptions of the mount command.Alternatively, you can mount on the client each
/home/UserName directory on the server over the/home/Username directory on the client so users can log in to different machines and still have access to their home directories. In this case, the/home/Username directories on the server and clients are both mounted with thenousidandnodevoptions of the mount command.
Exporting the /export/swap Directory
Export the /export/swap/Clienthostname file with read/write permissions and root access. No security measures are necessary. Users on the server do not have any access to the /export/swap/Clienthostname files.
Diskless mounts:
Although the file system of a diskless workstation is mounted from a server /exports directory, to the diskless machine, the file system looks just like the file system on a standalone machine.
The following shows the relationship between server exports, and the diskless workstation mount points:
/export/root/HostName —/ (root)/export/exec/SPOTName —/usr/export/home/HostName —/home/export/share—/usr/share/export/dump— Used by diskless client as dump space/export/swap— Used by diskless clients as remote paging space
For more information about the /export directory, see /export directory.
In general, users on a server do not have any access to the /export directory.
Exporting the /export/root Directory
The /export/root directory must be exported with read/write permissions, and the root user on the server must have access. However, you might want to mount this directory with the following options of the mount command:
- nosuid — Prevents a user on the server from running the setuid programs of the client
- nodev — Prevents a user from accessing the server devices using a device-special file of the client.
An alternative to mounting the /export/root directory with these options is to avoid giving users running on the server any access to the /export/root directory.
Exporting the /export/exec Directory
The /export/exec directory is exported with read-only permissions and must provide root access. However, you might want to mount this directory with the following options of the mount command:
- nosuid — Prevents a user on the server from running the setuid programs of the client. If you are exporting the server
/usrdirectory, you cannot use the nousid option. - nodev — Prevents a user from accessing the server devices using a device-special file of the client.
Exporting the /export/share Directory
The /export/share directory is exported with read-only permissions and must provide root access. Because this directory generally contains only data (no executables or devices), you do not need to use the mount security options.
Exporting the /export/home Directory
There are several ways to mount a user /home directory:
You can mount the
/export/home/Clienthostname directory over the client/homedirectory. In this case, the client has read/write permissions and the root user has access. To ensure system security, mount the/export/homedirectory with the following options to the mount command:nosuid — Prevents a user on the server from running the setuid programs of the client.
nodev — Prevents a user from accessing the server devices using a device-special file of the client.
You can mount the
/homedirectory on the server over the/homedirectory of the client. In this case, the/homedirectory is exported with read/write permissions and without root access. To ensure system security, mount the/homedirectory on both the server and client with the nosuid and nodev options of the mount command.Alternatively, you can mount on the client each
/home/UserName directory on the server over the/home/Username directory on the client so users can log in to different machines and still have access to their home directories. In this case, the/home/Username directories on the server and clients are both mounted with the nousid and nodev options of the mount command.
Exporting the /export/dump Directory
Export the /export/dump/Clienthostname directory with read/write permissions and root access. Users on the server do not have any access to the /export/dump/Clienthostname files.
Exporting the /export/swap Directory
Export the /export/swap/Clienthostname file with read/write permissions and root access. No security measures are necessary. Users on the server do not have any access to the /export/swap/Clienthostname files.