gdisk 명령어: 리눅스 파티션 설정과 GPT 파티션 생성, 삭제

공정위 광고 문구 Ver 3.1
공정위 광고 문구 Ver 3.2(모바일 전용)
테스트 환경RHEL 계열AlmaLinux 9.8root 계정
디스크 · 마운트 명령어gdisk 1.0.7위치/usr/sbin/gdisk

디스크를 GPT 방식으로 나눌 때는 gdisk 명령어로 파티션을 생성하고 삭제합니다. gdisk 뒤에 장치 파일 이름을 붙여 실행하면 대화형 화면이 열리며, 파티션 목록 확인은 p, 삭제는 d처럼 한 글자 옵션을 입력해 리눅스 파티션 설정을 진행합니다.

gdisk disk.img

글에 실린 gdisk 출력은 truncate로 만든 3 GiB 연습용 이미지 파일 disk.img에서 실행한 결과이며, 실제 디스크에서는 disk.img 자리에 /dev/sdb 같은 장치 파일 이름을 넣습니다.

마운트하기 전까지의 작업 순서는 아래와 같습니다.

  • 리눅스 파티션 설정 순서
  • 파티션 정보 편집을 원하는 장치 파일 이름 지정 후 명령어 실행
  • 파티션 목록 표시
  • 필요 없는 파티션 삭제
  • 새 파티션 생성
  • 파티션 정보 저장(w) 후 종료

w로 저장하기 전까지는 파티션 작업 내용이 디스크에 반영되지 않습니다.

1️⃣ gdisk 명령어로 리눅스 파티션 설정하기

gdisk는 GPT 파티션 테이블을 다루는 파티션 관리 유틸리티입니다. MBR 방식은 2TiB보다 큰 디스크를 다 쓰지 못하므로, 2TB 이상인 대용량 디스크는 GPT로 나누며 이때 gdisk나 parted로 파티션 작업을 하게 됩니다.

gdisk -[옵션] [대상 장치 파일]

설정된 파티션 정보는 gdisk 또는 fdisk 명령어에 -l 옵션을 붙여 확인할 수 있습니다.

gdisk -l disk.img
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk disk.img: 6291456 sectors, 3.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): ABA1DC8A-EB0E-4342-86D5-EEF52D68CD23
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 6291422
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         3147775   512.0 MiB   8200  Linux swap
   3         3147776         6291422   1.5 GiB     8300  Linux filesystem

1. gdisk 실행 화면

파티션 테이블이 없는 빈 disk.img에서 gdisk를 실행한 뒤 나오는 기본 화면입니다.

gdisk disk.img
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help):

2. gdisk p 옵션: 파티션 목록 확인

아래는 같은 disk.img에 파티션 셋(1 GiB, swap 512 MiB, 나머지 1.5 GiB)을 만들어 저장한 뒤 p로 본 목록입니다.

Command (? for help): p
Disk disk.img: 6291456 sectors, 3.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): ABA1DC8A-EB0E-4342-86D5-EEF52D68CD23
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 6291422
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         3147775   512.0 MiB   8200  Linux swap
   3         3147776         6291422   1.5 GiB     8300  Linux filesystem
p 출력 항목설명
DiskSectors 및 디스크의 전체 용량
Sector size논리 섹터 하나의 크기(이 글에서는 512 bytes)
Disk identifierGUID 정보를 보여줍니다.
Number파티션 번호
Start (sector)파티션 시작 섹터
End (sector)파티션 종료 섹터
Size파티션 용량
Code파티션 유형을 번호로 표시
Name파티션의 용도. c 명령어로 이름 변경 가능.

3. gdisk 파티션 생성

n을 입력하면 파티션 번호, 시작 섹터, 끝 섹터를 차례로 묻습니다. 아래는 1번 파티션만 있는 disk.img에서 번호와 시작 섹터는 기본값으로 두고, 끝 섹터에 +512M을 넣어 2번 파티션을 만든 예입니다.

Command (? for help): n
Partition number (2-128, default 2):
First sector (34-6291422, default = 2099200) or {+-}size{KMGTP}:
Last sector (2099200-6291422, default = 6291422) or {+-}size{KMGTP}: +512M
Current type is 8300 (Linux filesystem)

파티션 유형은 L 명령어로 확인할 수 있습니다.

