[Linux] 리눅스(virtualbox) 서버에 디스크 추가하기

 

서버에 하드 추가하기


 

vm 서버에 두 번째 "sdb" 디스크를 추가합니다.

추가 작업은 서버를 종료한 상태에서 진행합니다.

 

첫 번째 서버인 "linux_1"에서 진행합니다.

서버를 선택하고 설정 아이콘을 클릭합니다.

 

저장소 -> "컨트롤러:SATA"  선택 -> 하단의 3번째 아이콘 선택

 

만들기 들어가서 "VDI -> 동적할당 -> 5G"로 생성합니다.

혹시,  잘 모르시겠으면 아래 링크의 centos7 설치를 참고해 주시기 바랍니다.
(https://sh-safer.tistory.com/3)

 

디스크 추가 완료!!!

서버를 다시 부팅하고 접속합니다.

 

 

디스크 추가 확인


 

fdisk -l 명령어로 추가된 디스크를 확인합니다.

 

파티션 생성하기


"fdisk" 명령어로 sdb 디스크의 파티션 설정으로 들어갑니다.

그다음 'm' 커멘드로 전체 메뉴를 확인합니다.  

 

[root@linux-1 ~]# 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 0xed37f84f.

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' 커맨드로 새로운 파티션을 생성합니다.

그럼 파티션 타입을 선택하는 부분이 나오는데요.

종류는 두가지 Primaryexteded입니다.

 

일반적으로 하드디스크 하나에는 총 4개의 파티션 까지만 생성이 가능합니다.

그런데 만약, 5개 이상의 파티션 구성이 필요한 경우에는 어떡해야 할까요?

 

그럴 땐,  1~3번 파티션까지는 Primary 타입으로 생성하고

4번 파티션을 extended 타입으로 생성한 뒤

해당 파티션 안에 5,6,7.... 번 logical 파티션을 생성하시면 됩니다.

extended 파티션은 5개 이상의 파티션을 생성하기 위한, logical 파티션의 껍데기라고 보시면 됩니다.  

 

이제 'p'를 입력하여 pirmary 파티션을 생성합니다.

다음은 파티션의 용량을 정하는 부분입니다.

첫 번째 섹터를 입력합니다.

그냥 엔터를 눌러서 디폴트인 2048 섹터부터 시작하겠습니다.

여기서 또다시 엔터를 누르시면 디폴트로 마지막 섹터가 입력이 되고

디스크 하나가 파티션 하나로 통으로 잡힙니다.

저희는 1기가만 추가하여 생성하겠습니다.

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

 

'p'를 누르시면 생서한 파티션을 볼 수 있습니다.

참고로, 아직 wirte를 하지 않아서 완전히 생성된 것은 아닙니다.

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x1b2b7832

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

 

1기가짜리 파티션을 하나 더 생성해보겠습니다.(작업 내용은 생략합니다)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x1b2b7832

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     4196351     1048576   83  Linux

 

이제 'w'를 입력하여 생성한 파티션을 저장하겠습니다.

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

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

 

fdisk 명령어로 생성한 파티션을 확인해 봅니다.

 

 

파일 시스템 포맷 및 마운트


아직 끝이 아닙니다.

생성한 파티션을 사용하려면 포맷을 해야 합니다

xfs 파일 시스템으로 포맷을 진행합니다.

[root@linux-1 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=262144, 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

 

파티션을 연결할 디렉터리를 생성하고 

마운트 해줍니다. 

[root@linux-1 /]# mkdir /mnt/data_dir
[root@linux-1 /]# mount /dev/sdb1 /mnt/data_dir/

 

확인!!!

sdb1 파티션이 추가되었습니다.

fstab 등록


blkid로 sdb1의 UUID를 확인

[root@linux-1 /]# blkid
/dev/sda1: UUID="292da170-66f6-44d1-92f8-f762c87c28de" TYPE="xfs"
/dev/sda2: UUID="88679db8-a8a4-4564-a14f-4bba315b1601" TYPE="swap"
/dev/sda3: UUID="00e1b7e0-9f99-4d3a-a598-29421ee37bb4" TYPE="xfs"
/dev/sdb1: UUID="805781bb-aee4-4248-a302-85db7fe1b269" TYPE="xfs"

 

/etc/fstab에 추가하여 부팅 시 자동으로 마운트 되도록 설정합니다.

[root@linux-1 /]# cat /etc/fstab
UUID=00e1b7e0-9f99-4d3a-a598-29421ee37bb4 /                       xfs     defaults        0 0
UUID=292da170-66f6-44d1-92f8-f762c87c28de /boot                   xfs     defaults        0 0
UUID=88679db8-a8a4-4564-a14f-4bba315b1601 swap                    swap    defaults        0 0
UUID=805781bb-aee4-4248-a302-85db7fe1b269 /mnt/data_dir           xfs     defaults        0 0

 

댓글

Designed by JB FACTORY

loading