将镜像文件作为交换分区
创建镜像文件:
dd if=/dev/zero of=swap.img bs=512 count=131072
qemu-system-arm -nographic -M vexpress-a9 -m 64M -kernel arch/arm/boot/zImage -append "rdinit=/linuxrc console=ttyAMA0 loglevel=8" -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb -sd swap.img
~ # mkswap /dev/mmcblk0
Setting up swapspace version 1, size = 67104768 bytes
[ 62.306076] random: mkswap urandom read with 112 bits of entropy available
UUID=f1837026-d957-4153-97ab-31f549ec0534
~ # [ 72.694766] random: nonblocking pool is initialized
swapon /dev/mmcblk0
[ 83.105627] Adding 65532k swap on /dev/mmcblk0. Priority:-1 extents:1 across:65532k SS
~ # df -h
Filesystem Size Used Available Use% Mounted on
tmpfs 24.8M 0 24.8M 0% /tmp
tmpfs 24.8M 0 24.8M 0% /dev
~ # free
total used free shared buff/cache available
Mem: 50840 11948 32708 2152 6184 34028
Swap: 65532 0 65532
将镜像文件作为外挂磁盘
dd if=/dev/zero of=ext4.img bs=512 count=131072
格式化:
mkfs.ext4 ext4.img
挂载 ext4 文件系统需要打开如下配置的选项。
[arch/arm/configs/vexpress _ defconfig]CONFIG _ LBDAF=yCONFIG_EXT4 _ FS=y
重新编译内核
qemu-system-arm -nographic -M vexpress-a9 -m 64M -kernel arch/arm/boot/zImage -append "rdinit=/linuxrc console=ttyAMA0 loglevel=8" -dtb arch/arm/boot/dts/vexpress-v2p-ca9.dtb -sd ext4.img
系统启动后,手动挂载。
挂载成功。
未验证
在启动命令后使用-sd swap.img报错
WARNING: Image format was not specified for 'swap.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
qemu-system-aarch64: -sd swap.img: machine type does not support if=sd,bus=0,unit=0
解决办法: 将-sd swap.img替换为下面的形式
-drive format=raw,file=swap.img