$ fdisk, $ gdisk, sd card 포맷 후 파일시스템 할당

markyang92·2021년 9월 16일
1
post-thumbnail
  • fdisk: 링크참고
  • fdisk를 이용해 sd card /boot, root 파티션 나누고, 포맷 후 파일 시스템 할당 : 링크참고

파티셔닝 명령

  • 이전 글 파티션에서도 언급 했지만, 새로운 디스크 장착 시, 파티션 생성 필수!
  • 파티션을 MBR 파티션 테이블 방식으로 만들 것이면 MBR 파티션 테이블의 특징을 먼저 알자.
    • MBR은 fdisk 명령으로 파티션 관리
  • 파티션을 GPT 파티션 테이블 방식으로 만들 것이면 GPT 파티션 테이블의 특징을 먼저 알자
    • GPT는 gdisk 명령으로 파티션 관리

  • partedfdisk 차이
    • fdisk: 'w' 명령을 내리기 전 새로운 파티션 테이블 설계할 수 있다.
      • 파티션 테이블을 수정한 후, fdisk는 커널에 파티션 테이블을 다시 읽도록 지시하기 위해 디스크에 시스템 콜 요청
      • 커널 디버깅 메세지 출력 : e.g.sdf: sdf1 sdf2
    • parted: 명령을 실행하면 즉각 반영
      • 개별 명령을 즉각 커널에 신호 보낸다.
      • 커널 디버깅 메세지로 출력 X

# blockdev --rereadpt /dev/sdf

  • # blockdev --rereadpt /dev/sdf
    • /dev/sdf의 파티션 테이블 다시 로딩

fdisk

  • MBR 파티션 테이블용, Text 기반 파티셔닝 툴
$ 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 optionfunction
-a부팅 파티션 설정
-bBSD 디스크 라벨을 편집
-c도스 호환성 설정
-d파티션 삭제
-l사용 가능한 파티션 종류 출력
-m도움말 출력
-n새로운 파티션 추가
-o새로운 빈 DOS 파티션 생성
-p파티션 테이블 출력
-q작업 내용을 저장하지 않고 출력
-s새로운 빈 Sun 디스크 라벨 출력
-t파티션의 시스템 ID 변경(파일 시스템 종류 변경)
-u항목 정보 변경/출력
-v파티션 테이블 검사
-w파티션 정보를 디스크에 저장하고 종료
-x실린더 갯수 변경등 전문가를 위한 부가적 기능

p: 디스크 파티션 정보 조회

  1. 먼저 fdisk 사용 들어가자..

  1. 'p' 입력 : 해당 디스크 파티션 정보 조회

d: 파티션 제거

  1. 파티션 제거를 위해선 우선 umount미리 되어야함
$ umount <마운트 포인트>
				# 마운트 포인트에서 umount 안먹힘!!
e.g.
    $ sudo umount /media/pi/boot

  1. fdisk로 지정 디바이스 파일 관리 들어 간 후, 'd'로 파티션 삭제명령

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 변경(파일 시스템 종류 설정)

  • first partitionWIN 95 FAT32 (LBA) 로 셋
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 write

  • fdisk명령은 다 하고 나서 w로 마지막에 꼭 저장 후, fdisk 명령을 종료해야함★
Command (m for help): w		# 꼭 w 로 저장후 fdisk 명령을 종료해야함
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

사용 예

sdcard 포맷 후, 파일 시스템 할당

1. lsblk로 삭제할 디바이스 확인

  • lsblk삭제할 디바이스 확인. 여기서는 /dev/sda

1-1. 언마운트

$ sudo umount <마운트 포인트>

사용 예:
    $ sudo umount /media/pi/boot

2. fdisk로 boot, rootfs 파티션 구성

$ fdisk <devfile>

  • sdasda1, sda2로 파티션이 나뉘어져 있어도 sda를 선택해야함
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: 파티션 생성

  • n: 파티션 생성
    • primary partition
    • Partition Number: 1
    • Size: 16M,

t: 파티션 타입 변경

  • 파티션 타입만 변경하는 것이지 실제로 그 파일시스템으로 포맷되는 것은 아님!
  • 1 번째 파티션의 Type (filesystem) 이 Linux인데 이를, FAT32로 바꿔야한다.
  • t:파티션의 Type 변경
    • L: 변경할 수 있는 Type (filesystem) 나열
    • 여기서 c번: W95 FAT32 (LBA) 선택

  • 1 번째 파티션을 부팅 파티션으로 선택한다.
  • a: 부트 파티션 할당

  • 2 번째 파티션은 1Gext4로 할당한다.
  • 파티션을 생성했으면, 파일시스템은 나중에 수정해도 됨

  • w: 로 실제로 디스크에 Write해야한다!
    • w명령을 사용하지 않으면 위에한 것들이 의미가 없다.

3. mkfs로 파일 시스템 할당 + label 설정

3-1. ext4로 할당

  • sda2labelROOT, 파일시스템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으로 할당

  • sda1labelBOOT, 파일시스템vfat으로 셋
$ sudo mkfs.vfat -n "BOOT" /dev/sda1

4. 마운트

  • /dev/sda1/mnt로 마운트 해보자.
$ sudo mount <파티션> <마운트포인트>


$ sudo mount /dev/sda1 /mnt
$ cd /mnt
$ ls
lost+found
  • 방금 포맷한 파티션을 마운트 시켜보면 lost+found 밖에 없어 깔끔하게 포맷됨

5. eject로 제거

  • 항상 sdcard, USB flash drive를 제거하기 전, $ eject 명령 사용해서 제거해야함
$ sudo eject /dev/sda

$ gdisk

$ sudo gdisk <dev>
Optionsdescription
bback up GPT data to a file
cchange a partition's name
ddelete a partition
ishow detailed information on a partition
llist known partition types
nadd a new partition
ocreate a new empty GUID partition table (GPT)
pprint the partition table
qquit without saving changes
rrecovery and transformation options (experts only)
ssort partitions
tchange a partition's type code
vverify disk
wwrite table to disk and exit
xextra functionality (experts only)
?print this menu

parted

  • partedfdisk, gdisk와 다르게, 바로 명령이 적용되기 때문에 조심해야한다.
$ parted [options] [device [command [options...]...]]
Options                                                       description
-l, --listlists partition layout on all block devices
-m, --machinedisplays machine parseable output
-s, --scriptnever prompts for user intervention
-v, --versiondisplays the version
-a alignment-type
--align alignment-type
Set alignment for newly created partitions, valid alignment types are:

  • none: Use the minimum alignment allowed by the disk type.
  • cylinder: Align partitions to cylinders.
  • minimal: Use minimum alignment as given by the disk topology information. This and the opt value will use layout information provided by the disk to align the logical partition table addresses to actual physical blocks on the disks. The min value is the minimum aligment needed to align the partition properly to physical blocks, which avoids performance degradation.
  • optimal: Use optimum alignment as given by the disk topology information. This aligns to a multiple of the physical block size in a way that guarantees optimal performance.

  • 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.
  • profile
    pllpokko@alumni.kaist.ac.kr

    0개의 댓글