본문 바로가기
리눅스/서버운영

[리눅스] 파티션 복사 실습⑤ (SELinux비활성화)

by 상달군 2024. 1. 4.
728x90

✨✨2024.01.09 지금까지 cp로 작동 되지 않았던이유:

✨ SELinux 때문에 에러발생!!! Disable 또는 Permissive로 변경시 부팅완료 ! 그치만 Permissive 모드로 진행후 Log를 확인시 에러가 발생하는것을 확인할 수 있다.

✨ 확인결과 데몬들 모두 정상 작동을 하고 있습니다.

✨ 복사를 시작하전 SELinux를 비활성화 하고 시작 하면 모든 작업이 끝난후 부팅 되는것을 확인하고 SELinux를 활성화 해도 문제 없이 실행 가능하다. 

 

rsync를 사용할때는 SELinux랑 상관없이 가능한거 같은데 cp는 SELinux의 영향을 받는다. 


1.  파티션닝부터 다시시작

✔ sdb하드에 모든 내용지우기 

[root@localhost ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) p
Model: ATA Hitachi HDS72105 (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start  End  Size  Type  File system  Flags

 

✔ sdb하드 파티션닝

[root@localhost ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) mkp
Partition type?  primary/extended? p
File system type?  [ext2]? xfs
Start? 1
End? 10G

(parted) mkp
Partition type?  primary/extended? p
File system type?  [ext2]? xfs
Start? 10G
End? 40G

(parted) mkp
Partition type?  primary/extended? p
File system type?  [ext2]? xfs
Start? 40G
End? 60G

(parted) mkp
Partition type?  primary/extended? e
Start? 60G
End? 100%

(parted) mkp
Partition type?  [logical]?
File system type?  [ext2]? linux-swap
Start? 60G
End? 76G

(parted) mkp
Partition type?  [logical]?
File system type?  [ext2]? xfs
Start? 76G
End? 100%

(parted) p
Model: ATA Hitachi HDS72105 (scsi)
Disk /dev/sdb: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  10.0GB  9999MB  primary   xfs             lba
 2      10.0GB  40.0GB  30.0GB  primary   xfs             lba
 3      40.0GB  60.0GB  20.0GB  primary   xfs             lba
 4      60.0GB  500GB   440GB   extended                  lba
 5      60.0GB  76.0GB  16.0GB  logical   linux-swap(v1)  lba
 6      76.0GB  500GB   424GB   logical   xfs             lba

✔ sdb하드 파티션 포멧하기 

[root@localhost ~]# mkfs -t xfs -f /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=610304 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=2441216, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@localhost ~]# mkfs -t xfs -f /dev/sdb2
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=1831040 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=7324160, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=3576, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@localhost ~]# mkfs -t xfs -f /dev/sdb3
meta-data=/dev/sdb3              isize=512    agcount=4, agsize=1220672 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=4882688, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@localhost ~]# mkfs -t xfs -f /dev/sdb6
meta-data=/dev/sdb6              isize=512    agcount=4, agsize=25885440 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=103541760, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=50557, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@localhost ~]# mkswap /dev/sdb5
mkswap: /dev/sdb5: warning: wiping old swap signature.
Setting up swapspace version 1, size = 14.9 GiB (15999168512 bytes)
no label, UUID=7c79116d-42a2-4f73-826a-21bc8a2d3d08

2.  mkdir &  mount & 복사

✔ 디렉토리 생성 & 파티션 마운트

[root@localhost ~]# mkdir /sdbTest
[root@localhost ~]# mount /dev/sdb1 /sdbTest/

✔ 루트아래 있는 모든 디렉토리 생성

- /bin, /lib, /lib64, /sbin은 심볼릭 링크이기 때문에 복사할때 한번에 복사 할것이다.

[root@localhost ~]# find / -maxdepth 1 -mindepth 1 ! \( -path /sdbLog -o -path /sdb -o -path /sdbTest -o -path /bin -o -path /lib -o -path /lib64 -o -path /sbin \) -exec mkdir /sdbTest/{} \;
[root@localhost ~]# ll /sdbTest/
total 0
drwxr-xr-x. 2 root root 6 Jan  3 23:30 boot
drwxr-xr-x. 2 root root 6 Jan  3 23:30 dev
drwxr-xr-x. 2 root root 6 Jan  3 23:30 etc
drwxr-xr-x. 2 root root 6 Jan  3 23:30 home
drwxr-xr-x. 2 root root 6 Jan  3 23:30 media
drwxr-xr-x. 2 root root 6 Jan  3 23:30 mnt
drwxr-xr-x. 2 root root 6 Jan  3 23:30 opt
drwxr-xr-x. 2 root root 6 Jan  3 23:30 proc
drwxr-xr-x. 2 root root 6 Jan  3 23:30 root
drwxr-xr-x. 2 root root 6 Jan  3 23:30 run
drwxr-xr-x. 2 root root 6 Jan  3 23:30 scr
drwxr-xr-x. 2 root root 6 Jan  3 23:30 srv
drwxr-xr-x. 2 root root 6 Jan  3 23:30 sys
drwxr-xr-x. 2 root root 6 Jan  3 23:30 tmp
drwxr-xr-x. 2 root root 6 Jan  3 23:30 usr
drwxr-xr-x. 2 root root 6 Jan  3 23:30 var

 

✔루트 복사