Hex code or GUID (L to show codes, Enter = 8300): L
Type search string, or <Enter> to show all codes: 
0700 Microsoft basic data                0701 Microsoft Storage Replica         
0702 ArcaOS Type 1                       0c01 Microsoft reserved                
2700 Windows RE                          3000 ONIE boot                         
3001 ONIE config                         3900 Plan 9                            
4100 PowerPC PReP boot                   4200 Windows LDM data                  
4201 Windows LDM metadata                4202 Windows Storage Spaces            
7501 IBM GPFS                            7f00 ChromeOS kernel                   
7f01 ChromeOS root                       7f02 ChromeOS reserved                 
8200 Linux swap                          8300 Linux filesystem                  
8301 Linux reserved                      8302 Linux /home                       
8303 Linux x86 root (/)                  8304 Linux x86-64 root (/)             
8305 Linux ARM64 root (/)                8306 Linux /srv                        
8307 Linux ARM32 root (/)                8308 Linux dm-crypt                    
8309 Linux LUKS                          830a Linux IA-64 root (/)              
830b Linux x86 root verity               830c Linux x86-64 root verity          
830d Linux ARM32 root verity             830e Linux ARM64 root verity           
830f Linux IA-64 root verity             8310 Linux /var                        
8311 Linux /var/tmp                      8312 Linux user's home                 
8313 Linux x86 /usr                      8314 Linux x86-64 /usr                 
8315 Linux ARM32 /usr                    8316 Linux ARM64 /usr                  
8317 Linux IA-64 /usr                    8318 Linux x86 /usr verity             
Press the <Enter> key to see more codes, q to quit: 

파티션 유형 번호는 swap 파티션이 8200, Linux 파일 시스템이 8300이며, 이 번호를 입력해 유형을 설정합니다.

Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'

만든 파티션은 w로 디스크에 기록하며, 진행 여부를 물으면 Y를 입력합니다.

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to disk.img.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

4. gdisk 파티션 삭제

[d] 옵션으로 파티션을 삭제합니다. 번호를 물으면 지울 파티션 번호를 입력하고, 파티션이 1개만 있으면 번호를 묻지 않고 바로 삭제됩니다.

Command (? for help): d
Partition number (1-3): 3

🔲 gdisk 명령어 옵션

옵션복사설명
-l파티션 목록을 출력하고 바로 종료
p디스크의 파티션 목록 표시
n새 파티션 생성(번호, 시작 섹터, 끝 섹터 순서로 입력)
L유형 코드를 묻는 칸에서 파티션 유형 목록 표시
8200파티션 유형 코드 입력(n, t의 유형 칸)
w파티션 정보를 디스크에 저장한 뒤 종료
d파티션 삭제
옵션복사설명
c파티션 이름 변경
l파티션 유형 목록으로 표시
q파티션 정보를 저장하지 않고 종료
t파티션 유형 설정(기존 파티션 유형 변경 포함)
s파티션 정렬
?조작 명령을 목록으로 출력

🔲 gdisk 명령어 시뮬레이터

아래 시뮬레이터에서 gdisk disk.img를 실행하고 옵션 표의 p, n, d, w를 칩이나 키보드로 입력해, 저장하기 전의 메모리와 디스크 칸이 어떻게 달라지는지 확인할 수 있습니다.

gdisk 시뮬레이터연습용 디스크 disk.img · 3 GiB
[root@server ~]#
브라우저 안에서만 동작하며 실제 디스크에는 아무것도 기록되지 않습니다. w 로 저장하기 전까지 변경은 메모리에만 있고, q 로 나가면 사라집니다.

2️⃣ gdisk 명령어 실무 예시

  • ↪️ 연습용 이미지로 해 본 파티션 작업과 실수

먼저 truncate로 연습용 이미지 둘을 만들었습니다. 이 장의 출력은 새로 만든 3 GiB 이미지 disk.img와 1 GiB 이미지 data.img에서 받았으며, 같은 순서를 gdisk 명령어 시뮬레이터에서 직접 입력해 볼 수 있습니다.

truncate -s 3G disk.img
truncate -s 1G data.img

🔲 gdisk 파티션 생성과 삭제 예시

빈 disk.img에서 gdisk를 실행해 n으로 1 GiB 파티션과 512 MiB swap 파티션을 차례로 만들었습니다. 번호와 시작 섹터는 Enter로 기본값을 받고, 끝 섹터에 +1G와 +512M을, 둘째 파티션의 유형 코드에 8200을 입력했습니다.

gdisk disk.img
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): n
Partition number (1-128, default 1):
First sector (34-6291422, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-6291422, default = 6291422) or {+-}size{KMGTP}: +1G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'

Command (? for help): n
Partition number (2-128, default 2):
First sector (34-6291422, default = 2099200) or {+-}size{KMGTP}:
Last sector (2099200-6291422, default = 6291422) or {+-}size{KMGTP}: +512M
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'

w를 입력하기 전에 p로 목록을 먼저 확인했습니다. 파티션 둘이 입력한 크기와 유형 코드로 들어갔고, 빈 공간은 1.5 GiB로 나왔습니다.

