본문 바로가기

리눅스

[리눅스] LVM으로 구성된 ROOT(vg0-lv--0) 파티션 확장

728x90

LVM으로 구성된 ROOT(vg0-lv--0) 파티션 확장

테스트 환경

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
$ df -h | egrep -v tmpfs
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv--0   48G  9.7G   36G  22% /
/dev/sda2              974M  127M  780M  14% /boot

현재 구성된 볼륨 확인

Physical volume 확인

pvs
$ pvs
  PV         VG  Fmt  Attr PSize   PFree
  /dev/sda3  vg0 lvm2 a--  <49.00g    0
pvdisplay
$ pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               vg0
  PV Size               <49.00 GiB / not usable 0   
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              12543
  Free PE               0
  Allocated PE          12543
  PV UUID               EzR25A-XEmv-nNpb-ljAb-MnXI-rx6Z-6FCFBk

Logical volume 확인

lvs
$ lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv-0 vg0 -wi-ao---- <49.00g
lvdisplay
$ lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg0/lv-0
  LV Name                lv-0
  VG Name                vg0
  LV UUID                Fr3FaA-gfq8-CFqg-0O9n-45VI-PQFA-3c8sRs
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2022-10-17 20:44:41 +0900
  LV Status              available
  # open                 1
  LV Size                <49.00 GiB
  Current LE             12543
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Volume group 확인

vgs
$ vgs
  VG  #PV #LV #SN Attr   VSize   VFree
  vg0   1   1   0 wz--n- <49.00g    0
vgdisplay
$ vgdisplay 
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <49.00 GiB
  PE Size               4.00 MiB
  Total PE              12543
  Alloc PE / Size       12543 / <49.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               hphJDm-bnzU-vx3i-HPW3-PGM7-czM0-KPCZfH

디스크 추가 및 볼륨 추가 구성하기

추가된 물리 디스크 확인

- Disk /dev/sdb: 100 GiB

$ fdisk -l
...
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VBOX HARDDISK   
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: gpt
Disk identifier: 0DB033CB-3D5D-414E-B60E-6B9B2BF3708D

Device       Start       End   Sectors Size Type
/dev/sda1     2048      4095      2048   1M BIOS boot
/dev/sda2     4096   2101247   2097152   1G Linux filesystem
/dev/sda3  2101248 104855551 102754304  49G Linux filesystem


Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VBOX HARDDISK   
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 /dev/mapper/vg0-lv--0: 49 GiB, 52609155072 bytes, 102752256 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
lsblk --fs
$ lsblk --fs | egrep -v squashfs
NAME          FSTYPE      FSVER    LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
sda                                                                                            
├─sda1                                                                                         
├─sda2        ext4        1.0            7a7b9f02-1507-49ba-8b99-7640606ef946    779.6M    13% /boot
└─sda3        LVM2_member LVM2 001       EzR25A-XEmv-nNpb-ljAb-MnXI-rx6Z-6FCFBk                
  └─vg0-lv--0 ext4        1.0            e0c5de6f-2672-4ebc-b9bf-58c50698c30e     35.8G    20% /
sdb                                                                                            
sr0

추가 파티션 생성

- Disk /dev/sdb: 100 GiB

fdisk /dev/sdb
Command (m for help): n
Select (default p): p
Partition number (1-4, default 1): (Enter)
First sector (2048-209715199, default 2048): (Enter)
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199): (Enter)
Command (m for help): t
Hex code or alias (type L to list all): L
Hex code or alias (type L to list all): 8E
Command (m for help): p
Command (m for help): w
$ fdisk /dev/sdb

