lvm 筆記

下列為 kickstart 的範例

# System bootloader configuration
bootloader –append=” crashkernel=auto” –location=mbr –boot-drive=sda
# Partition clearing information
clearpart –all –initlabel –drives=sda

part /boot –fstype ext4 –size=1024
part pv.01 –size=1000 –grow –ondisk=sda
volgroup vg00 pv.01
logvol / –vgname=vg00 –fstype=xfs –size=40960 –name=lv_root
logvol swap –vgname=vg00 –fstype=swap –size=32768 –name=lv_swap
logvol /data –vgname=vg00 –fstype=xfs –size=10000 –name=lv_data –grow

下面為 lvm 的基本指令

vgs 指令列出 volume 群組資訊

# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz–n- <271.25g <187.25g

用 pvs 指令列出實體 volumes 的資訊

# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a– <271.25g <187.25g

用 lvs 指令 列出邏輯 volumes 的資訊

# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos -wi-a—– <217.25g
root centos -wi-ao—- 50.00g
swap centos -wi-ao—- 4.00g

要變更 volume 群組名稱用 vgrename 指令

# vgrename centos computenode1
Volume group “centos” successfully renamed to “computenode1”

要變更 lvm volume 名稱用下列指令

# lvrename computenode1 home data
Renamed “home” to “data” in volume group “computenode1
## 用 lvs 檢查一下結果
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data computenode1 -wi-a—– <217.25g
root computenode1 -wi-ao—- 50.00g
swap computenode1 -wi-ao—- 4.00g

改完之後記得去編輯一下 /etc/grub2.cfg 要不然無法開機

# vi /etc/grub2.cfg
linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/computenode1-root ro crashkernel=auto rd.lvm.lv=computenode1/root rd.lvm.lv=computenode1/swap rhgb quiet LANG=en_US.UTF-8

還有要建立 /data 掛載目錄及編輯 /etc/fstab

#mkdir /data
# vi /etc/fstab
/dev/mapper/computenode1-root / xfs defaults 0 0
UUID=8d6dec77-95e2-4cde-8e4b-35742cd6623b /boot xfs defaults 0 0
/dev/mapper/computenode1-data /data xfs defaults 0 0
/dev/mapper/computenode1-swap swap swap defaults 0 0

調整 lvm 大小範例:想要增加 / root 空間,為了方便調整 / root volume 的大小,所以先簡單的把 data volume 清除掉。當然可以先降低 data volume 之後再來調整 / root 大小,但就覺得麻煩。所先移除 data 邏輯 volume 。

# lvremove /dev/computenode1/data

再來增加 / root 空間,從 50GB 到 80GB。

# lvextend -L80G /dev/computenode1/root
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root computenode1 -wi-ao—- 80.00g
swap computenode1 -wi-ao—- 4.00g

因為檔案系統是 xfs 所以要用 xfs_growfs 調整,如果是 ext4 or ext3 就要用 resize2fs 指令

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

再把所有剩餘的空間,建立給 data volume,順便格式化。

# lvcreate -n data -l 100%FREE computenode1
Logical volume “data” created.
# mkfs.xfs /dev/mapper/computenode1-data
meta-data=/dev/mapper/computenode1-data isize=512 agcount=4, agsize=12271360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=49085440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=23967, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

這樣就可以掛載 /data 也把 / root 從 50GB 調整為 80GB

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/computenode1-root 80G 5.2G 75G 7% /
devtmpfs 48G 0 48G 0% /dev
tmpfs 48G 0 48G 0% /dev/shm
tmpfs 48G 9.5M 48G 1% /run
tmpfs 48G 0 48G 0% /sys/fs/cgroup
/dev/sda1 1014M 218M 797M 22% /boot
tmpfs 9.5G 0 9.5G 0% /run/user/0
/dev/mapper/computenode1-data 188G 33M 188G 1% /data

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.