IT정보공유

[ LINUX ] 리눅스 파티션 추가 및 디스크 마운트 방법

알지오™ 2020. 1. 21.

리눅스(CentOS) 하드디스크 추가 방법에 대한 글입니다.
준비물로는 우선 추가로 장착할 하드디스크가 필요하고 하드디스크를 연결해 놓은 상태에서
fdisk 명령어를 통해 파티션을 설정한 후, 포맷으로 파일시스템을 잡아주면 됩니다.

 

디스크 및 파티션 조회 명령어 fdisk -l

 

[root@ftpserver ~]# 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: 0x0002afae

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048        4095        1024   83  Linux
/dev/xvda2            4096     4198399     2097152   82  Linux swap / Solaris
/dev/xvda3   *     4198400   104857599    50329600   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 명령으로 조회한 파티션 리스트입니다.
새로 장착한 하드는 /dev/xvdb 2TB용량입니다. 시스템에 할당되어 있지 않은 상태입니다.

 

파티션 설정 명령어 fdisk [디스크이름]

새로 추가된 하드디스크인 /dev/xvdb 에 파티션 설정을 위해 작업을 진행합니다.


[root@ftpserver ~]# 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 0xd8e5348e.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

첫번째 묻는 질문은 위 옵션 중에서 어떤 작업을 할지 물어보는 건데 새로운 하드디스크에
새로운 파티션 생성 작업을 진행해야 하기 때문에 n (add a new partition) 을 입력합니다.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
   

 

두번째 질문은 파티션 타입을 주 파티션(p)으로 설정할지 확장파티션으로 이용할지인데, 보통은 p로 설정하면됩니다.
Partition number, First sector, Last sector 등은 디폴트로 설정합니다.
(디폴트로 설정할 경우 하드용량 전체를 사용합니다.)


Select (default p): p
Partition number (1-4, default 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

그리고 w (write table to disk and exit) 눌러 파티션 정보 설정을 저장하고 빠져나옵니다.

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

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

 

다시 fdisk -l 명령으로 파티션 할당이 잘 되어 있는지 확인합니다.

[root@ftpserver ~]# 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: 0x0002afae

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048        4095        1024   83  Linux
/dev/xvda2            4096     4198399     2097152   82  Linux swap / Solaris
/dev/xvda3   *     4198400   104857599    50329600   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: 0xd8e5348e

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

/dev/xvdb1 로 파티션 설정된 것을 확인할 수 있습니다.
파티션 설정 작업이 완료되었으면 이제 파일시스템을 생성해줄 차례입니다. 
(윈도우 포맷 같은 디스크 초기화 작업입니다. CentOS, Ubuntu 등 리눅스 종류에 따라 명령이 다를수 있으며 CentOS 7 기준입니다.)

 

파일시스템 생성 명령어 mkfs.xfs

 

[root@ftpserver ~]# mkfs.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

 

새로운 파티션에 파일시스템이 생성되었습니다. 
리눅스에서는 하드디스크 연결 후 사용을 하려면 특정디렉토리에 mount를 해야하는데
보통은 /mnt 디렉토리 아래로 디렉토리를 생성하고, mount 명령어를 통해 파티션을 디렉토리에 연결합니다.

[root@ftpserver ~]# mkdir /mnt/ftpstorage

[root@ftpserver ~]# mount /dev/xvdb1 /mnt/ftpstorage

 

하드를 마운트 했으면 df 명령어를 이용해 디스크용량이 정상적으로 할당되어 있는지 확인해줍니다.

 

디스크 사용량 확인 명령어 df -k

 

[root@ftpserver ~]# df -k
Filesystem      1K-blocks    Used  Available Use% Mounted on
/dev/xvda3       50305028 1955796   48349232   4% /
devtmpfs          1918928       0    1918928   0% /dev
tmpfs             1801800       0    1801800   0% /dev/shm
tmpfs             1801800    8516    1793284   1% /run
tmpfs             1801800       0    1801800   0% /sys/fs/cgroup
tmpfs              360364       0     360364   0% /run/user/0
/dev/xvdb1     2096126980   32944 2096094036   1% /mnt/ftpstorage

2TB의 용량이 /mnt/ftpstorage에 할당된것을 확인할 수 있습니다.

 

주의사항

리눅스 파티션을 마운트 한 이후, 리눅스를 재부팅하면 마운트 작업을 다시 해야합니다.
재부팅 이후에도 고정적으로 마운트를 지정하려면 /etc/fstab 을 vi 편집기를 통해 수정해야합니다.
fstab 설정방법은 본 포스팅에서 다루지 않습니다.

댓글

💲 추천 글