fdisk
명령으로 파티션 관리gdisk
명령으로 파티션 관리parted
와 fdisk
차이fdisk
: 'w' 명령을 내리기 전 새로운 파티션 테이블 설계할 수 있다.fdisk
는 커널에 파티션 테이블을 다시 읽도록 지시하기 위해 디스크에 시스템 콜 요청sdf: sdf1 sdf2
parted
: 명령을 실행하면 즉각 반영# blockdev --rereadpt /dev/sdf
# blockdev --rereadpt /dev/sdf
/dev/sdf
의 파티션 테이블 다시 로딩$ fdisk [option] <device file>
option:
-b <크기> 섹터 크기 지정(512, 1024, 2048, 4096)
-l 파티션 테이블 출력
아래표 참고
e.g.
$ fdisk /dev/sdb # /dev/sdb를 파티셔닝 할거임
$ fdisk -d /dev/sdb # /dev/sdb 파티션 삭제
주의 사항!
1. 옵션들이 있지만 먼저 $ fdisk /dev/sda
와 같이 디바이스 파일에 먼저 fdisk 툴 사용모드로 들어간 후,
하나하나 천천히 사용하길 바람
1.1 /dev/sda가 /dev/sda1, /dev/sda2 로 나뉘어져 있어도 '$ fdisk /dev/sda'를 선택해야함
2. fdisk
명령은 마지막에 꼭! 'w' 명령을 주어야 실제로 반영됨
fdisk option | function |
---|---|
-a | 부팅 파티션 설정 |
-b | BSD 디스크 라벨을 편집 |
-c | 도스 호환성 설정 |
-d | 파티션 삭제 |
-l | 사용 가능한 파티션 종류 출력 |
-m | 도움말 출력 |
-n | 새로운 파티션 추가 |
-o | 새로운 빈 DOS 파티션 생성 |
-p | 파티션 테이블 출력 |
-q | 작업 내용을 저장하지 않고 출력 |
-s | 새로운 빈 Sun 디스크 라벨 출력 |
-t | 파티션의 시스템 ID 변경(파일 시스템 종류 변경) |
-u | 항목 정보 변경/출력 |
-v | 파티션 테이블 검사 |
-w | 파티션 정보를 디스크에 저장하고 종료 |
-x | 실린더 갯수 변경등 전문가를 위한 부가적 기능 |
p
: 디스크 파티션 정보 조회d
: 파티션 제거$ umount <마운트 포인트>
# 마운트 포인트에서 umount 안먹힘!!
e.g.
$ sudo umount /media/pi/boot
n
: 파티션 생성
1. First sector: Sector 2048
2. Last sector: +38M
-> Result sector: 'Sector 2048' + 32MB
a
: boot flag 생성fdisk
에서 a
는 부팅 파티션 설정Command (m for help): a
Partition number (1,2, default 2): 1
The bootable flag on partition 1 is enabled now.
....
Command (m for help): p
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 67583 65536 32M c w95 FAT32 (LBA)
/dev/sda2 67584 62552063 62484480 29.8G 83 Linux
t
: 파티션 시스템 ID 변경(파일 시스템 종류 설정)Command (m for help): t # t 명령은 파티션의 시스템 ID 변경(파일 시스템 종류 변경)
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): L
...중략...
c W95 FAT32 (LBA)
...중략...
Hex code (type L to list all codes): c
Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.
Command (m for help): p
Disk /dev/sda: 29.8 GiB, 32026656768 bytes, 62552064 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: 0x7b59cb23
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 67583 65536 32M c w95 FAT32 (LBA)
/dev/sda2 67584 62552063 62484480 29.8G 83 Linux
Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wip ed.
w
: fdisk writefdisk
명령은 다 하고 나서 ★w
로 마지막에 꼭 저장 후, fdisk
명령을 종료해야함★ Command (m for help): w # 꼭 w 로 저장후 fdisk 명령을 종료해야함
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
lsblk
로 삭제할 디바이스 확인lsblk
로 삭제할 디바이스 확인. 여기서는 /dev/sda
$ sudo umount <마운트 포인트>
사용 예:
$ sudo umount /media/pi/boot
fdisk
로 boot, rootfs 파티션 구성$ fdisk <devfile>
sdb 8:16 1 14.9G 0 disk
├─sdb1 8:17 1 64M 0 part FAT32 (boot loader를 올릴 파티션)
└─sdb2 8:18 1 1G 0 part ext4 (rootfs 용)
d
: 파티션을 제거한다.Command (m for help): d
n
: 파티션 생성primary partition
1
16M
,Type
(filesystem) 이 Linux
인데 이를, FAT32
로 바꿔야한다.t
:파티션의 Type 변경L
: 변경할 수 있는 Type
(filesystem) 나열c
번: W95 FAT32 (LBA)
선택a
: 부트 파티션 할당1G
로 ext4
로 할당한다.w
: 로 실제로 디스크에 Write
해야한다!w
명령을 사용하지 않으면 위에한 것들이 의미가 없다.3-1. ext4로 할당
label
을 ROOT
, 파일시스템을 ext4
으로 셋$ sudo mkfs.ext4 -L "ROOT" /dev/sda2
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 7810560 4k blocks and 1954064 inodes
Filesystem UUID: eb928e08-5745-4b1a-9f16-31c17af70077
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: # 1~2 분 소요됨 -> done
3-2. vfat으로 할당
label
을 BOOT
, 파일시스템을 vfat
으로 셋$ sudo mkfs.vfat -n "BOOT" /dev/sda1
/dev/sda1
을 /mnt
로 마운트 해보자.$ sudo mount <파티션> <마운트포인트>
$ sudo mount /dev/sda1 /mnt
$ cd /mnt
$ ls
lost+found
lost+found
밖에 없어 깔끔하게 포맷됨$ sudo eject /dev/sda
$ sudo gdisk <dev>
Options | description |
---|---|
b | back up GPT data to a file |
c | change a partition's name |
d | delete a partition |
i | show detailed information on a partition |
l | list known partition types |
n | add a new partition |
o | create a new empty GUID partition table (GPT) |
p | print the partition table |
q | quit without saving changes |
r | recovery and transformation options (experts only) |
s | sort partitions |
t | change a partition's type code |
v | verify disk |
w | write table to disk and exit |
x | extra functionality (experts only) |
? | print this menu |
parted
는 fdisk
, gdisk
와 다르게, 바로 명령이 적용되기 때문에 조심해야한다.$ parted [options] [device [command [options...]...]]
Options | description |
---|---|
-l, --list | lists partition layout on all block devices |
-m, --machine | displays machine parseable output |
-s, --script | never prompts for user intervention |
-v, --version | displays the version |
-a alignment-type --align alignment-type | Set alignment for newly created partitions, valid alignment types are: |
Commands | description |
---|---|
[device] | The block device to be used. When none is given, parted will use the first block device it finds. |
[command [options]] | Specifies the command to be executed. If no command is given, parted will present a command prompt. Possible commands are:align-check alignment-type partition : Determine whether the starting sector of partition is aligned for the disk. alignment-type is "minimal" or "optimal".check partition :Do a simple check on partition. |