OS/Linux

[Linux] 디스크 추가

dalgong 2023. 2. 13. 21:50
반응형

Linux 디스크 추가 방법

 

1. 추가한 디스크 확인

[root@svr ~]# fdisk -l 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b9ca1

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   104851455    51376128   83  Linux

Disk /dev/xvdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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

fdisk -l 명령어를 통해 아래쪽에 Disk /dev/xvdb 디스크가 추가된 것을 확인할 수 있습니다.

 

2. 파티션 나누기

[root@svr ~]# fdisk /dev/xvdb 
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 0xa311b3e0.

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-4194303999, default 2048): 엔터
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303999, default 4194303999): 엔터
Using default value 4194303999
Partition 1 of type Linux and of size 2 TiB is set

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

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

파티션을 나누기 위해 fdisk /dev/xvdb 명령어 사용 후

나오는 Command에 순서대로 n-p-1-Enter-Enter-w를 입력하면

파티션이 나누어집니다. 

 

3. 나눠진 파티션 확인

[root@svr ~]# fdisk -l 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b9ca1

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048     2099199     1048576   83  Linux
/dev/xvda2         2099200   104851455    51376128   83  Linux

Disk /dev/xvdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xa311b3e0

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1            2048  4194303999  2097150976   83  Linux

이후 fdisk -l을 다시 사용하여 새로 생성된 /dev/xvdb 디스크가 /dev/xvdb1으로 파티션이 나누어진 것을 확인합니다.

 

4. 파일시스템 포맷

[root@svr ~]# mkfs -t xfs /dev/xvdb1 
meta-data=/dev/xvdb1             isize=512    agcount=4, agsize=131071936 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=524287744, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=255999, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

mkfs -t xfs /dev/xvdb1을 통해 새로 생성된 파티션을 포맷해줍니다.

xfs나 ext4등 사용하시는 파일 시스템을 입력하여 포맷해주시면 됩니다.

 

5. 마운트와 마운트 확인

[root@svr ~]# mkdir /data 
[root@svr ~]# mount -t xfs /dev/xvdb1 /data 
[root@svr ~]# df -h 
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
tmpfs            16G  9.0M   16G   1% /run
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/xvda2       49G  2.1G   47G   5% /
/dev/xvda1     1014M  145M  870M  15% /boot
tmpfs           3.2G     0  3.2G   0% /run/user/11000
/dev/xvdb1      2.0T   33M  2.0T   1% /data

우선 마운트해줄 디렉터리 생성 후 

mount 명령어를 통해 해당 디렉터리로 마운트 해줍니다. 

이전 파일시스템 포맷에서 xfs 로 마운트 한 경우 xfs로 

ext4로 마운트한 경우 ext4로 마운트를 하고

df -h 를 통해 마운트 된 것을 확인할 수 있습니다.

 

6. UUID 확인

[root@svr ~]# blkid
/dev/xvdb1: UUID="48f4cadc-caa8-444d-b172-************" TYPE="xfs"

새로 생성한 파일시스템을 fstab에 등록하기 위해

UUID를 확인해주고 UUID를 복사해줍니다.

 

7. fstab에 추가

[root@svr ~]# vim /etc/fstab

시스템 재부팅후에도 자동으로 파일시스템이 등록될 수 있도록 

위와 같은 형식으로 fstab에 UUID와 디렉터리를 등록 후 저장해줍니다.

 

반응형