드레스룸 시스템행거 인테리어

반응형

parted - linux 파티션 설정

 

 

이전 페이지에 raid구성을 한 관계로 이번에는

PARTED 명령어를 통한 partion작업 및 mount를 해보도록 하자~!

 

partition작업에는 크게 두 가지 정도가 있다.

 

fdisk를 통한 작업 과

parted를 통한 작업

 

fdisk는 작은 용량 2TB 이하의 MBR( Master Boot Record )이며,

parted는 2TB 이상의 GPT( Guid Partition Table )이다.

 

GPT와 MBR 차이점은 더 이상 알 필요 없을 것 같다. 

 

자 이제 파티션 잡아야 할 디스크를 확인해 보도록 하자

(base) root@ubuntu:~# fdisk -l
Disk /dev/sda: 465.3 GiB, 499558383616 bytes, 975699968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes


Disk /dev/sdb: 1.8 TiB, 1920383410176 bytes, 3750748848 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xd0673133

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdb1  *     2048 3750748159 3750746112  1.8T 83 Linux

 

이전 글에서 raid 1 설정 해 두었던 sda에 대하여 fdisk와 parted를 통해 파티션을 잡아 보자.

 

 

(base) root@ubuntu:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).
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 0x470a5310.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): p
Disk /dev/sda: 465.3 GiB, 499558383616 bytes, 975699968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disklabel type: dos
Disk identifier: 0x470a5310

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):
First sector (2048-975699967, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-975699967, default 975699967):

Created a new partition 1 of type 'Linux' and of size 465.3 GiB.

Command (m for help): p
Disk /dev/sda: 465.3 GiB, 499558383616 bytes, 975699968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disklabel type: dos
Disk identifier: 0x470a5310

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 975699967 975697920 465.3G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

(base) root@ubuntu:~#

 

m을 누르게 되면 친절하게 command설명이 나와 있다.

 

p를 눌러 현재 디스크 상태를 확인 해 보면 파티션이 잡혀 있지 않은 상태이다.

 

n을 눌러 add a new partition을 해보자. 파티션 타입은 p를 눌러 primary로 잡아 준 후

 

partition number (default 1) : enter 

 

first sector는 새로 생성하는 파티션이기 때문에 이것도 enter  2048 default로 해준다.

 

마찬가지로 디스크 한 개를 파티션 한 개로 만들기 위해서  last sector 역시 default 선택 enter

 

생성이 잘 됐는지 확인하기 위하여 p ( print partition table )을 눌러 /dev/sda1 이 생겼나 확인.

 

잘 생성되었다면 마지막으로 w를 눌러 디스크를 마무리해준다.

 

 

(base) root@ubuntu:~# fdisk -l /dev/sda
Disk /dev/sda: 465.3 GiB, 499558383616 bytes, 975699968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disklabel type: dos
Disk identifier: 0x470a5310

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 975699967 975697920 465.3G 83 Linux

 

위와 같이 fdisk -l 명령어로 sda 파티션을 다시 확인해주고 format 및 마운트를 해주면 완성이다.

 

 

(base) root@ubuntu:~# mkfs.ext4 /dev/sda1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 121962240 4k blocks and 30490624 inodes
Filesystem UUID: e677c232-8fc8-408e-aa20-ed16fbd1acb3
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000

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

vim /etc/fstab

### add ###
/dev/sda1                                 /data           ext4    defaults        0       0
###########

 

(base) root@ubuntu:~# mount -a
(base) root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G  1.6M  3.2G   1% /run
/dev/sdb1       1.8T   48G  1.6T   3% /
tmpfs            16G     0   16G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
tmpfs           3.2G     0  3.2G   0% /run/user/0
/dev/sda1       457G   73M  434G   1% /data

 

위와 같이 ext4 파일 시스템으로 포맷 후 /etc/fstab에 등록해주고 mount -a로 마운트 해주면 완성!!!

 

이제 parted를 통한 파티션 잡는 방법을 사용해 보자.

 

사실 fdisk 파티션 잡는 방법은 요즘 사용하지 않는다.


(base) root@ubuntu:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) m
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) p
Model: AVAGO SMC3108 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:

Number  Start  End  Size  Type  File system  Flags

(parted) mklabel gpt
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart
Partition name?  []?
File system type?  [ext2]? ext4
Start? 0
End? 100%
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: AVAGO SMC3108 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name  Flags
 1      17.4kB  500GB  500GB  ext4

(parted) q
Information: You may need to update /etc/fstab.

 

parted를 통한 작업도 전혀 어렵지 않다.

 

parted /dev/sda를 통해 sda의 파티션을 잡아 보겠다.

 

역시 m 혹은 help를 통해 command를 확인해 볼 수 있다.

 

p를 통해 현재 파티션 현황을 확인 해 보면 파티션이 잡혀 있지 않다. 아까 fdisk로 잡은 디스크는 다시 초기화를 했다.

 

현재 파티션 table이 msdos (MBR)로 되어있기 때문에 mklabel를 통한 gpt로 변경 후

 

mkpart를 통해 파티션 name과 파일 시스템으로 ext4로 변경해 준다.

 

start는 0부터 end는 적기 편하게 100% 주면 하드디스크의 용량을 전부 할당할 수 있다.

 

할당이 끝났으면 다시 p를 통해 파티션이 잘 잡혀 있나 확인해보자.

 

이후에  포맷은 fdisk에서 진행했던 것과 동일하다.

 

마운트 역시 동일하지만 사실 다른 방법이 있다.

 

위에 설명에는 /etc/fstab에 /dev/sda1 장치명으로 마운트를 했다면, 이번에는 파티션 생성 후 만들어진 uuid 값을 통해

 

마운트를 해보자.

 

(base) root@ubuntu:~# blkid |grep /dev/sda >> /etc/fstab
(base) root@ubuntu:~# vim /etc/fstab

 

fstab에 들어가게 되면 

 

/dev/sda1: UUID="54cd7620-fe48-4277-9471-de19850fbd7e" TYPE="ext4" PARTUUID="c688bec0-cfa3-4639-87e2-7d0f126f2a4c"

 

이런 식으로 제일 하단에 추가되어 있을 것이다. 물론 uuid값은 다들 다르게 생성이 될 것이다.

 

### /etc/fstab   edit ###
UUID=54cd7620-fe48-4277-9471-de19850fbd7e /data           ext4    defaults        0       0
#########################

필요 없는 부분을 모두 삭제 후 위와 같이 변경을 해주면 끝이다.

 

(base) root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G  1.6M  3.2G   1% /run
/dev/sdb1       1.8T   48G  1.6T   3% /
tmpfs            16G     0   16G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
tmpfs           3.2G     0  3.2G   0% /run/user/0
(base) root@ubuntu:~# mount /dev/sda1 /data
(base) root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G  1.6M  3.2G   1% /run
/dev/sdb1       1.8T   48G  1.6T   3% /
tmpfs            16G     0   16G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
tmpfs           3.2G     0  3.2G   0% /run/user/0
/dev/sda1       457G   73M  434G   1% /data

 

이로써 파티션 작업에 대해 알아보았다.

 

TIP : uuid 주소는 디스크를 포맷하게 되면 변경된다.

uuid는 hba카드 jbod 같은 스토리지에서 많이 사용된다. 그렇지 않으면 디스크의 순서들이 꼬이는 경우가 굉장히 많기 때문이다.

 

반응형

이 글을 공유합시다

facebook twitter kakaoTalk kakaostory naver band