[Linux 기초] 19. 디스크 관리 - fdisk 파티션 관리

Date:     Updated:

카테고리:

태그:


01. 볼륨과 파티션의 차이점


구 분 내 용
드라이브 (Drive) 보통 이것은 물리적인 저장 장치를 말한다. 하드 디스크라고 하지만 하드 디스크 드라이브로도 말한다. 저장 장치라고 하면 하드 디스크(Hard Disk), SSD(Solid-State Disk), USB 메모리 (Removable USB Flash Drive)등이 있다. 리눅스 디스크 디바이스 파일은 /dev 디렉터리에 존재한다. /dev/sda, /dev/sdb, /dev/sdc….
파티션 (Partition) 하드 디스크 드라이브를 논리적인 블록 디스크(Logic Block Disk)로 나눌 수 있다. 이러한 논리적 블록 디스크를 파티션이라 한다. /dev/sda1, /dev/sda2….
볼륨 (Volume) 볼륨도 논리적 블록 디스크이다. 하지만 파티션과 달리 용량에 대한 유연성을 가진다. 볼륨의 공간을 모두 사용했을 때 이를 늘릴 수가 있다. 그리고 볼륨은 여러 파티션을 포함할 수 있다. 볼륨을 관리하기 위해 볼륨 매니저가 사용되는데 리눅스는 LVM(Linux Volume Manager)이라는 것을 사용한다.


02. fdisk



■ 명령 형식

$ fdisk [옵션] [DISK Device]
옵션 설명
-l 디스크의 파티션 정보 또는 파티션의 정보를 보기 위해 사용된다. 실제로는 디스크의 파티션 테이블을 보는 것이다.
내부명령 설명
m 내부 명령의 도움말을 보여줍니다.
p 파티션 테이블을 보여줍니다.
n 새 파티션을 생성하기 위해 사용합니다.
d 파티션을 삭제하기 위해 사용합니다.
t 파티션 유형을 변경하기 위해 사용합니다. Linux, Linux LVM, FAT16 등등…
l 파티션 유형들을 확인하기 위해 사용합니다.
w 파티션 테이블 정보를 저장하고 종료하기 위해 사용합니다.
q 정보 저장없이 그냥 빠져 나가기 위해 사용합니다.


