웹사이트 검색

Linux 디스크 파티션을 관리하는 10가지 fdisk 명령


fdisk는 "고정 디스크 또는 포맷 디스크"를 의미하며 디스크 조작에 가장 일반적으로 사용되는 명령줄 기반 디스크 조작 유틸리티입니다. Linux/Unix 시스템. fdisk 명령을 사용하면 사용자 친화적인 텍스트 기반 메뉴 기반 인터페이스를 사용하여 하드 드라이브의 파티션을 보고, 생성하고, 크기 조정하고, 삭제하고, 변경하고, 복사하고 이동할 수 있습니다.

이 도구는 새 파티션을 위한 공간 생성, 새 드라이브를 위한 공간 구성, 기존 드라이브 재구성, 데이터를 새 디스크로 복사 또는 이동 측면에서 매우 유용합니다. 시스템에 있는 하드 디스크의 크기에 따라 최대 4개의 새로운 기본 파티션과 논리(확장) 파티션 수를 생성할 수 있습니다.

이 문서에서는 Linux 기반 시스템에서 파티션 테이블을 관리하는 10가지 기본 fdisk 명령을 설명합니다. fdisk 명령을 실행하려면 루트 사용자여야 합니다. 그렇지 않으면 "명령을 찾을 수 없음" 오류가 발생합니다.

1. Linux에서 모든 디스크 파티션 보기

다음 기본 명령은 시스템의 모든 기존 디스크 파티션을 나열합니다. 모든 파티션 나열을 나타내는 '-l' 인수는 Linux에서 사용 가능한 모든 파티션을 보기 위해 fdisk 명령과 함께 사용됩니다. 파티션은 장치 이름으로 표시됩니다. 예: /dev/sda, /dev/sdb 또는 /dev/sdc.

[[email  ~]# fdisk -l

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

2. Linux에서 특정 디스크 파티션 보기

특정 하드 디스크의 모든 파티션을 보려면 장치 이름과 함께 '-l' 옵션을 사용하십시오. 예를 들어, 다음 명령은 /dev/sda 장치의 모든 디스크 파티션을 표시합니다. 기기 이름이 다른 경우 간단히 기기 이름을 /dev/sdb 또는 /dev/sdc로 작성하세요.

[[email  ~]# fdisk -l /dev/sda

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

3. 사용 가능한 fdisk 명령을 모두 확인하세요.

fdisk에 사용할 수 있는 모든 명령을 보려면 다음을 수행하십시오. 아래와 같이 /dev/sda와 같은 하드 디스크 이름을 언급하여 다음 명령을 사용하면 됩니다. 다음 명령은 아래와 유사한 출력을 제공합니다.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help):

/dev/sda 하드 디스크에서 작동할 수 있는 fdisk의 사용 가능한 모든 명령 목록을 보려면 'm'을 입력하세요. 그런 다음 화면에 'm'을 입력하면 /dev/sda 장치에서 사용할 수 있는 fdisk에 대해 사용 가능한 모든 옵션이 표시됩니다.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

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
   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)

Command (m for help):

4. Linux에서 모든 파티션 테이블 인쇄

하드 디스크의 모든 파티션 테이블을 인쇄하려면 /dev/sda와 같은 특정 하드 디스크의 명령 모드에 있어야 합니다.

[root@tecmint ~]# fdisk /dev/sda

명령 모드에서는 이전처럼 'm' 대신 'p'를 입력합니다. 'p'를 입력하면 특정 /dev/sda 파티션 테이블이 인쇄됩니다.

Command (m for help): p

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

Command (m for help):

5. Linux에서 파티션을 삭제하는 방법

/dev/sda와 같은 특정 하드 디스크에서 특정 파티션(예: /dev/sda9)을 삭제하려는 경우. 이 작업을 수행하려면 fdisk 명령 모드에 있어야 합니다.

[root@tecmint ~]# fdisk /dev/sda

그런 다음 'd'를 입력하여 시스템에서 특정 파티션 이름을 삭제합니다. 'd'를 입력하면 /dev/sda 하드 디스크에서 삭제하려는 파티션 번호를 입력하라는 메시지가 표시됩니다. 여기에 숫자 '4'를 입력하면 파티션 번호 '4'(예: /dev/sda4) 디스크가 삭제되고 사용 가능 공간이 표시된다고 가정합니다. 파티션 테이블의 공간. 테이블을 디스크에 쓰고 파티션 테이블을 새로 변경한 후 종료하려면 'w'를 입력하세요. 새로운 변경 사항은 다음에 시스템을 재부팅한 후에만 적용됩니다. 이는 아래 출력을 통해 쉽게 이해할 수 있습니다.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d
Partition number (1-4): 4

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
You have new mail in /var/spool/mail/root

경고: 이 단계를 수행하는 동안 'd' 옵션을 사용하면 시스템에서 파티션이 완전히 삭제되고 파티션에 있는 모든 데이터가 손실될 수 있으므로 주의하세요.

6. Linux에서 새 파티션을 만드는 방법

기기 중 하나에 여유 공간이 남아 있으면 /dev/sda라고 말하고 그 아래에 새 파티션을 생성하고 싶습니다. 그런 다음 /dev/sda의 fdisk 명령 모드에 있어야 합니다. 특정 하드 디스크의 명령 모드로 들어가려면 다음 명령을 입력하십시오.

[root@tecmint ~]# fdisk /dev/sda

명령 모드로 들어간 후 이제 “n” 명령을 눌러 /dev/sda 아래에 특정 크기의 새 파티션을 만듭니다. 이는 다음 출력을 통해 입증할 수 있습니다.

