虚拟机磁盘扩容(parted、lvm)
1、虚拟化平台虚拟机添加硬盘
系统查看添加的硬盘
[root@yumserver ~] # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] sr0 11:0 1 4.4G 0 rom |
如果没有显示出来新加的硬盘,则执行下面命令
echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/scsi_host/host1/scan echo "- - -" > /sys/class/scsi_host/host2/scan |
再次查询,发现新添加的sdb已经可以看到了。
[root@yumserver ~] # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk sr0 11:0 1 4.4G 0 rom |
2、parted将sdb分区
[root@yumserver ~] # parted /dev/sdb GNU Parted 3.1 使用 /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt (parted) mkpart primary 0% 100% (parted) p Model: VMware Virtual disk (scsi) Disk /dev/sdb : 53.7GB Sector size (logical /physical ): 512B /512B Partition Table: gpt Disk Flags: Number Start End Size File system Name 标志 1 1049kB 53.7GB 53.7GB primary (parted) q 信息: You may need to update /etc/fstab . [root@yumserver ~] # |
再次查看,发现主分区sdb1出现了
[root@yumserver ~] # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 49.5G 0 part ├─centos-root 253:0 0 47.5G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk └─sdb1 8:17 0 50G 0 part sr0 11:0 1 1024M 0 rom [root@yumserver ~] # |
3 、查看现有vg,lv,确定扩容
[root@yumserver ~] # pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <49.51g 0 [root@yumserver ~] # vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <49.51g 0 [root@yumserver ~] # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <47.51g swap centos -wi-ao---- 2.00g [root@yumserver ~] # |
4、分别创建pv,扩容vg,扩容lv,扩容文件系统
##此处发现不能tab补全命令, yum install -y bash-completion
[root@yumserver ~] # pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. |
[root@yumserver ~] # vgextend centos /dev/sdb1 Volume group "centos" successfully extended |
[root@yumserver ~] # lvextend /dev/centos/root -l +100%FREE Size of logical volume centos /root changed from <47.51 GiB (12162 extents) to 97.50 GiB (24961 extents). Logical volume centos /root successfully resized. |
查看文件系统
[root@yumserver ~] # df -Th |
xfs 类型,使用 xfs_growfs,此处为xfs
[root@yumserver ~] # xfs_growfs /dev/centos/root |
ext 类型,使用 resize2fs
[root@yumserver ~] # resize2fs /dev/centos/root |
再次查看,/目录扩容成功
[root@yumserver ~] # df -h 文件系统 容量 已用 可用 已用% 挂载点 devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.9M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/mapper/centos-root 98G 1.4G 97G 2% / /dev/sda1 497M 143M 354M 29% /boot tmpfs 783M 0 783M 0% /run/user/0 |
转载:http://blog.itpub.net/70004783/viewspace-2790155/