ubuntu armhf cloud 发行版 仿真



4.cloud(其中包括arm arm64)//参考 https://ubuntu.com/download/cloud
	镜像位置 : https://cloud-images.ubuntu.com/
	镜像1文件名称:https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-armhf-disk1.img
	https://gist.github.com/tuxmartin/04d85009a3aaa968c3430678096e3ac6
	
	镜像2文件名称:https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-arm64-uefi1.img 
	https://blog.csdn.net/gong0791/article/details/86367187
————————————————
版权声明:本文为CSDN博主「__pop_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011011827/article/details/120590502
以 
	镜像1文件名称:https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-armhf-disk1.img
	https://gist.github.com/tuxmartin/04d85009a3aaa968c3430678096e3ac6
为参考
制作本文
以 https://gist.github.com/tuxmartin/04d85009a3aaa968c3430678096e3ac6 为参考
主要步骤为
	1. 获取 vmlinuz 文件
	2. 获取 设备树 文件
	3. 获取 initrd.img 文件
	4. 获取rootfs所在镜像文件
	5. qemu-system-arm -machine vexpress-a15 -cpu cortex-a15 -m 512M -kernel "vmlinuz" -initrd "initrd.img" -append "..." -dtb "设备树文件" -drive ...,file="rootfs镜像文件"
但是无法启动
目前已经做到的是
	1. 获取了 vmlinuz 文件 :  vmlinuz-4.4.0-210-generic-lpae
	2. 获取了 initrd 文件  :  initrd.img-4.4.0-210-generic-lpae
	3.qemu-system-arm -machine virt  -m 512M -kernel vmlinuz-4.4.0-210-generic-lpae -initrd initrd.img-4.4.0-210-generic-lpae -nographic
	// 注意 : 相对于参考 , 换了
		// 1. -machine virt (vexpress-a15->virt)
		// 2. vmlinuz 版本 (111->210)
		// 3. initrd.img 版本(111->210)
	启动做到了 启动到 initramfs
		(initramfs) uname -a 
		Linux (none) 4.4.0-210-generic-lpae #242-Ubuntu SMP Fri Apr 16 11:26:48 UTC 2021 armv7l GNU/Linux
	TODO : 设备树文件
		   rootfs所在镜像文件



xenial-server-cloudimg-armhf-disk1.img 现在获取的版本 中 
	vmlinuz 的版本 从 vmlinuz-4.4.0-209-generic-lpae 到 vmlinuz-4.4.0-210-generic-lpae
而 linux-image 版本中有
	111 - 210

所以 我会以 210 版本的 xenial-server-cloudimg-armhf-disk1.img 和 210版本的 linux-image 再研究
210 版本的 linux-image 只有一个有效文件 , 且和 xenial-server-cloudimg-armhf-disk1.img 中的文件相同,所以 210 的 linux-image 无需要研究

qemu-system-arm -machine virt  -m 512M -kernel vmlinuz-4.4.0-210-generic-lpae -initrd initrd.img-4.4.0-210-generic-lpae -nographic -append "console=ttyAMA0 earlyprintk=serial root=/dev/mmcblk0p1 ro rootfstype=ext4"  -drive if=none,file=xenial-server-cloudimg-armhf.img,id=hd0 -device virtio-blk-device,drive=hd0

会有如下打印  :
Begin: Running /scripts/init-premount ... done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... [   14.840245] Btrfs loaded
Scanning for Btrfs filesystems
done.
Begin: Waiting for root file system ... Begin: Running /scripts/local-block ... mdadm: CREATE group disk not found
mdadm: No arrays found in config file or automatically
done.
Begin: Running /scripts/local-block ... mdadm: CREATE group disk not found
mdadm: No arrays found in config file or automatically
done.
Begin: Running /scripts/local-block ... mdadm: CREATE group disk not found
mdadm: No arrays found in config file or automatically

qemu-system-arm -machine virt  -m 512M -kernel vmlinuz-4.4.0-210-generic-lpae -initrd initrd.img-4.4.0-210-generic-lpae -nographic \
-append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4 " \
-drive if=none,file=xenial-server-cloudimg-armhf.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0

Warning: fsck not present, so skipping root file system
mount: mounting /dev/vda on /root failed: Invalid argument
done.
Begin: Running /scripts/local-bottom ... done.
Begin: Running /scripts/init-bottom ... mount: mounting /dev on /root/dev failed: No such file or directory
done.
mount: mounting /run on /root/run failed: No such file or directory
run-init: current directory on the same filesystem as the root: error 0
Target filesystem doesn't have requested /sbin/init.
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
No init found. Try passing init= bootarg.


BusyBox v1.22.1 (Ubuntu 1:1.22.0-15ubuntu1.4) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs) qemu-system-arm: terminating on signal 15 from pid 3319 (killall)

qemu-system-arm -machine virt  -m 512M -kernel vmlinuz-4.4.0-210-generic-lpae -initrd initrd.img-4.4.0-210-generic-lpae -nographic \
-append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4 " \
-drive if=none,file=BiscuitOS.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0

$ file BiscuitOS.img
BiscuitOS.img: Linux rev 1.0 ext4 filesystem data, UUID=ededcbba-03b9-4bc6-b9fc-5662335a5eb6 (needs journal recovery) (extents) (large files) (huge files)

这个是OK的

所以 以  xenial-server-cloudimg-armhf-root.tar.xz  为基础 做一个 无分区镜像 rootfs.img // 参考 https://blog.csdn.net/u011011827/article/details/109650263

