리눅스/서버운영

[리눅스] 파티션 복사 실습② (원인파악중..)

상달군 2023. 12. 22. 17:35
728x90

부팅 로그에서 문제가 발생한 데몬들은 다음과 같습니다:

smartd: Self Monitoring and Reporting Technology (SMART) Daemon
firewalld: Dynamic firewall daemon
auditd: Security Auditing Service
dbus: D-Bus System Message Bus
chronyd: NTP client/server
systemd-logind: Login Service
unbound-anchor: Update of the root trust anchor for DNSSEC validation in unbound
NetworkManager: Network Manager


23. 12. 18 ~ 23. 12. 22
1. 데몬들이 문제 이기 때문에 /usr,/var을 삭제후 다시 복사 하고 마운트 해보기



[root@localhost ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs        24552796       0  24552796   0% /dev
tmpfs           24571516       0  24571516   0% /dev/shm
tmpfs           24571516   17436  24554080   1% /run
tmpfs           24571516       0  24571516   0% /sys/fs/cgroup
/dev/sda1        9754624  328888   9425736   4% /
/dev/sda2       29282336 2361292  26921044   9% /usr
/dev/sda3       19520512  362092  19158420   2% /var
/dev/sda6      413964812 2919300 411045512   1% /scr
tmpfs            4914300       0   4914300   0% /run/user/0
/dev/sdb1        9754624 2632964   7121660  27% /sdb
/dev/sdb3       19520512  361844  19158668   2% /test/3
/dev/sdb2       29282336  237272  29045064   1% /test/2


✔✔복사 후 마운트


[root@localhost ~]# cp -auf /usr/* /test/2
[root@localhost ~]# cp -auf /var/* /test/3

[root@localhost ~]# mkdir /sdb/usr
[root@localhost ~]# mkdir /sdb/var
[root@localhost ~]# mount /dev/sdb2 /sdb/usr
[root@localhost ~]# mount /dev/sdb3 /sdb/var


✔✔ 켜질때 grub에 들어가서 마운트 정보를 봐도 잘 마운트 되어 있음 

[root@localhost ~]# blkid
/dev/sdb1: UUID="e9950fa1-1f1d-4e02-a385-fa5f69170d31" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-01"
/dev/sdb2: UUID="10705a3d-fced-4084-b06b-8ce611adb3ae" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-02"
/dev/sdb3: UUID="6c198197-6b82-4b22-bdd1-7bcd96afa77f" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-03"
/dev/sdb5: UUID="ed25cc88-8da2-4944-9ef3-f5625a8d00a7" TYPE="swap" PARTUUID="b0c70856-05"
/dev/sdb6: UUID="92bb4f44-891e-4b10-9add-72e3272fa96a" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-06"
/dev/sda1: UUID="1ace0d6f-c787-4b8f-85ec-8ec442e99ed7" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-01"
/dev/sda2: UUID="f942a759-24c5-45f2-9ce8-a176f450a0bd" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-02"
/dev/sda3: UUID="5e14c968-6782-46f5-b983-23c53714ed47" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-03"
/dev/sda5: UUID="d7258d2d-be7b-48d5-85ed-78a12116e47c" TYPE="swap" PARTUUID="95ccf150-05"
/dev/sda6: UUID="72bab45a-dbe2-4b12-9bed-9981103293b1" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-06"

 

💢 다시 해봐도 똑같은 에러 발생 


2. OS를 가벼운걸로 재설치후 처음부터 다시 

1. /sdb 디렉토리 생성 및 / 하위 디렉토리만 생성 
2. 생성된 디렉토리에 파티션 마운트 
3. cp를 이용한 복사 
4. chroot
6. 부팅로더 설치 grup2-install



1. /sdb 디렉토리 생성 및 / 하위 디렉토리만 생성 


[root@localhost /]# mkdir /sdb
[root@localhost /]# mount /dev/sdb1 /sdb
[root@localhost /]# find / -maxdepth 1 -mindepth 1 -type d | grep -E -v '^/(sdb)$'| xargs -i mkdir -p /sdb/{}
[root@localhost /]# tree /sdb
/sdb
├── boot
├── dev
├── etc
├── home
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── scr
├── srv
├── sys
├── tmp
├── usr
└── var


2. 생성된 디렉토리에 파티션 마운트

 

각 디렉토리에 파티션 마운트 

[root@localhost /]# mount /dev/sdb1 /sdb
[root@localhost /]# mount /dev/sdb2 /sdb/usr
[root@localhost /]# mount /dev/sdb3 /sdb/var
[root@localhost /]# mount /dev/sdb6 /sdb/scr

[root@localhost /]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs        24552800       0  24552800   0% /dev
tmpfs           24571520       0  24571520   0% /dev/shm
tmpfs           24571520   17436  24554084   1% /run
tmpfs           24571520       0  24571520   0% /sys/fs/cgroup
/dev/sda1        9754624  319756   9434868   4% /
/dev/sda2       29282336 2361292  26921044   9% /usr
/dev/sda6      413964812 2919300 411045512   1% /scr
/dev/sda3       19520512  358220  19162292   2% /var
tmpfs            4914304       0   4914304   0% /run/user/0
/dev/sdb1        9754624  101208   9653416   2% /sdb
/dev/sdb2       29282336  237272  29045064   1% /sdb/usr
/dev/sdb3       19520512  169180  19351332   1% /sdb/var
/dev/sdb6      413964812 2919300 411045512   1% /sdb/scr

✔ 마운트 바인딩 3개 디렉토리 
[root@localhost /]# mount --bind /proc /sdb/proc/
[root@localhost /]# mount --bind /sys /sdb/sys/
[root@localhost /]# mount --bind /dev /sdb/dev/


3. cp를 이용한 복사

✔ proc, sys, dev, tmp, sdb 디렉토리를 제외한 파일 복사 
[root@localhost /]# find / -maxdepth 1 -mindepth 1 | grep -E -v '^/(proc|sys|dev|tmp|sdb)$'| xargs -i cp -auf {} /sdb


4. chroot

 

[root@localhost /]# chroot /sdb


5. 부팅로더 설치 grup2-install



✔ 부팅 로더를 인스톨 하기전 해야할 작업들 ...

 

6-1.  /etc/default/grub 확인 해보기 

- /etc/grub.d에 있는 스크립트들에서 사용할 옵션 설정을 포함합니다.
- 여기서 UUID를 바꿔 줘야 할거 같음. UUID가 sda로 되어 있음 
- grup2-mkconfig 하기전 UUID 수정하기 
  
[root@localhost /]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=d7258d2d-be7b-48d5-85ed-78a12116e47c rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true

 

✔ 노랑색 부분을 아래 UUID 노랑색 부분으로 수정해주어야 합니다. 

 

[root@localhost /]# blkid
/dev/sda1: UUID="1ace0d6f-c787-4b8f-85ec-8ec442e99ed7" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-01"
/dev/sda2: UUID="f942a759-24c5-45f2-9ce8-a176f450a0bd" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-02"
/dev/sda3: UUID="5e14c968-6782-46f5-b983-23c53714ed47" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-03"
/dev/sda5: UUID="d7258d2d-be7b-48d5-85ed-78a12116e47c" TYPE="swap" PARTUUID="95ccf150-05"
/dev/sda6: UUID="72bab45a-dbe2-4b12-9bed-9981103293b1" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="95ccf150-06"

/dev/sdb1: UUID="e9950fa1-1f1d-4e02-a385-fa5f69170d31" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-01"
/dev/sdb2: UUID="10705a3d-fced-4084-b06b-8ce611adb3ae" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-02"
/dev/sdb3: UUID="6c198197-6b82-4b22-bdd1-7bcd96afa77f" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-03"
/dev/sdb5: UUID="ed25cc88-8da2-4944-9ef3-f5625a8d00a7" TYPE="swap" PARTUUID="b0c70856-05"
/dev/sdb6: UUID="92bb4f44-891e-4b10-9add-72e3272fa96a" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="b0c70856-06"

6-2. resume UUID 변경 및 grub.cfg 파일 생성하기(grub2-mkconfig)


[root@localhost /]# grep UUID /boot/grub2/grub.cfg
  set kernelopts="root=UUID=1ace0d6f-c787-4b8f-85ec-8ec442e99ed7 ro crashkernel=auto resume=UUID=d7258d2d-be7b-48d5-85ed-78a12116e47c rhgb quiet "

[UUID 내용수정]
[root@localhost /]# vi /etc/default/grub 
[root@localhost /]# grub2-mkconfig

[resume UUID 변경완료]
[root@localhost /]# grep UUID /boot/grub2/grub.cfg
  set kernelopts="root=UUID=1ace0d6f-c787-4b8f-85ec-8ec442e99ed7 ro crashkernel=auto resume=UUID=d7258d2d-be7b-48d5-85ed-78a12116e47c rhgb quiet "

[/boot/grub2/grub.cfg 수정전 백업파일만들기]
[root@localhost /]# cp /boot/grub2/grub.cfg /boot/grub2/grubBackUP.cfg
[root@localhost /]# ll /boot/grub2/grub
grubBackUP.cfg  grub.cfg        grubenv

[sda UUID 검색]
[root@localhost /]# grep 1ace0d6f-c787-4b8f-85ec-8ec442e99ed7 /boot/grub2/grub.cfg
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  1ace0d6f-c787-4b8f-85ec-8ec442e99ed7
  search --no-floppy --fs-uuid --set=root 1ace0d6f-c787-4b8f-85ec-8ec442e99ed7
  search --no-floppy --fs-uuid --set=boot --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  1ace0d6f-c787-4b8f-85ec-8ec442e99ed7
  search --no-floppy --fs-uuid --set=boot 1ace0d6f-c787-4b8f-85ec-8ec442e99ed7
  set kernelopts="root=UUID=1ace0d6f-c787-4b8f-85ec-8ec442e99ed7 ro crashkernel=auto resume=UUID=d7258d2d-be7b-48d5-85ed-78a12116e47c rhgb quiet "

💢 바보 같이 수정이 안됐는데 그냥 넘어감.....


[root UUID 수정하기]
[root@localhost /]# vi /boot/grub2/grub.cfg
vi에서 치환 명령어 
:%s/원본/바꿀내용
:%s/1ace0d6f-c787-4b8f-85ec-8ec442e99ed7/e9950fa1-1f1d-4e02-a385-fa5f69170d31

[수정 내용 확인하기]
[root@localhost /]# vi /boot/grub2/grub.cfg
[root@localhost /]# grep 1ace0d6f-c787-4b8f-85ec-8ec442e99ed7 /boot/grub2/grub.cfg           [sda1 root UUID]
[root@localhost /]# grep e9950fa1-1f1d-4e02-a385-fa5f69170d31 /boot/grub2/grub.cfg            [sdb1 root UUID]
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  e9950fa1-1f1d-4e02-a385-fa5f69170d31
  search --no-floppy --fs-uuid --set=root e9950fa1-1f1d-4e02-a385-fa5f69170d31
  search --no-floppy --fs-uuid --set=boot --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  e9950fa1-1f1d-4e02-a385-fa5f69170d31
  search --no-floppy --fs-uuid --set=boot e9950fa1-1f1d-4e02-a385-fa5f69170d31
  set kernelopts="root=UUID=e9950fa1-1f1d-4e02-a385-fa5f69170d31 ro crashkernel=auto resume=UUID=d7258d2d-be7b-48d5-85ed-78a12116e47c rhgb quiet "

[grub2-install하기]
[root@localhost /]# grub2-install /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.

 

실패!!

[하드 교체해보기]
-  월컴 부팅 까지는 뜨는 검정색 화면에서 커서만 꿈벅꿈벅
-*- 왜그럴까??


[하나씩 찾아보기]
1. 너무 많은 작업을 한번에 하려니깐 순간 실수가 많아짐.

2. grub2명령어를 제대로 이해하지 못함

3. /boot/grub2/grub.cfg를 수정했지만 제대로 grub2-mkconfig를 하지 않음. 

4. 정상 하드디스크와 log 비교분석중... 이유를 찾지 못함... 

5. 의심이 되는부분은 복사 할때 뭔가 잘못되었다.... 

728x90