参考页面信息:https://openwrt.org/docs/guide-user/virtualization/vmware?s%5B%5D=esxi

在Linux下调整img文件的分区大小

1.准备工作

本操作需要用到qemu-img fdisk e2fsck resize2fs等工具,在ubuntu系统中,可以用下列命令安装

sudo apt-get install -y qemu-utils parted e2fsprogs

2.获取img文件

http://www.openwrt.org

3.扩展img文件大小

使用qemu-img工具扩展openwrt的img文件大小。本次扩展到1GB。

qemu-img resize -f raw 2openwrt.img 1G

4.调整img文件分区大小

  • 使用losetup将img文件挂载为环回设备:

    sudo losetup -fP ./2openwrt.img
    sudo losetup -a
    /dev/loop9: [64768]:6561801 (/home/user/openwrt-24.10/2openwrt.img)
  • 查看当前img文件的分区信息

    sudo parted /dev/loop9 unit s print
    Model: Loopback device (loopback)
    Disk /dev/loop9: 2097152s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start   End      Size     Type     File system  Flags
     1      512s    33279s   32768s   primary  ext2         boot
     2      33792s  246783s  212992s  primary  ext4
    
  • 用parted调整分区大小,不要删除分区,直接resizepart分区大小,不然如果你用的是EFI安装包的话,删除了分区后分区的uuid会发生变化。

    parted /dev/loop9
    print free
    resizepart 1GB
  • 同步分区信息

    sudo partx -u /dev/loop9

5.扩展新的root分区大小

  • 使用e2fsck 和 resize2fs 扩展新的root分区。

    sudo e2fsck -f /dev/loop9p2
    sudo resize2fs  /dev/loop9p2
    
    yangbo@homeserver2:~/openwrt-24.10$ sudo e2fsck -f /dev/loop9p2
    e2fsck 1.45.5 (07-Jan-2020)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    Padding at end of inode bitmap is not set. Fix<y>? yes
    
    rootfs: ***** FILE SYSTEM WAS MODIFIED *****
    rootfs: 1573/6656 files (0.0% non-contiguous), 7887/32768 blocks
    yangbo@homeserver2:~/openwrt-24.10$ 
    yangbo@homeserver2:~/openwrt-24.10$ sudo resize2fs  /dev/loop9p2
    resize2fs 1.45.5 (07-Jan-2020)
    Resizing the filesystem on /dev/loop9p2 to 257920 (4k) blocks.
    The filesystem on /dev/loop9p2 is now 257920 (4k) blocks long.
    
    yangbo@homeserver2:~/openwrt-24.10$ 

将img文件转换为VMDK文件

openwrt的img文件不论是直接下载的还是扩容后的,都不能直接用于VMware ESXi。需要将其转换为vmware 的vmdk文件。使用qemu-img文件,命令如下

qemu-img convert -f raw -O vmdk 2openwrt.img 2openwrt.vmdk

在ESXi中创建虚拟机并使用扩容后的VMDK文件

这个就不写了,无非不过上传VMDK文件,创建虚拟机,使用已存在的虚拟硬盘即可。

问题

如果partuudi发生了变化,1.可以查看新的partuuid,然后修改boot分区grub.cfg文件的内容。2.重新操作,注意不要让partuuid发生变化。

标签: openwrt, vmdk, emu-img, losetup, parted

添加新评论