Qemu-arm guest openwrt disk expanding question

Greetings and regards to everyone,

I am currently running the OpenWrt operating system on qemu-arm virtualization for some tests using the following command:

qemu-system-aarch64 -M virt -cpu cortex-a53 -m 4096 -smp 4 -nographic \
-kernel /home/erdem/openwrt-21.02.7-armvirt-64-Image \
-drive if=none,file=/home/erdem/openwrt-21.02.7-armvirt-64-rootfs-squashfs.img,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev tap,id=net0,ifname=tap4,script=no,downscript=no -device virtio-net-device,netdev=net0,mac=52:54:00:00:00:44 \  
-netdev tap,id=net1,ifname=tap5,script=no,downscript=no -device virtio-net-device,netdev=net1,mac=52:54:00:00:00:55 \  
-append "root=/dev/vda"

In order to conduct my tests, I need a substantial amount of disk space. However, the default ready-made images of OpenWrt do not provide this. I attempted to enlarge the image by following some documentation, but unfortunately, I was unsuccessful. The documents I followed were:

The current situation I am facing is as follows:
One of the last things I did was resize the image file:

-rw-rw-r-- 1 erdem erdem 5,0G Tem 11 18:27 openwrt-21.02.7-armvirt-64-rootfs-squashfs.img

However, it seems that OpenWrt is not aware of this change. It is possible that I may have inadvertently broken the partition table or encountered some other issue, as I am unable to reboot the machine:

[    0.374914] loop: module loaded
[    0.393863] virtio_blk virtio2: [vda] 10485760 512-byte logical blocks (5.37 GB/5.00 GiB)
[    0.410778]  vda:
[    0.417171] Loading iSCSI transport class v2.0-870.
[    0.437251] rtc-pl031 9010000.pl031: registered as rtc0
[    0.442429] NET: Registered protocol family 10
[    0.457177] Segment Routing with IPv6
[    0.457883] NET: Registered protocol family 17
[    0.458856] bridge: filtering via arp/ip/ip6tables is no longer available by default. Update your scripts to load br_netfilter if you need this.
[    0.459981] 8021q: 802.1Q VLAN Support v1.8
[    0.462022] 9pnet: Installing 9P2000 support
[    0.470976] rtc-pl031 9010000.pl031: setting system clock to 2023-07-12T09:53:43 UTC (1689155623)
[    0.486995] uart-pl011 9000000.pl011: no DMA platform data
[    0.505277] F2FS-fs (vda): Magic Mismatch, valid(0xf2f52010) - read(0x7c36e757)
[    0.505741] F2FS-fs (vda): Can't find valid F2FS filesystem in 1th superblock
[    0.506875] F2FS-fs (vda): Magic Mismatch, valid(0xf2f52010) - read(0x419a543c)
[    0.507484] F2FS-fs (vda): Can't find valid F2FS filesystem in 2th superblock
[    0.509101] List of all partitions:
[    0.509669] fe00         5242880 vda 
[    0.509716]  driver: virtio_blk
[    0.510192] No filesystem could mount root, tried: 
[    0.510222]  ext3
[    0.510517]  ext2
[    0.510637]  ext4
[    0.510761]  squashfs
[    0.510881]  f2fs
[    0.511277] 
[    0.511873] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(254,0)
[    0.512629] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.4.238 #0
[    0.512985] Hardware name: linux,dummy-virt (DT)
[    0.513629] Call trace:
[    0.513935]  0xffffffc01008fdb0
[    0.514251]  0xffffffc01008ff5c
[    0.514466]  0xffffffc01073ec00
[    0.514664]  0xffffffc010739ee4
[    0.514856]  0xffffffc01086142c
[    0.515107]  0xffffffc010861530
[    0.515410]  0xffffffc010861668
[    0.515697]  0xffffffc010860f70
[    0.515967]  0xffffffc01073ef84
[    0.516161]  0xffffffc0100865f4
[    0.516773] SMP: stopping secondary CPUs
[    0.517429] Kernel Offset: disabled
[    0.517830] CPU features: 0x00002,24002000
[    0.518062] Memory Limit: none
[    0.518630] Rebooting in 1 seconds..
[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]