[root@localhost ~]# find / -maxdepth 1 ! \( -path / -o -path /run -o -path /proc -o -path /dev -o -path /sys -o -path /sdbTest -o -path /sdb -o -path /sdbLog -o -path /usr -o -path /var -o -path /scr \) -exec /usr/bin/cp -aufv {} /sdbTest/ \;
[root@localhost ~]# ll /sdbTest/
total 24
lrwxrwxrwx.   1 root root    7 Oct  9  2021 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Dec 18 03:02 boot
drwxr-xr-x.   2 root root    6 Jan  3 22:51 dev
drwxr-xr-x. 102 root root 8192 Jan  3 21:32 etc
drwxr-xr-x.   2 root root    6 Oct  9  2021 home
lrwxrwxrwx.   1 root root    7 Oct  9  2021 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Oct  9  2021 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Oct  9  2021 media
drwxr-xr-x.   2 root root    6 Oct  9  2021 mnt
drwxr-xr-x.   2 root root    6 Oct  9  2021 opt
drwxr-xr-x.   2 root root    6 Jan  3 22:51 proc
dr-xr-x---.   4 root root  139 Jan  3 21:22 root
drwxr-xr-x.  36 root root 4096 Jan  3 21:32 run
lrwxrwxrwx.   1 root root    8 Oct  9  2021 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Jan  3 22:51 scr
drwxr-xr-x.   2 root root    6 Oct  9  2021 srv
drwxr-xr-x.   2 root root    6 Jan  3 22:51 sys
drwxrwxrwt.   8 root root 4096 Jan  3 22:51 tmp
drwxr-xr-x.   2 root root    6 Jan  3 22:51 usr
drwxr-xr-x.   2 root root    6 Jan  3 22:51 var

 

✔ sdb2, sdb3, sdb6 를 마운트

[root@localhost ~]# mount /dev/sdb2 /sdbTest/usr
[root@localhost ~]# mount /dev/sdb3 /sdbTest/var
[root@localhost ~]# mount /dev/sdb6 /sdbTest/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    9244  24562276   1% /run
tmpfs           24571520       0  24571520   0% /sys/fs/cgroup
/dev/sda1        9754624  328876   9425748   4% /
/dev/sda2       29282336 2361340  26920996   9% /usr
/dev/sda3       19520512  379772  19140740   2% /var
/dev/sda6      413964812 2919300 411045512   1% /scr
tmpfs            4914304       0   4914304   0% /run/user/0
/dev/sdb1        9754624  329468   9425156   4% /sdbTest
/dev/sdb2       29282336  237224  29045112   1% /sdbTest/usr
/dev/sdb3       19520512  169132  19351380   1% /sdbTest/var
/dev/sdb6      413964812 2919252 411045560   1% /sdbTest/scr

 

✔ usr, var, scr 복사

[root@localhost ~]# /usr/bin/cp -auf /usr/* /sdbTest/usr
[root@localhost ~]# /usr/bin/cp -auf /var/* /sdbTest/var
[root@localhost ~]# /usr/bin/cp -auf /scr/* /sdbTest/scr

3.  부팅 로더 설치전 준비 작업

 

✔ 부팅 로더 설치를 위한 mount 바인드해주기 

- 3개의 가상 파일 시스템 /sys /dev /proc 3개를 바인드해줍니다. 

[root@localhost ~]# mount --bind /sys /sdbTest/sys
[root@localhost ~]# mount --bind /proc /sdbTest/proc
[root@localhost ~]# mount --bind /dev /sdbTest/dev

💢 bind해줄때 /run도 같이 해줘야함 /run 처음에 cp로 복사하면

logger: socket /dev/log: Connection refused

에러남 bind를 해주면 에러 안남 ! 복사하지말고 bind해주삼 !! 

 

✔chroot

[root@localhost ~]# chroot /sdbTest/
[root@localhost /]#

✔ /etc/default/grub 를 먼저 수정해줄것이다. 

- 수정하기전 blkid 명령어를 이용하여 내 현재 UUID확인 

 

[root@localhost /]# blkid
/dev/sdb1: UUID="da6959e4-362e-449c-a1f4-109b7aabec9b" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="0eaf7bc9-01"
/dev/sdb2: UUID="3fa02449-c043-445d-a4ed-590af23117ec" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="0eaf7bc9-02"
/dev/sdb3: UUID="62deb28b-35f5-4fb3-8d44-85a85e3197c3" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="0eaf7bc9-03"
/dev/sdb5: UUID="7c79116d-42a2-4f73-826a-21bc8a2d3d08" TYPE="swap" PARTUUID="0eaf7bc9-05"
/dev/sdb6: UUID="de8314ef-863c-457e-bc0d-c8e87098bfb7" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="0eaf7bc9-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"

- 이 파일은 grub2-mkconfig 명령어를 실행시 이 파일의 정보를 참조하여 cfg 파일을 생성하게 된다. 

- grub파일에 있는 resume=UUID를 sdb5의 swap UUID로 변경 해주기 

[root@localhost /]# vi /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=7c79116d-42a2-4f73-826a-21bc8a2d3d08"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
~

✔ 수정후 mkconfig 명령어를 사용하면 생길 파일이라서 저는 그냥 지워버렸습니다. 

[root@localhost /]# rm -rf /boot/grub2/grub.cfg

✨ 부팅로더 설치전 모든 준비가 끝났습니다.


4.  grub2 명령어 사용

✔ install

- 저는 sdb에 grub 부팅로더를 설치할 예정이기 때문에 /dev/sdb 로 명령어 실행

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

 

✔ mkconfig

[root@localhost /]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
device-mapper: reload ioctl on osprober-linux-sda1 (253:0) failed: Device or resource busy
Command failed.
device-mapper: reload ioctl on osprober-linux-sda2 (253:0) failed: Device or resource busy
Command failed.
device-mapper: reload ioctl on osprober-linux-sda3 (253:0) failed: Device or resource busy
Command failed.
device-mapper: reload ioctl on osprober-linux-sda6 (253:0) failed: Device or resource busy
Command failed.
done
[root@localhost /]# exit
exit
[root@localhost ~]# init 0
728x90

댓글