赞
踩
目录
本文适用于虚拟化或者云平台场景下的LINUX分区扩容,虚拟机平台的磁盘支持扩容操作,虚拟机的操作系统采用了LVM的分区格式。本文以常见的VMWARE ESXI虚拟机为例。
思路:虚拟机的磁盘扩容---->虚拟机的磁盘容量更新识别---->虚拟机的分区扩容resize---->LVM的PV磁盘更新------>LogicVolume的扩容----> 文件系统xfs扩容
主要是数据备份、收集配置备份,扩容是对数据的高危操作,要十分谨慎。
- #lsblk
- #df -h
- #pvdisplay
- #vgdisplay
- #lvdisplay
- #parted -l
- #fdisk -l
比如原先是虚拟机是300的磁盘,扩容到600G。直接右键编辑虚拟机设置硬盘的新的容量。确认后保存。
- 刷新磁盘容量:
- [root@localhost ~]# ls /sys/class/scsi_device/
- 0:0:0:0 3:0:0:0
- [root@localhost ~]# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
- [root@localhost ~]# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 600G 0 disk
- ├─sda1 8:1 0 1G 0 part /boot
- └─sda2 8:2 0 296.1G 0 part
- ├─centos-root 253:0 0 270G 0 lvm /
- ├─centos-swap 253:1 0 16G 0 lvm [SWAP]
- └─centos-home 253:2 0 10.1G 0 lvm /home
- sr0 11:0 1 4.4G 0 rom
- [root@opscenter log]# parted (此处案例不是600G,主要是演示resize过程)
- GNU Parted 3.1
- Using /dev/sda
- Welcome to GNU Parted! Type 'help' to view a list of commands.
- (parted) p
- Model: VMware Virtual disk (scsi)
- Disk /dev/sda: 1100GB
- Sector size (logical/physical): 512B/512B
- Partition Table: msdos
- Disk Flags:
-
- Number Start End Size Type File system Flags
- 1 1049kB 1075MB 1074MB primary xfs boot
- 2 1075MB 1002GB 1001GB primary lvm
-
- (parted) 2
- align-check TYPE N check partition N for TYPE(min|opt) alignment
- help [COMMAND] print general help, or help on COMMAND
- mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
- mkpart PART-TYPE [FS-TYPE] START END make a partition
- name NUMBER NAME name partition NUMBER as NAME
- print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
- quit exit program
- rescue START END rescue a lost partition near START and END
-
- resizepart NUMBER END resize partition NUMBER
- rm NUMBER delete partition NUMBER
- select DEVICE choose the device to edit
- disk_set FLAG STATE change the FLAG on selected device
- disk_toggle [FLAG] toggle the state of FLAG on selected device
- set NUMBER FLAG STATE change the FLAG on partition NUMBER
- toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
- unit UNIT set the default unit to UNIT
- version display the version number and copyright information of GNU Parted
- (parted) resizepart #(调整分区功能)
- Partition number? 2 #(选择分区2)
- End? [1002GB]? 1052G #(写入新的容量,不需要管起始位置)
- (parted) p
- Model: VMware Virtual disk (scsi)
- Disk /dev/sda: 1100GB
- Sector size (logical/physical): 512B/512B
- Partition Table: msdos
- Disk Flags:
-
- Number Start End Size Type File system Flags
- 1 1049kB 1075MB 1074MB primary xfs boot
- 2 1075MB 1052GB 1051GB primary lvm
-
- (parted) w #(保存分区表)
- align-check TYPE N check partition N for TYPE(min|opt) alignment
- help [COMMAND] print general help, or help on COMMAND
- mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
- mkpart PART-TYPE [FS-TYPE] START END make a partition
- name NUMBER NAME name partition NUMBER as NAME
- print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
- quit exit program
- rescue START END rescue a lost partition near START and END
-
- resizepart NUMBER END resize partition NUMBER
- rm NUMBER delete partition NUMBER
- select DEVICE choose the device to edit
- disk_set FLAG STATE change the FLAG on selected device
- disk_toggle [FLAG] toggle the state of FLAG on selected device
- set NUMBER FLAG STATE change the FLAG on partition NUMBER
- toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
- unit UNIT set the default unit to UNIT
- version display the version number and copyright information of GNU Parted
- (parted) q
- Information: You may need to update /etc/fstab.
-
- [root@opscenter log]# parted # (确认生效)
- GNU Parted 3.1
- Using /dev/sda
- Welcome to GNU Parted! Type 'help' to view a list of commands.
- (parted) p
- Model: VMware Virtual disk (scsi)
- Disk /dev/sda: 1100GB
- Sector size (logical/physical): 512B/512B
- Partition Table: msdos
- Disk Flags:
-
- Number Start End Size Type File system Flags
- 1 1049kB 1075MB 1074MB primary xfs boot
- 2 1075MB 1052GB 1051GB primary lvm
-
- (parted)
- (parted) q
分区扩容完毕后,需要LVM重新识别PV容量
-
- [root@opscenter log]# pvresize /dev/sda2 #(调整识别新的pvsize分区大小)
- Physical volume "/dev/sda2" changed
- 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
- [root@opscenter log]# pvdisplay
- --- Physical volume ---
- PV Name /dev/sda2
- VG Name rhel
- PV Size <978.75 GiB / not usable 3.38 MiB
- Allocatable yes
- PE Size 4.00 MiB
- Total PE 250559
- Free PE 11968
- Allocated PE 238591
- PV UUID V25Vwm-yFff-Kcft-s69N-JKyb-mCV8-9O7XM9
-
- [root@opscenter ~]# vgdisplay #(查看free空间是否增加)
-
-
首先要扩容逻辑卷block设备。然后再扩容对应的文件系统。
-
-
-
- [root@opscenter ~]# lvextend -L +40G /dev/mapper/rhel-root # (演示扩容分区40G)
- Size of logical volume rhel/root changed from 900.00 GiB (230400 extents) to 940.00 GiB (240640 extents).
- Logical volume rhel/root successfully resized.
-
-
- [root@opscenter ~]# xfs_growfs /dev/mapper/rhel-root # (演示根分区/扩容xfs文件系统,如果是ext的话,应该采用resize2fs 命令来扩文件系统)
- meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=58982400 blks
- = sectsz=512 attr=2, projid32bit=1
- = crc=1 finobt=0 spinodes=0
- data = bsize=4096 blocks=235929600, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0 ftype=1
- log =internal bsize=4096 blocks=115200, version=2
- = sectsz=512 sunit=0 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
- data blocks changed from 235929600 to 246415360
- [root@opscenter ~]# df -h #(演示检查扩容结果)
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/rhel-root 940G 9.9G 930G 2% /
- devtmpfs 7.8G 0 7.8G 0% /dev
- tmpfs 7.8G 0 7.8G 0% /dev/shm
- tmpfs 7.8G 25M 7.8G 1% /run
- tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
- /dev/sda1 1014M 150M 865M 15% /boot
- tmpfs 1.6G 0 1.6G 0% /run/user/0
至此整个扩容结束。
本文是扩容直接磁盘的方式。此外还有往系统再增加一个物理硬盘,加入到rootvg中,再扩容LVM逻辑卷的方案。
对于采用Linux标准物理分区的系统,可能也可以适用,采用growpart工具扩容分区,等下次有空测试一下。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。