给虚拟机添加硬盘(或扩容)
- 停止虚拟机
- 在管理页面给虚拟机新增一块硬盘
- 重新启动虚拟机
登入虚拟机,对新增硬盘进行分区
下方所示为硬盘扩容非新增,但操作方式都一致
root@zentao:/home/ubuntu# fdisk /dev/sdaWelcome to fdisk (util-linux 2.27.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.The size of this disk is 4 TiB (4398046511104 bytes). DOS partition table format can not be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).Command (m for help): p ###查看已有分区Disk /dev/sda: 4 TiB, 4398046511104 bytes, 8589934592 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x039343bfDevice Boot Start End Sectors Size Id Type/dev/sda1 * 2048 1499135 1497088 731M 83 Linux/dev/sda2 1501182 419428351 417927170 199.3G 5 Extended/dev/sda5 1501184 419428351 417927168 199.3G 8e Linux LVMCommand (m for help): F ###查看可分配空间Unpartitioned space /dev/sda: 3.8 TiB, 4183299194880 bytes, 8170506240 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesStart End Sectors Size419428352 8589934591 8170506240 3.8TCommand (m for help): n ###创建分区Partition typep primary (1 primary, 1 extended, 2 free)l logical (numbered from 5)Select (default p): pPartition number (3,4, default 3):First sector (1499136-4294967295, default 1499136): 419428352Last sector, +sectors or +size{K,M,G,T,P} (419428352-4294967294, default 4294967294):Created a new partition 3 of type 'Linux' and of size 1.8 TiB.Command (m for help): pDisk /dev/sda: 4 TiB, 4398046511104 bytes, 8589934592 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x039343bfDevice Boot Start End Sectors Size Id Type/dev/sda1 * 2048 1499135 1497088 731M 83 Linux/dev/sda2 1501182 419428351 417927170 199.3G 5 Extended/dev/sda3 419428352 4294967294 3875538943 1.8T 83 Linux/dev/sda5 1501184 419428351 417927168 199.3G 8e Linux LVMPartition table entries are not in disk order.Command (m for help): t ###修改分区typePartition number (1-3,5, default 5): 3 ###指定要修改的分区Partition type (type L to list all types): 8e ###8e对应的type为Linux LVMChanged type of partition 'Linux' to 'Linux LVM'.Command (m for help): w ###写入分区表The partition table has been altered
扩容根目录
- 查看VG Name
root@zentao:/home/ubuntu# vgdisplay--- Volume group ---VG Name zentao-vgSystem IDFormat lvm2Metadata Areas 3Metadata Sequence No 7VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 3Act PV 3VG Size 4.00 TiBPE Size 4.00 MiBTotal PE 1048390Alloc PE / Size 1048390 / 4.00 TiBFree PE / Size 0 / 0VG UUID 8l2jBN-VnmO-TphJ-RqBA-rnda-ROoW-QE4pQ5
- 查看目录挂载信息
root@zentao:/home/ubuntu# df -hFilesystem Size Used Avail Use% Mounted onudev 3.9G 0 3.9G 0% /devtmpfs 799M 9.1M 790M 2% /run/dev/mapper/zentao--vg-root 2.2T 26G 2.1T 2% /tmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup/dev/sda1 720M 58M 625M 9% /bootoverlay 2.2T 26G 2.1T 2% /var/lib/docker/overlay2/6bc943202e08c87727eda74a4f454f62a10103e59f53be5e049ce1ee0d1298ce/mergedoverlay 2.2T 26G 2.1T 2% /var/lib/docker/overlay2/ed8c8d79e65da008e4fad92b40e9eba5632216832f941df1d1a933ca9753e36f/mergedoverlay 2.2T 26G 2.1T 2% /var/lib/docker/overlay2/5a36352524032e25eca0a973fbab10ca20b333f06ee871a34648fca264b97ea9/mergedtmpfs 799M 0 799M 0% /run/user/1000
- 分别执行以下命令对根目录进行扩容
mkfs.ext4 /dev/sda3pvcreate /dev/sda3vgextend zentao-bg /dev/sda3###直接将所有空余空间扩容,或者也可以指定扩容大小lvextend -l +100%FREE /dev/mapper/zentao--vg-rootresize2fs /dev/mapper/zentao--vg-root
- 查看扩容后的根目录大小
root@zentao:/home/ubuntu# df -hFilesystem Size Used Avail Use% Mounted onudev 3.9G 0 3.9G 0% /devtmpfs 799M 9.1M 790M 2% /run/dev/mapper/zentao--vg-root 4.0T 26G 3.8T 1% /tmpfs 3.9G 0 3.9G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup/dev/sda1 720M 58M 625M 9% /bootoverlay 4.0T 26G 3.8T 1% /var/lib/docker/overlay2/ed8c8d79e65da008e4fad92b40e9eba5632216832f941df1d1a933ca9753e36f/mergedoverlay 4.0T 26G 3.8T 1% /var/lib/docker/overlay2/6bc943202e08c87727eda74a4f454f62a10103e59f53be5e049ce1ee0d1298ce/mergedoverlay 4.0T 26G 3.8T 1% /var/lib/docker/overlay2/5a36352524032e25eca0a973fbab10ca20b333f06ee871a34648fca264b97ea9/mergedtmpfs 799M 0 799M 0% /run/user/1000root@zentao:/home/ubuntu#root@zentao:/home/ubuntu# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 4T 0 disk├─sda1 8:1 0 731M 0 part /boot├─sda3 8:3 0 1.8T 0 part│ └─zentao--vg-root 252:0 0 4T 0 lvm /└─sda5 8:5 0 199.3G 0 part├─zentao--vg-root 252:0 0 4T 0 lvm /└─zentao--vg-swap_1 252:1 0 980M 0 lvm [SWAP]sdb 8:16 0 2T 0 disk└─sdb1 8:17 0 2T 0 part└─zentao--vg-root 252:0 0 4T 0 lvm /sr0 11:0 1 873M 0 rom
