作者:CCTV知府影 | 来源:互联网 | 2023-10-11 20:07
记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux主机lv操作的常用命令,欢迎大家评论留言。1、df查看磁盘空间使用情况:root@xuhs:root
记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux主机lv操作的常用命令,欢迎大家评论留言。
1、df 查看磁盘空间使用情况:
root@xuhs:/root>df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.0M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/hdvg-rootlv 13G 5.2G 7.1G 43% /
/dev/sda1 1014M 171M 844M 17% /boot
/dev/mapper/hdvg-homelv 9.2G 34M 9.2G 1% /home
/dev/mapper/hdvg-varlv 1.2G 239M 968M 20% /var
/dev/mapper/hdvg-tmplv 1.2G 33M 1.2G 3% /tmp
/dev/mapper/hdvg-varloglv 1.2G 34M 1.2G 3% /var/log
tmpfs 98M 0 98M 0% /run/user/0
root@xuhs:/root>
2、fdisk 操作磁盘分区表:
root@xuhs:/root>fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b90ed
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
......
3、查看pv信息:
(1)pvs显示pv信息:
root@xuhs:/root>pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 hdvg lvm2 a-- <18.97g 0
/dev/sdb hdvg lvm2 a-- <9.97g <1.97g
root@xuhs:/root>
(2)pvdisplay显示pv的属性,比较详细的列出pv的各种属性,比如pv大小等等:
root@xuhs:/root>pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name hdvg
PV Size <19.00 GiB / not usable 31.00 MiB
Allocatable yes (but full)
PE Size 32.00 MiB
Total PE 607
Free PE 0
Allocated PE 607
PV UUID RO2a1g-jrqN-ZB8c-1EM3-EpPa-C4eE-z2NP6x
--- Physical volume ---
PV Name /dev/sdb
VG Name hdvg
PV Size 10.00 GiB / not usable 32.00 MiB
Allocatable yes
PE Size 32.00 MiB
Total PE 319
Free PE 63
Allocated PE 256
PV UUID 4IMsNS-8CL9-JdeZ-fX6u-syqU-43e6-wcXOVU
root@xuhs:/root>
4、查看vg信息:
(1)vgs显示vg信息:
root@xuhs:/root>vgs
VG #PV #LV #SN Attr VSize VFree
hdvg 2 6 0 wz--n- <28.94g <1.97g
root@xuhs:/root>
(2)vgdisplay显示vg的属性,比较详细的列出vg的各种属性,比如vg的名称等等:
root@xuhs:/root>vgdisplay
--- Volume group ---
VG Name hdvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 2
Act PV 2
VG Size <28.94 GiB
PE Size 32.00 MiB
Total PE 926
Alloc PE / Size 863 / <26.97 GiB
Free PE / Size 63 / <1.97 GiB
VG UUID QXUfkm-kfeA-vyrA-6Qm8-f5UT-xAj7-0ALc15
root@xuhs:/root>
5、查看lv信息:
(1)lvs显示lv信息:
root@xuhs:/root>lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
homelv hdvg -wi-ao---- <9.19g
rootlv hdvg -wi-ao---- <12.22g
swaplv hdvg -wi-ao---- 2.00g
tmplv hdvg -wi-ao---- <1.19g
varloglv hdvg -wi-ao---- <1.19g
varlv hdvg -wi-ao---- <1.19g
root@xuhs:/root>
(2)lvdisplay比较详细的显示lv信息,比如lv的名称、大小等:
root@xuhs:/root>lvdisplay
--- Logical volume ---
LV Path /dev/hdvg/swaplv
LV Name swaplv
VG Name hdvg
LV UUID ZUrBh8-bIEe-z6cA-C00c-G0Ig-IY7r-EBgQ8H
LV Write Access read/write
LV Creation host, time localhost, 2021-05-06 18:21:24 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 64
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
6、lvextend扩容lv:
root@xuhs:/root>lvextend -L +8G /dev/hdvg/homelv
Size of logical volume hdvg/homelv changed from <1.19 GiB (38 extents) to <9.19 GiB (294 extents).
Logical volume hdvg/homelv successfully resized.
root@xuhs:/root>
7、lvremove删除lv:
root@xuhs:/root>lvremove /dev/testvg/testlv
Do you really want to remove active logical volume testvg/testlv? [y/n]: y
Logical volume "testlv" successfully removed
root@xuhs:/root>
8、vgremove删除vg:
root@xuhs:/root>vgremove testvg
Volume group "testvg" successfully removed
root@xuhs:/root>
9、pvremove删除pv:
root@xuhs:/root>pvremove /dev/sdc2
Labels on physical volume "/dev/sdc2" successfully wiped.
root@xuhs:/root>
10、xfs_growfs扩展XFS文件系统,使用xfs_growfs这个命令,文件系统的现有内容不会受到干扰:
root@xuhs:/root>xfs_growfs /dev/hdvg/homelv
meta-data=/dev/mapper/hdvg-homelv isize=512 agcount=4, agsize=77824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=311296, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 311296 to 2408448
root@xuhs:/root>
11、mkfs.xfs格式化磁盘:
root@xuhs:/>mkfs.xfs /dev/dbvg/homelv
meta-data=/dev/dbvg/homelv isize=512 agcount=4, agsize=524288 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2097152, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0