当前位置: 首页 > 工具软件 > Xen > 使用案例 >

Xen On Qemu for arm64

壤驷俊逸
2023-12-01

首个用Xen同时启动dom0和domU的中文帖子——Xen On Qemu for arm64

我的第一份工作与虚拟化相关。为了学习Xen,我看过很多中文帖子,但几乎都无法复现。在一位大佬的指引下,我接触到了这篇博客:https://medium.com/@denisobrezkov/xen-on-arm-and-qemu-1654f24dea75(需要翻墙,复制的网页在文末)。经过不断的尝试和探索,成功把dom0和dom1运行在Xen之上。为了帮你们学习Xen以及绕过我踩过的坑,我写了这篇帖子。若复现遇到问题,欢迎联系我:fengpan0315@126.com。

操作系统:Ubuntu 20.04

下载安装Qemu for arm64

官方wiki: https://wiki.qemu.org/Hosts/Linux

官网下载qemu-3.1.0.tar.xz,解压:

tar xf qemu-3.1.0.tar.xz

先安装gcc, libglib2.0-dev, ibpixman-1-dev, make,再编译:

cd qemu-3.1.0
./configure --target-list=aarch64-softmmu
make -j4

使用qemu-system-aarch64查看版本,后面使用qemu必须使用这个文件夹下的这个命令:

./aarch64-softmmu/qemu-system-aarch64 -version

安装交叉编译工具

#sudo apt install gcc-aarch64-linux-gnu

下载Linux kernel、Busybox、Xen、u-boot

建立工作目录(export只对当前命令行窗口有效):

cd ~
export WORK_DIR=~/Projects/xenonarm
mkdir -pv $WORK_DIR
cd $WORK_DIR

下载太慢的话使用国内镜像,百度搜mirror就行:

wget -c https://busybox.net/downloads/busybox-1.30.1.tar.bz2
tar xf busybox-1.30.1.tar.bz2
wget -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.20.11.tar.xz
tar xf linux-4.20.11.tar.xz
wget -c https://downloads.xenproject.org/release/xen/4.12.0/xen-4.12.0.tar.gz
tar xf xen-4.12.0.tar.gz
wget -c ftp://ftp.denx.de/pub/u-boot/u-boot-2019.01.tar.bz2
tar xf u-boot-2019.01.tar.bz2