■ 예제

  • 디스크 및 파티션 정보 확인

      $ fdisk -l
      Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
      Disk model: VMware Virtual S
      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: 0x6b7d3c13
    
      Device     Boot   Start      End  Sectors Size Id Type
      /dev/sda1  *       2048  2099199  2097152   1G 83 Linux
      /dev/sda2       2099200 41943039 39843840  19G 8e Linux LVM
    
    
      Disk /dev/mapper/rl-root: 17 GiB, 18249416704 bytes, 35643392 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 /dev/mapper/rl-swap: 2 GiB, 2147483648 bytes, 4194304 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 /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
      Disk model: VMware Virtual S
      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 /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
      Disk model: VMware Virtual S
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
    
      $ fdisk -l /dev/sda
      Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
      Disk model: VMware Virtual S
      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: 0x6b7d3c13
    
      Device     Boot   Start      End  Sectors Size Id Type  
      /dev/sda1  *       2048  2099199  2097152   1G 83 Linux
      /dev/sda2       2099200 41943039 39843840  19G 8e Linux LVM
    
  • 20GB 디스크를 5GB 용량과 나머지 용량으로 각각 파티션을 분할

      $ lsblk | grep disk
      sda           8:0    0   20G  0 disk
      sdb           8:16   0   20G  0 disk
      sdc           8:32   0   20G  0 disk
    
    
      $ fdisk /dev/sdb
    
      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.
    
      Device does not contain a recognized partition table.
      Created a new DOS disklabel with disk identifier 0x6370e769.
    
      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-41943039, default 2048):
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): +5G
    
      Created a new partition 1 of type 'Linux' and of size 5 GiB.    
    
      Command (m for help): n
      Partition type
         p   primary (1 primary, 0 extended, 3 free)
         e   extended (container for logical partitions)
      Select (default p): p
      Partition number (2-4, default 2): 2
      First sector (10487808-41943039, default 10487808):
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-41943039, default 41943039):
    
      Created a new partition 2 of type 'Linux' and of size 15 GiB.
    
      Command (m for help): p 
      Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
      Disk model: VMware Virtual S
      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: 0x6370e769
    
      Device     Boot    Start      End  Sectors Size Id Type
      /dev/sdb1           2048 10487807 10485760   5G 83 Linux
      /dev/sdb2       10487808 41943039 31455232  15G 83 Linux
    
      Command (m for help): w
      The partition table has been altered.   
      Calling ioctl() to re-read partition table. 
      Syncing disks.
    
    
      $ fdisk -l /dev/sdb
      Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
      Disk model: VMware Virtual S
      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: 0x6370e769
    
      Device     Boot    Start      End  Sectors Size Id Type 
      /dev/sdb1           2048 10487807 10485760   5G 83 Linux
      /dev/sdb2       10487808 41943039 31455232  15G 83 Linux
    
  • /dev/sdb1 파티션에 EXT4 파일시스템 생성 및 /data01 디렉터리에 마운트

      $ lsblk /dev/sdb
      NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
      sdb      8:16   0  20G  0 disk
      ├─sdb1   8:17   0   5G  0 part
      └─sdb2   8:18   0  15G  0 part
    
    
      $ mkdir /data01
    
    
      $ mkfs -t ext4 /dev/sdb1
      mke2fs 1.46.5 (30-Dec-2021)
      Creating filesystem with 1310720 4k blocks and 327680 inodes
      Filesystem UUID: d9dbaa9a-3294-4f9f-8da4-326180a77d7c
      Superblock backups stored on blocks:
              32768, 98304, 163840, 229376, 294912, 819200, 884736
    
      Allocating group tables: done
      Writing inode tables: done
      Creating journal (16384 blocks): done
      Writing superblocks and filesystem accounting information: done
    
    
      $ blkid /dev/sdb1
      /dev/sdb1: UUID="d9dbaa9a-3294-4f9f-8da4-326180a77d7c" TYPE="ext4" PARTUUID="6370e769-01"
    
    
      $ mount /dev/sdb1 /data01
    
        
      $ df -h /data01
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/sdb1       4.9G   24K  4.6G   1% /data01
    


03. MBR과 GPT의 차이점


MBR과 GPT는 하드디스크에 대한 파티션 정보를 저장하기 위해 사용되는 표준으로 이 둘은 디스크의 첫 번때 섹터 또는 그 이후의 위치에 저장됩니다.

  • MBR 같은 경우 파티션 크기에 대한 제한을 받는데, 왜냐하면 파티션 정보를 저장하기 위해 512 Bytes(Zero Sector)만 사용하여 많은 정보를 저장할 수 없기 때문입니다.

  • 요즘은 대용량 파일시스템을 많이 사용하기 때문에 큰 용량의 파티션 정보를 저장하기 위해서는 GPT 방식을 사용해야 합니다.

  • fdisk 명령을 사용하여 2TB 이상의 디스크를 파티션 분할을 하려 한다면 아래와 같은 메시지를 보게 될 것이다.

      $ lsblk | grep disk
      fd0           2:0    1    4K  0 disk 
      sda           8:0    0   40G  0 disk 
      sdb           8:16   0   20G  0 disk 
      sdc           8:32   0    4T  0 disk 
    
      $  fdisk /dev/sdc
      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 0x0195c729.
    
      WARNING: The size of this disk is 4.4 TB (4398046511104 bytes).
      DOS partition table format can not be used on drives for volumes
      larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
      partition table format (GPT).
    

LINUX 카테고리 내 다른 글 보러가기

댓글 남기기