리눅스/설치

[리눅스] Rescue Mode

ㅎㄷㄹㅁㅇ 2022. 2. 7. 14:58
반응형

Rescue Mode

Rescue Mode 란? 

리눅스 시스템 OS 부팅 시 정상적인 부팅이 되지 않을 때 또는 root 패스워드를 잃어버렸을 때 변경할 수 있도록 도와주는 것이 리눅스의 복구 모드입니다. 최악의 경우는 OS에서 사용하는 라이브러리나 패키지나 디렉토리를 삭제했을 경우에도 사용됩니다.  

 

 

복구가 필요한 상황

위에서 말씀드린 바와 같이 다양한 경우에 복구모드가 필요합니다. 

  • OS 가 정상적인 부팅을 하지 못하는 경우
  • 하드웨어 or 소프트웨어 등의 이상으로 특정한 DATA를 가져오려는 경우
  • ROOT 패스워드를 잃어버린 경우
  • 시스템의 라이브러리릉 삭제하는 경우
  • initramfs를 재생성하는 경우 
  • etc...

 

 

구성 환경

[가상머신_KVM]
Processor : 1
RAM : 2G
Network : 
필요 없음.
 
[OS Version_RHEL/CentOS 7]
RHEL/CentOS 7.6

 

예제) libc.so.6 파일 삭제로 인한 명령어 수행 불가 상태 발생

Step 1. 문제 상황 발생 및 복구 진행

* /lib64/libc.so.6 파일 삭제로 인한 명령어 수행 불가 상태
1. 시스템 연동 상태에서 긴급 복구
2. Rescue Mode를 통한 복구

 

 

Step 2. libc.so.6 파일 위치 확인

[root@test_rescue ~]# hostname
test_rescue
[root@test_rescue ~]# ls -la /lib64/libc.so.6 
lrwxrwxrwx. 1 root root 12 Jan 20 02:26 /lib64/libc.so.6 -> libc-2.17.so
[root@test_rescue ~]# rpm -qf /lib64/libc.so.6
glibc-2.17-260.el7.x86_64
[root@test_rescue ~]#
* 참고
/lib64/libc.so.6 파일은 libc-2.17.so 파일에 심볼릭 링크가 걸려 있다.
libc.so.6 파일은 glibc 패키지와 관련된 라이브러리 파일로 시스템의 명령어를 사용 할 수 있게 합니다.

 

 

 

Step 3. 시스템 연동 상태에서의 긴급 복구 진행 (온라인 중 복구) 

# libc.so.6 파일 삭제
[root@test_rescue ~]# rm -rf /lib64/libc.so.6

[root@test_rescue ~]# ls
ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@test_rescue ~]# cp 
cp: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@test_rescue ~]# scp
scp: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@test_rescue ~]# ls
ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

[root@test_rescue ~]# ln
ln: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
  • ln 명령어 또한 수행이 불가합니다.

 

# sln 명령어를 통한 link 생성
[root@test_rescue ~]# sln /lib64/libc-2.17.so /lib64/libc.so.6 


[root@test_rescue ~]# ls
anaconda-ks.cfg
[root@test_rescue ~]# cp
cp: missing file operand
Try 'cp --help' for more information.
[root@test_rescue ~]# scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
[root@test_rescue ~]# ln
ln: missing file operand
Try 'ln --help' for more information.
* 참고
장비 접속 상태에서 lib를 삭제한 상황이라면 sln 명령어로 link 수행이 가능합니다.
sln 명령어를 통해 link를 걸어주면 명령어 수행이 가능합니다.

 

 

Step 4. Rescue Mode 를 통한 복구

[root@test_rescue ~]# rm -rf /lib64/libc.so.6
* 참고
/lib64/libc.so.6 파일을 삭제합니다.

 

 

* VM ISO 이미지 마운트 후 ISO 이미지 부팅 

이미지 선택
부팅 순서 변경

  • TEST 장비는 KVM을 사용하고 있으며, ISO 이미지를 통한 복구를 진행합니다.
  • 시스템과 동일한 ISO 버전을 연동해줍니다
  • 부팅 순서 변경을 해줍니다.
  • 마지막에 부팅 순서를 원래대로 복구시켜야 합니다.
* 참고
VirtualBox, VirtualMachine 도 동일한 방법으로 마운트 해주고 진행하면 됩니다.

 

 

Step 5. Rescue 모드로 진입 

Rescue Mode 진입 #1
Rescue Mode 진입#2

  • Troubleshooting – Resuce a CentOS system

 

 

 

Rescue Mode 진입#3

 

* 참고
Continue 선택하면, /mnt/sysimage/ 디렉토리 아래에 파일 시스템을 마운트 하려고 시도하고 파티션을 마운트 하는 것에 실패하면 실패 통지를 합니다.
Read-only mount선택하면, 읽기 전용 모드로 /mnt/sysimage/ 디렉토리에 파일 시스템을 마운트 시도합니다.
Skip to shell 을 선택하면, 파일 시스템을 마운트 하지 않습니다. 3번을 선택합니다.

 

 

 

Step 6. / 파티션을 /mnt/sysimage 로 mount

* 참고
파티션을 /mnt/sysimage 하위 디렉토리에 마운트 해줍니다.
LVM으로 파티셔닝/ 영역을 마운트 하기 위해서 vgchange –ay 명령어를 통해 LVM을 활성화 해준 뒤
마운트 해줍니다.

LVM이 아닐경우에는 lsblk 명령어를 통해, 기존에 있던 / 파티션을 /mnt/sysimage에 마운트해줍니다. 
# mount /dev/sda2 /mnt/sysimage 

 

 

 

Step 7. /lib64 로 이동 후 ln 명령어를 통한 심볼릭 링크 생성

ln 명령어를 통한 심볼릭 링크 연결

 

* 참고
/mnt/sysimage/lib64에서 ln 명령어를 통해 libc-2.17.so 파일과 libc.so.6 파일을 심볼링 링크로 연결합니다.

 

 

Step 8. ls  명령어를 통해 심볼릭 링크 확인 진행

서버 재시작 이후 확인

* 참고
/lib64 하위에 있는 libc.so.6 파일을 확인하고 다른 명령어가 수행되는 것을 확인한다.

 

 

 

Ref

* 참고 사이트 & 문헌
Rescue Mode Assistant | Red Hat Customer Portal Labs
Basic System Recovery :: CentOS Docs Site

 

반응형

'리눅스 > 설치' 카테고리의 다른 글

[LINUX] SuSE 15 설치  (0) 2023.02.16
[LINUX] 1. ANSIBLE 설치  (0) 2022.03.01
[리눅스] ReaR(Relax-and-Recover) 백업  (0) 2022.02.03
[Ubuntu] DevStack 설치하기  (0) 2021.12.30
TOP