상세 컨텐츠

본문 제목

[CentOS 8] Disk 관리 | mount, umount

Linux

by mp.jamong 2020. 7. 15. 10:00

본문

서버를 운영하게 되면 디스크 공간이 부족한 경우가 생깁니다. 디스크 공간이 부족해서 막무가내로 시스템을 통째로 바꾸기보다는 원하는 만큼의 디스크를 추가하여, 사용 공간을 확보할 수 있습니다.

 

CentOS 8에서 디스크를 추가하고, 볼륨 설정 후 시스템에 마운트하는 과정에 대해 알아보겠습니다.

 

1. Disk 관리 | Disk 추가와 확인

# 디스크 확인하기 - 디스크만 연결된 상태(사용 불가)
[root@magicpipe ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xde72a551

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 62914559 60815360  29G 8e Linux LVM

Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-root: 26.8 GiB, 28806479872 bytes, 56262656 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-swap: 2.2 GiB, 2327838720 bytes, 4546560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

# 하드디스크 선택
[root@magicpipe ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xc7c7634d.
# 명령어 설명 확인 (이 단계는 생략해도 괜찮음)
Command (m for help):  m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

# 새로운 파티션 분할
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
# Primary 파티션 선택
Select (default p): p
# 파티션 번호 1번 선택
Partition number (1-4, default 1): 1
# 시작 섹터 지정 (별도 지정없이 '엔터')
First sector (2048-4194303, default 2048): ENTER
# 마지막 섹터 지정 (별도 지정없이 '엔터')
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): ENTER

Created a new partition 1 of type 'Linux' and of size 2 GiB.

# 설정 내용 확인
Command (m for help): p
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc7c7634d

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4194303 4192256   2G 83 Linux

# 설정 저장 
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# 디스크 확인 : 볼륨 생성 확인
[root@magicpipe ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xde72a551

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 62914559 60815360  29G 8e Linux LVM

Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc7c7634d

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4194303 4192256   2G 83 Linux

Disk /dev/mapper/cl-root: 26.8 GiB, 28806479872 bytes, 56262656 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-swap: 2.2 GiB, 2327838720 bytes, 4546560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

# 신규 파티션을 EXT4 파일시스템로 만들기
[root@magicpipe ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 524032 4k blocks and 131072 inodes
Filesystem UUID: 250ee135-713a-4df4-822c-008b27d68a3e
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

 

 

2. Disk 관리 | Disk mount (볼륨 연결)

# 새로 생성한 볼륨과 연동할 신규 디렉토리 생성
[root@magicpipe ~]# mkdir /testmount

# 마운트 테스트용 임의 파일 2개 생성
[root@magicpipe ~]# touch test1.txt
[root@magicpipe ~]# touch test2.txt

# 마운트 전 신규 생성한 디렉토리로 test1.txt 파일 이동과 확인
[root@magicpipe ~]# mv test1.txt /testmount/
[root@magicpipe ~]# ls -al /testmount
total 0
drwxr-xr-x   2 root root  23 Jul 15 09:19 .
dr-xr-xr-x. 18 root root 261 Jul 15 09:17 ..
-rw-r--r--   1 root root   0 Jul 15 09:17 test1.txt

# 마운트 전 볼륨 확인
[root@magicpipe ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             382M     0  382M   0% /dev
tmpfs                410M     0  410M   0% /dev/shm
tmpfs                410M  6.3M  404M   2% /run
tmpfs                410M     0  410M   0% /sys/fs/cgroup
/dev/mapper/cl-root   27G  5.0G   22G  19% /
/dev/sda1            976M  244M  666M  27% /boot
tmpfs                 82M  1.2M   81M   2% /run/user/42
tmpfs                 82M  4.0K   82M   1% /run/user/1000

# 새로 생성한 볼륨을 신규 디렉토리에 마운트 연결
[root@magicpipe ~]# mount /dev/sdb1 /testmount

# 마운트 전에 생성한 test1.txt 파일이 보이지 않음 (마운트로 인해 새로운 디스크에 있는 내용이 보임)
[root@magicpipe ~]# ls -al /testmount
total 20
drwxr-xr-x   3 root root  4096 Jul 15 09:14 .
dr-xr-xr-x. 18 root root   261 Jul 15 09:17 ..
drwx------   2 root root 16384 Jul 15 09:14 lost+found

# 마운트 후 신규 생성한 디렉토리로 test2.txt 파일 이동과 확인
[root@magicpipe ~]# mv test2.txt /testmount/
  [root@magicpipe ~]# ls -al /testmount
total 20
drwxr-xr-x   3 root root  4096 Jul 15 09:20 .
dr-xr-xr-x. 18 root root   261 Jul 15 09:17 ..
drwx------   2 root root 16384 Jul 15 09:14 lost+found
-rw-r--r--   1 root root     0 Jul 15 09:17 test2.txt

# 마운트 후 볼륨 확인
[root@magicpipe ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             382M     0  382M   0% /dev
tmpfs                410M     0  410M   0% /dev/shm
tmpfs                410M  6.3M  404M   2% /run
tmpfs                410M     0  410M   0% /sys/fs/cgroup
/dev/mapper/cl-root   27G  5.0G   22G  19% /
/dev/sda1            976M  244M  666M  27% /boot
tmpfs                 82M  1.2M   81M   2% /run/user/42
tmpfs                 82M  4.0K   82M   1% /run/user/1000
/dev/sdb1            2.0G  6.0M  1.9G   1% /testmount

# 재부팅 후 마운트 해제 안 되도록 설정하기
[root@magicpipe ~]# vi /etc/fstab

# 설정 전
# /etc/fstab
# Created by anaconda on Sat Jun 27 11:16:20 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=a1dec119-5afb-4119-ac5e-17d1176b3d64 /boot                   ext4    defaults        1 2
/dev/mapper/cl-swap     swap                    swap    defaults        0 0

# 설정 후
# /etc/fstab
# Created by anaconda on Sat Jun 27 11:16:20 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=a1dec119-5afb-4119-ac5e-17d1176b3d64 /boot                   ext4    defaults        1 2
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
/dev/sdb1               /testmount              ext4    defaults        1 2

 

 

3. Disk 관리 | umount (볼륨 해제)

# 마운트 해제
[root@magicpipe ~]# umount /testmount

# 마운트 해제 후 볼륨 확인
[root@magicpipe ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             382M     0  382M   0% /dev
tmpfs                410M     0  410M   0% /dev/shm
tmpfs                410M  6.3M  404M   2% /run
tmpfs                410M     0  410M   0% /sys/fs/cgroup
/dev/mapper/cl-root   27G  5.0G   22G  19% /
/dev/sda1            976M  244M  666M  27% /boot
tmpfs                 82M  1.2M   81M   2% /run/user/42
tmpfs                 82M  4.0K   82M   1% /run/user/1000

 

 

4. Disk 관리 | Disk UUID 확인과 fstab 설정

# Disk UUID 확인 - 간혹 fstab 파일에 마운트 경로가 시스템에서 인지못하는 경우가 있어 UUDI를 fstab 파일에 지정한다
[root@magicpipe ~]# blkid
/dev/mapper/cl-root: UUID="a9be5715-92a2-41d6-b0b6-b0164bad97d8" TYPE="xfs"
/dev/sda2: UUID="Kn1eN9-4b4I-udbT-yE3P-F7eb-TBk3-XOYTxC" TYPE="LVM2_member" PARTUUID="de72a551-02"
/dev/sda1: UUID="a1dec119-5afb-4119-ac5e-17d1176b3d64" TYPE="ext4" PARTUUID="de72a551-01"
/dev/sdb1: UUID="250ee135-713a-4df4-822c-008b27d68a3e" TYPE="ext4" PARTUUID="c7c7634d-01"
/dev/mapper/cl-swap: UUID="9a55b7b0-9e0b-46e8-96d3-57e104b44747" TYPE="swap"

# fstab 설정을 UUID로 설정
[root@magicpipe ~]# vi /etc/fstab

# 설정 전
# /etc/fstab
# Created by anaconda on Sat Jun 27 11:16:20 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=a1dec119-5afb-4119-ac5e-17d1176b3d64 /boot                   ext4    defaults        1 2
/dev/mapper/cl-swap     swap                    swap    defaults        0 0

# 설정 후
# /etc/fstab
# Created by anaconda on Sat Jun 27 11:16:20 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=a1dec119-5afb-4119-ac5e-17d1176b3d64 /boot                   ext4    defaults        1 2
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
UUID=250ee135-713a-4df4-822c-008b27d68a3e /testmount              ext4    defaults        1 2

 

 

관련글 더보기

댓글 영역