KVM虚拟机扩展硬盘

装的armbian系统的虚拟机硬盘不够了,准备增加个10G,记录如下:

在宿主机执行 qemu-img resezi指令扩展虚拟磁盘

sudo qemu-img resize virtualmachines/VirtualDisk/Armbian.qcow2 +10G

查看硬盘信息

$ sudo qemu-img info /virtualmachines/virtualmachines/VirtualDisk/Armbian.qcow2
反馈

image: virtualmachines/VirtualDisk/Armbian.qcow2
file format: qcow2
virtual size: 19.6 GiB (21093154816 bytes)
disk size: 13.5 GiB
cluster_size: 65536
Snapshot list:
ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT
1         snapshot1        2.73 GiB 2024-08-16 20:33:20 00:14:38.780           
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
Child node '/file':
    filename: /virtualmachines/virtualmachines/VirtualDisk/Armbian.qcow2
    protocol type: file
    file length: 13.5 GiB (14456324096 bytes)
    disk size: 13.5 GiB

进入虚拟机

开机
$ virsh start linux2022

Domain 'linux2022' started

ssh进入
$ ssh siit@192.168.122.43

| | | | ____|  ___|_ _| __  _( _ ) / /_  
| | | |  _| | |_   | |  \ \/ / _ \| '_ \ 
| |_| | |___|  _|  | |   >  < (_) | (_) |
 \___/|_____|_|   |___| /_/\_\___/ \___/ 
                                         
Welcome to Armbian 24.5.5 Bookworm with Linux 6.6.42-current-x86

System load:   112%           	Up time:       0 min	
Memory usage:  7% of 3.84G  	IP:	       172.17.0.1 192.168.122.43
Usage of /:    91% of 9.2G   	

[ General system configuration (beta): armbian-config ]

此时,可以看出虚拟机文件系统仍旧为9.2G。
执行reseze2fs拓展文件系统,在此之前需要通过lsblk指令先查看下虚拟机的文件系统。
$ lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
zram0  251:0    0  1.9G  0 disk [SWAP]
zram1  251:1    0   50M  0 disk /var/log
zram2  251:2    0    0B  0 disk 
vda    252:0    0 19.6G  0 disk 
├─vda1 252:1    0    4M  0 part 
├─vda2 252:2    0  256M  0 part /boot/efi
└─vda3 252:3    0 19.4G  0 part /var/log.hdd

通过resize2fs指令拓展文件系统
$ sudo resize2fs /dev/vda3

resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/vda3 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/vda3 is now 5082107 (4k) blocks long

通过df -h查看拓展后的文件系统大小
$ df -h

文件系统        大小  已用  可用 已用% 挂载点
udev            1.9G     0  1.9G    0% /dev
tmpfs           393M  5.9M  388M    2% /run
/dev/vda3        19G  8.1G   11G   44% /
tmpfs           2.0G     0  2.0G    0% /dev/shm
tmpfs           5.0M     0  5.0M    0% /run/lock
tmpfs           2.0G  4.0K  2.0G    1% /tmp
/dev/vda2       253M  138K  252M    1% /boot/efi
/dev/zram1       47M  3.5M   40M    9% /var/log
tmpfs           393M   44K  393M    1% /run/user/110
tmpfs           393M   40K  393M    1% /run/user/1000
overlaid        393M   40K  393M    1% /run/user/1000/siit-chromium

发现/dev/vda3的可用空间拓展了10G。

posted @ 2024-08-28 09:28  科里布  阅读(112)  评论(0)    收藏  举报