본문 바로가기

Linux/2) 리눅스 서버 관리자 과정

2_2 Device Reconfiguration & Partition - fdisk 명령어를 통한 디스크 파티션 구성

∇ 펌웨어 & 파티션 형식

FW : BIOS UEFI
DISK :  MBR GPT

- BIOS (Basic Input/ Output System)

- UEFI (Extensible Firmware Interface)

- MBR (Master Boot Record) : 파티션 (P4 or P3 + E1), 2TB 지원

- GPT (GUID Partition Table) : 파티션 (128), 8ZB 지원

 

∇ 파티션 작업 툴

- fdisk CMD : 2TB 이하

- gdisk CMD : 2TB 초과

- parted CMD : 2TB 초과

 

: fdisk 명령어는 크기가 2TB 넘는 디스크에서 파티션 설정을 할 수 없음 (현재 불가능하지는 않음)

 -> parted 명령어를 사용해 파티션 설정해야 함

: 현재 2TB 파티션 용량을 위해 PC-BIOS 파티션 테이블 GPT로 대체됨

 -> fdisk 명령어는 GPT 파티션을 지원X ==> 이런 경우 parted/ gdisk 명령어를 사용해야함

 

fdisk 명령어를 통한 디스크 파티션 구성

fdisk를 이용해 새로운 파티션의 생성, 기존 파티션 삭제, 파티션의 타입 결정 등의 작업 수행 할 수 있음

but, Red Hat 계열의 배포판은 설치 시 대부분 Disk Druid 유틸리티를 이용해 파티션을 분할,

      전통적으로 fdisk를 사용하며 Disk Druid 보다 유연하기에 설치 시에 이 프로그램을 사용

 

- fdisk 프로그램은 한번에 한 디스크에 대해서만 작업 수행

- fdisk는 명령어 프롬프트 중심의 매우 간단한 인터페이스를 가짐

 

∇ 명령어 형식

# fdisk -l   (# fdisk -l | grep Disk)

# fdisk -l /dev/sda

# fdisk /dev/ sda

 

∇ 명령어 옵션

옵션 설명
-l List the partition tables
-v Print version number of fdisk program and exit
-s The size of the partition (in blocks) is printed on the standard output
-b sectorsize Specify the sector size of the disk

 

1. 파티션 정보 확인

# fdisk -l /dev/sda      -l 옵션: 파티션 테이블 나열

# fdisk -l

: 모든 디스크/ 파티션에 대한 정보 출력

[root@server1 ~]# fdisk -l /dev/sda
Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 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
Disklabel type: dos
Disk identifier: 0x0e1f3f3e

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 125829119 123729920  59G 8e Linux LVM

 

2. 파티션 작업 - 새로운 파티션 생성(1)

∇ 작업 계획

: DISK (/dev/sdb(1GB)) - /dev/sdb1 (500M) + Unused (나머지)

: /dev/sdb1 (Primary partition)

 

# fdisk /dev/sdb

Help:

 p   print the partition table

 n   add a new partition

 w   write table to disk and exit

 

Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)

 

[root@server1 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x7556a027.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  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
   u   change display/entry units
   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): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-2097151, default 2048): <ENTER>
Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151, default 2097151): +500M

Created a new partition 1 of type 'Linux' and of size 500 MiB.

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 1026047 1024000  500M 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

 

# partprobe 

: 커널에게 partition table 정보를 다시 로드(reload)하도록 함

: (필요한 경우)

  - 사용중인 디스크에 남아 있는 공간에 대한 파티션 작업을 수행했을 때

  - 가상 디스크 파일일 때 : 사용중인 디스크에 남아 있는 공간에 대한 파티션 작업을 수행했을 때 

 

