본문 바로가기

리눅스

리눅스에서 LVM으로 구성된 ROOT(centos-root) 파티션을 확장

728x90

LVM으로 구성된 ROOT(centos-root) 파티션을 확장

테스트 환경

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

$ df -Th | egrep -v tmpfs
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       8.0G  1.6G  6.5G  19% /
/dev/sda1               xfs      1014M  167M  848M  17% /boot

물리적 디스크 증설

- 10GB DISK 증설

추가된 DISK(sdb 디스크)

lsblk
$ lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   10G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0    9G  0 part
  ├─centos-root 253:0    0    8G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk
sr0              11:0    1 1024M  0 rom

LVM 구성하기

기존 Logical Volume 확인

lvdisplay
$ lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                trWXTj-Kz8t-FsW5-kYUz-vjlf-Vf0L-KyFdtD
  LV Write Access        read/write
  LV Creation host, time backup, 2021-08-12 07:33:13 -0400
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2sEmk2-uP1V-XFQ3-Nplu-fwaH-UzKq-BeM2IU
  LV Write Access        read/write
  LV Creation host, time backup, 2021-08-12 07:33:14 -0400
  LV Status              available
  # open                 1
  LV Size                <8.00 GiB
  Current LE             2047
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

물리 디스크 확인

- /dev/sdb(10 GB) 추가

fdisk -l
$ fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos
Disk identifier: 0x000c1034

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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

fdisk 명령으로 파티션 설정

fdisk /dev/sdb
$ fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0xb4b13c6f.

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):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

Calling ioctl() to re-read partition table.
Syncing disks.

blkid 명령으로 LVM2_member로 지정되어 있는지 확인

$ blkid
/dev/sda1: UUID="4702fde8-6f7e-411c-8564-3fb0fcf53609" TYPE="xfs"
/dev/sda2: UUID="YlzqyR-j3zj-UIph-Zwd8-X7aU-sgqF-Ea27B7" TYPE="LVM2_member"
/dev/sdb1: UUID="ef0kFO-W00J-vyCy-cQ6b-OL4T-oHAe-L0ti3R" TYPE="LVM2_member"
/dev/mapper/centos-root: UUID="da42f4e0-c733-4228-9a4b-5ad601a13926" TYPE="xfs"
/dev/mapper/centos-swap: UUID="dfea2579-f2a4-4a63-b10c-f0c3a78ab6a0" TYPE="swap"

pvcreate 명령으로 파티셔닝된 디스크를 물리 볼륨으로 생성

fdisk 명령으로 'Device Boot' 확인

blkid
$ fdisk -l
...
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 label type: dos
Disk identifier: 0xb4b13c6f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20971519    10484736   8e  Linux LVM
728x90

 

pvcreate 명령으로 물리 볼륨 생성

pvcreate /dev/sdb1
$ pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

pvscan명령으로 생성된 물리 볼륨 확인

pvscan
$ pvscan
  PV /dev/sda2   VG centos          lvm2 [<9.00 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [<10.00 GiB]
  Total: 2 [<19.00 GiB] / in use: 1 [<9.00 GiB] / in no VG: 1 [<10.00 GiB]

vgdisplay 명령으로 'VG Name' 확인

vgdisplay
$ vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <9.00 GiB
  PE Size               4.00 MiB
  Total PE              2303
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               V6A7Aa-Uq5g-Foqu-VoIl-Fvq3-ccnT-9jE60g
pvdisplay
$ pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <9.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2303
  Free PE               0
  Allocated PE          2303
  PV UUID               YlzqyR-j3zj-UIph-Zwd8-X7aU-sgqF-Ea27B7

  "/dev/sdb1" is a new physical volume of "<10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               <10.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ef0kFO-W00J-vyCy-cQ6b-OL4T-oHAe-L0ti3R

vgextend 명령으로 ROOT 디스크 증설

vgextend centos /dev/sdb1
$ vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
vgdisplay
$ vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               18.99 GiB
  PE Size               4.00 MiB
  Total PE              4862
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       2559 / <10.00 GiB
  VG UUID               V6A7Aa-Uq5g-Foqu-VoIl-Fvq3-ccnT-9jE60g

root(/dev/mapper/centos-root) 파일시스템 확인

df -hT | egrep -v tmpfs
$ df -hT | egrep -v tmpfs
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       8.0G  1.6G  6.5G  19% /
/dev/sda1               xfs      1014M  167M  848M  17% /boot

로지컬 볼륨 확장(Free  PE / Size)

 - lvextend /dev/centos/root -l +2559

lvextend /dev/centos/root -l +2559
$ lvextend /dev/centos/root -l +2559
  Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 17.99 GiB (4606 extents).
  Logical volume centos/root successfully resized.

xfs 포맷

xfs_growfs /dev/centos/root
$ xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=524032 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2096128, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2096128 to 4716544

디스크 증설 확인

df -h | egrep -v tmpfs
$ df -h | egrep -v tmpfs
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G  1.6G   17G   9% /
/dev/sda1               1014M  167M  848M  17% /boot

 

728x90