Command (? for help): p
Disk disk.img: 6291456 sectors, 3.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 85C84C15-686C-4505-BE51-CF9025D04020
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 6291422
Partitions will be aligned on 2048-sector boundaries
Total free space is 3145661 sectors (1.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         3147775   512.0 MiB   8200  Linux swap

목록을 확인한 뒤 w와 Y를 입력해 디스크에 기록했습니다.

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to disk.img.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

삭제도 같은 순서로 진행했습니다. gdisk를 다시 실행해 d에 2를 입력하고, p로 1번 파티션만 남은 것을 확인한 뒤 w로 저장했습니다.

Command (? for help): d
Partition number (1-2): 2

Command (? for help): p
Disk disk.img: 6291456 sectors, 3.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 85C84C15-686C-4505-BE51-CF9025D04020
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 6291422
Partitions will be aligned on 2048-sector boundaries
Total free space is 4194237 sectors (2.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem

🔲 gdisk 사용 시 자주 하는 실수

처음 사용할 때 하기 쉬운 실수는 w 없이 q로 종료하는 경우입니다. 1번 파티션만 있는 disk.img에 n으로 swap 파티션을 추가하고 p로 2번 파티션까지 확인한 다음, w를 입력하지 않고 q로 종료해 보았습니다.

Command (? for help): n
Partition number (2-128, default 2):
First sector (34-6291422, default = 2099200) or {+-}size{KMGTP}:
Last sector (2099200-6291422, default = 6291422) or {+-}size{KMGTP}: +512M
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'

Command (? for help): p
Disk disk.img: 6291456 sectors, 3.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 85C84C15-686C-4505-BE51-CF9025D04020
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 6291422
Partitions will be aligned on 2048-sector boundaries
Total free space is 3145661 sectors (1.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         3147775   512.0 MiB   8200  Linux swap

Command (? for help): q

다시 [gdisk -l]로 확인해 보니 2번 파티션은 없고 1번 파티션만 남아 있었습니다. p 목록에 나온 파티션도 w로 저장해야 디스크에 기록됩니다.

gdisk -l disk.img
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk disk.img: 6291456 sectors, 3.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 85C84C15-686C-4505-BE51-CF9025D04020
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 6291422
Partitions will be aligned on 2048-sector boundaries
Total free space is 4194237 sectors (2.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem

다른 디스크를 지정하는 실수는 작업 전에 [gdisk -l]로 크기와 파티션 목록을 먼저 확인해 방지할 수 있습니다. 아래는 1 GiB 이미지 data.img에 같은 명령을 실행한 출력이며, [Disk data.img: 2097152 sectors, 1024.0 MiB] 줄과 비어 있는 파티션 목록으로 disk.img와 구분할 수 있었습니다.

gdisk -l data.img
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.
Disk data.img: 2097152 sectors, 1024.0 MiB
Sector size (logical): 512 bytes
Disk identifier (GUID): E8F9E93B-4299-41F3-8985-37973CBAEFFF
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097118
Partitions will be aligned on 2048-sector boundaries
Total free space is 2097085 sectors (1024.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name

🔲 gdisk 출력 변화 확인

파티션을 생성하거나 삭제한 뒤에는 p 출력에서 파티션 목록의 줄 수와 [Total free space] 줄이 함께 바뀝니다. 파티션 둘을 만든 직후에는 [Total free space is 3145661 sectors (1.5 GiB)]였고, 512 MiB인 2번 파티션을 삭제한 뒤에는 [Total free space is 4194237 sectors (2.0 GiB)]로 늘었습니다.

Code 칸에는 입력한 유형 코드가 그대로 나왔습니다. Enter로 기본값을 받은 1번 파티션은 8300, 8200을 입력한 2번 파티션은 8200이었습니다.

저장 여부는 gdisk 첫 화면의 [Partition table scan] 아래에서도 구분할 수 있었습니다. 저장하기 전의 빈 이미지에서는 [GPT: not present]였고, w로 저장한 뒤에는 [GPT: present]와 [Found valid GPT with protective MBR; using GPT.] 줄이 나왔습니다.

🔢 FAQ & 추천 콘텐츠

q를 입력하면 바꾼 내용을 디스크에 쓰지 않고 gdisk를 종료합니다. n이나 d로 바꾼 내용은 메모리에만 있다가 w를 입력할 때 디스크에 기록되므로, 잘못 만들었을 때는 q로 나온 뒤 다시 진행합니다.

w 출력의 [Warning: The kernel is still using the old partition table.] 줄처럼, 저장 직후에도 커널은 이전 파티션 테이블을 계속 사용합니다. 새 테이블은 재부팅하거나 partprobe 또는 kpartx를 실행한 뒤에 반영됩니다.

gdisk는 파티션 시작 위치를 2048 섹터 단위로 맞추며, p 출력의 [Partitions will be aligned on 2048-sector boundaries] 줄이 이 설정입니다. 그래서 34~2047 섹터는 비어 있고, 파티션 셋을 만든 disk.img의 빈 공간 2014 섹터가 이 자리입니다.

ℹ️ 제휴 안내
본 사이트의 콘텐츠에는 제휴 링크가 포함되어 있습니다. 방문자가 이 링크를 통해 상품 또는 서비스를 구매하면 본 사이트는 판매처로부터 수수료를 지급받습니다. 이 과정에서 구매자가 지불하는 금액(이벤트 할인 시 금액이 내려갑니다↓)은 오르지 않습니다. 게시된 가격·할인·재고 정보는 작성 시점 기준이며 실제와 다를 수 있으므로, 구매 전 판매처에서 최종 확인하시기 바랍니다. 상품 선정과 평가는 자체 기준에 따라 작성되며, 수수료 지급 여부가 소개 순서나 평가 내용에 영향을 주지 않습니다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

인간임을 증명하세요: 4   +   8   =