블로그 이미지
인터넷 해외선교를 기본으로 하는 개인적 내용과 학점은행제 관련한 것을 한꺼번에 남겨볼께요. 항상 행.복.하시길~ 주문처럼 외우는 엠토리가 운영하는 블로그입니다
엠토리

공지사항

최근에 올라온 글

최근에 달린 댓글

글 보관함

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

[링크(Link)]
<하드 링크와 심볼릭 링크>

◆리눅스 파티션 구조

---------------
파티션테이블
---------------
super block
---------------
inode table
---------------
data block
---------------

<하드 링크>
1) 동일한 데이타 블록을 참조하는 서로 다른 파일 이름
2) 파일에 대해서만 만들 수 있다.(디렉토리는 만들수 없음)
3) 같은 파티션 내에서만 만들 수 있다.
4) 하드 링크를 만들면 ls -l 의 두번째 숫자가 하나 증가한다.
5) 하드 링크가 있으면 원본이 없어져도 데이타에 접근 가능하다.
6) 하드 링크를 만들어도 하드디스크 용량은 늘어나지 않는다.
7) 아이노드(파일을 구분하는 번호)가 같다.


<심볼릭 링크>
1) 윈도우의 바탕화면 단축 아이콘과 비슷하다.
2) 파일 및 디렉토리에 대해서 모두 만들 수 있다.
3) 작은 용량의 새로운 파일이다. ---> 아이노드가 원본과 틀리다.
4) 다른 파티션에도 만들 수 있다.
5) 원본을 삭제하면 사용할 수 없다. 

//////////////////////////////////////////////////////
스크립트 : 리눅스 명령어와 프로그래밍 요소(if문 등)로
             이루어진 실행가능한 텍스트 파일
      여러가지 작업을 한 번에 할 수 있어서
      리눅스에서 많이 사용된다.
////////////////////////////////////////////////////// 

#cd  /work
#vi  run.sh (--->간단한 형태의 스크립트 파일)
date
cal

#chmod u+x run.sh
#ll run.sh
-rwxr--r--  1 root root 9 Aug 12 14:22 run.sh
스크립트 파일의 경우 r 과 x 권한이 있어야
일반계정도 실행할 수 있고
루트의 경우에는 실행권한만 있어도 된다.

//////////////////////////////////////////////////////
캡춰 결과
[root@cent work]# ll run.sh
-rw-r--r--  1 root root 9 10월  8 00:08 run.sh
[root@cent work]# chmod u+x run.sh
[root@cent work]# ./run.sh
//////////////////////////////////////////////////////

 
◆하드 링크 생성 방법
ln  원본파일명  링크파일명

#ll run.sh
-rwxr--r--  1 root root 9  7월 15 13:14 run.sh
#
#ln  run.sh  good.sh
#ll
합계 8
-rwxr--r--  2 root root 9  1월  7 12:31 good.sh
-rw-r--r--  1 bin  root 0  1월  7 11:50 hello.exe
-rwxr--r--  2 root root 9  1월  7 12:31 run.sh
#
#./good.sh (run.sh 를 실행한 것과 동일)

 
#ll run.sh good.sh
-rwxr--r--  2 root root 9 Aug 12 14:22 good.sh
-rwxr--r--  2 root root 9 Aug 12 14:22 run.sh
#

#ls -il (아이노드 넘버 출력 ls 옵션 : -i)
합계 8
376145 -rwxr--r--  2 root root 9  1월  7 12:31 good.sh
376143 -rw-r--r--  1 bin  root 0  1월  7 11:50 hello.exe
376145 -rwxr--r--  2 root root 9  1월  7 12:31 run.sh
#
---> 하드링크 파일은 아이노드가 똑 같다.
      복사한 경우에는 아이노드가 틀리다.

◆하드링크 예
#ls -il /bin/gzip /bin/gunzip /bin/ls
245334 -rwxr-xr-x  3 root root 56048  9월 20  2006 /bin/gunzip
245334 -rwxr-xr-x  3 root root 56048  9월 20  2006 /bin/gzip
 

#chmod g-r,o-r good.sh
#ll run.sh good.sh (또는 ll  *.sh)
-rwx------  2 root root 9 Aug 12 14:22 good.sh
-rwx------  2 root root 9 Aug 12 14:22 run.sh
#
하드링크는 아이노드가 동일하므로 둘 다 똑같이 출력된다.

