ubuntu X86环境构建ARM虚拟机

Prerequisite: the aarch64 cross-compile chain which can download from Linaro.

 

1. Get the qemu source code

git clone git://git.qemu-project.org/qemu.git

2. Compile the qemu source code

    cd qemu/

    ./configure --target-list=aarch64-softmmu

    make 

 Then will get the binary 'qemu-system-aarch64' in the 'qemu/aarch64-softmmu/'

3. Compile the kernel

    git clone http://rnd-github.xxxx.com/kernel/xxx.git

    cd xxx/

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

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

    Then will get the kernel image 'Image' in the 'hulk/arch/arm64/boot/'.

4. Use the busybox

    1) Download the source code 

http://busybox.net/downloads/busybox-1.22.1.tar.bz2

    2)Decompression

    

tar jxvf busybox-1.22.1.tar.bz2

    3)Buid code

    cd busybox-1.22.1/

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

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

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

  Build BusyBox as a static binary (found in 'Busybox Settings --> Build Options')

    cd _install/

    mkdir proc sys dev etc etc/init.d

    cd ..

    create a new _install/etc/init.d/rcS with the following content

        #!/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

    2) Run QEMU with the busybox

    cd qemu/

    ./aarch64-softmmu/qemu-system-aarch64 \

        -machine virt -cpu cortex-a57 \

        -kernel /arch/arm64/boot/Image \

        -initrd /rootfs.img.gz \

        -append 'console=ttyAMA0 root=/dev/ram rdinit=/sbin/init' \

        -nographic

 

 5. Use the open-embedded rootfs

    Download the image from Linaro -- http://releases.linaro.org/latest/openembedded/aarch64/

    gunzip vexpress64-openembedded_minimal-armv8-gcc-4.8_20140417-63022.img.gz

    mv vexpress64-openembedded_minimal-armv8-gcc-4.8_20140417-63022.img fs.img
    cd qemu/

    ./aarch64-softmmu/qemu-system-aarch64 \

        -machine virt -cpu cortex-a57 \

        -kernel /arch/arm64/boot/Image \

        -drive if=none,file=/fs.img,id=fs \

        -device virtio-blk-device,drive=fs \

        -append 'console=ttyAMA0 root=/dev/vda2' \

        -nographic

6. Use the ubuntu rootfs

    1) Download the rootfs 

    Download the tar file from Ubuntu -- http://cdimage.ubuntu.com/ubuntu-core/releases/14.04/release/

    Download the script used to make image -- http://people.canonical.com/~apw/arm64/arm64-prepare-image

 

    2) kernel configuration

    CONFIG_DEVTMPFS_MOUNT=y (Device Drivers -> Generic Driver Options -> Automount devtmpfs at /dev, after the kernel mounted the rootfs)

    3) Run the qemu    

 ./arm64-prepare-image ubuntu-core-14.04-core-arm64.tar.gz 

    mv ubuntu-core-14.04-core-arm64.img fs.img

    cd qemu/

    ./aarch64-softmmu/qemu-system-aarch64 \

        -machine virt -cpu cortex-a57 \

        -kernel /arch/arm64/boot/Image \

        -drive if=none,file=/fs.img,id=fs \

        -device virtio-blk-device,drive=fs \

        -append 'console=ttyAMA0 root=/dev/vda' \

        -nographic

 

7. Use the virtio-net-device

    1) kernel configuration

    CONFIG_VIRTIO_NET=y (Device Drivers -> Network device support -> Virtio network driver)

 

    2) Run the qemu  

  ./aarch64-softmmu/qemu-system-aarch64 \

        -machine virt -cpu cortex-a57 \

        -kernel /arch/arm64/boot/Image \

        -drive if=none,file=/fs.img,id=fs \

        -device virtio-blk-device,drive=fs \

        -netdev user,id=net0 \

        -device virtio-net-device,netdev=net0 \

        -append 'console=ttyAMA0 root=/dev/vda2' \

        -nographic

 

    Then can use the 'scp' command to copy the file between host and guest.

 

8. Set up virtFS between host and guest OS

    1) install dependency libraries

    sudo apt-get install libcap-dev libattr1-dev

    2) rebuild the QEMU

    make distclean

    ./configure --target-list=aarch64-softmmu

    make 

    3) rebuild the kernel and enable the followint configuration

    CONFIG_NET_9P=y

    CONFIG_NET_9P_VIRTIO=y

    4) run the qemu

    ./aarch64-softmmu/qemu-system-aarch64 \

        -machine virt -cpu cortex-a57 \

        -kernel /arch/arm64/boot/Image \

        -initrd /rootfs.img.gz \

        -fsdev local,id=r,path=,security_model=none \

        -device virtio-9p-device,fsdev=r,mount_tag=r \

        -append 'console=ttyAMA0 root=/dev/ram rdinit=/sbin/init' \

        -nographic

      5) mount the FS

    after the virtual machine boot up, then run this command:

 

        mount -t 9p -o trans=virtio r /mnt

 

