centos lvm 扩容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos lvm 扩容相关的知识,希望对你有一定的参考价值。
参考技术A vvilog@centos /h/vvilog> /sbin/vgdisplay--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <110.81 GiB
PE Size 4.00 MiB
Total PE 28367
Alloc PE / Size 28367 / <110.81 GiB
Free PE / Size 0 / 0
VG UUID Nt91Zx-Haal-LOPL-fDJF-XGjk-SvaA-yl9hgL
vvilog@centos /h/vvilog> /sbin/vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <110.81 GiB
PE Size 4.00 MiB
Total PE 28367
Alloc PE / Size 28367 / <110.81 GiB
Free PE / Size 0 / 0
VG UUID Nt91Zx-Haal-LOPL-fDJF-XGjk-SvaA-yl9hgL
vvilog@centos /h/vvilog> /sbin/lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID NUekJb-ZCIc-mwcL-ExzX-ROYd-bD7T-HmPqql
LV Write Access read/write
LV Creation host, time centos, 2018-07-11 19:47:08 +0800
LV Status available
# open 1
LV Size 60.00 GiB
Current LE 15360
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID eShHQo-MewK-xN7H-ZqBu-GIV6-KMQI-YA606U
LV Write Access read/write
LV Creation host, time centos, 2018-07-11 19:47:09 +0800
LV Status available
# open 1
LV Size 48.00 GiB
Current LE 12288
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID hwO7J7-gmbh-jgiT-vFLA-jsdI-8241-CSHEM8
LV Write Access read/write
LV Creation host, time centos, 2018-07-11 19:47:10 +0800
LV Status available
# open 2
LV Size <2.81 GiB
Current LE 719
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
vvilog@centos /h/vvilog> /sbin/fdisk /dev/sda
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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): t
Partition number (1-4, default 4): 4
Partition type (type L to list all types): 8e
Type of partition 4 is unchanged: Linux filesystem
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.
vvilog@centos /h/vvilog> /sbin/partprobe
vvilog@centos /h/vvilog> /sbin/fdisk /dev/sda
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 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: gpt
Disk identifier: 30B84C4D-0A79-4BAE-8950-8C0FDF86949E
# Start End Size Type Name
1 2048 1026047 500M EFI System EFI System Partition
2 1026048 2050047 500M Microsoft basic
3 2050048 234440703 110.8G Linux LVM
4 234440704 1953523711 819.7G Linux filesyste
Command (m for help): t
Partition number (1-4, default 4): 4
Partition type (type L to list all types): l
19 Linux swap 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
31 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF928
Partition type (type L to list all types): t
Type of partition 4 is unchanged: Linux filesystem
Command (m for help): t
Partition number (1-4, default 4): 4
Partition type (type L to list all types): 31
Changed type of partition 'Linux filesystem' to 'Linux LVM'
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.
vvilog@centos /h/vvilog> /sbin/partprobe
vvilog@centos /h/vvilog> /usr/sbin/vgextend centos /dev/sda4
Volume group "centos" successfully extended
vvilog@centos /h/vvilog> whereis lvextend
lvextend: /usr/sbin/lvextend /usr/share/man/man8/lvextend.8.gz
vvilog@centos /h/vvilog> /sbin/lvextend -L +760g /dev/centos/home
Size of logical volume centos/home changed from 48.00 GiB (12288 extents) to 808.00 GiB (206848 extents).
Logical volume centos/home successfully resized.
vvilog@centos /h/vvilog> df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 60G 5.5G 55G 10% /
devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs 1.7G 0 1.7G 0% /dev/shm
tmpfs 1.7G 9.6M 1.7G 1% /run
tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup
/dev/sda2 497M 178M 320M 36% /boot
/dev/sda1 500M 9.8M 490M 2% /boot/efi
/dev/mapper/centos-home 48G 5.6G 43G 12% /hom e
tmpfs 344M 12K 344M 1% /run/user/1000
vvilog@centos /h/vvilog> /sbin/resize2fs /dev/centos/home
resize2fs 1.42.9 (28-Dec-2013)
/sbin/resize2fs: Bad magic number in super-block while trying to open /dev/centos/home
Couldn't find valid filesystem superblock.
vvilog@centos /h/vvilog> /sbin/xfs_growfs /dev/centos/home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=3145728 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=12582912, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6144, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12582912 to 211812352
vvilog@centos /h/vvilog> df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 60G 5.5G 55G 10% /
devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs 1.7G 0 1.7G 0% /dev/shm
tmpfs 1.7G 9.6M 1.7G 1% /run
tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup
/dev/sda2 497M 178M 320M 36% /boot
/dev/sda1 500M 9.8M 490M 2% /boot/efi
/dev/mapper/centos-home 808G 5.6G 803G 1% /home
tmpfs 344M 12K 344M 1% /run/user/1000
CentOS系统LVM扩容的快捷方法
LVM扩容时或新建vg时需要使用系列命令,各个命令的用法多样,本文介绍一个最省力的姿势。
一、首先创建一块新的分区:
fdisk /dev/sda p n p #选择逻辑分区,如果没有,则首先创建扩展分区,然后再添加逻辑分区(硬盘:最多四个分区P-P-P-P或P-P-P-E) 3 #分区号(从2开始),/dev/sda3 t 3 8e #分区类型8e表示LVM分区 w #写入分区表 partprobe #重读分区表,重读失败则要重启 partx /dev/sda #查看当前硬盘的分区表及使用情况
二、创建PV,扩容VG、LV
pvcreate /dev/sda3 vgdisplay #查看当前已经存在的VG信息,以存在VG:VolGroup为例 vgextend VolGroup /dev/sda3 #扩展VolGroup lvdisplay #查看已经存在的LV信息,以存在LV:lv_root为例 lvextend /dev/VolGroup/lv_root /dev/sda3 #扩展LV #其他用法 lvextend –L 50G /dev/VolGroup/lv_root #其他用法 lvextend –L +20G /dev/VolGroup/lv_root #其他用法 lvextend /dev/mapper/VolGroup-lv_root -l +100%FREE /dev/sdb1 resize2fs /dev/VolGroup/lv_root #执行该重设大小,对于当前正在使用的lv_root有效 #注意:在Centos7.x中,文件系统格式是xfs时,使用xfs_growfs命令重设lv大小,如 xfs_growfs /dev/mapper/centos-root df –h #查看挂载情况,已经扩容
三、创建新LV
pvcreate /dev/sdb1 #partprobe #pvdisplay vgcreate vg_mqtag /dev/sdb1 #vgdisplay lvcreate -n lvData -l 100%FREE vg_mqtag #lvdisplay mkfs.ext4 /dev/vg_mqtag/lvData mount /dev/vg_mqtag/lvData /opt/ df -h echo "/dev/mapper/vg_mqtag-lvData /opt ext4 defaults 0 0" >> /etc/fstab
以上是关于centos lvm 扩容的主要内容,如果未能解决你的问题,请参考以下文章