본문 바로가기
IT/LINUX

[LINUX][RHEL7] LVM 사용하기

by 양눈 2016. 12. 16.
반응형

 

 

[LINUX][RHEL7] LVM 사용 

- LVM을 사용한 전체적인 파일시스템 생성 과정

 

1. 파티션 생성 1GB 크기의 물리적인 파티션을 생성

 

[TEST-root] rh70:/#fdisk /dev/sdc
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 0xace77f11.

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): o
Building a new DOS disklabel with disk identifier 0x83695c0d.

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

Command (m for help): t
Selected partition 1
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.
[TEST-root] rh70:/dev/mapper#partprobe /dev/sdc

[TEST-root] rh70:/database#fdisk -l /dev/sdc

Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 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: 0x83695c0d

Device Boot Start End Blocks Id System
/dev/sdc1 2048 2099199 1048576 8e Linux LVM

 

2. PV생성 - 만들어진 물리 파티션을 physical volume으로 생성합니다.

[TEST-root] rh70:/dev/mapper# pvcreate /dev/sdc1
WARNING: crypto_LUKS signature detected on /dev/sdc1 at offset 0. Wipe it? [y/n] y
Wiping crypto_LUKS signature on /dev/sdc1.
Physical volume "/dev/sdc1" successfully created
[TEST-root] rh70:/dev/mapper#

 

3. VG생성 - volume group datavol 생성합니다.
[TEST-root] rh70:/dev/mapper#vgcreate -s 8M datavol /dev/sdc1
Volume group "datavol" successfully created

4. LV생성 - datavol 그룹에 8M extent 40개를 가지는 database 라는 이름의 logical volume 생성합니다
[TEST-root] rh70:/dev/mapper#lvcreate -l 40 -n database datavol
Logical volume "database" created
[TEST-root] rh70:/dev/mapper#
[TEST-root] rh70:/dev/mapper#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
database datavol -wi-a----- 320.00m
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g

5. FS생성 마운트
# mkdir /database
[TEST-root] rh70:/database
# lvdisplay datavol
--- Logical volume ---
LV Path /dev/datavol/database
LV Name database
VG Name datavol
LV UUID zHJMhj-2xfh-9Vs0-iGOP-hOxI-BfN3-4JdvJf
LV Write Access read/write
LV Creation host, time rh70, 2015-02-12 16:36:21 +0900
LV Status available
# open 0
LV Size 320.00 MiB
Current LE 40
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2


[TEST-root] rh70:/database# mkfs -t ext4 /dev/mapper/datavol-database
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
81920 inodes, 327680 blocks
16384 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33947648
40 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[TEST-root] rh70:/database#mount /dev/mapper/datavol-database /database
[TEST-root] rh70:/database#
[TEST-root] rh70:/database#
[TEST-root] rh70:/database#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/datavol-database 302M 2.1M 280M 1% /database

[TEST-root] rh70:/database # vi /etc/fstab
/dev/mapper/datavol-database /database ext4 defaults 1 1


6. FS
확장 (320M -> 640M resize2fs 사용)
[TEST-root] rh70:/database#vgs
VG #PV #LV #SN Attr VSize VFree
datavol 1 1 0 wz--n- 1016.00m 696.00m
rhel 2 2 0 wz--n- 49.50g 6.00g
[TEST-root] rh70:/database#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
database datavol -wi-ao---- 320.00m
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g

[TEST-root] rh70:/database#lvextend -l +40 /dev/mapper/datavol-database
Extending logical volume database to 640.00 MiB
Logical volume database successfully resized

[TEST-root] rh70:/database#resize2fs /dev/datavol/database
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/datavol/database is mounted on /database; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/datavol/database is now 655360 blocks long.

[TEST-root] rh70:/database#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/datavol-database 612M 2.3M 577M 1% /database

7. 추가 남은공간 전체 확장 (lvextend -r 옵션사용시 FS까지 확장됨)
[TEST-root] rh70:/database# lvextend -l +100%FREE -r /dev/datavol/database
Extending logical volume database to 1016.00 MiB
Logical volume database successfully resized
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/datavol-database is mounted on /database; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 8
The filesystem on /dev/mapper/datavol-database is now 1040384 blocks long.