9. Use the OpenSuse rootfs

    1) Download the rootfs

    http://download.opensuse.org/ports/aarch64/distribution/13.1/appliances/openSUSE-13.1-ARM-JeOS-vexpress64.aarch64-1.12.1-Build35.2.raw.xz

 

    2) Run the qemu

    xz -d openSUSE-13.1-ARM-JeOS-vexpress64.aarch64-1.12.1-Build35.2.raw.xz

    mv openSUSE-13.1-ARM-JeOS-vexpress64.aarch64-1.12.1-Build35.2.raw fs.raw

    ./aarch64-softmmu/qemu-system-aarch64 \

        -machine virt -cpu cortex-a57 \

        -kernel /arch/arm64/boot/Image \

        -drive if=none,file=/fs.raw,id=fs \

        -device virtio-blk-device,drive=fs \

        -append 'console=ttyAMA0 root=/dev/vda2' \

        -nographic

 

10. Use the Fedora rootfs
     1) Download the rootfs
     http://dmarlin.fedorapeople.org/fedora-arm/aarch64/F21-20140407-foundation-v8.tar.xz

 

     2) Run the qemu
     xz -d F21-20140407-foundation-v8.tar.xz
     mv F21-20140407-foundation-v8.img fs.img
     ./aarch64-softmmu/qemu-system-aarch64 \
        -machine virt -cpu cortex-a57 \
        -kernel /arch/arm64/boot/Image \

        -drive if=none,file=/fs.img,id=fs \

        -device virtio-blk-device,drive=fs \
        -append 'console=ttyAMA0 root=/dev/vda4' \
        -nographic

 

11. Mount the rootfs from the NFS

1) config the NFS server

i. Install nfs server in ubuntu.

sudo apt-get install nfs-kernel-server

 

ii. Export the rootfs

Add the entry in exports file.

127.0.0.1(rw,sync,no_subtree_check,no_root_squash,insecure)

 

sudo exportfs –av

 

iii. Restart the NFS server

sudo service nfs-kernel-server restart

 

2) Run the qemu

./aarch64-softmmu/qemu-system-aarch64 \

-machine virt -cpu cortex-a57 \

-kernel /arch/arm64/boot/Image \

-netdev user,id=net0 \

-device virtio-net-device,netdev=net0 \

-append "console=ttyAMA0 root=/dev/nfs \

nfs_root=10.0.2.2: ip=10.0.2.15::10.0.2.1:255.255.255.0 init=/sbin/init" \

-nographic

 

12. Use the tap network device

1) install the tunctl

apt-get install uml-utilities

 

2) setup a tap device

run the runqemu-ifup script (need the root privilege).

./runqemu-ifup

 

3) Run the qemu (e.g. use the tap2)

sudo ./aarch64-softmmu/qemu-system-aarch64 \

-machine virt -cpu cortex-a57 \

-kernel /arch/arm64/boot/Image \

-netdev tap,ifname=tap2,id=net0,script=no,downscript=no \

-device virtio-net-device,netdev=net0 \

-append "console=ttyAMA0 root=/dev/nfs \

nfs_root=192.168.7.1: ip=192.168.7.6::192.168.7.5:255.255.255.0 init=/sbin/init" \

-nographic

 

4) set down the tap device

run the runqemu-ifdown script (need the root privilege, e.g. use the tap2).

./runqemu-ifdown tap2

 

 

Reference

[1] Busybox for ARM on QEMU -- http://balau82.wordpress.com/2010/03/27/busybox-for-arm-on-qemu/

[2] AArch64 OpenEmbedded -- http://releases.linaro.org/latest/openembedded/aarch64/

[3] Ubuntu FoundationModel Wiki -- https://wiki.ubuntu.com/ARM64/FoundationModel

[4] QEMU Networking -- http://wiki.qemu.org/Documentation/Networking

[5] QEMU 9psetup -- http://wiki.qemu.org/Documentation/9psetup

[6] Running Linux in QEMU’s aarch64 system emulation mode -- http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode

[7] Fedora QuickStart -- http://fedoraproject.org/wiki/Architectures/ARM/AArch64/QuickStart

[8] Linux NFS Root under QEMU ARM emulator -- http://balau82.wordpress.com/2010/04/27/linux-nfs-root-under-qemu-arm-emulator/

[9] The usage of virtio network device -- http://wenku.baidu.com/view/566a4fdf28ea81c758f578fc.html

你可能感兴趣的:(ubuntu X86环境构建ARM虚拟机)