[root@tecmint ~]# fdisk  /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e

새 파티션을 생성하는 동안 '확장' 또는 '기본' 파티션 생성 옵션 두 가지를 묻는 메시지가 표시됩니다. 확장 파티션의 경우 'e'를 누르고 기본 파티션의 경우 'p'를 누릅니다. 그런 다음 다음 두 가지 입력을 입력하라는 메시지가 표시됩니다.

  1. 생성할 파티션의 첫 번째 실린더 번호입니다.
  2. 생성할 파티션의 마지막 실린더 번호(마지막 실린더, +cylinders 또는 +size).

마지막 실린더에 "+5000M"을 추가하여 실린더 크기를 입력할 수 있습니다. 여기서 '+'는 추가를 의미하고 5000M은 새 파티션의 크기(예: 5000MB)를 의미합니다. 새 파티션을 생성한 후 'w' 명령을 실행하여 파티션 테이블에 대한 새로운 변경 사항을 변경 및 저장하고 마지막으로 시스템을 재부팅하여 새로 생성된 파티션을 확인해야 한다는 점을 명심하십시오.

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

7. Linux에서 파티션을 포맷하는 방법

새 파티션이 생성된 후에는 'mkfs' 명령을 사용하여 새로 생성된 파티션을 포맷하는 과정을 건너뛰지 마세요. 파티션을 포맷하려면 터미널에 다음 명령을 입력하세요. 여기 /dev/sda4는 새로 생성된 파티션입니다.

[root@tecmint ~]# mkfs.ext4 /dev/sda4

8. Linux에서 파티션 크기를 확인하는 방법

새 파티션을 포맷한 후 fdisk 명령으로 플래그 's'(크기를 블록 단위로 표시)를 사용하여 해당 파티션의 크기를 확인하십시오. 이렇게 하면 특정 장치의 크기를 확인할 수 있습니다.

[root@tecmint ~]# fdisk -s /dev/sda2
5194304

9. 파티션 테이블 순서를 수정하는 방법

논리 파티션을 삭제하고 다시 만든 경우 '파티션 순서가 잘못되었습니다' 문제 또는 '파티션 테이블 항목이 디스크 순서가 아닙니다와 같은 오류 메시지가 표시될 수 있습니다. '.

예를 들어, (sda4, sda5sda6)과 같은 세 개의 논리 파티션이 삭제되고 새 파티션이 생성되면 새 파티션이 생성될 것으로 예상할 수 있습니다. 파티션 이름은 sda4입니다. 하지만 시스템에서는 이를 sda5로 생성합니다. 이는 파티션이 삭제된 후 sda7 파티션이 sda4로 이동되고 여유 공간이 끝으로 이동했기 때문에 발생합니다.

이러한 파티션 순서 문제를 해결하고 새로 생성된 파티션에 sda4를 할당하려면 'x'를 실행하여 추가 기능 섹션을 입력한 다음 'f<를 입력하세요.' 전문가 명령을 사용하면 아래와 같이 파티션 테이블의 순서를 수정할 수 있습니다.

[root@tecmint ~]# fdisk  /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): x

Expert command (m for help): f
Done.

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

그런 다음 'f' 명령을 실행한 후 'w' 명령을 실행하여 저장하고 fdisk 명령 모드를 종료하는 것을 잊지 마세요. 파티션 테이블 순서를 수정하면 더 이상 오류 메시지가 표시되지 않습니다.

10. 파티션의 부팅 플래그(*)를 비활성화하는 방법

기본적으로 fdisk 명령은 각 파티션에 부팅 플래그(예: '*') 기호를 표시합니다. 특정 파티션에서 부팅 플래그를 활성화하거나 비활성화하려면 다음 단계를 수행하십시오.

[root@tecmint ~]# fdisk  /dev/sda

현재 파티션 테이블을 보려면 'p' 명령을 누르세요. /dev/에 부팅 플래그(주황색의 별표(*) 기호)가 있는 것을 볼 수 있습니다. sda1 디스크는 아래와 같습니다.

[root@tecmint ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

다음으로 'a' 명령을 입력하여 부팅 플래그를 비활성화한 다음 제 경우에는 파티션 번호 '1'을 (예: /dev/sda1)로 입력하세요. . 이렇게 하면 /dev/sda1 파티션의 부팅 플래그가 비활성화됩니다. 별표(*) 플래그가 제거됩니다.

Command (m for help): a
Partition number (1-9): 1

Command (m for help): p

Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          13      104391   83  Linux
/dev/sda2              14        2624    20972857+  83  Linux
/dev/sda3            2625        4582    15727635   83  Linux
/dev/sda4            4583       77541   586043167+   5  Extended
/dev/sda5            4583        5887    10482381   83  Linux
/dev/sda6            5888        7192    10482381   83  Linux
/dev/sda7            7193        7845     5245191   83  Linux
/dev/sda8            7846        8367     4192933+  82  Linux swap / Solaris
/dev/sda9            8368       77541   555640123+  8e  Linux LVM

Command (m for help):

나는 fdisk 명령의 거의 모든 기본 명령을 포함하려고 최선을 다했지만 여전히 fdisk에는 'x'를 입력하여 사용할 수 있는 다양한 다른 전문 명령이 포함되어 있습니다. 자세한 내용은 터미널에서 'man fdisk' 명령을 확인하세요. 중요한 명령을 놓친 경우 댓글 섹션을 통해 공유해 주세요.

추가 읽기:

  1. Linux에서 디스크 공간을 확인하는 12가지 “df” 명령
  2. 파일 및 디렉터리의 디스크 사용량을 찾는 데 유용한 10가지 "du" 명령