Welcome to fdisk (util-linux 2.37.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.
Created a new DOS disklabel with disk identifier 0xb5f1ea38.

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

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

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

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

Aliases:
   linux          - 83
   swap           - 82
   extended       - 05
   uefi           - EF
   raid           - FD
   lvm            - 8E
   linuxex        - 85
Hex code or alias (type L to list all): 8E
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VBOX HARDDISK   
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: 0xb5f1ea38

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1  2048 209715199 209713152  100G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
fdisk -l /dev/sdb
$ fdisk -l /dev/sdb
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VBOX HARDDISK   
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: 0x9a514aba

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 209715199 209713152  100G 8e Linux LVM
lsblk | egrep -v 'loop|sr0'
$ lsblk | egrep -v 'loop|sr0'
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                         8:0    0   25G  0 disk 
├─sda1                      8:1    0    1M  0 part 
├─sda2                      8:2    0    2G  0 part /boot
└─sda3                      8:3    0   23G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0 11.5G  0 lvm  /
sdb                         8:16   0   100G 0 disk 
└─sdb1                      8:17   0   100G 0 part

Physical volume 생성

- /dev/sdb1 생성

pvcreate /dev/sdb1
$ pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created.
$ pvs
  PV         VG  Fmt  Attr PSize    PFree   
  /dev/sda3  vg0 lvm2 a--   <49.00g       0 
  /dev/sdb1      lvm2 ---  <100.00g <100.00g

Volume group 확장

- /dev/sdb1 확장

$ pvdisplay | egrep "PV Name"
  PV Name               /dev/sda3
  PV Name               /dev/sdb1
$ vgdisplay | egrep "VG Name"
  VG Name               vg0
vgextend vg0 /dev/sdb1
$ vgextend vg0 /dev/sdb1 
  Volume group "vg0" successfully extended
$ vgdisplay 
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               148.99 GiB
  PE Size               4.00 MiB
  Total PE              38142
  Alloc PE / Size       12543 / <49.00 GiB
  Free  PE / Size       25599 / <100.00 GiB
  VG UUID               hphJDm-bnzU-vx3i-HPW3-PGM7-czM0-KPCZfH

Logical volume 확장

$ lvdisplay | egrep "LV Path"
  LV Path                /dev/vg0/lv-0
lvextend --extents +100%FREE /dev/vg0/lv-0
$ lvextend --extents +100%FREE /dev/vg0/lv-0
  Size of logical volume vg0/lv-0 changed from <49.00 GiB (12543 extents) to 148.99 GiB (38142 extents).
  Logical volume vg0/lv-0 successfully resized.
lvs
$ lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv-0 vg0 -wi-ao---- 148.99g
lvdisplay | egrep "LV Path"
$ lvdisplay | egrep "LV Path"
  LV Path                /dev/ubuntu-vg/ubuntu-lv
resize2fs /dev/vg0/lv-0
$ resize2fs /dev/vg0/lv-0
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/vg0/lv-0 is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 19
The filesystem on /dev/vg0/lv-0 is now 39057408 (4k) blocks long.

구성된 파일시스템 확인

df -h | egrep -v tmpfs
$ df -h | egrep -v tmpfs
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv--0  147G   12G  129G   9% /
/dev/sda2              974M  127M  780M  14% /boot
lsblk --fs | egrep -v squashfs
$ lsblk --fs | egrep -v squashfs
NAME          FSTYPE      FSVER    LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
sda                                                                                            
├─sda1                                                                                         
├─sda2        ext4        1.0            7a7b9f02-1507-49ba-8b99-7640606ef946    779.6M    13% /boot
└─sda3        LVM2_member LVM2 001       EzR25A-XEmv-nNpb-ljAb-MnXI-rx6Z-6FCFBk                
  └─vg0-lv--0 ext4        1.0            e0c5de6f-2672-4ebc-b9bf-58c50698c30e    128.3G     8% /
sdb                                                                                            
└─sdb1        LVM2_member LVM2 001       5J9rik-XGqX-pIEt-IvAZ-nA5x-JHh2-SZAUpJ                
  └─vg0-lv--0 ext4        1.0            e0c5de6f-2672-4ebc-b9bf-58c50698c30e    128.3G     8% /
sr0
728x90