# QEMU 5.0.0 and QEMU 2.x.x
###### tags: `linux` `busybox` `QEMU` `kernel`
<style>
.blue {
color: blue;
}
.bgblue {
color: blue;
font-size: 24px;
font-weight: bold;
}
.red {
color: red;
font-size: 24px;
font-weight: bold;
}
h1 {text-align: center;}
</style>
Author: WhoAmI
Date: 20220805
E-mail: kccddb@gmail.com
Copyright: CC BY-NC-SA

---
<h1>運用 QEMU 學習 make Linux kernel 與 製作rootfs
</h1>

:::info
Ubuntu-16.04.7 server version (X86-64)
1. VM (QEMU) or Real Embedded System (e.g, Banana Pie, Raspberry Pi,...)
2. toolchain (gcc, make, lib...)
3. Linux kernel source
4. Busybox (build root file system)
:::
**kclai@ubuntu16:~$ cat /proc/version**
Linux version 4.4.0-186-generic (buildd@lcy01-amd64-002) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) ) #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020
kclai@ubuntu16:~$
or
**kclai@ubuntu16:~$ dmesg | grep version**
[ 0.000000] Linux version 4.4.0-186-generic (buildd@lcy01-amd64-002) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) ) #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 (Ubuntu 4.4.0-186.216-generic 4.4.228)
[ 0.000000] IOAPIC[0]: apic_id 1, version 32, address 0xfec00000, GSI 0-23
[ 0.439388] acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5
[ 0.553811] libata version 3.00 loaded.
[ 1.224805] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[ 1.228305] fuse init (API version 7.23)
[ 1.231219] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 249)
[ 1.234097] pci_hotplug: PCI Hot Plug PCI Core version: 0.5
[ 1.234652] pciehp: PCI Express Hot Plug Controller Driver version: 0.4
[ 1.243908] ata_piix 0000:00:01.1: version 2.13
[ 1.248291] PPP generic driver version 2.4.2
[ 1.354608] device-mapper: uevent: version 1.0.3
[ 1.358337] registered taskstats version 1
[ 1.565939] e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
[ 1.633099] AVX2 version of gcm_enc/dec engaged.
[ 2.084882] ahci 0000:00:0d.0: version 3.0
[ 9.937136] vboxguest: Successfully loaded version 5.0.18_Ubuntu (interface 0x00010004)
kclai@ubuntu16:~$
**Install OpenSSH**
sudo apt-get install openssh-server
sudo service ssh status
Modify sshd_config
sudo vim /etc/ssh/sshd_config
sudo service ssh restart
**Change** VM NIC setting, bridged mode, Promiscuous Mode>>> Allow All
You need understand:
**ip addr**
**ip route**
**ifconfig**
Check ip address and route.
You need to install the following packages
Ref. [Ubuntu packages](https://packages.ubuntu.com/search?keywords=ncurses+&searchon=names&suite=kinetic§ion=all)
:::info
sudo apt-get install make
sudo apt-get install gcc
sudo apt-get install pkg-config
sudo apt-get install libglib2.0-dev
sudo apt-get install libpixman-1-dev
sudo apt-get install flex
sudo apt-get install bison
sudo apt-get install libncurses-dev
:::
**kclai@ubuntu16:~$ gcc -v**
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)
kclai@ubuntu16:~$
:::info
**kclai@ubuntu16:~$ cat net.sh**
#/bin/sh
sudo ifconfig enp0s8 up
sudo ip addr add 192.168.1.31/24 dev enp0s8
sudo ip addr add 192.168.68.31/24 dev enp0s8
sudo service ssh restart
sudo service ssh status
sudo /etc/init.d/samba reload
:::
Windows: [MobaXterm](https://mobaxterm.mobatek.net/download.html) or putty
Find packages: http://packages.ubuntu.com/
e.g.,
ip : 192.168.1.31
**Samba**
https://www.configserverfirewall.com/ubuntu-linux/install-samba-ubuntu-server-16-04/
sudo smbpasswd -a yourname
Modify smb.conf, add [tmp] [share]
sudo /etc/init.d/samba reload
:::info
Try \\\\192.168.1.31\tmp
:::
<h1>QEMU-5.0.0</h1>
**避免您 進入 版本大海裏, 別用 太新的版本**
wget https://download.qemu.org/qemu-5.0.0.tar.xz
tar xvJf qemu-5.0.0.tar.xz
kclai@u1604-7:~/qemu$ cd qemu-5.0.0/
kclai@u1604-7:~/qemu/qemu-5.0.0$
./configure
make
**讓你的可愛電腦忙, 自己可以做做李鳳山師父平甩功也讓眼睛休息~**

**sudo make install**
kclai@u1604-7:~$ qemu-system-x86_64 -h
QEMU emulator version 5.0.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
usage: qemu-system-x86_64 [options] [disk_image]
'disk_image' is a raw hard disk image for IDE hard disk 0
Standard options:
-h or -help display this help and exit
-version display version information and exit
-machine [type=]name[,prop[=value][,...]]
selects emulated machine ('-machine help' for list)
property accel=accel1[:accel2[:...]] selects accelerator
supported
...
:::info
**Download pre-builded kernel images and root file system:**
[Testing/System Images](https://wiki.qemu.org/Testing/System_Images)
**Download** test image (arm eabi little endian)
kernel: vmlinuz-2.6.32-5-versatile
rootfs: initrd.img-2.6.32-5-versatile
:::
:::info
kernel:
wget https://people.debian.org/~aurel32/qemu/armel/vmlinuz-2.6.32-5-versatile --no-check-certificate
rootfs:
wget https://people.debian.org/~aurel32/qemu/armel/initrd.img-2.6.32-5-versatile --no-check-certificate
:::
:::info
Remark. [ttyAMA0](https://unix.stackexchange.com/questions/307390/what-is-the-difference-between-ttys0-ttyusb0-and-ttyama0-in-linux)
:::
**Test arm-versatile:**
:::info
qemu-system-arm -M versatileab -m 128M -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -nographic -append "root=/dev/ram rdinit=/bin/sh console=ttyAMA0"
:::
kclai@ubuntu16:/share$ qemu-system-arm -M versatileab -m 128M -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -nographic -append "root=/dev/ram rdinit=/bin/sh console=ttyAMA0"
---
**STEP 1:**
**Uncompressing Linux... done, booting the kernel.**
**STEP 2:**
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 2.6.32-5-versatile (Debian 2.6.32-48squeeze4) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 Wed Sep 25 00:01:55 UTC 2013
[ 0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00093177
[ 0.000000] CPU: VIVT data cache, VIVT instruction cache
[ 0.000000] Machine: ARM-Versatile AB
[ 0.000000] Memory policy: ECC disabled, Data cache writeback
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
[ 0.000000] Kernel command line: root=/dev/ram rdinit=/bin/sh console=ttyAMA0
[ 0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[ 0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[ 0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[ 0.000000] Memory: 128MB = 128MB total
[ 0.000000] Memory: 123504KB available (3056K code, 562K data, 112K init, 0K highmem)
[ 0.000000] SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] Hierarchical RCU implementation.
[ 0.000000] NR_IRQS:192
[ 0.000000] VIC @f1140000: id 0x00041190, vendor 0x41
[ 0.000000] Console: colour dummy device 80x30
[ 1.813614] Calibrating delay loop... 747.11 BogoMIPS (lpj=3735552)
[ 2.051431] Security Framework initialized
[ 2.053231] SELinux: Disabled at boot.
[ 2.053809] Mount-cache hash table entries: 512
[ 2.065284] Initializing cgroup subsys ns
[ 2.065635] Initializing cgroup subsys cpuacct
[ 2.065810] Initializing cgroup subsys devices
[ 2.065951] Initializing cgroup subsys freezer
[ 2.066034] Initializing cgroup subsys net_cls
[ 2.066747] CPU: Testing write buffer coherency: ok
[ 2.086796] devtmpfs: initialized
[ 2.096946] regulator: core version 0.5
[ 2.099461] NET: Registered protocol family 16
[ 2.110770] Serial: AMBA PL011 UART driver
[ 2.113625] dev:f1: ttyAMA0 at MMIO 0x101f1000 (irq = 12) is a AMBA/PL011
[ 2.141401] console [ttyAMA0] enabled
[ 2.144493] dev:f2: ttyAMA1 at MMIO 0x101f2000 (irq = 13) is a AMBA/PL011
[ 2.145098] dev:f3: ttyAMA2 at MMIO 0x101f3000 (irq = 14) is a AMBA/PL011
[ 2.147179] PCI core found (slot 11)
[ 2.155283] PCI: bus0: Fast back to back transfers disabled
[ 2.162341] PCI map irq: slot 0, pin 1, devslot 12, irq: 27
[ 2.175298] bio: create slab <bio-0> at 0
[ 2.184318] vgaarb: loaded
[ 2.199411] Switching to clocksource timer3
[ 2.232862] NET: Registered protocol family 2
[ 2.242136] IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 2.254027] TCP established hash table entries: 4096 (order: 3, 32768 bytes)
[ 2.260146] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[ 2.261996] TCP: Hash tables configured (established 4096 bind 4096)
[ 2.263547] TCP reno registered
[ 2.266267] NET: Registered protocol family 1
[ 2.275483] Unpacking initramfs...
[ 2.588522] Freeing initrd memory: 2440K
[ 2.594042] NetWinder Floating Point Emulator V0.97 (double precision)
[ 2.598288] audit: initializing netlink socket (disabled)
[ 2.609842] type=2000 audit(0.767:1): initialized
[ 2.640479] VFS: Disk quotas dquot_6.5.2
[ 2.646891] Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[ 2.652245] msgmni has been set to 246
[ 2.667593] alg: No test for stdrng (krng)
[ 2.675890] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
[ 2.682446] io scheduler noop registered
[ 2.683754] io scheduler anticipatory registered
[ 2.684762] io scheduler deadline registered
[ 2.686219] io scheduler cfq registered (default)
[ 2.692150] CLCD: Versatile hardware, VGA display
[ 2.742031] Console: switching to colour frame buffer device 80x30
[ 2.780587] mice: PS/2 mouse device common for all mice
[ 2.794159] rtc-pl031 dev:e8: rtc core: registered pl031 as rtc0
[ 2.804724] TCP cubic registered
[ 2.806325] NET: Registered protocol family 17
[ 2.807951] VFP support v0.3: implementor 41 architecture 1 part 10 variant 9 rev 0
[ 2.811938] registered taskstats version 1
[ 2.816685] rtc-pl031 dev:e8: setting system clock to 2022-09-29 07:40:17 UTC (1664437217)
[ 2.821089] Initalizing network drop monitor service
[ 2.823598] Freeing init memory: 112K
[ 2.894295] input: AT Raw Set 2 keyboard as /devices/fpga:06/serio0/input/input0
**STEP 3:**
BusyBox v1.17.1 (Debian 1:1.17.1-8) built-in shell (ash)
Enter 'help' for a list of built-in commands.
/bin/sh: can't access tty; job control turned off

---
**Install Xfce Desktop Environment if you need it.**
:::info
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xfce4
sudo startx
:::
[QEMU documentation](https://www.qemu.org/docs/master/)
:::info
**TEST init 用 /bin/sh**
qemu-system-arm -M versatilepb -m 128M -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -nographic -append “root=/dev/ram init=/bin/sh console=ttyAMA0”
:::
---
**Futher Reading:**
[QEMU linux kernel and rootfs x86 version (busybox-1.22.0 and linux-4.4.50)](https://hackmd.io/@pingulinux/QEMUlinuxkernelrootfs)
**QEMU 2.x.x 會比較容易使用**
[qemu的两种安装方式](https://blog.csdn.net/M82_A1/article/details/91346784)
FreeDos
****
https://how-to.fandom.com/wiki/How_to_install_FreeDOS_in_QEMU