[TEST-root] rh70:/database#
[TEST-root] rh70:/database#
[TEST-root] rh70:/database#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/datavol-database 976M 2.8M 926M 1% /database

[TEST-root] rh70:/database#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
database datavol -wi-ao---- 1016.00m
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g

8. FS축소 (fsadm 온라인가능, resize2fs umount 변경가능)
- fsadm
통한 축소
[TEST-root] rh70:/database# fsadm -e -y resize /dev/datavol/database 500M
Do you want to unmount "/database"? [Y|n] y
fsck from util-linux 2.23.2
/dev/mapper/datavol-database: 11/260096 files (0.0% non-contiguous), 43833/1040384 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/datavol-database to 512000 (1k) blocks.
The filesystem on /dev/mapper/datavol-database is now 512000 blocks long.

[TEST-root] rh70:/database#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/datavol-database 477M 2.3M 449M 1% /database -->
즉시반영됨

[TEST-root] rh70:/database#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
database datavol -wi-ao---- 1016.00m
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g
[TEST-root] rh70:/database#lvreduce -L 500M /dev/datavol/database
Rounding size to boundary between physical extents: 504.00 MiB
WARNING: Reducing active and open logical volume to 504.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce database? [y/n]: y
Reducing logical volume database to 504.00 MiB
Logical volume database successfully resized

[TEST-root] rh70:/database#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
database datavol -wi-ao---- 504.00m
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g
[TEST-root] rh70:/database#

- resize2fs 통한 축소

[TEST-root] rh70:/database#resize2fs /dev/datavol/database 100M
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/datavol/database is mounted on /database; on-line resizing required
resize2fs: On-line shrinking not supported -->
마운트 되어있는상태에서 축소가 안됨

[TEST-root] rh70:/database#umount /database
[TEST-root] rh70:/database#resize2fs /dev/datavol/database 100M
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/datavol/database' first. --> e2fsck
먼저 수행해야함

[TEST-root] rh70:/database#e2fsck -f /dev/datavol/database
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/datavol/database: 11/129024 files (0.0% non-contiguous), 26801/512000 blocks

[TEST-root] rh70:/database#resize2fs /dev/datavol/database 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/datavol/database to 102400 (1k) blocks.
The filesystem on /dev/datavol/database is now 102400 blocks long. --> e2fck
수행후 FS 정상축소됨

[TEST-root] rh70:/database#lvreduce -L 100M /dev/datavol/database
Rounding size to boundary between physical extents: 104.00 MiB
WARNING: Reducing active logical volume to 104.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce database? [y/n]: y
Reducing logical volume database to 104.00 MiB
Logical volume database successfully resized

[TEST-root] rh70:/database#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
database datavol -wi-a----- 104.00m
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g

[TEST-root] rh70:/database#mount /dev/mapper/datavol-database /database
[TEST-root] rh70:/database#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/datavol-database 89M 1.6M 81M 2% /database


2)
논리볼륨확장

-- xfs 확장은되지만 축소는 되지 않는 파일시스템

-- xfs 확장
# xfs_growfs /
마운트포인트

-- ext4 확장
# resize2fs [
디바이스명] 100M

# fsadm -e -y resize /dev/datavol/database 500M

1. 파티션 생성

1) 디스크 디바이스 확인

[TEST-root] rh70:/root#lsscsi
[0:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
[0:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb
[0:0:2:0] disk VMware Virtual disk 1.0 /dev/sdc
[2:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0


2)
파티션 정보확인
[TEST-root] rh70:/root#fdisk -l /dev/sdc

Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 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: 0x83695c0d

Device Boot Start End Blocks Id System

3) 파티션 생성
[TEST-root] rh70:/root#fdisk /dev/sdc
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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

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

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to '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):
First sector (2099200-4194303, default 2099200):

Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-4194303, default 4194303):
Using default value 4194303
Partition 2 of type Linux and of size 1023 MiB is set

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): w
The partition table has been altered!

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

4)파티션 테이블 반영
[TEST-root] rh70:/root#partprobe

5)
파티션 정보보기
[TEST-root] rh70:/root#fdisk -l /dev/sdc

Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 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: 0x83695c0d

