Second222None / rootfs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rootfs

Quick Start on X86_64

  • Download linux-5.0 source code
  • Change to linux-5.0 directory
cp run_ubuntu_x86_64.sh ../
cp rootfs_ubuntu_x86_64.tar.xz
cp x86_64_ubuntu_defconfig ../arch/x86/configs/ubuntu_defconfig
cd ..
./run_ubuntu_x86_64.sh build_kernel
sudo ./run_ubuntu_x86_64.sh build_rootfs
sudo ./run_ubuntu_x86_64.sh run

username: root

password: 111111

build rootfs

  • Get the ubuntu-base-18.04-base-amd64.tar.gz
http://cdimage.ubuntu.com/ubuntu-base/releases/18.04.3/release/ubuntu-base-18.04-base-amd64.tar.gz
  • Unpack and Mount
sudo tar xvf ubuntu-base-18.04-base-amd64.tar.gz -C rootfs_ubuntu_x86_64
sudo ./mount.sh -m rootfs_ubuntu_x86_64/
  • Copy宿主机的/etc/resolve.conf文件
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 114.114.114.114
nameserver 8.8.8.8
  • Operation in rootfs
# apt update
# apt install systemd (init process)
# apt install vim
# apt install ifupdown/netplan
# apt install iputils-ping
# apt install pciutils
# atp install module-init-tools
  • set hostname, user, password
  • compress rootfs-ubuntu-x86-64
sudo tar cfv rootfs_ubuntu_x86_64.tar rootfs_ubuntu_x86_64

Access QEMU Monitor

telnet 127.0.0.1 4445

Use the libvirt NAT default Network

  • Create virtual tap device and add it to virbr0
sudo ip tuntap add dev mytap1 mode tap
sudo brctl addif virbr0 mytap1
sudo ip link set mytap1 up
  • Add the following QEMU command line arguments
-netdev tap,ifname=mytap1,id=myhostnet0,script=no \
-device virtio-net-pci,netdev=myhostnet0 \

Convert raw image to qcow2

qemu-img convert -f raw -O qcow2 rootfs_ubuntu_x86_64.ext4 rootfs_ubuntu_x86_64.qcow2

Tracing I/O Interactions

All primary exits from kvm to QEMU are via the return path of KVM_RUN ioctl. Fortunately for us QEMU already has built in instrumentation for tracing. We will leverage that to selectively trace the return path of KVM_RUN and record the exit reasons

There is a second class of KVM-QEMU interaction that go through the ioeventfs,irqfd mechanism which we will instrument later.

Compile QEMU with log trace backend

(qemu) trace-event virtio_notify on 
(qemu) trace-event virtio_queue_notify on 

Problems

Fixed the following problems:

  • During boot, Kernel is stuck with the information looks like so: Time out waiting for the device dev-ttyAMA0.device.

    • Solution: Change BindsTo=dev-%i.device to BindsTo=dev-%i in $rootfs_path/lib/systemd/system/serial-getty@.service
  • Problem: Kernel enter the bash command directly without login.

    • Solution: apt install systemd. Without systemd kernel runs /bin/sh and enter the bash command directly.
  • Share files between host and VM, enable the following build configuration options:

    CONFIG_NET_9P=y (defconfig)
    CONFIG_9P_FS=y  (defconfig)
    CONFIG_VIRTIO_PCI=y (defconfig)
    CONFIG_NET_9P_VIRTIO=y (defconfig)
    CONFIG_9P_FS_POSIX_ACL=y (add manually)
    CONFIG_NET_9P_DEBUG=y (Optional)
    
  • Connect to internet

    • Solution: apt install ifupdown/netplan

About


Languages

Language:Shell 100.0%