/ (루트)가 마운트 된 디스크 확장하기

728x90

안녕하세요!

오늘은 / (루트)가 마운트 된 디스크 확장하기에 대하여 알아보겠습니다.

 

 

growpart 설치하기

 

growpart는 쉽게 파티션을 확장할 수 있고 명령이 단순합니다.
적용 전에 작업 전/후 변경 사항을 확인할 수 있으며, 파티션 확장 시 섹터 정보를 알지 못하더라도, 자동으로 처리해 줍니다.
growpart를 사용하기 위한 제한 사항으로는 파티션의 마지막 섹터 주소 이후에 연속된 빈 공간이 있어야 하며, 디스크 확장을 한 경우, 확장할 파티션이 디스크 레이아웃 상 마지막 파티션이어야 합니다.

 

growpart는 cloud-utils-growpart 명령어로 설정합니다.

설치가 되지 않는다면 epel repository를 추가한 후 진행합니다.

[root@localhost ~]# yum install cloud-utils-growpart
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>


[root@localhost ~]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# yum repolist all


[root@localhost ~]# yum install cloud-utils-growpart

[root@localhost ~]# growpart
growpart disk partition
   rewrite partition table so that partition takes up all the space it can
   options:
    -h | --help       print Usage and exit
         --fudge F    if part could be resized, but change would be
                      less than 'F', do not resize (default: 20480)
    -N | --dry-run    only report what would be done, show new 'sfdisk -d'
    -v | --verbose    increase verbosity / debug
    -u | --update  R  update the the kernel partition table info after growing
                      this requires kernel support and 'partx --update'
                      R is one of:
                       - 'auto'  : [default] update partition if possible
                       - 'force' : try despite sanity checks (fail on failure)
                       - 'off'   : do not attempt
                       - 'on'    : fail if sanity checks indicate no support

   Example:
    - growpart /dev/sda 1
      Resize partition 1 on /dev/sda
must supply disk and partition-number

 

 

 

 

growpart로 용량 증설하기

 

[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda        8:0    0  100G  0 disk
├─sda1   8:1    0  300M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 47.7G   0 part /
sr0       11:0    1 1024M  0 rom
[root@localhost ~]# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  316MB   315MB   primary  xfs             boot
 2      316MB   2464MB  2149MB  primary  linux-swap(v1)
 3      2464MB  53.7GB  51.2GB  primary  xfs

lsblk로 확인해 보면 sda3의 용량은 47.7G입니다.
parted 명령어로 확인해 보면 /dev/sda의 용량은 107GB입니다.

 

growpart 에는 --dry-run이 옵션이 있습니다. 이 옵션은 어떻게 실행되는지 결과만 보여줍니다.

old와 new로 나눠서 보여줍니다. start sector은 48128000이고 size가 100044800에서 204899710으로 늘어난다고 되어 있습니다.

 

[root@localhost ~]# parted /dev/sda unit s print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 209715200s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start     End         Size        Type     File system     Flags
 1      2048s     616447s     614400s     primary  xfs             boot
 2      616448s   4812799s    4196352s    primary  linux-swap(v1)
 3      4812800s  104857599s  100044800s  primary  xfs

parted로 sector을 확인해도 old의 start와 size가 동일한 것을 확인할 수 있습니다.

--dry-run 옵션 없이 growpart 명령어를 실행합니다.

[root@localhost ~]# growpart  /dev/sda 3
CHANGED: partition=3 start=4812800 old: size=100044800 end=104857600 new: size=204899710,end=209712510

sda3가 늘어난 것을 lsblk 명령어를 통해 확인할 수 있습니다.

 

 

 

루트 파일시스템 확장하기

파일 시스템의 환경까지 늘려줘야 합니다. df 명령어를 사용해 보면 아직 sda3의 용량은 48G입니다.

[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        900M     0  900M   0% /dev
tmpfs           910M     0  910M   0% /dev/shm
tmpfs           910M  9.7M  901M   2% /run
tmpfs           910M     0  910M   0% /sys/fs/cgroup
/dev/sda3        48G  1.8G   46G   4% /
/dev/sda1       297M  132M  166M  45% /boot
tmpfs           182M     0  182M   0% /run/user/0

xfs_growfs 명령어는 디바이스가 마운트 된 상태에서 실행하며, 명령어의 인자로 마운트 된 디렉터리를 주면 됩니다.

[root@localhost ~]# xfs_growfs /
meta-data=/dev/sda3              isize=512    agcount=4, agsize=3126400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=12505600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6106, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12505600 to 25612463

df -hT 명령어를 통해 확인해 보면 sda3의 용량은 98G로 확장된 것을 확인할 수 있습니다.


참고
https://tech.osci.kr/growpart-%EC%99%80-%EB%A3%A8%ED%8A%B8-%ED%8C%8C%EC%9D%BC-%EC%8B%9C%EC%8A%A4%ED%85%9C-%ED%99%95%EC%9E%A5-1%ED%8E%B8/


 

 

 

 

 

이상입니다.

감사합니다!

728x90
반응형

'Linux(리눅스)' 카테고리의 다른 글

yum 명령어  (1) 2024.02.29
커널(Kernel)이란?  (0) 2024.02.16
SELinux(Security-Ehacned Linux) Boolean(부울)  (0) 2024.02.13
SELinux(Security-Enhanced Linux)  (0) 2024.02.12
Linux 디스크 파티셔닝(MBR, GPT)  (0) 2024.02.02