我编译busybox-1.30.1和1.31.1时,遇到了“undefined reference to `stime'”的问题,可参考:https://git.busybox.net/busybox/commit/?id=d3539be8f27b8cbfdfee460fe08299158f08bcd9。建议使用链接里的源码包,这样就不会遇到这个问题。Ubuntu 18.04编译busybox-1.30.1不会遇到这个问题。

编译Busybox

建立编译目录:

export BUILD_DIR=~/Projects/xenonarm/build
mkdir -pv $BUILD_DIR/busybox_arm64

生成.config,在其中增加CONFIG_STATIC=y:

cd $WORK_DIR/busybox-1.30.1
make 0=$BUILD_DIR/busybox_arm64/ ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- defconfig
vim .config

先装libncurses5-dev,编译再安装:

make -j2 0=$BUILD_DIR/busybox_arm64/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
make install 0=$BUILD_DIR/busybox_arm64/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

制作文件系统:

cd _install/
mkdir proc sys dev etc etc/init.d
cd ..
vim _install/etc/init.d/rcS

在rcS中增加以下代码:

#! /bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s

使其可执行:

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

制作镜像,压缩再复制:

cd _install
find . | cpio -o --format=newc > ../rootfs.img
cd ..
gzip -c rootfs.img > rootfs.img.gz
cp rootfs.img.gz $BUILD_DIR/busybox_arm64/

编译Linux kernel for dom0,运行kernel+busybox

需要安装bison, flex, libssl-dev:

cd $WORK_DIR/linux-4.20.11/
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig

修改.config:

CONFIG_XEN_DOM0=y
CONFIG_XEN=y

编译kernel,复制kernel镜像:

make -j4 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
cp ./arch/arm64/boot/Image.gz $BUILD_DIR/busybox_arm64/
cp ./arch/arm64/boot/Image $BUILD_DIR/busybox_arm64/

在Qemu上运行kernel+busybox:

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -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"

virt board的信息请参考: https://www.qemu.org/docs/master/system/arm/virt.html,也可以使用qemu-system-aarch64 -machine virt -help查看选项含义。

U-Boot

配置u-boot:

cd u-boot-2019.01
make CROSS_COMPILE=aarch64-linux-gnu- qemu_arm64_defconfig

在.config中增加代码:

CONFIG_ARCH_QEMU=y
CONFIG_TARGET_QEMU_ARM_64BIT=y

编译:

make CROSS_COMPILE=aarch64-linux-gnu- -j4

复制u-boot.bin:

cp u-boot.bin $BUILD_DIR/busybox_arm64/
cd $BUILD_DIR/busybox_arm64/

先启动u-boot:

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 512M -bios u-boot.bin -device loader,file=Image,addr=0x45000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

再启动kernel:

booti 0x45000000 - 0x40000000

0x45000000是kernel image的地址,0x40000000是qemu’s device tree blob的默认地址。

编译Xen

编译时若报错:“error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value”。修改xen/Rules.mk,去掉-Werror。

make dist-xen XEN_TARGET_ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

复制xen镜像:

cp xen/xen $BUILD_DIR/busybox_arm64/

在Qemu上运行Xen、kernel、busybox

生成device tree blob:

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -display none -machine dumpdtb=virt-gicv3.dtb

在Xen运行Linux dom0:

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image.gz,addr=0x47000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

修改device tree blob,在u-boot中写入如下命令,需要在/chosen/module@0 reg中替换你的Image.gz的大小(0x7cc783):

fdt addr 0x44000000
fdt resize

fdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>

fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x7cc783>
fdt set /chosen/module@0 bootargs "earlyprintk=serial,ttyAMA0 console=ttyAMA0,115200n8 earlycon=xenboot"

booti 0x49000000 - 0x44000000

Image.gz的大小可以这样计算:

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

上面可以启kernel,但是没加rootfs,所以kernel panic了。现在我们开始加入rootfs:

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image.gz,addr=0x47000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -device loader,file=rootfs.img.gz,addr=0x42000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

需要在/chosen/module@1 reg中替换你的rootfs.img.gz的大小(0x118b47),执行以下命令:

fdt addr 0x44000000
fdt resize

fdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>

fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x7cc783>
fdt set /chosen/module@0 bootargs "rw root=/dev/ram rdinit=/sbin/init earlyprintk=serial,ttyAMA0 console=hvc0 earlycon=xenboot"
fdt mknod /chosen module@1
fdt set /chosen/module@1 compatible "xen,linux-initrd" "xen,multiboot-module"
fdt set /chosen/module@1 reg <0x42000000 0x118b47>

booti 0x49000000 - 0x44000000

出现命令行后,使用如下命令uname,若出现Linux,则代表成功:

# uname
Linux

在Qemu-arm64上同时运行dom0 and dom1

编译linux for dom1:

cd $WORK_DIR
mkdir linux-for-domU
cp linux-4.20.11.tar.xz linux-for-domU/
cd linux-for-domU/
tar xf linux-4.20.11.tar.xz
cd linux-4.20.11
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-
CP ./arch/arm64/boot/Image $BUILD_DIR/busybox_arm64/ImageU

从设备树运行dm0 and dom1时,不要忘记计算kernel和rootfs的大小并在fdt中修改一下,以及确保不要overlap:

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image,addr=0x47000000 -device loader,file=ImageU,addr=0x53000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -device loader,file=rootfs.img.gz,addr=0x42000000 -device loader,file=rootfs.img.gz,addr=0x58000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

修改设备树:

setenv xen_bootargs 'dom0_mem=512M'

fdt addr 0x44000000
fdt resize 8192
fdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>
fdt set /chosen xen,xen-bootargs \"$xen_bootargs\"

fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x1241200>
fdt set /chosen/module@0 bootargs "rw root=/dev/ram rdinit=/sbin/init earlyprintk=serial,ttyAMA0 console=hvc0 earlycon=xenboot"
fdt mknod /chosen module@1
fdt set /chosen/module@1 compatible "xen,linux-initrd" "xen,multiboot-module"
fdt set /chosen/module@1 reg <0x42000000 0x118b47>

fdt mknod /chosen domU1
fdt set /chosen/domU1 compatible "xen,domain"
fdt set /chosen/domU1 \#address-cells <1>
fdt set /chosen/domU1 \#size-cells <1>
fdt set /chosen/domU1 \cpus <1>
fdt set /chosen/domU1 \memory <0 548576>
fdt set /chosen/domU1 vpl011

fdt mknod /chosen/domU1 module@0
fdt set /chosen/domU1/module@0 compatible "multiboot,kernel" "multiboot,module"
fdt set /chosen/domU1/module@0 reg <0x53000000 0x1241200>
fdt set /chosen/domU1/module@0 bootargs "rw root=/dev/ram rdinit=/sbin/init console=ttyAMA0"
fdt mknod /chosen/domU1 module@1
fdt set /chosen/domU1/module@1 compatible "multiboot,ramdisk" "multiboot,module"
fdt set /chosen/domU1/module@1 reg <0x58000000 0x118b47>

booti 0x49000000 - 0x44000000

我们增加了一个节点domU1,在这个节点中我们创建了a virtual console vpl011。按Ctrl+A三次即可切换dom0、dom、xen,使用dmesg查看现在处于哪个机器:

dmesg

或者在dom0中设置变量:

export DOM='dom0'

按三次Ctrl+A切换到dom1,设置变量:

export DOM='dom1'

切换后,使用:

echo $DOM

如果在dom0中输出dom0 ,在dom1中输出dom1 ,那么xen with dom0 and dom1就启动成功了。

-----------------------------------------------------------------链接原文-----------------------------------------------------------------------------

In this post I want to show you how to set up Xen for Arm with Qemu emulator. Mainly, we are going to follow this guide https://wiki.xenproject.org/wiki/Xen_ARM_with_Virtualization_Extensions/qemu-system-aarch64 with some notes and fixes. In order to accomplish this we need to take few steps:

  1. Download and install Qemu for arm64

  2. Choose Linux Dom0 and Linux DomU configurations

  3. Download and build arm64 toolchain

  4. Cross-compile Linux Dom0 image

  5. Cross-compile Linux DomU image

  6. Build Xen and Xen-tools

  7. Run Dom0 image and start DomU image from Dom0

Download and install Qemu for arm64

Firstly, we should get Qemu. If you don’t want to have the latest stable version you can install qemu from the repo (for Debian):

# apt install qemu-system-aarch64

The following text is for Linux version of Qemu. User documentation can be found here: https://qemu.weilnetz.de/doc/qemu-doc.html

The wiki-page for Linux is here: https://wiki.qemu.org/Hosts/Linux

In order to get the latest stable version we should download Qemu from the official site qemu.org. Now, we can unpack it:

tar -Jxf qemu-3.1.0.tar.xz

And build it:

cd qemu-3.1.0
./configure --target-list=aarch64-softmmu
make -j4

Now, we can check how it works:

./aarch64-softmmu/qemu-system-aarch64 -version

We should obtain the output specifying version of our built qemu.

Choose Linux Dom0 and Linux DomU configurations

We are going to use a set of Linux Vanilla Kernel and Busybox (and if needed ulibc) for both Dom0 and DomU machines. Their configuration will be different.

Download and build arm toolchain

The easiest way to install arm toolchain is to install it from your repo, on Debian do:

# apt install gcc-aarch64-linux-gnu

After that, you can cross-compile everything.

Cross-compile Linux Dom0 image

Let’s create our working directory:

cd ~
export WORK_DIR=~/Projects/xenonarm
mkdir -pv $WORK_DIR
cd $WORK_DIR

First of all, we should get our Buildbox and Linux images:

wget -c https://busybox.net/downloads/busybox-1.30.1.tar.bz2
tar xf busybox-1.30.1.tar.bz2wget -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.20.11.tar.xz
tar xf linux-4.20.11.tar.xzwget -c https://downloads.xenproject.org/release/xen/4.12.0/xen-4.12.0.tar.gz
tar xf xen-4.12.0.tar.gz

Building Busybox

Let’s create a folder for temporary files:

export BUILD_DIR=~/Projects/xenonarm/build
mkdir -pv $BUILD_DIR/busybox_arm64

and build busybox:

cd $WORK_DIR/busybox-1.30.1
make 0=$BUILD_DIR/busybox_arm64/ ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- defconfig
make 0=$BUILD_DIR/busybox_arm64/ ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- menuconfig

Don’t forget to save the created config, e.g. in new_config. Open created file new_config and add line CONFIG_STATIC=y in order to make Busybox be complied as a static library. Save the file and copy it to .config:

cp new_config .config

and make it:

make -j2 0=$BUILD_DIR/busybox_arm64/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
make install  0=$BUILD_DIR/busybox_arm64/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

At the moment we can create a root file system:

cd _install/
mkdir proc sys dev etc etc/init.d
cd ..
vim _install/etc/init.d/rcS

To the created file we should add:

#! /bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s

and make it executable:

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

Let’s create a rootfs image itself:

cd _install
find . | cpio -o --format=newc > ../rootfs.img
cd ..
gzip -c rootfs.img > rootfs.img.gz

Now, we can copy it to the distinct folder:

cp rootfs.img.gz $BUILD_DIR/busybox_arm64/

Building Linux kernel

Now, we can copy all needed files to another folder:

cd $WORK_DIR/linux-4.20.11/
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- defconfig

Now, we should add few lines to .config (though, they should be there by default):

CONFIG_XEN_DOM0=y
CONFIG_XEN=y

Now, we can build the kernel:

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

Let’s copy created files:

cp ./arch/arm64/boot/Image.gz $BUILD_DIR/busybox_arm64/

Running Busybox, Linux and Qemu

qemu-system-aarch64  -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -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"

U-Boot

Let’s download the U-Boot bootloader for embedded Linux.

wget -c ftp://ftp.denx.de/pub/u-boot/u-boot-2019.01.tar.bz2
tar xf u-boot-2019.01.tar.bz2

Now, we can configure it:

cd u-boot-2019.01
make CROSS_COMPILE=aarch64-linux-gnu- qemu_arm64_defconfig

Add the following lines to the u-boot .config file:

CONFIG_ARCH_QEMU=y
CONFIG_TARGET_QEMU_ARM_64BIT=y

And build the u-boot:

make CROSS_COMPILE=aarch64-linux-gnu- -j4

Let’s copy the binary:

cp u-boot.bin $BUILD_DIR/busybox_arm64/
cd $BUILD_DIR/busybox_arm64/

You should be able to run u-boot with Linux:

qemu-system-aarch64  -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 512M -bios u-boot.bin -device loader,file=Image,addr=0x45000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

and we can start Linux with this command:

bootm 0x45000000 - 0x40000000

where 0x45000000 is the address of our kernel image and 0x40000000 is the default address of the qemu’s device tree blob.

After execution of the command we should have the kernel booting and failing on trying to load a rootfs (since we haven’t provided it).

Building Xen

Let’s build Xen:

make dist-xen XEN_TARGET_ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

and copy the raw image:

cp xen/xen $BUILD_DIR/busybox_arm64/

Running everything on Qemu

Let’s generate a device tree blob:

qemu-system-aarch64  -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -display none -machine dumpdtb=virt-gicv3.dtb

now we can run xen with Linux as dom0:

qemu-system-aarch64  -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image.gz,addr=0x47000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

In order to start the dom0 we should modify a device tree blob by writing the following commands to u-boot (substitute the right value instead of 0x7F31CE in /chosen/module@0 which is a size of Image.gz):

fdt addr 0x44000000
fdt resizefdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x7F31CE>
fdt set /chosen/module@0 bootargs "earlyprintk=serial,ttyAMA0
console=ttyAMA0,115200n8 earlycon=xenboot"booti 0x49000000 - 0x44000000

The size of Image.gz, can be calculated this way:

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

This time you should see booting of xen and then booting of Linux kernel and its failure on the attempt of booting rootfs.

And now we can boot xen, Linux and Busybox on qemu:

qemu-system-aarch64  -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image.gz,addr=0x47000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -device loader,file=rootfs.img.gz,addr=0x42000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

and run in u-boot (substitute the right value instead of 0x121e65 in /chosen/module@1 which is a size of rootfs.img.gz):

fdt addr 0x44000000
fdt resizefdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x7F31CE>
fdt set /chosen/module@0 bootargs "rw root=/dev/ram rdinit=/sbin/init   earlyprintk=serial,ttyAMA0 console=hvc0 earlycon=xenboot"
fdt mknod /chosen module@1
fdt set /chosen/module@1 compatible "xen,linux-initrd" "xen,multiboot-module"
fdt set /chosen/module@1 reg <0x42000000 0x121e65>booti 0x49000000 - 0x44000000

After having an input promt, we can check that the system works:

# uname
Linux

If it works it works!

Running Dom0 and DomU simultaneously on Qemu-arm64

In order to run Dom0 and DomU from a device tree we should use a dom0less technology.

Let’s run Qemu. Note that due to some restrictions we should use uncompressed Linux images (don’t forget to measure their sizes and change them in fdt commands, make sure that your images don’t overlap in memory):

qemu-system-aarch64  -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 4096 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=Image,addr=0x47000000 -device loader,file=Image,addr=0x53000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -device loader,file=rootfs.img.gz,addr=0x42000000  -device loader,file=rootfs.img.gz,addr=0x58000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

Now, we should use the modified device tree:

setenv xen_bootargs 'dom0_mem=512M'fdt addr 0x44000000
fdt resize
fdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>
fdt set /chosen xen,xen-bootargs \"$xen_bootargs\"
fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x1281a00>
fdt set /chosen/module@0 bootargs "rw root=/dev/ram rdinit=/sbin/init   earlyprintk=serial,ttyAMA0 console=hvc0 earlycon=xenboot"
fdt mknod /chosen module@1
fdt set /chosen/module@1 compatible "xen,linux-initrd" "xen,multiboot-module"
fdt set /chosen/module@1 reg <0x42000000 0x121e65>fdt mknod /chosen domU1
fdt set /chosen/domU1 compatible "xen,domain"
fdt set /chosen/domU1 \#address-cells <1>
fdt set /chosen/domU1 \#size-cells <1>
fdt set /chosen/domU1 \cpus <1>
fdt set /chosen/domU1 \memory <0 548576>fdt set /chosen/domU1 vpl011
fdt mknod /chosen/domU1 module@0
fdt set /chosen/domU1/module@0 compatible "multiboot,kernel" "multiboot,module"
fdt set /chosen/domU1/module@0 reg <0x53000000 0x1281a00>
fdt set /chosen/domU1/module@0 bootargs "rw root=/dev/ram rdinit=/sbin/init console=ttyAMA0"fdt mknod /chosen/domU1 module@1
fdt set /chosen/domU1/module@1 compatible "multiboot,ramdisk" "multiboot,module"
fdt set /chosen/domU1/module@1 reg <0x58000000 0x121e65>booti 0x49000000 - 0x44000000

You can see that we added a node for domU. In this node we also asked xen to create a virtual console vpl011. Those machines are lying in different parts of memory and do not interfere.

In order to switch between your machines you can push Ctrl+A for three times. To check, whether dom0 and domU work you can run dmesg on both machines:

dmesg

or to export variables with the same name on different machines , for dom0:

export DOM='dom0'

switch to domU (push CTRL+A for three times to switch between dom0, domU and xen) and type:

export DOM='domU'

Now, you can switch between machines and check the variables:

echo $DOM

if the output for dom0 is dom0 and for domU is domU then xen with dom0 and domU is working.

 类似资料:

相关阅读

相关文章

相关问答