编辑虚拟机,增加硬盘到50G。
到虚机里执行命令
echo "- - -" > /sys/class/scsi_host/host0/scan
echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
确认是第0个硬盘
root@ubuntu-server:/home/ubuntu# cat /proc/scsi/scsi
Attached devices:
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware SATA CD00 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi32 Channel: 00 Id: 00 Lun: 00
Vendor: VMware Model: Virtual disk Rev: 2.0
Type: Direct-Access ANSI SCSI revision: 06
ANSI SCSI revision: 05
使用fdisk/parted扩容
方法一:
步骤:删除分区--->新建分区---->写入变化。 查看当前状态
查看
ubuntu@ubuntu-server:~$ sudo fdisk -l
[sudo] password for ubuntu:
Disk /dev/loop0: 55.48 MiB, 58159104 bytes, 113592 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 /dev/loop1: 55.39 MiB, 58073088 bytes, 113424 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 /dev/loop3: 69.78 MiB, 73150464 bytes, 142872 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 /dev/loop4: 69.9 MiB, 73277440 bytes, 143120 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 /dev/loop5: 31.9 MiB, 32600064 bytes, 63672 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 /dev/loop6: 31.9 MiB, 32595968 bytes, 63664 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
GPT PMBR size mismatch (62914559 != 104857599) will be corrected by write.
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual disk
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: 73CA90F8-B1EF-4B4B-8BB8-941F31782480
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 62912511 60811264 29G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 20 GiB, 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
ubuntu@ubuntu-server:~$ fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
fdisk: cannot open /dev/sda: Permission denied
扩容
ubuntu@ubuntu-server:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (62914559 != 104857599) will be corrected by write.
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 has been deleted.
Command (m for help): n
Partition number (3-128, default 3):
First sector (2101248-104857566, default 2101248):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2101248-104857566, default 104857566):
Created a new partition 3 of type 'Linux filesystem' and of size 49 GiB.
Partition #3 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: N
(!!!谨慎操作。如果选了yes所有分区磁盘就没了,也启动不了)
The signature will be removed by a write command.
Command (m for help): t
Partition number (1-3, default 3):
Partition type (type L to list all types): 8e
Type of partition 3 is unchanged: Linux filesystem.
Command (m for help): w
The partition table has been altered.
Syncing disks.
方法二:
使用parted工具
查看当前状态
ubuntu@ubuntu-server:~$ sudo parted /dev/sda print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 1076MB 1074MB xfs
3 1076MB 53.7GB 52.6GB
扩容/验证
ubuntu@ubuntu-server:~$ sudo parted /dev/sda resizepart 3 100%
Information: You may need to update /etc/fstab.
ubuntu@ubuntu-server:~$ sudo parted /dev/sda print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 1076MB 1074MB xfs
3 1076MB 53.7GB 52.6GB
LVM扩容
使用fdisk扩容的需要重启 或 直接执行
partprobe
ubuntu@ubuntu-server:~$ sudo partprobe
ubuntu@ubuntu-server:~$ sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
ubuntu@ubuntu-server:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- <49.00g <29.00g
ubuntu@ubuntu-server:~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 20.00 GiB (5120 extents) to <49.00 GiB (12543 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
ubuntu@ubuntu-server:~$ sudo xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv
meta-data=/dev/mapper/ubuntu--vg-ubuntu--lv isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=5242880, 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
data blocks changed from 5242880 to 12844032