#rm run.sh
rm: remove regular file `run.sh'? y
#ls
ex3.txt   good.sh       hell.exe  hello.exe  services

#./good.sh (원본을 지워도 하드링크 파일로 실행할 수 있다.)

#ll good.sh
(원본을 삭제했으므로 링크카운트가 2에서 1로 감소)
-rwx------  1 root root 9 Aug 12 14:22 good.sh
#

Q)하드링크 된 파일 찾기
(find 명령 이용하여 gzip 의 하드 링크 파일 찾기)

#man  find

       -inum n
              File has inode number n.

#ls -il /bin/gzip
635286 -rwxr-xr-x  3 root root 56048  9월 20  2006 /bin/gzip

#find  /bin  -inum  아이노드번호
/bin/gunzip
/bin/gzip
/bin/zcat

cat : 파일을 읽어서 출력
zcat : gzip 파일을 압축 해제후 읽어서 출력

#cd  /tmp
#ls
boot2.tar.gz
#cat  my1.tar.gz  |  file  -  또는  #file  my1.tar.gz
gzip 으로 출력( - 는 파이프를 사용하라는 의미)


#zcat  my1.tar.gz  |  file  -
tar 로 출력

 ◆심볼릭 링크 생성 : -s 옵션 사용
ln  -s  원본파일명  링크파일명

#cd  /work
#pwd
/work
#ls
#ln  -s  good.sh  go
#

#ll good.sh go
lrwxrwxrwx  1 root root 7 Aug 12 14:47 go -> good.sh
-rwx------  1 root root 9 Aug 12 14:22 good.sh
#
---> 심볼릭 링크파일은 l 로 시작해서 퍼미션이 모두
셋팅되서 나타나므로 실제 퍼미션은 원본 파일을 확인해야 한다.


#./go(--->good.sh 가 실행된다.)

 

#ls  -il  good.sh  go
981304 lrwxrwxrwx  1 root root 7 Aug 12 14:47 go -> good.sh
981301 -rwx------  1 root root 9 Aug 12 14:22 good.sh
#
---> 심볼릭 링크는 새로운 파일이므로 아이노드 번호가 원본과 틀리다.

#chmod u-w go
#ls -il good.sh go
981304 lrwxrwxrwx  1 root root 7 Aug 12 14:47 go -> good.sh
981301 -r-x------  1 root root 9 Aug 12 14:22 good.sh
#
---> 원본의 퍼미션이 변경된다.

#rm  good.sh
#ll
#./go
--->원본 파일을 삭제했으므로 실행되지 않는다.

//////////////////////////////////////////////////////
결과 캡춰

#rm good.sh
rm: remove 일반 파일 `good.sh'? y
#ll
합계 9784
drwxr-xr-x  3 root root    4096  6월  9 15:04 boot
lrwxrwxrwx  1 root root       7  6월 16 20:31 go -> good.sh
-rw-r--r--  1 root root     122  6월  9 19:42 hello.c
-rw-r--r--  1 bin  root       0  6월 16 19:00 hello.exe
-rw-r--r--  1 root root      52  6월  9 18:00 linux.txt
-rw-r--r--  1 root root      52  6월  9 18:00 linux2.txt
-rw-r--r--  1 root root      53  6월  9 18:11 linux3.txt
-rw-r--r--  1 root root   20381  6월  9 17:55 services
-r--r--r--  1 root root  116262  4월 22 00:46 zip-2.3-27.i386.rpm
drwxr-xr-x  3 root root    4096  6월 16 20:28 zzz
-rw-r--r--  1 root root       0  6월 16 20:26 zzz.exe
#./go
-bash: ./go: 그런 파일이나 디렉토리가 없음
#

//////////////////////////////////////////////////////


<백업(BACKUP>
원본 파일이나 디렉토리를 다른 디렉토리나 다른 하드디스크,
다른 컴퓨터에 저장해 두는 것을 백업이라 하고
예기치 않은 데이타 손실이 발생했을 경우 백업을 해 두었다면
다시 데이타를 원상복구 할 수 있다.
시스템 관리자의 기본적이면서도 중요한 업무중의 하나가 백업이다.
tar, dd, mkisofs, cdrecord 등을 이용하여 백업을 할 수 있고
간단한 파일은 복사(cp) 를 해도 된다.

백업의 대상은 파티션 전체, 특정 디렉토리나 파일, 응용 프로그램,
시스템 설정파일, 로그파일, 사용자 파일 및 디렉토리 등이다.

1. tar : 디렉토리 백업, 운영체제 백업
2. mkisofs : CD 이미지 파일로 백업
3. dd : 파티션 복제

//////////////////////////////////////////////////////////////////////////

-------------------
표준입력(stdin,0)    <-------------------  키보드
-------------------

-------------------
표준출력(stdout,1)   -------------------> 모니터
-------------------

#man  tar
       -f, --file [HOSTNAME:]F
              use archive file or device F (default "-", meaning stdin/stdout)

#cd  /work
#tar  cvf  -  score.c
#tar  cvf  -  score.c  |  tar  tvf  -
       ------------------------------
       파이프를 이용한 전송---->
       ------------------------------

//////////////////////////////////////////////////////////////////////////

♠tar 를 이용한 로컬 데이타 미러링(mirroring)
---> A 폴더를 B 폴더로 복제할 때 사용
복사를 할 경우 옵션을 사용하지 않을 경우 원본 파일의 정보가 유지되지
않으므로 원본 파일의 정보를 유지하고 싶을 때 이 방법을 사용한다.

형식)
tar   cpf   -   --directory=백업경로   .   |   (cd 백업저장경로 ; tar  xpf  -)


#mkdir  /home3
#cd  /home
#touch  bk1.txt  bk2.txt  bk3.txt
#tar   cpf   -   --directory=/home  .  |  (cd  /home3  ;  tar  xpf  -)
#ls  /home
#ls  /home3