I would like to express my gratitude in advance for any assistance you can provide in expanding the disk size for virtualization using qemu-system-aarch64.

hello, here are my notes how I did the resize:

qemu-img resize -f raw openwrt-*.img 300M

# Install packages (running image)
opkg update
opkg install parted losetup resize2fs
 
# Identify disk name and partition number
echo -e "ok\nfix" | parted -l ---pretend-input-tty
 
# Expand root partition
parted -s /dev/vda resizepart 1 100%
 
# Apply changes
reboot
 
# Map loop device to root partition
losetup /dev/loop1 /dev/vda
 
# Expand root filesystem
resize2fs -f /dev/loop1
 
# Apply changes
reboot

I hope its helpful!

so long

Dear,

Firstly, I would like to express my appreciation for your prompt response.

I am writing to you in order to provide detailed information regarding the steps I have performed as per your guidance. Unfortunately, despite your instructions, I encountered some difficulties while attempting to assign a disk label and create a partition on my disk. As a result, it seems my disk has become corrupted.

root@OpenWrt21DEx:/# echo -e "ok\nfix" | parted -l ---pretend-input-tty
Error: /dev/vda: unrecognised disk label
Model: Virtio Block Device (virtblk)                                      
Disk /dev/vda: 3146MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 

root@OpenWrt21DEx:/# 
root@OpenWrt21DEx:/# parted -s /dev/vda resizepart 1 100%
Error: /dev/vda: unrecognised disk label
root@OpenWrt21DEx:/#
root@OpenWrt21DEx:/# parted /dev/vda mklabel gpt
Information: You may need to update /etc/fstab.

root@OpenWrt21DEx:/# parted -s /dev/vda resizepart 1 100%
Error: Partition doesn't exist.
root@OpenWrt21DEx:/# echo -e "ok\nfix" | parted -l ---pretend-input-tty
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 3146MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags


root@OpenWrt21DEx:/#
root@OpenWrt21DEx:/# parted -s /dev/vda resizepart 1 100%
Error: Partition doesn't exist.
root@OpenWrt21DEx:/# 
root@OpenWrt21DEx:/# parted -s /dev/vda mkpart primary 0% 100%
root@OpenWrt21DEx:/# 
root@OpenWrt21DEx:/# parted -s /dev/vda resizepart 1 100%
root@OpenWrt21DEx:/# 
root@OpenWrt21DEx:/#
root@OpenWrt21DEx:/# reboot
root@OpenWrt21DEx:/# [  650.795386] br-lan: port 1(eth0) entered disabled state
[  650.813897] device eth0 left promiscuous mode
[  650.814645] br-lan: port 1(eth0) entered disabled state
[  655.406748] reboot: Restarting system
[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 5.4.238 (builder@buildhost) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r16847-f8282da11e)) #0 SMP Mon Apr 17 13:15:36 2023
[    0.000000] Machine model: linux,dummy-virt
[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv0.2 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: Trusted OS migration not required
[    0.000000] percpu: Embedded 20 pages/cpu s44440 r8192 d29288 u81920
[    0.000000] Detected VIPT I-cache on CPU0
[    0.000000] CPU features: detected: ARM erratum 843419
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 1032192
[    0.000000] Kernel command line: root=/dev/vda
[    0.000000] Dentry cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
[    0.000000] Inode-cache hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] software IO TLB: mapped [mem 0xfbfff000-0xfffff000] (64MB)
[    0.000000] Memory: 4037816K/4194304K available (6974K kernel code, 404K rwdata, 1048K rodata, 512K init, 289K bss, 156488K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu: 	CONFIG_RCU_FANOUT set to non-default value of 32.
[    0.000000] rcu: 	RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=4.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=4
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] GICv2m: range[mem 0x08020000-0x08020fff], SPI[80:143]
[    0.000000] arch_timer: cp15 timer(s) running at 62.50MHz (virt).
[    0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[    0.000088] sched_clock: 56 bits at 62MHz, resolution 16ns, wraps every 4398046511096ns
[    0.007811] Console: colour dummy device 80x25
[    0.009015] printk: console [tty0] enabled
[    0.009977] Calibrating delay loop (skipped), value calculated using timer frequency.. 125.00 BogoMIPS (lpj=250000)
[    0.010109] pid_max: default: 32768 minimum: 301
[    0.011386] Mount-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.011474] Mountpoint-cache hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.037211] /cpus/cpu-map: empty cluster
[    0.044724] ASID allocator initialised with 32768 entries
[    0.045462] rcu: Hierarchical SRCU implementation.
[    0.049252] smp: Bringing up secondary CPUs ...
[    0.051795] Detected VIPT I-cache on CPU1
[    0.052546] CPU1: Booted secondary processor 0x0000000001 [0x410fd034]
[    0.057564] Detected VIPT I-cache on CPU2
[    0.057814] CPU2: Booted secondary processor 0x0000000002 [0x410fd034]
[    0.059512] Detected VIPT I-cache on CPU3
[    0.059652] CPU3: Booted secondary processor 0x0000000003 [0x410fd034]
[    0.060273] smp: Brought up 1 node, 4 CPUs
[    0.060382] SMP: Total of 4 processors activated.
[    0.060457] CPU features: detected: 32-bit EL0 Support
[    0.060513] CPU features: detected: CRC32 instructions
[    0.061866] CPU features: emulated: Privileged Access Never (PAN) using TTBR0_EL1 switching
[    0.062075] CPU: All CPU(s) started at EL1
[    0.062312] alternatives: patching kernel code
[    0.077573] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.077747] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    0.087634] NET: Registered protocol family 16
[    0.092575] DMA: preallocated 256 KiB pool for atomic allocations
[    0.098006] cpuidle: using governor menu
[    0.099391] Serial: AMBA PL011 UART driver
[    0.120212] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 39, base_baud = 0) is a PL011 rev1
[    0.138208] printk: console [ttyAMA0] enabled
[    0.173061] cryptd: max_cpu_qlen set to 1000
[    0.184805] SCSI subsystem initialized
[    0.201093] clocksource: Switched to clocksource arch_sys_counter
[    0.221539] thermal_sys: Registered thermal governor 'step_wise'
[    0.223565] NET: Registered protocol family 2
[    0.225859] IP idents hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.243741] tcp_listen_portaddr_hash hash table entries: 2048 (order: 3, 32768 bytes, linear)
[    0.244777] TCP established hash table entries: 32768 (order: 6, 262144 bytes, linear)
[    0.245535] TCP bind hash table entries: 32768 (order: 7, 524288 bytes, linear)
[    0.246827] TCP: Hash tables configured (established 32768 bind 32768)
[    0.250111] UDP hash table entries: 2048 (order: 4, 65536 bytes, linear)
[    0.250981] UDP-Lite hash table entries: 2048 (order: 4, 65536 bytes, linear)
[    0.254618] NET: Registered protocol family 1
[    0.255555] PCI: CLS 0 bytes, default 64
[    0.292172] workingset: timestamp_bits=46 max_order=20 bucket_order=0
[    0.307427] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.307688] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.310670] 9p: Installing v9fs 9p2000 file system support
[    0.318095] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.325866] atomic64_test: passed
[    0.330902] pl061_gpio 9030000.pl061: PL061 GPIO chip registered
[    0.332641] pci-host-generic 4010000000.pcie: host bridge /pcie@10000000 ranges:
[    0.333421] pci-host-generic 4010000000.pcie:    IO 0x3eff0000..0x3effffff -> 0x00000000
[    0.334154] pci-host-generic 4010000000.pcie:   MEM 0x10000000..0x3efeffff -> 0x10000000
[    0.334505] pci-host-generic 4010000000.pcie:   MEM 0x8000000000..0xffffffffff -> 0x8000000000
[    0.335420] pci-host-generic 4010000000.pcie: ECAM at [mem 0x4010000000-0x401fffffff] for [bus 00-ff]
[    0.336787] pci-host-generic 4010000000.pcie: PCI host bridge to bus 0000:00
[    0.337391] pci_bus 0000:00: root bus resource [bus 00-ff]
[    0.337724] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[    0.337993] pci_bus 0000:00: root bus resource [mem 0x10000000-0x3efeffff]
[    0.338281] pci_bus 0000:00: root bus resource [mem 0x8000000000-0xffffffffff]
[    0.340066] pci 0000:00:00.0: [1b36:0008] type 00 class 0x060000
[    0.353813] Serial: 8250/16550 driver, 16 ports, IRQ sharing enabled
[    0.360306] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.380120] loop: module loaded
[    0.404789] virtio_blk virtio2: [vda] 6144000 512-byte logical blocks (3.15 GB/2.93 GiB)
[    0.422770]  vda: vda1
[    0.429837] Loading iSCSI transport class v2.0-870.
[    0.450400] rtc-pl031 9010000.pl031: registered as rtc0
[    0.453920] NET: Registered protocol family 10
[    0.464154] Segment Routing with IPv6
[    0.465539] NET: Registered protocol family 17
[    0.466604] bridge: filtering via arp/ip/ip6tables is no longer available by default. Update your scripts to load br_netfilter if you need this.
[    0.467116] 8021q: 802.1Q VLAN Support v1.8
[    0.469379] 9pnet: Installing 9P2000 support
[    0.480902] rtc-pl031 9010000.pl031: setting system clock to 2023-07-14T12:02:39 UTC (1689336159)
[    0.491705] uart-pl011 9000000.pl011: no DMA platform data
[    0.511364] F2FS-fs (vda): Magic Mismatch, valid(0xf2f52010) - read(0xfc63daf)
[    0.511977] F2FS-fs (vda): Can't find valid F2FS filesystem in 1th superblock
[    0.512994] F2FS-fs (vda): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[    0.513275] F2FS-fs (vda): Can't find valid F2FS filesystem in 2th superblock
[    0.513814] List of all partitions:
[    0.514139] fe00         3072000 vda 
[    0.514169]  driver: virtio_blk
[    0.514500]   fe01         3070959 vda1 9ef72506-fabb-4cc4-bf17-566c841c2df9
[    0.514514] 
[    0.514923] No filesystem could mount root, tried: 
[    0.514942]  ext3
[    0.515162]  ext2
[    0.515255]  ext4
[    0.515352]  squashfs
[    0.515449]  f2fs
[    0.515567] 
[    0.516021] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(254,0)
[    0.516761] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.4.238 #0
[    0.517063] Hardware name: linux,dummy-virt (DT)
[    0.517608] Call trace:
[    0.517873]  0xffffffc01008fdb0
[    0.518159]  0xffffffc01008ff5c
[    0.518346]  0xffffffc01073ec00
[    0.518533]  0xffffffc010739ee4
[    0.518717]  0xffffffc01086142c
[    0.518897]  0xffffffc010861530
[    0.519076]  0xffffffc010861668
[    0.519247]  0xffffffc010860f70
[    0.519420]  0xffffffc01073ef84
[    0.519568]  0xffffffc0100865f4
[    0.519999] SMP: stopping secondary CPUs
[    0.520490] Kernel Offset: disabled
[    0.520901] CPU features: 0x00002,24002000
[    0.521197] Memory Limit: none
[    0.521828] Rebooting in 1 seconds..

I would highly appreciate any further guidance or assistance on this matter.

Kind regards,
Erdem.

Hi again,

Just wanted to let you know that I figured out the issue. Turns out, it was the disk image I was using that was causing the problem.

Once I switched to using the "openwrt-21.02.7-armvirt-64-rootfs-ext4.img" image and followed your instructions, the disk resized without any hitches. Everything is working as expected now.

root@OpenWrt:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 2.9G     13.6M      2.9G   0% /
tmpfs                     1.9G     52.0K      1.9G   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
root@OpenWrt:/# 

Really appreciate all your help!

Best Regards,
Erdem.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.