Profile picture

[Linux] 클라우드 디스크 추가 (2TB) - fdisk

JaehyoJJAng2023년 06월 20일

사전 준비

💡 Infos

클라우드에서 스토리지를 추가적으로 구매할 경우 해당 디스크의 마운트 작업은 셀프인 경우가 많다.
실습을 위해 VMware를 이용하여 테스트를 진행하겠다.


기존에 설치된 CentOS 7 머신에 10GB의 디스크를 추가해보자.
image


1. 디스크 확인

$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk
├─sda1            8:1    0    4G  0 part /boot
└─sda2            8:2    0   26G  0 part
  ├─centos-root 253:0    0   25G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk
sr0              11:0    1 1024M  0 rom

sdb 8:16 0 10G 0 disk
sdb라는 이름으로 10G짜리 디스크가 추가된 것을 알 수 있다.


2. 디바이스 찾기

$ find / -name "sdb" -type b 2>/dev/null
/dev/sdb

find 명령어로 시스템에 추가된 sdb 디스크를 찾을 수 있다.


3. 파티션 나누기

$ fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.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
Building a new DOS disklabel with disk identifier 0x3e6d4917.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 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
Disk label type: dos
Disk identifier: 0x3e6d4917

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

다음과 같이 디스크를 1개의 용량으로 몰아줌.

Command (m for help): n // add a new partition
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p // primary type
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048): // Enter(기본값)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): // Enter (기본값))
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): w // write table to disk and exit
The partition table has been altered!

4. 파티션 확인

$ fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 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
Disk label type: dos
Disk identifier: 0x3e6d4917

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   83  Linux

sdb1이라는 이름으로 파티션이 새로 추가됨.
/dev/sdb1 2048 20971519 10484736 83 Linux


5. 파일 시스템 포맷

파일 시스템은 다음과 같이 권장함. (실제 현업에서도 이렇게 사용)
• 2TB 이상일 경우 ext4 (추가적으로 2TB 이상일 경우 fdisk 말고 parted 명령어를 이용하여 설정할 것은 권장)
• 2TB 미만일 경우 xfs

$ mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621184, 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

6. 마운트

1. 디렉토리 생성
마운트 할 디렉토리 생성

$ mkdir /disk

2. UUID 확인
/etc/fstab 파일에 마운트 등록을 위해 UUID 확인

$ blkid | grep 'sdb1' | awk '{print $2}' | awk -F'=' '{print $2}'
"0b1c1b7c-c6ab-4743-996d-e3e956f63617"

3. fstab 등록
재부팅 시에도 자동으로 마운트 하기 위해 /etc/fstab 파일에 마운트 정보 등록

$ cat >> /etc/fstab << EOF
UUID=0b1c1b7c-c6ab-4743-996d-e3e956f63617 /disk xfs defaults 0 0
EOF

4. 마운트
fstab에 있는 모든 파일 시스템 마운트

$ mount -a

7. 마운트 확인

$ df -h | grep "/dev/sd.*"
/dev/sda1                4.0G  151M  3.9G   4% /boot
/dev/sdb1                 10G   33M   10G   1% /disk # sdb1이 /disk에 마운트 되었음.

Loading script...