[root@server1 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (읽기전용 파일 시스템).  /dev/sr0 has been opened read-only.

----------------------------------(설정후)---------------------------------------------
[root@server1 ~]# partprobe

 

※ 참고 

" Warning: Unable to open /dev/sr0 read-write (읽기전용 파일 시스템).  /dev/sr0 has been opened read-only. "

 

VMware > VM > Settings > CD/DVD

[ ] Connected

[ ] Connect at power on

 

∇ 명령어를 통해 확인

# ls -l /dev/sdb*       //SCSI 디스크 나열,  -l 옵션 : 자세한 내용 출력

 

[root@server1 ~]# ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16  8월 23 19:31 /dev/sdb
brw-rw---- 1 root disk 8, 17  8월 23 19:31 /dev/sdb1

 

# fdisk -l /dev/sdb    // /dev/sdb 디스크 및 파티션 보기

/dev/sdb1        2048 1026047 1024000  500M 83 Linux

 

[root@server1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 1026047 1024000  500M 83 Linux

 

# lsblk : 리눅스 디바이스 정보를 출력하는 명령어로 옵션없이 사용하면 트리 형식으로 모든 스토리지 디바이스 출력

sdb           8:16   0    1G  0 disk 
└─sdb1        8:17   0  500M  0 part 

 

[root@server1 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   60G  0 disk 
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   59G  0 part 
  ├─cl-root 253:0    0 38.2G  0 lvm  /
  ├─cl-swap 253:1    0  2.1G  0 lvm  [SWAP]
  └─cl-home 253:2    0 18.7G  0 lvm  /home
sdb           8:16   0    1G  0 disk 
└─sdb1        8:17   0  500M  0 part 
sdc           8:32   0    1G  0 disk 
sr0          11:0    1  8.6G  0 rom

 

3. 파티션 작업 - 새로운 파티션 생성 (2)

∇ 작업 계획

- 작업 디스크 (/dev/sdb) : P1 (500M) + E2 (L5 +L6)

- E2 : 나머지 공간 (약 500M)

- L5 : 300M

- L6 : 나머지 공간 (약 200M)

 

# fdisk /dev/sdb

 

[root@server1 ~]# fdisk /dev/sdb

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


Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  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
   u   change display/entry units
   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): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 1026047 1024000  500M 83 Linux

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 2
First sector (1026048-2097151, default 1026048): <ENTER>
Last sector, +sectors or +size{K,M,G,T,P} (1026048-2097151, default 2097151): <ENTER>

Created a new partition 2 of type 'Extended' and of size 523 MiB.

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 1026047 1024000  500M 83 Linux
/dev/sdb2       1026048 2097151 1071104  523M  5 Extended

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (1028096-2097151, default 1028096): <ENTER>
Last sector, +sectors or +size{K,M,G,T,P} (1028096-2097151, default 2097151): +300M

Created a new partition 5 of type 'Linux' and of size 300 MiB.

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 6
First sector (1644544-2097151, default 1644544): <ENTER>
Last sector, +sectors or +size{K,M,G,T,P} (1644544-2097151, default 2097151): <ENTER>

Created a new partition 6 of type 'Linux' and of size 221 MiB.

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 1026047 1024000  500M 83 Linux
/dev/sdb2       1026048 2097151 1071104  523M  5 Extended
/dev/sdb5       1028096 1642495  614400  300M 83 Linux
/dev/sdb6       1644544 2097151  452608  221M 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

 

# partprobe

# fdisk -l /dev/sdb  : 디스크 및 파티션 확인

/dev/sdb2       1026048 2097151 1071104  523M  5 Extended
/dev/sdb5       1028096 1642495  614400  300M 83 Linux
/dev/sdb6       1644544 2097151  452608  221M 83 Linux

 

[root@server1 ~]# partprobe

[root@server1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 1026047 1024000  500M 83 Linux
/dev/sdb2       1026048 2097151 1071104  523M  5 Extended
/dev/sdb5       1028096 1642495  614400  300M 83 Linux
/dev/sdb6       1644544 2097151  452608  221M 83 Linux

 

4. 파티션 삭제

∇ 작업 계획

- 새로 만들어진 파티션 전체 삭제

- /dev/sdb6 -> /dev/sdb2 -> /dev/sdb1

 

# fdisk /dev/sdb

  Generic
   d   delete a partition

 

[root@server1 ~]# fdisk /dev/sdb

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


Command (m for help): p            //p : print
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 1026047 1024000  500M 83 Linux
/dev/sdb2       1026048 2097151 1071104  523M  5 Extended
/dev/sdb5       1028096 1642495  614400  300M 83 Linux
/dev/sdb6       1644544 2097151  452608  221M 83 Linux

Command (m for help): d       // d : delete 
Partition number (1,2,5,6, default 6): 6

Partition 6 has been deleted.

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot   Start     End Sectors  Size Id Type
/dev/sdb1          2048 1026047 1024000  500M 83 Linux
/dev/sdb2       1026048 2097151 1071104  523M  5 Extended
/dev/sdb5       1028096 1642495  614400  300M 83 Linux

Command (m for help): d
Partition number (1,2,5, default 5): 2

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048 1026047 1024000  500M 83 Linux

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027

Command (m for help): w     // w : write
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

 

# partprobe

# fdisk -l /dev/sdb  : 디스크 및 파티션 확인

 

[root@server1 ~]# partprobe

[root@server1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 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
Disklabel type: dos
Disk identifier: 0x7556a027