在qemu virt平台运行xen,guest OS Dom0 Linux和Dom1 Linux

文章介绍了如何下载、配置并编译适用于ARM64架构的Linux内核,包括设置Dom0支持与Xen功能,并通过QEMU模拟测试。此外,还详细说明了BusyBox的编译、静态配置及创建根文件系统的过程。

1)编译linux内核

内核下载地址:The Linux Kernel Archives

配置Dom0 Linux内核:

 make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig

在生成的.config文件中添加下面两个选项:

CONFIG_XEN_DOM0=y
CONFIG_XEN=y

编译内核:

make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

测试编译生成的linux内核镜像:

qemu-system-aarch64 -M vexpress-a15 -m 512M -kernel zImage -dtb vexpress-v2p-ca15_a7.dtb -append "init=/linuxrc root=/dev/mmcblk0 rw rootwait console=ttyAMA0" -nographic

2)编译busybox

 busybox下载地址:BusyBox

配置busybox:

make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- defconfig

make ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- menuconfig

勾选  Settings-> [*] Build static binary (no shared libs)

编译busybox:

make -j4 ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-

安装busybox:

make install ARCH=arm CROSS_COMPILE=aarch64-linux-gnu-

创建rootfs image镜像:

cd _install/

mkdir proc sys dev etc etc/init.d

vim ./etc/init.d/rcS

#! /bin/sh

mount -t proc none /proc

mount -t sysfs none /sys

/sbin/mdev -s

chmod +x ./etc/init.d/rcS

find . | cpio -o --format=newc > ../rootfs.img

cd ..

gzip -c rootfs.img > rootfs.img.gz

测试Image.gz和rootfs.img.gz