♠tar 를 이용한 리눅스 운영체제 백업
/proc, /mnt, /media, /tmp 디렉토리는 제외해도 되며, 제외할 디렉토리는
--exclude 옵션을 이용한다.
형식)
tar  cpvfz  /backup/백업파일명.tar.gz  --exclude=제외디렉토리  --absolute-name  /

#date
#date  +%Y%m%d
---> 날짜를 변환해서 출력시키기
변환 문자 :
%Y 년도(Year)
%m 월(month)
%d 일(day)

#mkdir  /backup
#tar  cpvfz  /backup/mybackup_`date  +%Y%m%d`.tar.gz  --exclude=/proc  --exclude=/tmp  --exclude=/media  --exclude=/backup  --absolute-name  /

♠tar 를 이용한 증가형 백업
1. 전체백업(full backup)
--->처음 백업할 때
2. 증가형 백업(incremental backup)
--->풀백업을 한 후 변경된 내용만 백업할 때
    --listed-incremental 또는 -g 옵션 사용

#mkdir  /home2
#cd /home2
#touch  data1.txt  data2.txt  data3.txt

#tar  zcpf  /backup/full.tar.gz  --listed-incremental  /backup/bklist.txt  /home2

bklist.txt 파일에는 백업되는 파일정보(파일이 포함된 디렉토리의 시간정보)가 기록되고
증가형 백업을 할 때 이용된다.
tar  zcvpf 를 사용하면 백업되는 파일이 화면에 출력되고
v 를 빼고 tar  zcpf 를 사용하면
tar: Removing leading `/' from member names
메시지만 출력된다.

#ls /backup
bklist.txt  full.tar.gz

#pwd
(/home2)
#touch  data5.txt

               /
               |
   +---------+---------+
backup                  home2
1,2,3                     1,2,3,5

/home2 에 있는 자료를 /backup 디렉토리 안에
incre.tar.gz 로 증가형 백업하기

#tar  zcvpf  /backup/incre.tar.gz  --listed-incremental  /backup/bklist.txt  /home2

--->/home2 에 있는 data1.txt, data2.txt, data3.txt 는
    /backup 에 이미 저장되어 있으므로
    data5.txt 만 백업됨

#cd  /backup
#ls

#tar ztvf full.tar.gz
data1.txt
data2.txt
data3.txt

#tar ztvf incre.tar.gz
data5.txt

 

☞복원
#pwd
(/backup)
#tar  zxvf  full.tar.gz  -g  ./bklist.txt
#ls
#ls home2(/backup/home2 가 보여진다.)
data1.txt  data2.txt  data3.txt 
#
/backup/home2 에 새로운 파일을 만들었을 경우
-g 옵션을 생략하면 새로운 파일이 보존이 되지만
-g 옵션을 이용하면 원본 그대로 복구하므로 새 파일이 삭제 된다.

#tar zxvf incre.tar.gz  -g  ./bklist.txt
home2/
home2/data5.txt
#
#ls home2
data1.txt  data2.txt  data3.txt  data5.txt
#

♠CD 이미지 백업
CD 레코더 장치 검색
#cdrecord  -scanbus


☞실제 리눅스 머신에서 테스트한 결과
[root@server ~]# cdrecord -scanbus
Cdrecord-Clone 2.01 (cpu-pc-linux-gnu) Copyright (C) 1995-2004 J▒rg Schilling
Note: This version is an unofficial (modified) version with DVD support
Note: and therefore may have bugs that are not present in the original.
Note: Please send bug reports or support requests to http://bugzilla.redhat.com/bugzilla
Note: The author of cdrecord should not be bothered with problems in this version.
Linux sg driver version: 3.5.27
Using libscg version 'schily-0.8'.
cdrecord: Warning: using inofficial libscg transport code version (schily - Red Hat-scsi-linux-sg.c-1.83-RH '@(#)scsi-linux-sg.c        1.83 04/05/20 Copyright 1997 J. Schilling').
scsibus1:
        1,0,0   100) 'TSSTcorp' 'CDDVDW SH-S223C ' 'SB02' Removable CD-ROM
        1,1,0   101) *
        1,2,0   102) *
        1,3,0   103) *
        1,4,0   104) *
        1,5,0   105) *
        1,6,0   106) *
        1,7,0   107) *
[root@server ~]#

하드디스크 데이타를 CD 이미지 파일로 백업하기
#mkdir  /backup3
#cd  /backup3
#mkisofs  -R  -J  -V  Linux  -o  homeimage.iso  /home
-R : 퍼미션 유지
-J  : 긴 파일이름 인식
-V :  볼륨 이름
-o : 출력 파일명

 

CD 이미지 파일을 마운트해서 사용하기
#mkdir  /mnt/test
#mount  -t  iso9660  -r  -o  loop  homeimage.iso   /mnt/test

//////////////////////////////////////////////////////////////////////////
#man  mkisofs

       -J     Generate Joliet directory records in addition to regular iso9660
              file  names.   This is primarily useful when the discs are to be
              used on Windows-NT or Windows-95 machines.  The Joliet filenames
              are specified in Unicode and each path component can be up to 64
              Unicode characters long.  Note that Joliet is no standard - CD’s
              that  use  only  Joliet  extensions  but  no standard Rock Ridge
              extensions may usually only be used on Microsoft Win32  systems.
              Furthermore, the fact that the filenames are limited to 64 char-
              acters and the fact that Joliet uses the UTF-16 coding for  Uni-
              code characters causes interoperability problems.

       -R     Generate SUSP and RR records using the Rock  Ridge  protocol  to
              further describe the files on the iso9660 filesystem.

       -V volid
              Specifies the volume ID (volume name or  label)  to  be  written
              into  the master block.

#man  mount

       -r     읽기만 가능하게 마운트한다. 같은 옵션으로는 -o ro   이
              있다.

iso9660 화일 시스템에 대한 옵션
       Normal iso9660 화일명이 8.3 형식으로 나타나게 한다.( 즉 DOS 식 화 일 명
       제 한을 사용한다. ) 그리고 모두 대문자로 표시되게 한다. 또한 소 유권, 허
       가권, 링크 수, 블럭/문자장치 표시 등의 필드를 없앤다.

       락 릿지(Rock Ridge)는 iso9660 시스템에 유닉스의 모든 기능을 제공하는 확
       장기능이다.

루프 장치(THE LOOP DEVICE)
       또 다른 타입 중 하나로서 루트 장치를 통한 마운트를 들 수 있다.

//////////////////////////////////////////////////////////////////////////

CD 이미지 파일을 공 CD 에 저장하기
#cdrecord  dev=1,0,0  -data  -v  -eject  speed=4  homeimage.iso

dev=scsibus 번호, target 번호, lun 번호(cdrecord  -scanbus 로 확인)
data : 데이타 CD 지정
eject : 작업후 CD 배출
speed : 쓰기 속도 지정

//////////////////////////////////////////////////////////////////////////
#man  cdrecord

    -data  If  this  flag is present, all subsequent tracks are written
              in CD-ROM mode 1 (Yellow Book) format. The data  size  is  a
              multiple  of  2048  bytes.   The file with track data should
              contain an ISO-9660 or  Rock  Ridge  filesystem  image  (see
              mkisofs  for  more  details).

    -eject Eject  disk  after  doing  the  work. 

speed=#
              Set  the  speed factor of the writing process to #.  # is an
              integer
//////////////////////////////////////////////////////////////////////////

☞실제 리눅스 머신에서 테스트한 결과
[root@server ~]# cdrecord dev=1,0,0 -data -v -eject speed=4 aa.iso
cdrecord: No write mode specified.
cdrecord: Asuming -tao mode.
cdrecord: Future versions of cdrecord may have different drive dependent defaults.
cdrecord: Continuing in 5 seconds...
Cdrecord-Clone 2.01 (cpu-pc-linux-gnu) Copyright (C) 1995-2004 J▒rg Schilling
Note: This version is an unofficial (modified) version with DVD support
Note: and therefore may have bugs that are not present in the original.
Note: Please send bug reports or support requests to http://bugzilla.redhat.com/bugzilla
Note: The author of cdrecord should not be bothered with problems in this version.
TOC Type: 1 = CD-ROM
scsidev: '1,0,0'
scsibus: 1 target: 0 lun: 0
Linux sg driver version: 3.5.27
Using libscg version 'schily-0.8'.
cdrecord: Warning: using inofficial libscg transport code version (schily - Red Hat-scsi-linux-sg.c-1.83-RH '@(#)scsi-linux-sg.c        1.83 04/05/20 Copyright 1997 J. Schilling').
SCSI buffer size: 64512
atapi: 1
Device type    : Removable CD-ROM
Version        : 5
Response Format: 2
Capabilities   :
Vendor_info    : 'TSSTcorp'
Identifikation : 'CDDVDW SH-S223C '
Revision       : 'SB02'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.
Current: 0x0000
Profile: 0x002B
Profile: 0x001B
Profile: 0x001A
Profile: 0x0016
Profile: 0x0015
Profile: 0x0014
Profile: 0x0013
Profile: 0x0012
Profile: 0x0011
Profile: 0x0010
Profile: 0x000A
Profile: 0x0009
Profile: 0x0008
Using generic SCSI-3/mmc   CD-R/CD-RW driver (mmc_cdr).
Driver flags   : MMC-3 SWABAUDIO BURNFREE
Supported modes: TAO PACKET SAO SAO/R96P SAO/R96R RAW/R16 RAW/R96P RAW/R96R
Drive buf size : 720896 = 704 KB
FIFO size      : 4194304 = 4096 KB
Track 01: data    33 MB
Total size:       38 MB (03:47.34) = 17051 sectors
Lout start:       38 MB (03:49/26) = 17051 sectors
cdrecord: Input/output error. test unit ready: scsi sendcmd: no error
CDB:  00 00 00 00 00 00
status: 0x2 (CHECK CONDITION)
Sense Bytes: 70 00 02 00 00 00 00 0A 00 00 00 00 3A 01 00 00
Sense Key: 0x2 Not Ready, Segment 0
Sense Code: 0x3A Qual 0x01 (medium not present - tray closed) Fru 0x0
Sense flags: Blk 0 (not valid)
cmd finished after 0.001s timeout 40s
cdrecord: No disk / Wrong disk!
[root@server ~]#

♠실습
1. /dev/hda1, /dev/hdb1 을  150M 으로 파티션 설정하기
2. /dev/hda1 을 포맷한 후 /disk2 디렉토리에 마운트하기
   (/disk2 없으면 #mkdir  /disk2 로 생성)
3. /backup3 디렉토리를 /disk2 에 복사하기
4. /dev/hda1 마운트 해제하기
5. dd 이용하여 /dev/hda1 을 /dev/hdb1 으로 복제하기

//////////////////////////////////////////////////////////////////////////

#fdisk  /dev/hda
파티션 모두 삭제(d 입력)
n
p
1
엔터
+150M
w
#

/dev/hdb 도 동일하게 파티션 설정

#mkfs.ext3  /dev/hda1
#mount /dev/hda1 /disk2
#
#ls /disk2
lost+found
#
#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G  7.4G  6.4G  54% /
none                  252M     0  252M   0% /dev/shm
/dev/sda3             4.3G   47M  4.1G   2% /home
/backup3/homeimage.iso
                      5.6M  5.6M     0 100% /mnt/test
/dev/hda1             140M  5.6M  127M   5% /disk2
#
#cp -r /backup3 /disk2
#umount  /disk2

dd 명령어는 마운트를 해제후 사용해야 함

#dd if=/dev/hda1 of=/dev/hdb1 bs=1024
147136+1개의 레코드를 입력하였습니다
147136+1개의 레코드를 출력하였습니다
#
#mkdir /disk3
#mount /dev/hdb1 /disk3
#df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              15G  7.4G  6.4G  54% /
none                  252M     0  252M   0% /dev/shm
/dev/sda3             4.3G   47M  4.1G   2% /home
/backup3/homeimage.iso
                      5.6M  5.6M     0 100% /mnt/test
/dev/hdb1             140M   12M  121M   9% /disk3
#ls /disk3
backup3  lost+found
#ls /disk3/backup3/
homeimage.iso
#
//////////////////////////////////////////////////////////////////////////


[부팅과정]

1. BIOS 단계
POST(Power On Self Test)
하드웨어에 문제가 없는지 체크하는 과정,
BIOS(Basic Input/Output System)에 의해서 실행

CMOS(Complementary Metal Oxide Semiconductor) : 기억장치 종류
BIOS는 CMOS 설정에 의해서 부트디스크의
가장 앞쪽 부분인 MBR을 읽는다.

2. MBR(Master Boot Record)
MBR의 크기는 512 바이트
MBR에 부트로더 정보가 들어 있다.

3. 부트로더(Boot Loader)
(부팅을 도와주는 프로그램)
LILO-이전에 사용되던 부트로더
GRUB-현재 사용하는 부트로더
부트로더에 의해서 커널이 메모리에 로딩된다.

4. init 단계
부트로더는 swapper pid 0 번 프로세스를 실행
swapper 는 pid 1 번 init(/sbin/init) 을 실행하고
init 은 /etc/inittab 을 참조한다.


▣레드햇 리눅스의 부팅종류 : 런레벨(runlevel) 또는 실행수준
(성격이 다른 부팅 종류)

0 : 시스템 종료
1 : 단일 사용자(루트) 모드, 싱글 모드라고 부른다.
2 : NFS 를 지원하지 않는 다중 사용자 모드
3 : 텍스트 다중 사용자 모드(NFS 포함)
4 : 사용 안함
5 : 그래픽 다중 사용자 환경(디폴트)
6 : 리부팅

주로 사용되는 런레벨은 3번과 5번이다.

#cp  /etc/inittab  /etc/inittab.old
---> /etc/inittab 을 잘못 설정하면 부팅중에 멈추므로
      백업을 해 둔다.
#ls  /etc/inittab*


#vi  /etc/inittab
리눅스 설정파일에서 라인이 #으로 시작하면 주석(설명)으로 프로그램에 의해서 무시된다.

/etc/inittab 파일 한 줄(Entry)의 형식

name : level-number : options : process -options
  (1)          (2)              (3)             (4)

(1)name : 각 행을 구분하는 이름(Label)

(2)level-number : 실행할 런레벨을 뜻함

(3)options : 프로세스 실행시킬 때의 속성
        wait  ---> 한 프로세스가 완료될 때까지 대기
  respawn  ---> 프로세스가  종료되면 다시 시작
                     respawn 속성에 의해서 아이디/암호가 틀렸을 경우
       다시 로그인 프롬프트가 출력 된다.

(4)process -options : 실행할 명령어 또는 스크립트와 옵션

id:5:initdefault:
---> 부팅시 사용할 디폴트 런레벨 설정

/etc/rc.d/rc.sysinit 에는
네트워크 설정, fsck 로 파일시스템 점검, 커널 모듈 로딩 등
시스템 초기화 하는 내용이 들어 있다.


각 런레벨에서 실행할 스크립트 설정
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
.....  

l6:6:wait:/etc/rc.d/rc 6


# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
---> 콘솔 모드(서버앞 런레벨 3 상태)에서 ctrl+alt+delete 키를 눌렀을 때
리부팅되게 하는 설정


pf행은 UPS전원이 부족할 경우 2분후에 시스템을 shutdown 시키는 내용

pr행은 다시 전원공급이 되었을 shutdown 을 자동취소시키는 내용


리눅스는 6개의 가상터미널(콘솔)을 제공함
(alt + F1 ~ F6)

1:2345:respawn:/sbin/mingetty tty1 은 첫번째 가상터미널
2:2345:respawn:/sbin/mingetty tty2 은 두번째 가상터미널
3:2345:respawn:/sbin/mingetty tty3 은 세번째 가상터미널
...

6:2345:respawn:/sbin/minegetty tty6 은 여섯번째 가상터미널

쉘로 빠져 나오기

#runlevel
N  5
runlevel : 런레벨 확인 명령

N은 이전 런레벨
5는 현재 런레벨

부팅된 상태에서 런레벨을 변경하는 방법은
#init  런레벨번호  
를 사용한다.


#init  3
---> 3번 런레벨로 전환
---> putty 가 아니라 리눅스 가상머신 터미널에서 실행하기

윈도우가 종료되면서
Starting anacron 메시지가 출력되고
멈춘 것처럼 보인다.
Starting anacron 메시지가 보이지 않으면 리눅스를 종료후
다시 부팅해서 테스트 한다.
(Cent 5 버전에서는 init 3 할 경우 텍스트 로그인 화면이 나타난다.)

윈도우가 종료되므로 가상터미널로 로그인 해서 계속 작업을 할 수 있다.

alt + F1 입력 ---> 가상 터미널 화면이 나타난다.
root 로 로그인 한다.
#id
--->리눅스는 사용자를 숫자로 구분하고 id 명령은 사용자의
uid(사용자번호) 와 gid(그룹번호) 를 출력해 준다.
uid=0 이 관리자 계정이다.

#runlevel
5 3 (---> 5번 런레벨에서 3번으로 변경된 상태)

#vi  /etc/inittab
아래와 같이 변경하고 저장후 종료
18 번 라인의 5를 3으로 변경

18 id:3:initdefault:
---> 부팅시 런레벨을 결정하는 항목

#init  6
--->리부팅을 의미

런레벨을 3으로 변경했으므로 그래픽 로그인 화면이 아니라
텍스트 로그인 화면이 출력된다.
루트로 로그인 하기

#ls  /etc/rc.d
#ls  /etc/rc.d/rc3.d(또는 /etc/rc3.d)
#ls  /etc/rc.d/rc5.d(또는 /etc/rc5.d)
#ls  /etc/rc.d/rc0.d(또는 /etc/rc0.d)

[root@cent ~]# ll /etc/rc3.d
lrwxrwxrwx  1 root root 10  2월  9 14:16 /etc/rc3.d -> rc.d/rc3.d
[root@cent ~]#
---> /etc/rc3.d 는 /etc/rc.d/rc3.d 의 심볼릭 링크 파일이다.

rc : runlevel  change

/etc/rc.d/rc번호.d  ---> 각 런레벨에서 실행되는 데몬을 관리하는
                              스크립트 파일이 들어있는 디렉토리
S(대문자) 는 Start script(프로그램을 메모리로 로딩)
K(대문자) 는 Kill script(프로그램 종료)

rc0.d 는 런레벨 0 이 종료이므로 대부분 Kill 스크립트가 들어가 있다.

런레벨 디렉토리에서 대문자 S로 시작하는 스크립트를 소문자 s 로
바꾸거나 스크립트를 삭제하면 부팅시 해당 프로그램이 시작되지 않는다.


스크립트 : 리눅스 명령어와 프로그래밍 요소(if 문)를 이용하여
             여러 가지 작업이 한 번에 처리될 수 있도록
      만들어 놓은 실행가능한 텍스트 파일
      (ls 는 스크립트가 아니고 바이너리 실행파일이다.)

#runlevel
N  3

텍스트 모드(런레벨 3)에서 그래픽 모드(런레벨 5)로 전환하려면
startx  또는  init  5  하면 된다.

#startx
--->x-윈도우 시작(런레벨은 변경되지 않는다.)
리눅스의 윈도우 프로그램을 X-윈도우 또는 X-서버 라 부른다.

터미널 실행
#vi  /etc/inittab
디폴트 런레벨 5로 변경하기
id:5:initdefault
---> 리부팅하면 그래픽 환경으로 부팅된다.

저장후 종료
#

로그아웃
(로그아웃 단축키 : ctrl+alt+백스페이스)


#init 5
런레벨을 변경하는 것이므로 그래픽 로그인 화면이 나타난다.
루트로 로그인

<리부팅, 종료 방법>
리부팅 : reboot,  init 6, shutdown  -r  now(시간)
종료   : halt, init 0, poweroff, shutdown  -h  now(시간)


☞shutdown 형식 :
shutdown  옵션  시간  메시지

사용 예 :
1)shutdown  -r  +2 (분단위) ---> 2분뒤에 리부팅 하는 명령
2)shutdown  -h  now ---> 즉시 종료
3)shutdown  -r  now  "system check"
---> 즉시 리부팅, system check 메시지가 접속한 사용자들에게 전달 됨
4)shutdown  -c ---> 셧다운 취소


-r : reboot
-h : halt (종료)
-c : cancel

//////////////////////////////////////////////////////////////////////////
#man shutdown

time            When to shutdown.

warning-message
                Message to send to all users.

The time argument can have different formats.  First, it can be an
absolute time in the format hh:mm, in which hh is the hour (1 or 2
digits) and mm is the minute of the hour (in two digits).  Second,
it can be in the format +m, in which m is the number of minutes to
wait.  The word now is an alias for +0.
//////////////////////////////////////////////////////////////////////////

<reboot 와 shutdown 그리고 init 6 의 차이>
reboot   --->   shutdown   --->  init
(reboot 는 shutdown 을 호출하고 shutdown 은 init 을 호출한다.)


#man   reboot
DESCRIPTION
       Halt 명령은 /var/log/wtmp 파일에 시스템 종료 기록을 남기고, 시스템 종료
       나 리부팅 작업을 한다.  만약 runlevel이 0이나 6이 아닌 상태의 시스템 에
       서  halt 나 reboot 명령이 사용되면, shutdown(8) 명령이호출된다.(-h나 -r
       옵션 기능을 함)


#man  shutdown
       Shutdown은 init 프로세서의 시그날 처리에 의해서 수행되며,
       runlevel 바꾸기를 요청한다

가상머신에서 터미널 2개 실행

1번 터미널
#shutdown -h +2
--->2분뒤 종료


2번 터미널
#shutdown -c
--->셧다운 취소

#shutdown -h +1
---> 1분 뒤에 init 프로세스에 의해서
      /etc/rc.d/rc0.d 의 스크립트가 실행된 후 종료가 된다.
      /etc/rc.d/rc0.d 에는 메모리의 프로그램을
      종료시키는 Kill 스크립트들이 들어 있다.

<싱글(single) 부팅하기>
☞싱글 부팅을 사용하는 경우
1) grub 암호(부팅시 암호설정) 잃어버렸을 때
2) 루트 암호 잃어버렸을 때
3) 장애가 발생해서 정상부팅이 안 될 때


☞싱글 부팅하는 방법
1) 리눅스 1번 CD 이용하는 방법
2) grub 설정 이용하는 방법(grub 암호 잃어버렸을 때는 사용 못함)

※1번 방법 실습(리눅스 1번 CD 이용)
종료된 리눅스 가상머신 화면의 Devices 항목에서
CD 장치를 더블 클릭하기

[v]Connect at power on 에 체크하기
Use ISO Image file 선택후
Browse 버튼을 눌러서 리눅스 1번 CD를 입력하고 부팅시키기


하드디스크로 다시 부팅되면
ctrl + alt + insert 키를 누르거나
vmware 아이콘 표시줄의 ■(사각형 버튼)을 눌러서 종료후 다시 부팅시킨다.

ctrl + alt + delete 가 재부팅 단축키 이지만
ctrl + alt + delete 를 누르면 윈도우가 반응하므로 ctrl + alt + insert 를 이용한다.

부팅초기 VMWARE 메시지가 나올 때 리눅스 가상머신 안에서 F2 키를 누른다.
(이 때, 리눅스 화면에서 왼쪽 마우스를 입력해서 리눅스안에 들어온 상태이어야 한다.)
---> 가상머신 바이오스 화면으로 진입하기


Bios 화면 Boot 메뉴에서
CD-ROM Drive 에 커서 위치시키고  + 키 눌러서
아래와 같이 첫번째로 이동시키기

Boot
CD-Rom Drive
Removable Devices
Hard Drive
Network boot from AMD


F10 누른후 Yes 에 커서 위치시키고 엔터를 눌러서 리부팅하기


boot: 라고 나온 화면에서 F1 ~ F5 를 누르면 도움말을 확인할 수 있다.
cdrom 으로 부팅되서 boot: 라고 나오면 아래와 같이 입력하고 엔터 누르기
boot: linux  rescue
--->CD 를 이용한 싱글부팅을 의미함


(아래와 같이 설정)
언어선택-English
키보드-us
네트워크-NO
Rescue-Continue
--->Skip 을 선택하면 하드디스크가 인식되지 않고
    Read-Only 를 선택하면 하드디스크 파일을 변경할 수 없다.

OK(엔터 입력)

-/bin/sh-3.00#
(---> CD 로 싱글 부팅한 상태)

-/bin/sh-3.00#chroot  /mnt/sysimage
sh-3.00#

1번 cd 로 부팅하면 cd 가 / 로 지정이 되고 하드디스크
루트 파티션은 /mnt/sysimage 디렉토리에 연결된다.
그러므로 /mnt/sysimage 를 최상위 디렉토리 / 로
변경시켜주어야 하는데
chroot  /mnt/sysimage 해주면 1번 cd 의 루트에서
하드디스크 루트로 변경된다.
---> change root 를 의미


change root 를 하기 전에는 하드디스크의 파일을 접근할 때
#vi  /mnt/sysimage/etc/grub.conf 라고 적어야 하지만
change root 를 한 후에는
#vi  /etc/grub.conf 를 입력하면 된다.

루트 암호 초기화 설정
#vi  /etc/shadow (--->사용자의 암호가 저장되어 있는 파일)
root::14523:0:99999:7:::

첫번째 라인의 두번째 필드를 삭제하고
--->명령상태에서 x 입력 또는 delete 키 사용
--->콜론(:) 사이의 문자열만 삭제하라는 의미
--->콜론(:) 사이에 공백이 존재하면 안 된다.

강제저장후 종료하기(esc  :wq!)
--->esc :wq 로 하면 읽기전용 파일이라서 저장되지 않는다.

변경전)
root:$1!3fjefdewrdtdff$fdxerfdfdfdex:14523:0:99999:7:::

변경후)
root::14523:0:99999:7:::

또는
#passwd 명령을 입력하고 루트 암호를 다시 설정해도 된다.

가상머신 오른쪽 하단 CD-ROM 아이콘 클릭해서 1번 CD 제거하기(Use physical drive 선택)

sh-3.00#exit
-/bin/sh-3.00#exit


cd 로 부팅했을 때 리부팅이 안 되는 경우도 있는데
red 사각형 아이콘(■)을 눌러서 종료한 다음
부팅(▶아이콘 클릭)시키면 된다.

--->로그인 화면에서 root 만 입력하면 패스워드 입력없이 로그인 된다.

루트암호 다시 설정하기
#grep  root  /etc/shadow
#passwd (또는 passwd  root)
암호 두번 입력하기(입력문자는 안 보인다.)
#grep  root  /etc/shadow
--->설정된 암호 확인

passwd       : 암호 설정 명령어
/etc/shadow : 암호가 저장되어 있는 파일

※2번 방법 실습(grub 을 이용한 싱글 부팅)

리눅스 리부팅후 grub 화면(Press any key ... , 하늘색 화면) 나왔을 때 엔터 입력
첫번째 라인(CentOS-4 i386 ...)에 커서 막대 위치시키고
e 입력(Edit 를 의미)
두번째 kernel 라인에서 e 입력
grub edit> kernel  /boot/vmlinuz ... root=LABEL=/ rhgb quiet single

---> kernel 로 시작하는 라인의 마지막에 single(또는 숫자 1)
      단어 입력후 엔터 누르기
      (숫자를 3으로 적으면 런레벨 3으로 부팅됨)

그 다음 b 입력(Boot 를 의미)

rhgb  : Redhat Graphical Boot
quiet : 커널메시지 숨기기

#id
uid=0(root)
#ifconfig
---> 싱글부팅을 했으므로 네트워크 구성은 되지 않는다.
#passwd
루트 암호 설정(기존 암호와 다르게 입력)
passwd 명령을 이용하면 /etc/shadow 파일의 내용이 변경된다.

#reboot

루트로 로그인


<ACL(Access Control List)>
파일과 디렉토리의 확장 속성
getfacl : acl 확인
setfacl : acl 설정
  -m 수정
  -x 삭제

형식)
#getfacl  파일명
#setfacl  -m  [acl]  파일명
#setfacl  -x  [acl]  파일명

#setfacl  -m  u:apple:7  파일명

operation not permitted 로 나올경우
/etc/fstab 에 acl 추가후  remount 하고 테스트

//////////////////////////////////////////////////////////////////////////
#man  getfacl

GETFACL(1)                   Access Control Lists                  GETFACL(1)

NAME
       getfacl - get file access control lists

SYNOPSIS
       getfacl [-dRLPvh] file ...

       getfacl [-dRLPvh] -

DESCRIPTION
       For  each  file, getfacl displays the file name, owner, the group, and
       the Access Control List (ACL). If a directory has a default ACL,  get-
       facl  also  displays  the  default  ACL.  Non-directories  cannot have
       default ACLs.


#man  setfacl

SETFACL(1)                   Access Control Lists                  SETFACL(1)

NAME
       setfacl - set file access control lists

SYNOPSIS
       setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ...

       setfacl --restore=file

DESCRIPTION
       This  utility  sets  Access Control Lists (ACLs) of files and directo-
       ries.  On the command line, a sequence of commands is  followed  by  a
       sequence  of  files (which in turn can be followed by another sequence
       of commands, ...).

 

EXAMPLES
       Granting an additional user read access
              setfacl -m u:lisa:r file

       Revoking  write  access from all groups and all named users (using
 the
       effective rights mask)
              setfacl -m m::rx file

       Removing a named group entry from a file’s ACL
              setfacl -x g:staff file
//////////////////////////////////////////////////////////////////////////

#getfacl  /root

#setfacl  -m  u:apple:7  /root
#getfacl  /root


"명령이 지원되지 않음" 또는
operation not permitted 로 나올경우 아래와 같이 설정후 테스트하기

#vi  /etc/fstab
루트 파티션의 defaults 다음에 acl 추가하기

# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/                 /                       ext3    defaults,acl        1 1


#mount  -o  remount  /

▣실습
1. D:\리눅스2공용\fedora.alz 를 자신의 폴더에 압축 풀고
   vmware 에서 불러오기(파일이 없으면 수업용 서버 "4_가상머신" 폴더에서 다운받기)
2. fedora 리눅스에서 centos 1번 CD 를 이용해서 싱글부팅 한 후
   /etc/shadow 파일을 vi 로 open 해서 루트 암호를 초기화하기
   리부팅 해서 루트암호 입력없이 로그인 되는지 확인하기


에고.. 강의 자료 취합이 이리 늦어서야..ㅠ 어찌되었든 10번째로 남깁니다.
항상 행.복.하기 아시지요? ^^?