Device Boot Start End Blocks Id System
/dev/sdc1 2048 2099199 1048576 8e Linux LVM
/dev/sdc2 2099200 4194303 1047552 8e Linux LVM

[TEST-root] rh70:/root#

2. PV생성

[TEST-root] rh70:/root#pvcreate /dev/sdc1 /dev/sdc2
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdc2" successfully created

3. VG 생성

[TEST-root] rh70:/root#vgcreate -s 4 uservg /dev/sdc1
Volume group "uservg" successfully created

[TEST-root] rh70:/root#vgs
VG #PV #LV #SN Attr VSize VFree
rhel 2 2 0 wz--n- 49.50g 6.00g
uservg 1 0 0 wz--n- 1020.00m 1020.00m

[TEST-root] rh70:/root#vgdisplay uservg
--- Volume group ---
VG Name uservg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 0 / 0
Free PE / Size 255 / 1020.00 MiB
VG UUID 6btSlf-kaQv-F10J-EOnn-OkDe-0epn-e9bbf8

4. LV생성


[TEST-root] rh70:/root#lvcreate -l 100 -n userlv uservg
WARNING: ext4 signature detected on /dev/uservg/userlv at offset 1080. Wipe it? [y/n] y
Wiping ext4 signature on /dev/uservg/userlv.
Logical volume "userlv" created

[TEST-root] rh70:/root#lvdisplay uservg
--- Logical volume ---
LV Path /dev/uservg/userlv
LV Name userlv
VG Name uservg
LV UUID IarT1r-6chm-feoC-DLd6-64Jv-2Qcz-tDudEn
LV Write Access read/write
LV Creation host, time rh70, 2015-02-13 13:45:11 +0900
LV Status available
# open 0
LV Size 400.00 MiB
Current LE 100
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

[TEST-root] rh70:/root#vgdisplay uservg
--- Volume group ---
VG Name uservg
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 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 100 / 400.00 MiB
Free PE / Size 155 / 620.00 MiB

VG UUID 6btSlf-kaQv-F10J-EOnn-OkDe-0epn-e9bbf8

5. FS생성(XFS) 마운트

[TEST-root] rh70:/root#mkfs -t xfs /dev/mapper/uservg-userlv
meta-data=/dev/mapper/uservg-userlv isize=256 agcount=4, agsize=25600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=102400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[TEST-root] rh70:/root#
[TEST-root] rh70:/root#vi /etc/fstab
[TEST-root] rh70:/root#
[TEST-root] rh70:/root#cat /etc/fstab | grep uservg
/dev/mapper/uservg-userlv /database xfs defaults 1 2

[TEST-root] rh70:/root#mount -a

[TEST-root] rh70:/root#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/uservg-userlv 397M 21M 377M 6% /database

6. FS확장하기
1) LV
확장
[TEST-root] rh70:/root#lvextend -l +155 /dev/uservg/userlv
Extending logical volume userlv to 1020.00 MiB
Logical volume userlv successfully resized

2) VG
정보 확인
[TEST-root] rh70:/root#vgdisplay uservg
--- Volume group ---
VG Name uservg
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 255 / 1020.00 MiB
Free PE / Size 0 / 0
VG UUID 6btSlf-kaQv-F10J-EOnn-OkDe-0epn-e9bbf8

3) FS
확장
[TEST-root] rh70:/root#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/uservg-userlv 397M 21M 377M 6% /database

[TEST-root] rh70:/root#xfs_growfs /database
meta-data=/dev/mapper/uservg-userlv isize=256 agcount=4, agsize=25600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=102400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 102400 to 261120

[TEST-root] rh70:/root#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/uservg-userlv 1017M 21M 997M 3% /database

7. VG확장하기
[TEST-root] rh70:/root# vgdisplay uservg
--- Volume group ---
VG Name uservg
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 255 / 1020.00 MiB
Free PE / Size 0 / 0
VG UUID 6btSlf-kaQv-F10J-EOnn-OkDe-0epn-e9bbf8


[TEST-root] rh70:/root
#vgextend uservg /dev/sdc2
Volume group "uservg" successfully extended

[TEST-root] rh70:/root
#vgdisplay uservg
--- Volume group ---
VG Name uservg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 255 / 1020.00 MiB
Free PE / Size 255 / 1020.00 MiB

