Skip to content

Instantly share code, notes, and snippets.

@leewin12
Last active October 7, 2019 07:47
Show Gist options
  • Save leewin12/982ace9f24a11aee2bdb505726e63d77 to your computer and use it in GitHub Desktop.
Save leewin12/982ace9f24a11aee2bdb505726e63d77 to your computer and use it in GitHub Desktop.
CentOS_6/7 lvm 추가하는 방법
0. lvm 설치
$ yum install lvm2 -y
1. 디스크 먼저 추가
(/dev/xvdb 라고 가정)
2. fdisk 로 해당 디스크 파티셔닝 및 파일시스템을 Linux LVM (8e) 타입으로 변경
$ fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe866154b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4438, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-4438, default 4438):
Using default value 4438
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.1 추가된 디스크 파티션을 기준으로 LVM PV 생성
$ vgcreate VolGroup00 /dev/xvdb1
3.2 추가된 디스크 파티션 (예:/dev/sdb1) 을 LVM pv로 등록
$ pvcreate /dev/xvdb1
-- pv 확인
$ pvdisplay
4. 볼륨그룹에 해당 pv 를 추가
-- 볼륨그룹 확인방법
$ vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV Lh4J3khz2
Max PV 0
Cur PV 2
Act PV 2
VG Size 69.84 GB
PE Size 32.00 MB
Total PE 2235
Alloc PE / Size 2235 / 69.84 GB
Free PE / Size 0 / 0
VG UUID c0VfnV-tkri-vcAz-Z9Nz-bhBc-hfsX-Xdbupi
-- 볼륨그룹에 pv를 추가
$ vgextend VolGroup00 /dev/xvdb1
-- 볼륨그룹 증가된 부분 확인
$ vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
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 69.84 GB
PE Size 32.00 MB
Total PE 2235 ---> 증가된 부분 확인
Alloc PE / Size 2235 / 69.84 GB
Free PE / Size 0 / 0 ---> 남은 공간 (추가된 디스크 만큼의 용량)
VG UUID c0VfnV-tkri-vcAz-Z9Nz-bhBc-hfsX-Xdbupi
5.1 LV 생성
$ lvcreate -n LogVol01 -l+100%FREE VolGroup00
$ mkfs.ext4 /dev/VolGroup00/LogVol01
5.2 볼륨그룹내 LV 의 크기를 증가.
vgdisplay 의 결과중 TotalPE의 크기만큼 증가시킨다.
즉, 추가할 PE만큼 늘리는게 아니라 목표하는 전체 PE의 크기만큼 지정해준다.
$ lvextend -l +100%FREE /dev/mapper/VolGroup00-LogVol01
-- vg와 lv 를 모두 확인
$ vgdisplay
$ lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID Mlt1AT-b5aP-k1L8-355J-i9dT-3Fak-BNcmQz
LV Write Access read/write
LV Status available
# open 1
LV Size 68.84 GB --> 최종 증가된 분량 확인
Current LE 2203
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
6. 파일시스템에 적용
--> LV까지 증가시켰는데도 파일시스템이 증가하지 않는다.
수동으로 증가시켜야 한다.
$ resize2fs /dev/mapper/VolGroup00-LogVol01
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol01 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol01 to 18046976 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol01 is now 18046976 blocks long.
주의) centos7에서는 $ fsadm resize /dev/centos/root 을 통해서 resize할 수 있다.
Centos7에서의 에러 내용
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
7. 확인
$ df -k 로 확인했을때 늘어난 용량을 확인할 수 있다.
원본: http://www.ischo.net/1390
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment