1.lvm创建
添加一块硬盘
[[email protected] ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
#创建datavg
[[email protected] ~]# vgcreate datavg /dev/sdb1
Volume group "datavg" successfully created
[[email protected] ~]# vgdisplay
--- Volume group ---
VG Name datavg
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 <20.00 GiB
PE Size 4.00 MiB
Total PE 5119
Alloc PE / Size 0 / 0
Free PE / Size 5119 / <20.00 GiB
VG UUID gOCOED-3SG4-zXdJ-nbPF-onqW-lYdX-1Fk6Kw
#创建100M lv
[[email protected] ~]# lvcreate -L 100M -n lv1 datavg
Logical volume "lv1" created.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 datavg -wi-a----- 100.00m
[[email protected] ~]# lvcreate -l 25 -n lv2 datavg #和上面一样大小
Logical volume "lv2" created.
[[email protected] ~]# lvscan
ACTIVE ‘/dev/datavg/lv1‘ [100.00 MiB] inherit
ACTIVE ‘/dev/datavg/lv2‘ [100.00 MiB] inherit
#格式化为ext4
[[email protected] ~]# mkfs.ext4 /dev/datavg/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
#格式化为xfs
[[email protected] ~]# mkfs.xfs /dev/datavg/lv2
meta-data=/dev/datavg/lv2 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# vim /etc/fstab #设置开机挂载
/dev/datavg/lv1 /mnt/lv1 ext4 defaults 0 0
/dev/datavg/lv2 /mnt/lv2 xfs defaults 0 0
[[email protected] ~]# mount -a
[[email protected] ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda3 xfs 18G 1.6G 17G 9% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 492M 0 492M 0% /dev/shm
tmpfs tmpfs 492M 7.5M 484M 2% /run
tmpfs tmpfs 492M 0 492M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 126M 71M 64% /boot
tmpfs tmpfs 99M 0 99M 0% /run/user/0
/dev/mapper/datavg-lv1 ext4 93M 1.6M 85M 2% /mnt/lv1
/dev/mapper/datavg-lv2 xfs 97M 5.3M 92M 6% /mnt/lv2
2.vg扩容
[[email protected] ~]# vgextend datavg /dev/vdc
3.vg缩小
[[email protected] ~]# pvmove /dev/vdb
[[email protected] ~]# vgreduce datavg /dev/vdb
4.lvm扩容
[[email protected] ~]# lvscan
ACTIVE ‘/dev/datavg/lv1‘ [100.00 MiB] inherit
ACTIVE ‘/dev/datavg/lv2‘ [100.00 MiB] inherit
[[email protected] ~]# lvextend -L 200M /dev/datavg/lv1
Size of logical volume datavg/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
Logical volume datavg/lv1 successfully resized.
[[email protected] ~]# lvextend -L +200M /dev/datavg/lv2
Size of logical volume datavg/lv2 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).
Logical volume datavg/lv2 successfully resized.
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 datavg -wi-ao---- 200.00m
lv2 datavg -wi-ao---- 300.00m
[[email protected] ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 18G 1.6G 17G 9% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 492M 0 492M 0% /dev/shm
tmpfs tmpfs 492M 7.5M 484M 2% /run
tmpfs tmpfs 492M 0 492M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 126M 71M 64% /boot
tmpfs tmpfs 99M 0 99M 0% /run/user/0
/dev/mapper/datavg-lv1 ext4 93M 1.6M 85M 2% /mnt/lv1
/dev/mapper/datavg-lv2 xfs 97M 5.3M 92M 6% /mnt/lv2
5.FS扩容
[[email protected] ~]# xfs_growfs /dev/datavg/lv2 #xfs格式
meta-data=/dev/mapper/datavg-lv2 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 76800
[[email protected] ~]# resize2fs /dev/datavg/lv1 #ext4格式
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/datavg/lv1 is mounted on /mnt/lv1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/datavg/lv1 is now 204800 blocks long.
[[email protected] ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 18G 1.6G 17G 9% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 492M 0 492M 0% /dev/shm
tmpfs tmpfs 492M 7.5M 484M 2% /run
tmpfs tmpfs 492M 0 492M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 126M 71M 64% /boot
tmpfs tmpfs 99M 0 99M 0% /run/user/0
/dev/mapper/datavg-lv1 ext4 190M 1.6M 178M 1% /mnt/lv1
/dev/mapper/datavg-lv2 xfs 297M 5.6M 292M 2% /mnt/lv2
原文地址:https://blog.51cto.com/13528668/2422206
时间: 2024-11-13 09:43:05