Try ubuntu core (by quqi99)

作者:张华 发表于:2024-07-20
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明(http://blog.csdn.net/quqi99)

try ubuntu core on qemu

复制代码
#ovmf is to ensure compatibility with the required UEFI features in ubuntu core
sudo apt install qemu-kvm ovmf
kvm-ok
#swtpm is to provide a TPM emulator
sudo snap install --edge test-snapd-swtpm
#Download ubuntu core - https://ubuntu.com/core/docs/supported-platforms
wget https://cdimage.ubuntu.com/ubuntu-core/24/stable/current/ubuntu-core-24-amd64.img.xz
xz -d ubuntu-core-24-amd64.img.xz
#With TPM emulation and full disk encryption
sudo qemu-system-x86_64 -enable-kvm -smp 1 -m 2048 -machine q35 -cpu host -global ICH9-LPC.disable_s3=1 \
 -net nic,model=virtio -net user,hostfwd=tcp::8022-:22,hostfwd=tcp::8090-:80  \
 -drive file=/usr/share/OVMF/OVMF_CODE.secboot.fd,if=pflash,format=raw,unit=0,readonly=on \
 -drive file=/usr/share/OVMF/OVMF_VARS.ms.fd,if=pflash,format=raw,unit=1 \
 -drive "file=/images/kvm/ubuntu-core-24-amd64.img",if=none,format=raw,id=disk1 \
 -device virtio-blk-pci,drive=disk1,bootindex=1 -serial mon:stdio
#https://login.ubuntu.com  and https://login.ubuntu.com/ssh-keys
ssh <your-name>@localhost -p 8022

try ubuntu core on raspberry pi

复制代码
#download image from https://ubuntu.com/core/docs/supported-platforms , eg: ubuntu-core-24-arm64+raspi.img.xz
xz -d ubuntu-core-24-arm64+raspi.img.xz
sudo dd if=ubuntu-core-24-arm64+raspi.img of=/dev/sdb status=progress; sync

try ubuntu core on x64 computer

复制代码
#dd to usb or disk
sudo dd if=/images/kvm/ubuntu-core-24-amd64.img of=/dev/sdb status=progress; sync

树霉派上的linux启动流程理论分析

注意:下面的过程只是我从网上做的一个理论分析,并没有做实验,只是想让自己大致心里清楚有些大致的步骤。

树莓派4b启动流程:romboot-->uboot-->kernel-->rootfs

1, 第一阶段bootloader, 上电后,加载bootrom(固化在芯片内部,4b之前通过EEPROM加载SD上的bootcode.bin)到GPU中运行来初始化PLL, DDR等

2, 第二阶段bootloader, 从SD/网络/USB等加载start4.elf, 接着读取config.txt去进行uboot的启动流程

3, 启动kernel

通过JTAG将uboot引导安装到开发板Nor Flash/BIOS中,有两类,一类是并口,一类是USB代替并口(/dev/ttyUSB0)

通过uboot将OS(如tftp)引导安装到开发板NAND Flash中

打开Raspberry Pi Imager烧录镜(romboot)像到SD中, 默认串口没有输出,需修改config.txt在末尾添加enable_uart=1

1, 交叉编译工具的安装与uboot的编译

复制代码
wget https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
tar -xvf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz -C /bak/soft/arm
alias crosscompiler='export KERNEL=kernel8;export ARCH=arm64;export CROSS_COMPILE=/bak/soft/arm/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-'
git clone https://github.com/u-boot/u-boot.git
cp ./u-boot <your-sd>
git checkout v2020.04-rc3
sudo apt install u-boot-tools bison bc make flex libssl-dev ncurses-* -y
crosscompiler
make rpi_4_defconfig
make -j $(nproc)
cat << EOF |tee ./config.txt
ls u-boot.bin
arm_control=0x200  #64 bits
kernel=u-boot.bin
dtoverlay=disable-bt #If serial debugging is enabled, Bluetooth cannot be used
EOF

下面是一个客户使用的config.txt, 本来无法进入ubuntu core内核,但改为dtoverlay=vc4-kms-v3d就修复了
[cm4]
otg_mode=1
[pi4]
kernel=uboot_rpi_4.bin
dtoverlay=vc4-fkms-v3d,cma-128
dtoverlay=dwc2,dr_mode=host
[pi3]
kernel=uboot_rpi_3.bin
dtoverlay=vc4-fkms-v3d,cma-128
max_framebuffers=2
[all]
arm_64bit=1
enable_uart=1

2, 编译树莓派Linux源代码, 并通过tftp加载kernel

复制代码
git clone --branch rpi-5.6.y https://github.com/raspberrypi/linux
mkdir rpi_hw
make O=rpi_hw bcm2711_defconfig
make O=rpi_hw menuconfig
make O=rpi_hw -j $(nproc)
ls rpi_hw/arch/arm64/boot
sudo cp rpi_hw/arch/arm64/boot/Image /bak/tftp/

进入u-boot命令窗口(就像进入bios一样的, 可能需要在出现"Hit any key to stop autoboot: 3"时,按下空格键)后运行

复制代码
sudo minicom -D /dev/ttyUSB0 -b 115200  #press power key
setenv ipaddr 10.1.1.100 #设置开发板的静态地址(自定义)
setenv serverip 10.1.1.160 #设置根文件系统的nfs服务器地址
setenv netmask 255.255.255.0
saveenv
reset
setenv kernel_addr_r 0x8000
setenv kernel Image
setenv netboot 'tftp ${kernel_addr_r} ${kernel} && booti ${kernel_addr_r} - ${fdtcontroladdr}'
setenv bootcmd 'run netboot'
setenv bootargs 'console=ttyAMA0'
saveenv
reset

设置cmdline, 可以用下列的u-boot命令设置,也可以在/run/mnt/ubuntu-seed/cmdline.txt中设置

复制代码
setenv nfsroot /opt/nfs/
setenv bootargs "console=ttyAMA0,115200 root=/dev/nfs rw nfsroot=${serverip}:${nfsroot},v3,tcp ip=$ipaddr:$serverip::$netmask::eth0:off"
saveenv

搭建tftp服务器的步骤:

复制代码
#windows client is Tftp64
sudo apt install tftpd-hpa tftp-hpa -y  
cat << EOF |tee /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/bak/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure --create"
EOF
sudo chown tftp:tftp /bak/tftp
sudo systemctl restart tftpd-hpa
echo 'test' |sudo tee /bak/tftp/test.txt
tftp 127.0.0.1 -c get test.txt

3, 从nfs文件系统中挂载根文件系统

复制代码
sd里有两个分区,一个rootfs一个boot, 将boot分区的所有文件拷到file路径下
sudo cp <rootfs_in_sd> /opt/nfs/ -R
sudo mkdir -p /opt/nfs/file
sudo cp <all-files-in-boot> /opt/nfs/file/
sudo vim etc/fstab
 10.1.1.160:/opt/nfs/file /boot nfs defaults,vers=4.1,proto=tcp 0 0

Reference

1\] https://ubuntu.com/core/docs/testing-with-qemu \[2\] https://blog.csdn.net/quqi99/article/details/80425722 \[3\] https://cloud.tencent.com/developer/article/1806436

相关推荐
qq_3129201122 分钟前
Nginx限流与防爬虫与安全配置方案
运维·爬虫·nginx·安全
GanGuaGua28 分钟前
Linux系统:线程的互斥和安全
linux·运维·服务器·c语言·c++·安全
lsnm38 分钟前
【LINUX网络】IP——网络层
linux·服务器·网络·c++·网络协议·tcp/ip
全糖去冰吃不了苦38 分钟前
ELK 集群部署实战
运维·jenkins
不掰手腕1 小时前
在UnionTech OS Server 20 (统信UOS服务器版) 上离线安装PostgreSQL (pgsql) 数据库
linux·数据库·postgresql
Lynnxiaowen1 小时前
今天继续昨天的正则表达式进行学习
linux·运维·学习·正则表达式·云计算·bash
努力学习的小廉1 小时前
深入了解linux系统—— POSIX信号量
linux·运维·服务器
刘一说2 小时前
CentOS部署ELK Stack完整指南
linux·elk·centos
从零开始的ops生活2 小时前
【Day 50 】Linux-nginx反向代理与负载均衡
linux·nginx
IT成长日记2 小时前
【Linux基础】Linux系统配置IP详解:从入门到精通
linux·运维·tcp/ip·ip地址配置