-
기존 디스크 확장하여 LVM 구성 (2)Linux 2020. 9. 5. 15:20
전체 순서
1. 기존 디스크 확장
2. 파티션 생성 (fdisk /dev/sdb)
3. pv 생성 (pvcreate /dev/sdb2)
4. VG 확장 (vgextend MyVG /dev/sdb2)
5. LV 확장 (lvextend -L+9.99G /dev/mapper/MyVG-MyLV)
6. 리사이즈 (resize2fs /dev/mapper/MyVG-MyLV)
7. 확인 (df -h)
이번 시간에는 바로전 포스트(https://yeajs.tistory.com/29?category=933210)에서 만든 디스크를 확장(20G->30G) 후 LVM에 추가하는 방법을 알아보겠습니다.
1. 기존 디스크 확장



리눅스에서 lsblk 명령어로 디스크 용량이 30G 가 되었는지 확인한다.
[root@centos7-02 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 200M 0 part /boot/efi ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 48.8G 0 part ├─centos-root 253:0 0 46G 0 lvm / └─centos-swap 253:1 0 2.8G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part └─MyVG-MyLV 253:2 0 20G 0 lvm /data sr0 11:0 1 4.4G 0 rom물리장치(sdb)의 표시 용량이 설정한(30G) 값으로 표시되어야 합니다.
만약 변경된 값으로 표시된 경우 -> 다음 단계 진행.
만약 변경된 값으로 표시되지 않은 경우 -> 재부팅 후, 다음 단계 진행.값 변화가 없으므로 재부팅 합니다.
[root@centos7-02 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 200M 0 part /boot/efi ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 48.8G 0 part ├─centos-root 253:0 0 46G 0 lvm / └─centos-swap 253:1 0 2.8G 0 lvm [SWAP] sdb 8:16 0 30G 0 disk └─sdb1 8:17 0 20G 0 part └─MyVG-MyLV 253:2 0 20G 0 lvm /data sr0 11:0 1 4.4G 0 rom재부팅 후 sdb값이 30G로 잘 표기됩니다.
2. 파티션 생성
/dev/sdb에 sdb2파트션을 만들고 Linux LVM으로 바꿔 줍니다.
[root@centos7-02 ~]# fdisk /dev/sdb The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. 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. Command (m for help): p Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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 Disk label type: dos Disk identifier: 0x739547a2 Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 8e Linux LVM Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p # 파티션 생성 Partition number (2-4, default 2): 2 # 2번 파티션 생성 First sector (41943040-62914559, default 41943040): Using default value 41943040 Last sector, +sectors or +size{K,M,G} (41943040-62914559, default 62914559): Using default value 62914559 Partition 2 of type Linux and of size 10 GiB is set Command (m for help): p Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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 Disk label type: dos Disk identifier: 0x739547a2 Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 8e Linux LVM /dev/sdb2 41943040 62914559 10485760 83 Linuxn -> p -> 2(파티션 번호, 파티션이 없으므로 1번을 누른다) -> 엔터 -> 엔터 를 눌러 2번 파티션을 만들었습니다. 이후 p를 눌려 보면 system: Linux라고 보이는데 이를 linux LVM으로 변경해야 합니다.
Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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 Disk label type: dos Disk identifier: 0x739547a2 Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 8e Linux LVM /dev/sdb2 41943040 62914559 10485760 8e Linux LVMt를 누른후 list입려하여 보면 Linux LVM 파티션 타입이 8e 값을 나타내기에 8e 값을 입력하였습니다. 하지만 최신 버전의 fdisk에서는 Linux LVM 값이 31을 나타낼 수 있습니다. 따라서 지원되는 파티션 유형을 확인 후 정확한 값을 입력해 주시기 바랍니다.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.* 오류 원인:
/dev/sdb 디스크가 사용중인 경우 위와 같은 메시지가 나타날 수 있습니다. (현재 사용중인 HDD에 특정 파티션을 추가 하거나 변형 했을 경우 해당 오류 발생됨)
*해결:
이 경우 partprobe 명령어를 실행하여 리부팅 없이 사용 중인 파티션을 재인식 시킬수 있습니다. (예: partprobe /dev/sdb)
[root@centos7-02 ~]# partprobe /dev/sdb3. pv 생성
pvcreate 로 물리 볼륨 생성합니다.
[root@centos7-02 ~]# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created.pvdisplay 로 물리볼륨 확인합니다.
[root@centos7-02 ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name MyVG PV Size <20.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 5119 Free PE 0 Allocated PE 5119 PV UUID G5oaVd-sudE-D2V4-nkaw-Uy20-Q1WT-bbL7ve "/dev/sdb2" is a new physical volume of "10.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID uXzRBd-sDBI-GmiZ-JTe2-ny3m-1SP1-fg0jUi4. VG 확장
vgextend로 볼륨 그룹을 확장합니다.
[root@centos7-02 ~]# vgextend MyVG /dev/sdb2 Volume group "MyVG" successfully extendedvgdisplay로 볼륨 그룹 크기 확인 합니다.
[root@centos7-02 ~]# vgdisplay --- Volume group --- VG Name MyVG System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 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 29.99 GiB PE Size 4.00 MiB Total PE 7678 Alloc PE / Size 5119 / <20.00 GiB Free PE / Size 2559 / <10.00 GiB VG UUID rlLIH3-f6Nj-6AMb-DJiM-ZUI2-O7Uv-k2Fv8K5. LV 확장
lvdisplay로 물리 볼륨 확인한다.
[root@centos7-02 ~]# lvdisplay --- Logical volume --- LV Path /dev/MyVG/MyLV LV Name MyLV VG Name MyVG LV UUID ZOOLXc-tCkw-RYm4-RfGp-eL9I-fowH-rVaKgH LV Write Access read/write LV Creation host, time centos7-02, 2020-09-05 14:57:53 +0900 LV Status available # open 1 LV Size <20.00 GiB Current LE 5119 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2lvextend로 물리 볼륨 용량 증가시킨다.
[root@centos7-02 ~]# lvextend -L+9.99G /dev/mapper/MyVG-MyLV Rounding size to boundary between physical extents: 9.99 GiB. Size of logical volume MyVG/MyLV changed from <20.00 GiB (5119 extents) to <29.99 GiB (7677 extents). Logical volume MyVG/MyLV successfully resized.[root@centos7-02 ~]# lvextend -l 100%FREE /dev/mapper/MyVG-MyLV New size given (5120 extents) not larger than existing size (7677 extents) [root@centos7-02 ~]# lvextend -l +100%FREE /dev/mapper/MyVG-MyLV Size of logical volume MyVG/MyLV changed from <29.99 GiB (7677 extents) to <49.99 GiB (12797 extents). Logical volume MyVG/MyLV successfully resized.+를 빼면 오류 생기므로 lvextend -l +100%FREE 처럼 앞에 +입력해야 합니다.
6. 리사이즈
[root@centos7-02 ~]# resize2fs /dev/mapper/MyVG-MyLV resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/mapper/MyVG-MyLV is mounted on /data; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 4 The filesystem on /dev/mapper/MyVG-MyLV is now 7861248 blocks long.-------
<리사이즈 오류 해결>
* 오류 메시지:
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/MyVG-MyLV
Couldn't find valid filesystem superblock.
* 원인:
blkid /dev/mapper/MyVG-MyLV 명령어로 타입을 확인해본다. TYPE="xfs"이 경우 오류발생
*해결:
xfs_growfs /dev/mapper/MyVG-MyLV 명령어 입력
-------
7. 확인
[root@centos7-02 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 452M 0 452M 0% /dev tmpfs 464M 0 464M 0% /dev/shm tmpfs 464M 6.2M 457M 2% /run tmpfs 464M 0 464M 0% /sys/fs/cgroup /dev/mapper/centos-root 47G 1.4G 45G 3% / /dev/sda2 1014M 128M 887M 13% /boot /dev/sda1 200M 12M 189M 6% /boot/efi /dev/mapper/MyVG-MyLV 30G 44M 28G 1% /data tmpfs 93M 0 93M 0% /run/user/0'Linux' 카테고리의 다른 글
배포서버 구축 (2) (0) 2020.09.05 배포서버 구축 (1) (0) 2020.09.05 디스크 추가하여 LVM 구성 (1) (0) 2020.09.05 SVN, HTTP, LDAP 모두 연동 (0) 2020.04.16 LDAP 설치 (0) 2020.04.16