본문 바로가기
IT

ext4 파일시스템으로 포맷하기

by Oh.mogilalia 2018. 4. 3.

새로 설치한 하드디스크의 파티션을 생성하고 이를 EXT4로 포맷한다.
파티션 설정
먼저 fdisk 명령어를 이용하여 새로 설치한 하드디스크를 확인하자.

$ sudo fdisk -l
... 중략 ...
Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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 identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table
... 중략 ...

새로 설치한 하드가 /dev/sdb 임을 확인하고 이에 대한 파티션 설정 작업을 fdisk 명령어를 이용하여 진행한다.

$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7ae23e0a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help):

확인할 수 있듯이 'm'을 입력하면 fdisk에서 사용할 수 있는 명령어들이 나온다.

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)

'p' 명령어를 이용하면 현재 하드디스크의 파티션 정보를 확인할 수 있다. 새로 산 하드디스크의 경우 파티션 정보가 없으므로 아래와 같이 나온다.

Command (m for help): p

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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 identifier: 0x7ae23e0a

   Device Boot      Start         End      Blocks   Id  System

'n' 명령어를 이용하여 파티션을 생성하자.
하드디스크 전체를 하나의 파티션으로 생성하려면 특별한 입력 없이 엔터키만으로 default 값을 입력하여 파티션을 생성할 수 있다.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-312581807, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-312581807, default 312581807):
Using default value 312581807

'w' 명령어를 이용하여 설정한 파티션을 저장하고 fdisk를 종료한다

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

Calling ioctl() to re-read partition table.
Syncing disks.
xxxx@xxxx:~$

파티션 포맷

파일 시스템을 EXT4로 포맷하기 위해 mkfs.ext4 명령어를 이용한다.

xxxx@xxxx:~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42 (29-Nov-2011)
Discarding device blocks: done                          
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
9773056 inodes, 39072470 blocks
1953623 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1193 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done    

xxxx@xxxx:~$

마운트 설정

시스템 부팅 시 포맷한 파일 시스템을 특정 경로에 연결하기 위해 /etc/fstab 을 수정한다.
먼저 다음 명령어를 이용하여 파티션의 UUID를 확인한다. (귀찮으면 그냥 /dev/sdb1 형태로 입력해도 된다.)

xxxx@xxxx:~$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10  7월 22 11:05 469c0e1d-708b-41e5-9ad9-6285a526c1f4 -> ../../sda1
lrwxrwxrwx 1 root root 10  7월 22 11:05 93c4555f-0915-47bf-ab38-2ca499de3500 -> ../../dm-1
lrwxrwxrwx 1 root root  9  7월 22 18:01 b344a9ef-e53a-4b21-bf7e-0a834ee45b1b -> ../../sdc
lrwxrwxrwx 1 root root 10  7월 22 20:58 c0a9190e-9189-49be-9ef0-a6dc4b1e8eb3 -> ../../sdb1
lrwxrwxrwx 1 root root 10  7월 22 11:05 f6e7a383-6e5c-4fad-980e-97d80ef661c4 -> ../../dm-0

UUID를 확인하고 이를 이용하여 /etc/fstab 을 수정한다.

xxxx@xxxx:~$ sudo vi /etc/fstab
... 중략 ...
UUID=c0a9190e-9189-49be-9ef0-a6dc4b1e8eb3 /home/ssd      ext4    defaults 0 0
... 중략 ...

만약 마운트 설정을 잘못하면 부팅이 되지 않을 수 있으므로, 반드시 다음 명령어를 이용하여 설정한 fstab을 확인하자.

x@x:~$ sudo mount -a

'IT' 카테고리의 다른 글

버츄얼박스에 우분투 서버 설치 중...  (0) 2018.04.03
내 아이피 주소 알아내기  (0) 2018.04.03
우분투 노틸러스에서 SSH로 다른 컴퓨터 연결하기  (0) 2018.01.14
갤럭시 S4 루팅  (0) 2017.09.26
ubuntu dvd mount  (0) 2017.05.21