文章目录
- 1、需求
- 2、vSphere 操作流程
- 3、服务器操作
- 3.1、查看分区空间大小
- 3.2、列出所有可用块设备的信息
- 3.3、新建分区
- 3.4、重读分区表信息
- 3.5、格式化分区信息
- 3.6、查看卷组的详细状态
- 3.7、创建物理卷
- 3.8、扩容卷组
- 3.9、逻辑卷在线扩容
- 3.10、显示物理卷属性
- 3.11、XFS 文件系统的大小
1、需求
vCenter虚拟机中把硬盘扩容,vCenter本质上只有一个磁盘,一个磁盘分为多个分区。原磁盘位置已经不够使用,需要给磁盘进行扩容。
然后给 /home 分区扩容
2、vSphere 操作流程
在数据中找到需要扩容的虚拟机,找到操作按钮,选择编辑设置,找到硬盘选项,添加硬盘的容量。
示例如下:
3、服务器操作
进入到服务器的shell命令行
3.1、查看分区空间大小
df -h
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 492K 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/rl-root 150G 5.8G 145G 4% /
/dev/mapper/rl-home 1.9T 511G 1.4T 28% /home
/dev/sda2 10G 360M 9.7G 4% /boot
/dev/sda1 1022M 5.8M 1017M 1% /boot/efi
tmpfs 3.2G 0 3.2G 0% /run/user/0
3.2、列出所有可用块设备的信息
列出所有可用块设备的信息,而且还能显示他们之间的依赖关系
此时我们可以清晰的看到磁盘sda有3T的空间,但是下方有依赖关系的分区只使用了2T
我们现在需求是为了给 /home 也就是 /dev/mapper/rl-home 分区扩容,请记住它的分区类型lvm
lsblk
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3T 0 disk
├─sda1 8:1 0 1G 0 part /boot/efi
├─sda2 8:2 0 10G 0 part /boot
└─sda3 8:3 0 2T 0 part ├─rl-root 253:0 0 150G 0 lvm /├─rl-swap 253:1 0 15.8G 0 lvm [SWAP]└─rl-home 253:2 0 1.8T 0 lvm /home
sr0 11:0 1 1024M 0 rom
3.3、新建分区
新建一个分区sda4
fdisk /dev/sda
$ fdisk /dev/sdaWelcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.### n代表新建分区
Command (m for help): n
### 直接回车,选择默认值
Partition number (4-128, default 4): 4
### 直接回车,选择默认值开始位置
First sector (4294965248-6442450910, default 4294965248):
### 直接回车,选择默认值结束位置
Last sector, +sectors or +size{K,M,G,T,P} (4294965248-6442450910, default 6442450910): Created a new partition 4 of type 'Linux filesystem' and of size 1 TiB.### t代表设置分区类型
Command (m for help): t
### 输入刚才输入的分区数字
Partition number (1-4, default 4): 4
### 输入L获取所有类型,找到我们要扩容分区的类型,记住序号,然后:q退出类型查看
Partition type (type L to list all types): L1 EFI System C12A7328-F81F-11D2-BA4B-00A0C93EC93B2 MBR partition scheme 024DEE41-33E7-11D3-9D69-0008C781F39F3 Intel Fast Flash D3BFE2DE-3DAF-11DF-BA40-E3A556D895934 BIOS boot 21686148-6449-6E6F-744E-6565644546495 Sony boot partition F4019732-066E-4E12-8273-346C5641494F6 Lenovo boot partition BFBFAFE7-A34F-448A-9A5B-6213EB736C227 PowerPC PReP boot 9E1A2D38-C612-4316-AA26-8B49521E5A8B8 ONIE boot 7412F7D5-A156-4B13-81DC-8671749293259 ONIE config D4E6E2CD-4469-46F3-B5CB-1BFF57AFC14910 Microsoft reserved E3C9E316-0B5C-4DB8-817D-F92DF00215AE11 Microsoft basic data EBD0A0A2-B9E5-4433-87C0-68B6B72699C712 Microsoft LDM metadata 5808C8AA-7E8F-42E0-85D2-E1E90434CFB313 Microsoft LDM data AF9B60A0-1431-4F62-BC68-3311714A69AD14 Windows recovery environment DE94BBA4-06D1-4D40-A16A-BFD50179D6AC15 IBM General Parallel Fs 37AFFC90-EF7D-4E96-91C3-2D7AE055B17416 Microsoft Storage Spaces E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D17 HP-UX data 75894C1E-3AEB-11D3-B7C1-7B03A000000018 HP-UX service E2A1E728-32E3-11D6-A682-7B03A000000019 Linux swap 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F20 Linux filesystem 0FC63DAF-8483-4772-8E79-3D69D8477DE421 Linux server data 3B8F8425-20E0-4F3B-907F-1A25A76F98E822 Linux root (x86) 44479540-F297-41B2-9AF7-D131D5F0458A23 Linux root (ARM) 69DAD710-2CE4-4E3C-B16C-21A1D49ABED324 Linux root (x86-64) 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B70925 Linux root (ARM-64) B921B045-1DF0-41C3-AF44-4C6F280D3FAE26 Linux root (IA-64) 993D8D3D-F80E-4225-855A-9DAF8ED7EA9727 Linux reserved 8DA63339-0007-60C0-C436-083AC823090828 Linux home 933AC7E1-2EB4-4F13-B844-0E14E2AEF91529 Linux RAID A19D880F-05FC-4D3B-A006-743F0F84911E30 Linux extended boot BC13C2FF-59E6-4262-A352-B275FD6F717231 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF92832 FreeBSD data 516E7CB4-6ECF-11D6-8FF8-00022D09712B33 FreeBSD boot 83BD6B9D-7F41-11DC-BE0B-001560B84F0F34 FreeBSD swap 516E7CB5-6ECF-11D6-8FF8-00022D09712B35 FreeBSD UFS 516E7CB6-6ECF-11D6-8FF8-00022D09712B36 FreeBSD ZFS 516E7CBA-6ECF-11D6-8FF8-00022D09712B37 FreeBSD Vinum 516E7CB8-6ECF-11D6-8FF8-00022D09712B38 Apple HFS/HFS+ 48465300-0000-11AA-AA11-00306543ECAC39 Apple UFS 55465300-0000-11AA-AA11-00306543ECAC40 Apple RAID 52414944-0000-11AA-AA11-00306543ECAC41 Apple RAID offline 52414944-5F4F-11AA-AA11-00306543ECAC42 Apple boot 426F6F74-0000-11AA-AA11-00306543ECAC43 Apple label 4C616265-6C00-11AA-AA11-00306543ECAC44 Apple TV recovery 5265636F-7665-11AA-AA11-00306543ECAC45 Apple Core storage 53746F72-6167-11AA-AA11-00306543ECAC46 Solaris boot 6A82CB45-1DD2-11B2-99A6-08002073663147 Solaris root 6A85CF4D-1DD2-11B2-99A6-08002073663148 Solaris /usr & Apple ZFS 6A898CC3-1DD2-11B2-99A6-08002073663149 Solaris swap 6A87C46F-1DD2-11B2-99A6-08002073663150 Solaris backup 6A8B642B-1DD2-11B2-99A6-08002073663151 Solaris /var 6A8EF2E9-1DD2-11B2-99A6-08002073663152 Solaris /home 6A90BA39-1DD2-11B2-99A6-08002073663153 Solaris alternate sector 6A9283A5-1DD2-11B2-99A6-08002073663154 Solaris reserved 1 6A945A3B-1DD2-11B2-99A6-08002073663155 Solaris reserved 2 6A9630D1-1DD2-11B2-99A6-080020736631### 输入刚到记住的类型序号
Partition type (type L to list all types): 31Changed type of partition 'Linux filesystem' to 'Linux LVM'.### 输入w保存我们的配置
Command (m for help): w
The partition table has been altered.
Syncing disks.
3.4、重读分区表信息
partprobe
fdisk -l
$ partprobe
$ fdisk -l
Disk /dev/sda: 3 TiB, 3298534883328 bytes, 6442450944 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
Disklabel type: gpt
Disk identifier: 0988E2ED-39B3-4128-BA84-8F99010C4CD6Device Start End Sectors Size Type
/dev/sda1 2048 2099199 2097152 1G EFI System
/dev/sda2 2099200 23070719 20971520 10G Linux filesystem
/dev/sda3 23070720 4294965247 4271894528 2T Linux LVM
/dev/sda4 4294965248 6442450910 2147485663 1T Linux LVMDisk /dev/mapper/rl-root: 150 GiB, 161061273600 bytes, 314572800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rl-swap: 15.8 GiB, 16915628032 bytes, 33038336 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rl-home: 1.8 TiB, 2009230999552 bytes, 3924279296 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
3.5、格式化分区信息
mkfs.xfs /dev/sda4
$ mkfs.xfs /dev/sda4
meta-data=/dev/sda4 isize=512 agcount=4, agsize=67108927 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=0= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=268435707, imaxpct=5= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=131072, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
3.6、查看卷组的详细状态
记住下方 VG Name 的值 rl 下方要用到
vgdisplay
$ vgdisplay --- Volume group ---VG Name rlSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 3Open LV 3Max PV 0Cur PV 1Act PV 1VG Size <1.99 TiBPE Size 4.00 MiBTotal PE 521471Alloc PE / Size 521471 / <1.99 TiBFree PE / Size 0 / 0 VG UUID UjKiNx-bg9k-JGUV-wJ3P-uneJ-smV0-rtlMtg
3.7、创建物理卷
pvcreate /dev/sda4
$ pvcreate /dev/sda4
WARNING: xfs signature detected on /dev/sda4 at offset 0. Wipe it? [y/n]: yWiping xfs signature on /dev/sda4.Physical volume "/dev/sda4" successfully created.
3.8、扩容卷组
扩容卷组,即把物理卷加入卷组
vgextend rl /dev/sda4
$ vgextend rl /dev/sda4Volume group "rl" successfully extended
3.9、逻辑卷在线扩容
逻辑卷在线扩容
lvextend -l +100%FREE /dev/mapper/rl-home
$ lvextend -l +100%FREE /dev/mapper/rl-homeSize of logical volume rl/home changed from <1.83 TiB (479038 extents) to <2.83 TiB (741181 extents).Logical volume rl/home successfully resized.
3.10、显示物理卷属性
显示物理卷属性
pvdisplay
$ pvdisplay --- Physical volume ---PV Name /dev/sda3VG Name rlPV Size <1.99 TiB / not usable 2.00 MiBAllocatable yes (but full)PE Size 4.00 MiBTotal PE 521471Free PE 0Allocated PE 521471PV UUID gZTu7E-xJG4-UcoT-SfxT-LbDM-OEyL-MlL4rw--- Physical volume ---PV Name /dev/sda4VG Name rlPV Size 1.00 TiB / not usable 4.98 MiBAllocatable yes (but full)PE Size 4.00 MiBTotal PE 262143Free PE 0Allocated PE 262143PV UUID 62dZHF-RaoD-VLTf-ccaf-eFT8-8AKv-rS60kU
3.11、XFS 文件系统的大小
/home 是 /dev/mapper/rl-home的实际目录
xfs_growfs /home
$ xfs_growfs /home
meta-data=/dev/mapper/rl-home isize=512 agcount=4, agsize=122633728 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=0= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=490534912, imaxpct=5= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=239519, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 490534912 to 758969344