dd if=/dev/zero of=rootfs.img bs=1M count=1024
mkfs.ext4 -F rootfs.img
mkdir -p tmpfs
sudo mount -t ext4 rootfs.img tmpfs/ -o loop
sudo cp -raf ${
    
    ROOTFS_NAME}/*  tmpfs/
sync
sudo umount tmpfs
rm -rf tmpfs


qemu-system-arm -machine virt  -m 512M -kernel vmlinuz-4.4.0-210-generic-lpae -initrd initrd.img-4.4.0-210-generic-lpae -nographic \
-append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4" \
-drive if=none,file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0

该镜像可正常启动到 ubuntu的 systemd启动
[   29.322327] systemd[1]: systemd 229 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN)
...
[  OK  ] Listening on Load/Save RF Kill Switch Status /dev/rfkill Watch.
sudo mount -t ext4 -o loop rootfs.img /mnt
sudo rm /mnt/etc/init/cloud-*
sudo cp $(which qemu-arm-static) /mnt/usr/bin/
sudo chroot /mnt qemu-arm-static /bin/bash
passwd ubuntu
passwd root
exit
Ubuntu 16.04.7 LTS ubuntu ttyAMA0

ubuntu login: root
Password: 
Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-210-generic-lpae armv7l)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 updates can be applied immediately.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.




root@ubuntu:~# uname -a 
Linux ubuntu 4.4.0-210-generic-lpae #242-Ubuntu SMP Fri Apr 16 11:26:48 UTC 2021 armv7l armv7l armv7l GNU/Linux
// 网络支持
qemu-system-arm \
-machine virt \
-m 512M \
-kernel vmlinuz-4.4.0-210-generic-lpae \
-initrd initrd.img-4.4.0-210-generic-lpae \
-nographic \
-append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4" \
-drive if=none,file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
-net nic -net user,hostfwd=tcp::2222-:22 -display none
// kvm 支持
qemu-system-arm \
-machine virt,virtualization=true,type=virt \
-m 512M \
-kernel vmlinuz-4.4.0-210-generic-lpae \
-initrd initrd.img-4.4.0-210-generic-lpae \
-nographic \
-append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4" \
-drive if=none,file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
-net nic -net user,hostfwd=tcp::2222-:22 -display none

root@ubuntu:~# ls /dev/kvm 
/dev/kvm

网络
L0 : -netdev user,id=hostnet0,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=hostnet0

L1 :/etc/ssh/sshd_config
修改 PasswordAuthentication yes // 修复可登陆(Permission denied (publickey))
修改 PermitRootLogin yes // 修复root可密码登陆
L1:mkdir /var/run/sshd ;service sshd restart

L0:ssh ubuntu@localhost -p 2222 ; ssh root@localhost -p 2222


在 qemu-arm 虚拟机 中 搭建 以下平台
	1. qemu // https://launchpad.net/ubuntu/xenial/armhf 中有 qemu-system-arm
		apt install qemu-system-arm
	2. 拷贝 initrd.img-4.4.0-210-generic-lpae vmlinuz-4.4.0-210-generic-lpae 到 /root
		// scp -P2222 vmlinuz-4.4.0-210-generic-lpae root@localhost:/root
	3./root 下执行 qemu-system-arm -machine virt -enable-kvm -m 256M -kernel vmlinuz-4.4.0-210-generic-lpae -initrd initrd.img-4.4.0-210-generic-lpae -nographic // -enable-kvm 表示使用 /dev/kvm , 否则 不使用,完全由 qemu 仿真
	4. 成功!!! // 成功启动到 initramfs 的 命令行

L1内核升级
利用 xenial-server-cloudimg-armhf-disk1.img 中的 config-4.4.0-210-generic-lpae ,编译 linux-5.6
生成 arch/arm/boot/zImage
注意 :  initrd.img(独立式initramfs) 和 rootfs.img(最终根文件系统) 不用换


qemu-system-arm \
    -machine virt,virtualization=true,type=virt \
    -m 512M \
    -kernel ~/work/linux/linux-5.6/arch/arm/boot/zImage \
    -initrd initrd.img-4.4.0-210-generic-lpae \
    -nographic \
    -append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4" \
    -drive if=none,file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
    -net nic -net user,hostfwd=tcp::2222-:22 -display none

  • debug
1. 安装 arm-linux-none-gdb
2. 运行
qemu-system-arm \
    -machine virt,virtualization=true,type=virt \
    -m 512M \
    -kernel ~/work/linux/linux-5.6/arch/arm/boot/zImage \
    -initrd initrd.img-4.4.0-210-generic-lpae \
    -nographic \
    -append "console=ttyAMA0 earlyprintk=serial root=/dev/vda rw rootfstype=ext4" \
    -drive if=none,file=rootfs.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
    -net nic -net user,hostfwd=tcp::2222-:22 -display none -S -s
3.
// arm-none-eabi-gdb 的安装
// https://zhuanlan.zhihu.com/p/134031693
// sudo dpkg -i gdb-arm-none-eabi_7.10-1ubuntu3+9_amd64.deb // 
// sudo apt --fix-broken install
bash> arm-none-eabi-gdb  --tui ~/work/linux/linux-5.6/vmlinux
gdb> target remote localhost:1234
gdb> b start_kernel
gdb> b arm_init
gdb> c

Guess you like

Origin blog.csdn.net/u011011827/article/details/120599618