Linux/CentOS Stream 9

Linux - Centos Stream 9 - fdisk로 추가 디스크 파티션 잡기

Ryan's Tech Note 2023. 2. 21. 16:20

디스크 추가 후에 파티션을 잡아보자. 윈도우 처럼 그놈 데스크탑으로 편하게 하려 했는데 제대로 되지를 않는다. 터미널로 작업해야 한다.

 

# fdisk -l
(...생략...)
Disk /dev/sda: 2.73 TiB, 3000592982016 bytes, 5860533168 sectors
Disk model: HGST HDN724030AL
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 39CA40F7-9462-46F0-A3BF-1A375F0C6AD2

위에 진한 글씨로 HGST 2.73 TiB (3TB) 가 오늘 새로 추가한 하드이다.

이 하드의 장치ID는 /dev/sda 이니 헷갈리지 말고 꼭 정확히 메모해두자. 안그러면 엉뚱한 파티션을 날릴수있다.

 

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Command (m for help): m

Help:

  GPT
   M   enter protective/hybrid MBR

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help):

m을 쳐서 fdisk 명령어를 확인해보자. 앞으로 치는 명령어는 자동으로 모두 /dev/sda 하드에 하는 작업이다.

n   add a new partition 을 해보자.

 

Command (m for help): n
Partition number (1-128, default 1):
First sector (34-5860533134, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-5860533134, default 5860533134): +1TB

Created a new partition 1 of type 'Linux filesystem' and of size 931.3 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): n
Partition number (2-128, default 2):
First sector (1953126400-5860533134, default 1953126400):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1953126400-5860533134, default 5860533134): +2TB

Created a new partition 2 of type 'Linux filesystem' and of size 1.8 TiB.

3TB 하드를 1TB + 2TB 로 나누었다.

Do you want to remove the signature? 질문은 기존 데이타가 삭제되는데 진행하시겠습니까 라는 의미이다.

 

Command (m for help): w
The partition table has been altered.
Syncing disks.

마지막에 w 를 입력해야 반영이 된다. w 를 입력안하고 종료하면 반영이 안된다.

 

# fdisk -l
(...생략...)
Disk /dev/sda: 2.73 TiB, 3000592982016 bytes, 5860533168 sectors
Disk model: HGST HDN724030AL
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 39CA40F7-9462-46F0-A3BF-1A375F0C6AD2

Device          Start        End    Sectors   Size Type
/dev/sda1        2048 1953126399 1953124352 931.3G Linux filesystem
/dev/sda2  1953126400 5859377151 3906250752   1.8T Linux filesystem

다시 fdisk -l 을 해보면 방금 파티션을 추가한 931.3G (1TB), 1.8T (2TB) 파티션이 보인다.

각각의 장치ID는 /dev/sda1, /dev/sda2 이다.

그럼 포맷을 해보자. 리부팅을 해야 방금 나눈 파티션을 포맷할 수 있다. 리부팅을 안하면 장치가 동작중이라는 오류가 뜬다. 포맷 명령어를 칠때 장치ID 아이디를 틀리지 말고 정확히 입력하라. 스펠링 하나 틀렸다가 엉뚱한 하드가 포맷된다.

 

sda1 은 백업용으로 사용하기 위해 XFS 파티션으로 포맷하고, sda2 는 NAS 용으로 사용하기 위해 NTFS 파티션으로 포맷해 보자.

# mkfs.xfs -f /dev/sda1

meta-data=/dev/sda1              isize=512    agcount=4, agsize=61035136 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=244140544, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=119209, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

sda1 xfg로 포맷 완료.

 

다음 NTFS 로 포맷하기 위해 Centos Stream 9 에서 약간 번거로운 작업이 필요하다. 기존 epel-release 를 제거하고, 다시 설치한 후, ntfs-3g를 설치해야 인식한다. 이 부분에서 삽질을 했지만 여러분은 바로 넘어가길 바란다.

dnf remove epel-release
dnf -y install epel-release
dnf -y install ntfs-3g

 

ntfs-3g 설치가 성공하면 다음을 실행한다.

# mkntfs -f /dev/sda2
bash: mkntfs: command not found...
Install package 'ntfsprogs' to provide command 'mkntfs'? [N/y] y


 * Waiting in queue...
 * Loading list of packages....
The following packages have to be installed:
 ntfsprogs-2:2022.10.3-1.el9.x86_64     NTFS filesystem libraries and utilities
Proceed with changes? [N/y] y


 * Waiting in queue...
 * Waiting for authentication...
 * Waiting in queue...
 * Downloading packages...
 * Requesting data...
 * Testing changes...
 * Installing packages...
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.

추가적으로 ntfsprogs를 설치할거냐고 묻는데 y를 누르고 설치한 후에 NTFS 포맷을 실행한다.

2TB 파티션이 NTFS 파티션으로 포맷이 완료되었다.

 

# mount /dev/sda1 -t xfs /backup

1TB XFS 파티션을 /backup 으로 마운트 하였다. mkdir /backup 을 별도로 할 필요는 없다.

 

# mkdir /nas
# mount /dev/sda2 -t ntfs-3g /nas

2TB NTFS 파티션을 /nas 로 마운트 하였다. mkdir /nas 를 해서 디렉토리를 생성해준 후 마운트를 해야 한다.

 

# df -m
Filesystem                1M-blocks  Used Available Use% Mounted on
/dev/sda1                    953209  6679    946531   1% /backup
/dev/sda2                   1907349   123   1907227   1% /nas

 

마지막으로 하나더 해야한다. 이대로 리눅스를 끄면 마운트가 사라진다 재부팅후에도 마운트가 보이게 하려면 아래와 같이 추가해준다. 내용은 적용하는 컴퓨터마다 다를수 있으니 아래 형식만 참고한다.

vi /etc/fstab
/dev/sda1 /backup xfs defaults 0 0
/dev/sda2 /scm ntfs defaults 0 0

 

 

이상입니다.

 

도움이 되었면 공감 클릭과, 댓글 한번 부탁합니다.