硬盘扩容, PVE, Archlinux
硬盘扩容 pve ext4 根分区磁盘扩容 虚拟机关机 在 pve 里给硬盘扩容: vm>hardware> Hard Disk> Disk Action> resize: 填写新增的容量 挂载 archlinux iso, 修改引导顺序, 让虚拟机从 iso 启动 启动虚拟机 # 列出所有块设备(磁盘及分区)的信息,以树状结构显示设备名、大小、挂载点等 lsblk # 看到磁盘总大小增加了,但分区大小没变。 fdisk -l # 调整分区表, 扩容, 用 fdisk 调整分区表一般不会丢数据,但是最好备份一下。 fdisk /dev/sda # 如果不是从 iso 引导,直接在操作系统里执行, 会提示 This disk is currently in use - repartitioning is probably a bad idea. It's recommended to umount all file systems, nd swapoff all swap partitions on this disk. # print the partition table Command (m for help): p Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: QEMU HARDDISK 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: dos Disk identifier: 0x1bc64ef0 Device Boot Start End Sectors Size Id Type /dev/sda1 * 6144 2103295 2097152 1G b W95 FAT32 /dev/sda2 2103296 20971519 18868224 9G 83 Linux # delete partition 2 Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 has been deleted. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) # 输入 p Select (default p): p # 使用默认值 2 Partition number (2-4, default 2): # 输入分区的起始扇区, 要和删除的分区起始扇区一样, 注意!默认值会是2048, 不要使用这个默认值, 要输入前面打印分区表时看到的分区 2 的起始扇区值, 否则会丢数据, 这里是2103296 First sector (2048-41943039, default 2048): 2103296 # 输入分区的结束扇区, 使用默认值, 即使用所有剩余空间 Last sector, +/-sectors or +/-size{K,M,G,T,P} (2103296-41943039, default 41943039): Created a new partition 2 of type 'Linux' and of size 19 GiB. Partition #2 contains a ext4 signature. # 输入 y 确认删除 ext4 签名 Do you want to remove the signature? [Y]es/[N]o: Y The signature will be removed by a write command. # 再次打印分区表, 应该能看到分区 2 已经变大了 Command (m for help): p Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: QEMU HARDDISK 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: dos Disk identifier: 0x1bc64ef0 Device Boot Start End Sectors Size Id Type /dev/sda1 * 6144 2103295 2097152 1G b W95 FAT32 /dev/sda2 2103296 41943039 39839744 19G 83 Linux Filesystem/RAID signature on partition 2 will be wiped. # 输入命令 w 保存分区表 Command (m for help): w The partition table has been altered. Syncing disks. # 强制检查 ext2/ext3/ext4 文件系统的一致性,-f 表示即使文件系统标记为干净也强制执行检查 e2fsck -f /dev/sda2 # 有可能会询问是否优化,输入 y, 后面可能会有很多类似的提示,全部输入 y 即可, 还有可能提示输入 a: 确认全部 root@archiso ~ # e2fsck -f /dev/sda2 e2fsck 1.47.3 (8-Jul-2025) ext2fs_open2: Bad magic number in super-block e2fsck: Superblock invalid, trying backup blocks... Pass 1: Checking inodes, blocks, and sizes Inode 287507 extent tree (at level 1) could be narrower. Optimize<y>? # resize the filesystem # resize2fs 要求文件系统在扩容前必须是干净状态(通过 e2fsck 校验),否则拒绝执行 resize2fs /dev/sda2 # 分区扩容完成,重启虚拟机 PVE ext4 disk resize Online Lossless Expansion of EXT4 Partition ...