본문 바로가기

⭐ AWS/EBS

리눅스에 생성한 볼륨을 마운트 하기 (ext4)

# 생성한 볼륨을 리눅스에 마운트하는 방법

1. 리눅스에서 생성한 볼륨 정보를 확인한다.

lsblk
ec2-user:/dev $ lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  10G  0 disk 
└─xvda1 202:1    0  10G  0 part /
xvdf    202:80   0  10G  0 disk
sudo su - # root 계정으로 로그인 후

fdisk -l

- Disk /dev/xvdf: 10 GiB, 10737418240 bytes, 20971520 sectors 내용을 확인하면 10기가의 볼륨을 추가로 마운트가 가능하다.

[root@ip-172-16-0-22 ~]# fdisk -l
GPT PMBR size mismatch (20971519 != 41943039) will be corrected by w(rite).
Disk /dev/xvda: 20 GiB, 21474836480 bytes, 41943040 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: gpt
Disk identifier: 65E66B8B-7479-4A5D-8D3C-3570E8F219E7

Device       Start      End  Sectors Size Type
/dev/xvda1    4096 20971486 20967391  10G Linux filesystem
/dev/xvda128  2048     4095     2048   1M BIOS boot

Partition table entries are not in disk order.


Disk /dev/xvdf: 10 GiB, 10737418240 bytes, 20971520 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

2. 미사용 볼륨정보 확인 : data라고 나온다면 정상적으로 할당이 가능하다.

sudo file -s /dev/xvdf
ec2-user:/dev $ sudo file -s /dev/xvdf
/dev/xvdf: data

3. 확인된 디스크 경로에 파티션을 생성합니다.

mkfs -t ext4

- 파티션 관련 옵션 설명
- Command(m for help): n (
새로운 파티션 분할 명령어)
- Select (default p): p (
파티션 생성 시 p, 추가 시 e)
- Partitions number (1-4, default 1): 1
- First sector: Enter
- Command: w (
생성 한 파티션을 저장)

[root@ip-172-16-0-22 ~]# fdisk /dev/xvdf

Welcome to fdisk (util-linux 2.30.2).
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 0x5d5c25ed.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048): 

Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): #ENTER 입력

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

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

4. 생성한 파티션을 확인한다.

fdisk -l

- 하단에 dev/xvdf1로 10GB의 파티션이 생성된 것을 확인 할 수 있다.

[root@ip-172-16-0-22 ~]# fdisk -l
GPT PMBR size mismatch (20971519 != 41943039) will be corrected by w(rite).
Disk /dev/xvda: 20 GiB, 21474836480 bytes, 41943040 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: gpt
Disk identifier: 65E66B8B-7479-4A5D-8D3C-3570E8F219E7

Device       Start      End  Sectors Size Type
/dev/xvda1    4096 20971486 20967391  10G Linux filesystem
/dev/xvda128  2048     4095     2048   1M BIOS boot

Partition table entries are not in disk order.

Disk /dev/xvdf: 10 GiB, 10737418240 bytes, 20971520 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: 0x5d5c25ed

Device     Boot Start      End  Sectors Size Id Type
/dev/xvdf1       2048 20971519 20969472  10G 83 Linux

5. 생성된 파티션을 ext4 타입으로 포멧을 합니다.

mkfs –t ext4 /dev/xvdf1

6. 생성된 파티션에 마운트를 설정 합니다.

#mkdir /datafile (/datafile 폴더를 생성)
#
chmod 777 /datafile (/datafile에 모든 권한을 할당)
#mount /dev/xvdg1 /
datafile (/datafile/dev/xvdg1 파티션을 마운트)
#mount

mkdir /datafile
chmod 777 /datafile
mount /dev/xvdg1 /datafile
mount

7. df –h 명령어를 통해 /datafile이 정상적으로 마운트 되었는지 확인

df -h
df -TH

8. 재 시작시 자동마운트가 되도록 설정

vi /etc/fstab

/dev/xvdf1	/datafile		ext4	defaults	0     0

- fstab 내용

#
UUID=7a487823-831a-47e0-b9c5-97a7edc90077     /           xfs    defaults,noatime  1   1
/var/swapfile swap swap defaults 0 0
/dev/xvdf1      /datafile               ext4    defaults        0     0

- 지금까지 ext4 타입으로 마운트 하는 방법에 대해서 알아 보았습니다.

'⭐ AWS > EBS' 카테고리의 다른 글

EBS CSI Driver 설치하기 (추가 기능 활용)  (0) 2023.10.25
EBS 볼륨 확장 방법  (0) 2022.08.03
EC2에 볼륨 추가하기  (0) 2021.10.20