VG UUID 6btSlf-kaQv-F10J-EOnn-OkDe-0epn-e9bbf8

8. LV, FS 재확장
1) LV
확장

[TEST-root] rh70:/root#lvextend -l +100%FREE /dev/uservg/userlv
Extending logical volume userlv to 1.99 GiB
Logical volume userlv successfully resized

[TEST-root] rh70:/root
#lvdisplay uservg
--- Logical volume ---
LV Path /dev/uservg/userlv
LV Name userlv
VG Name uservg
LV UUID IarT1r-6chm-feoC-DLd6-64Jv-2Qcz-tDudEn
LV Write Access read/write
LV Creation host, time rh70, 2015-02-13 13:45:11 +0900
LV Status available
# open 1
LV Size 1.99 GiB
Current LE 510
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

2) FS확장 (fsadm 명령사용)
[TEST-root] rh70:/root
#df -h | grep database
/dev/mapper/uservg-userlv 1017M 21M 997M 3% /database

[TEST-root] rh70:/root
# fsadm -e -y resize /dev/uservg/userlv
meta-data=/dev/mapper/uservg-userlv isize=256 agcount=11, agsize=25600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=261120, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 261120 to 522240

[TEST-root] rh70:/root#df -h | grep database
/dev/mapper/uservg-userlv 2.0G 21M 2.0G 2% /database

9. FS축소 하기
1) FS 재생성 -> xfs 축소가안됨
[TEST-root] rh70:/root#mkfs -t ext4 /dev/uservg/userlv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
130560 inodes, 522240 blocks
26112 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=534773760
16 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

2) FS
축소
[TEST-root] rh70:/root#e2fsck -f /dev/uservg/userlv
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/uservg/userlv: 11/130560 files (0.0% non-contiguous), 17926/522240 blocks

[TEST-root] rh70:/root
#resize2fs /dev/uservg/userlv 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/uservg/userlv to 25600 (4k) blocks.
The filesystem on /dev/uservg/userlv is now 25600 blocks long.

[TEST-root] rh70:/root#mount -a

[TEST-root] rh70:/root#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 40G 7.8G 32G 20% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/mapper/uservg-userlv 66M 1.1M
58M 2% /database

3) LV
축소

[TEST-root] rh70:/root#lvreduce -L 100M /dev/uservg/userlv
WARNING: Reducing active and open logical volume to 100.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce userlv? [y/n]: y
Reducing logical volume userlv to 100.00 MiB
Logical volume userlv successfully resized

[TEST-root] rh70:/root#lvdisplay uservg
--- Logical volume ---
LV Path /dev/uservg/userlv
LV Name userlv
VG Name uservg
LV UUID IarT1r-6chm-feoC-DLd6-64Jv-2Qcz-tDudEn
LV Write Access read/write
LV Creation host, time rh70, 2015-02-13 13:45:11 +0900
LV Status available
# open 1
LV Size 100.00 MiB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2


4) VG
축소
[TEST-root] rh70:/root#pvmove /dev/sdc2 /dev/sdc1
No data to move for uservg


[TEST-root] rh70:/root#vgreduce uservg /dev/sdc2
Removed "/dev/sdc2" from volume group "uservg"

[TEST-root] rh70:/root#vgdisplay uservg
--- Volume group ---
VG Name uservg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 11
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 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 25 / 100.00 MiB
Free PE / Size 230 / 920.00 MiB

VG UUID 6btSlf-kaQv-F10J-EOnn-OkDe-0epn-e9bbf8

10. VG삭제
[TEST-root] rh70:/root#lvremove /dev/uservg/userlv
Do you really want to remove active logical volume userlv? [y/n]: y
Logical volume "userlv" successfully removed
[TEST-root] rh70:/root#vgremove uservg
Volume group "uservg" successfully removed
[TEST-root] rh70:/root#
[TEST-root] rh70:/root#lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 39.62g
swap rhel -wi-ao---- 3.89g
[TEST-root] rh70:/root#pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- 39.51g 0
/dev/sdb rhel lvm2 a-- 10.00g 6.00g
/dev/sdc1 lvm2 a-- 1.00g 1.00g
/dev/sdc2 lvm2 a-- 1023.00m 1023.00m

 

반응형

댓글