qemu-system-aarch64  -machine virt -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 2048 -smp 4 -kernel Image.gz -nographic -no-reboot -initrd rootfs.img.gz -append "rw root=/dev/ram rdinit=/sbin/init  earlyprintk=serial,ttyAMA0 console=ttyAMA0"

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x411fd070]
[    0.000000] Linux version 4.20.0 (hdwei@ubuntu) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #1 SMP PREEMPT Fri Feb 11 23:18:03 PST 2022
[    0.000000] Machine model: linux,dummy-virt
[    0.000000] efi: Getting EFI parameters from FDT:
[    0.000000] efi: UEFI not found.
[    0.000000] cma: Reserved 32 MiB at 0x00000000be000000
[    0.000000] NUMA: No NUMA configuration found
[    0.000000] NUMA: Faking a node at [mem 0x0000000040000000-0x00000000bfffffff]
[    0.000000] NUMA: NODE_DATA [mem 0xbdfea840-0xbdfebfff]
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000040000000-0x00000000bfffffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000040000000-0x00000000bfffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000040000000-0x00000000bfffffff]
[    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] random: get_random_bytes called from start_kernel+0xa8/0x418 with crng_init=0
[    0.000000] percpu: Embedded 23 pages/cpu @(____ptrval____) s55704 r8192 d30312 u94208
[    0.000000] Detected PIPT I-cache on CPU0
[    0.000000] CPU features: enabling workaround for ARM erratum 832075
[    0.000000] CPU features: enabling workaround for ARM erratum 834220
[    0.000000] CPU features: enabling workaround for EL2 vector hardening
[    0.000000] CPU features: detected: Kernel page table isolation (KPTI)
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 516096
[    0.000000] Policy zone: DMA32
[    0.000000] Kernel command line: rw root=/dev/ram rdinit=/sbin/init  earlyprintk=serial,ttyAMA0 console=ttyAMA0
[    0.000000] Memory: 2009656K/2097152K available (10876K kernel code, 1414K rwdata, 5100K rodata, 1344K init, 380K bss, 54728K reserved, 32768K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu: 	RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=4.
[    0.000000] 	Tasks RCU enabled.
[    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] GIC: Using split EOI/Deactivate mode
[    0.000000] GICv2m: range[mem 0x08020000-0x08020fff], SPI[80:143]
[    0.000000] arch_timer: cp15 timer(s) running at 62.50MHz (phys).
[    0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[    0.000059] sched_clock: 56 bits at 62MHz, resolution 16ns, wraps every 4398046511096ns
[    0.002586] Console: colour dummy device 80x25
[    0.007701] Calibrating delay loop (skipped), value calculated using timer frequency.. 125.00 BogoMIPS (lpj=250000)
[    0.007787] pid_max: default: 32768 minimum: 301
[    0.008499] LSM: Security Framework initializing
[    0.010774] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
[    0.011580] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
[    0.011721] Mount-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.011754] Mountpoint-cache hash table entries: 4096 (order: 3, 32768 bytes)
[    0.061653] ASID allocator initialised with 32768 entries
[    0.070428] rcu: Hierarchical SRCU implementation.
[    0.083096] EFI services will not be available.
[    0.090315] smp: Bringing up secondary CPUs ...
[    0.130862] Detected PIPT I-cache on CPU1
[    0.131372] CPU1: Booted secondary processor 0x0000000001 [0x411fd070]
[    0.169365] Detected PIPT I-cache on CPU2
[    0.169493] CPU2: Booted secondary processor 0x0000000002 [0x411fd070]
[    0.208866] Detected PIPT I-cache on CPU3
[    0.209000] CPU3: Booted secondary processor 0x0000000003 [0x411fd070]
[    0.209631] smp: Brought up 1 node, 4 CPUs
[    0.209687] SMP: Total of 4 processors activated.
[    0.209743] CPU features: detected: 32-bit EL0 Support
[    0.209791] CPU features: detected: CRC32 instructions
[    0.245877] CPU: All CPU(s) started at EL2
[    0.246140] alternatives: patching kernel code
[    0.260161] devtmpfs: initialized
[    0.270870] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.271013] futex hash table entries: 1024 (order: 4, 65536 bytes)
[    0.274065] pinctrl core: initialized pinctrl subsystem
[    0.283795] DMI not present or invalid.
[    0.286994] NET: Registered protocol family 16
[    0.289235] audit: initializing netlink subsys (disabled)
[    0.290712] audit: type=2000 audit(0.228:1): state=initialized audit_enabled=0 res=1
[    0.297609] cpuidle: using governor menu
[    0.299240] vdso: 2 pages (1 code @ (____ptrval____), 1 data @ (____ptrval____))
[    0.299331] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[    0.306273] DMA: preallocated 256 KiB pool for atomic allocations
[    0.309162] Serial: AMBA PL011 UART driver
[    0.332236] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 40, base_baud = 0) is a PL011 rev1
[    0.343079] printk: console [ttyAMA0] enabled
[    0.390772] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages
[    0.394602] cryptd: max_cpu_qlen set to 1000
[    0.400092] ACPI: Interpreter disabled.
[    0.407305] vgaarb: loaded
[    0.409517] SCSI subsystem initialized
[    0.412276] usbcore: registered new interface driver usbfs
[    0.413044] usbcore: registered new interface driver hub
[    0.413493] usbcore: registered new device driver usb
[    0.415247] pps_core: LinuxPPS API ver. 1 registered
[    0.415420] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    0.415891] PTP clock support registered
[    0.416588] EDAC MC: Ver: 3.0.0
[    0.420545] Advanced Linux Sound Architecture Driver Initialized.
[    0.427516] clocksource: Switched to clocksource arch_sys_counter
[    0.428295] VFS: Disk quotas dquot_6.6.0
[    0.428511] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.429665] pnp: PnP ACPI: disabled
[    0.470804] NET: Registered protocol family 2
[    0.476352] tcp_listen_portaddr_hash hash table entries: 1024 (order: 2, 16384 bytes)
[    0.476681] TCP established hash table entries: 16384 (order: 5, 131072 bytes)
[    0.477013] TCP bind hash table entries: 16384 (order: 6, 262144 bytes)
[    0.477304] TCP: Hash tables configured (established 16384 bind 16384)
[    0.478437] UDP hash table entries: 1024 (order: 3, 32768 bytes)
[    0.478685] UDP-Lite hash table entries: 1024 (order: 3, 32768 bytes)
[    0.479981] NET: Registered protocol family 1
[    0.482526] RPC: Registered named UNIX socket transport module.
[    0.482640] RPC: Registered udp transport module.
[    0.482727] RPC: Registered tcp transport module.
[    0.482791] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.485159] Unpacking initramfs...
[    0.548071] Freeing initrd memory: 1148K
[    0.551153] hw perfevents: enabled with armv8_pmuv3 PMU driver, 5 counters available
[    0.552229] kvm [1]: 8-bit VMID
[    0.552364] kvm [1]: IPA Size Limit: 44bits
[    0.555106] kvm [1]: vgic interrupt IRQ1
[    0.556722] kvm [1]: Hyp mode initialized successfully
[    0.706848] Initialise system trusted keyrings
[    0.708727] workingset: timestamp_bits=44 max_order=19 bucket_order=0
[    0.721962] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.724163] NFS: Registering the id_resolver key type
[    0.724386] Key type id_resolver registered
[    0.724554] Key type id_legacy registered
[    0.724723] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.725467] 9p: Installing v9fs 9p2000 file system support
[    0.817213] Key type asymmetric registered
[    0.817398] Asymmetric key parser 'x509' registered
[    0.817821] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 245)
[    0.818114] io scheduler noop registered
[    0.818593] io scheduler deadline registered
[    0.819990] io scheduler cfq registered (default)
[    0.820147] io scheduler mq-deadline registered
[    0.820938] io scheduler kyber registered
[    0.837042] pl061_gpio 9030000.pl061: PL061 GPIO chip @0x0000000009030000 registered
[    0.841156] pci-host-generic 4010000000.pcie: host bridge /pcie@10000000 ranges:
[    0.841660] pci-host-generic 4010000000.pcie:    IO 0x3eff0000..0x3effffff -> 0x00000000
[    0.842123] pci-host-generic 4010000000.pcie:   MEM 0x10000000..0x3efeffff -> 0x10000000
[    0.842321] pci-host-generic 4010000000.pcie:   MEM 0x8000000000..0xffffffffff -> 0x8000000000
[    0.843075] pci-host-generic 4010000000.pcie: ECAM at [mem 0x4010000000-0x401fffffff] for [bus 00-ff]
[    0.844798] pci-host-generic 4010000000.pcie: PCI host bridge to bus 0000:00
[    0.845328] pci_bus 0000:00: root bus resource [bus 00-ff]
[    0.845539] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[    0.845704] pci_bus 0000:00: root bus resource [mem 0x10000000-0x3efeffff]
[    0.845858] pci_bus 0000:00: root bus resource [mem 0x8000000000-0xffffffffff]
[    0.854637] pci 0000:00:01.0: BAR 6: assigned [mem 0x10000000-0x1003ffff pref]
[    0.854953] pci 0000:00:01.0: BAR 4: assigned [mem 0x8000000000-0x8000003fff 64bit pref]
[    0.855157] pci 0000:00:01.0: BAR 1: assigned [mem 0x10040000-0x10040fff]
[    0.855291] pci 0000:00:01.0: BAR 0: assigned [io  0x1000-0x101f]
[    0.860252] EINJ: ACPI disabled.
[    0.873116] virtio-pci 0000:00:01.0: enabling device (0000 -> 0003)
[    0.889512] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.894199] SuperH (H)SCI(F) driver initialized
[    0.894964] msm_serial: driver initialized
[    0.897794] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.918282] loop: module loaded
[    0.929849] libphy: Fixed MDIO Bus: probed
[    0.930902] tun: Universal TUN/TAP device driver, 1.6
[    0.943837] thunder_xcv, ver 1.0
[    0.944041] thunder_bgx, ver 1.0
[    0.944199] nicpf, ver 1.0
[    0.945000] hclge is initializing
[    0.945220] hns3: Hisilicon Ethernet Network Driver for Hip08 Family - version
[    0.945330] hns3: Copyright (c) 2017 Huawei Corporation.
[    0.945592] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
[    0.945691] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[    0.945892] igb: Intel(R) Gigabit Ethernet Network Driver - version 5.4.0-k
[    0.946008] igb: Copyright (c) 2007-2014 Intel Corporation.
[    0.946205] igbvf: Intel(R) Gigabit Virtual Function Network Driver - version 2.4.0-k
[    0.946678] igbvf: Copyright (c) 2009 - 2012 Intel Corporation.
[    0.948235] sky2: driver version 1.30
[    0.950325] VFIO - User Level meta-driver version: 0.3
[    0.953289] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.953557] ehci-pci: EHCI PCI platform driver
[    0.953877] ehci-platform: EHCI generic platform driver
[    0.954168] ehci-orion: EHCI orion driver
[    0.954446] ehci-exynos: EHCI EXYNOS driver
[    0.954747] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.954902] ohci-pci: OHCI PCI platform driver
[    0.955154] ohci-platform: OHCI generic platform driver
[    0.955480] ohci-exynos: OHCI EXYNOS driver
[    0.957355] usbcore: registered new interface driver usb-storage
[    0.964041] rtc-pl031 9010000.pl031: registered as rtc0
[    0.966051] i2c /dev entries driver
[    0.973395] sdhci: Secure Digital Host Controller Interface driver
[    0.973635] sdhci: Copyright(c) Pierre Ossman
[    0.974511] Synopsys Designware Multimedia Card Interface Driver
[    0.976132] sdhci-pltfm: SDHCI platform and OF driver helper
[    0.978894] ledtrig-cpu: registered to indicate activity on CPUs
[    0.981647] usbcore: registered new interface driver usbhid
[    0.981776] usbhid: USB HID core driver
[    0.988908] NET: Registered protocol family 17
[    0.990112] 9pnet: Installing 9P2000 support
[    0.990504] Key type dns_resolver registered
[    0.993181] registered taskstats version 1
[    0.993295] Loading compiled-in X.509 certificates
[    1.003399] input: gpio-keys as /devices/platform/gpio-keys/input/input0
[    1.005858] rtc-pl031 9010000.pl031: setting system clock to 2022-02-12 07:32:58 UTC (1644651178)
[    1.008462] ALSA device list:
[    1.008570]   No soundcards found.
[    1.010677] uart-pl011 9000000.pl011: no DMA platform data
[    1.212933] Freeing unused kernel memory: 1344K
[    1.215851] Run /sbin/init as init process

Please press Enter to activate this console. 
/ # 

3)配置设备树信息

计算Image.gz的大小:

printf "0x%x\n" $(stat -c %s Image.gz)

计算rootfs.img.gz的大小:

printf "0x%x\n" $(stat -c %s rootfs.img.gz)

修改设备树:
# 告诉 u-boot 设备树的加载位置
fdt addr $dtb_addr_r

# 调整FDT的大小以防万一
fdt resize

# 根据$xen_bootargs设置Xen参数
fdt set /chosen xen,xen-bootargs \"$xen_bootargs\"

#setenv bootargs $xen_bootargs # 在Xen不稳定时,xen cmdline在bootargs中

# 根据$dom0_bootargs设置Dom0参数
fdt set /chosen xen,dom0-bootargs \"$dom0_bootargs\"

# 创建模块节点
fdt mknode /chosen modules
fdt set /chosen/modules '#address-cells' <1&g

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值