|
4 | 4 | Virtual Machine Setup
|
5 | 5 | =====================
|
6 | 6 |
|
7 |
| -Exercises are designed to run on a qemu based virtual machine. In |
8 |
| -order to run the virtual machine you will need following packages: |
| 7 | +Practice work is designed to run on a QEMU based virtual machine. Kernel code |
| 8 | +is developed and built on the host machine and then deployed and run on the |
| 9 | +virtual machine. |
9 | 10 |
|
10 |
| -* build-essential |
11 |
| -* qemu-system-x86 |
12 |
| -* qemu-system-arm |
13 |
| -* kvm |
14 |
| -* python3 |
| 11 | +In order to run and use the virtual machine the following packages are required |
| 12 | +on a Debian/Ubuntu system: |
15 | 13 |
|
16 |
| -The virtual machine setup uses prebuild Yocto images that it downloads |
17 |
| -from downloads.yocyoproject.org and a kernel image that it builds |
18 |
| -itself. The following images are supported: |
| 14 | +* ``build-essential`` |
| 15 | +* ``gcc-multilib`` |
| 16 | +* ``libncurses5-dev`` |
| 17 | +* ``qemu-system-x86`` |
| 18 | +* ``qemu-system-arm`` |
| 19 | +* ``kvm`` |
| 20 | +* ``python3`` |
| 21 | +* ``minicom`` |
19 | 22 |
|
20 |
| -* core-image-minimal-qemu |
21 |
| -* core-image-minimal-dev-qemu |
22 |
| -* core-image-sato-dev-qemu |
23 |
| -* core-image-sato-qemu |
24 |
| -* core-image-sato-sdk-qemu |
| 23 | +The virtual machine setup uses prebuild Yocto images that it downloads and a |
| 24 | +kernel image that it builds itself. The following images are supported: |
25 | 25 |
|
26 |
| -and can be selected from tools/labs/qemu/Makefile. |
| 26 | +* ``core-image-minimal-qemu`` |
| 27 | +* ``core-image-minimal-dev-qemu`` |
| 28 | +* ``core-image-sato-dev-qemu`` |
| 29 | +* ``core-image-sato-qemu`` |
| 30 | +* ``core-image-sato-sdk-qemu`` |
27 | 31 |
|
| 32 | +By default, ``core-image-minimal-qemu`` it used. This setting can be changed by |
| 33 | +updating the ``YOCTO_IMAGE`` variable in ``tools/labs/qemu/Makefile``. |
28 | 34 |
|
29 |
| -Starting the VM |
30 |
| ---------------- |
| 35 | +Starting the Virtual Machine |
| 36 | +---------------------------- |
31 | 37 |
|
32 |
| -The virtual machine scripts are available in tools/labs/qemeu and you |
33 |
| -can can start the virtual machine by using the **boot** make target in |
34 |
| -tools/labs: |
| 38 | +You start the virtual machine in the ``tools/labs/`` folder by running ``make |
| 39 | +boot``: |
35 | 40 |
|
36 | 41 | .. code-block:: shell
|
37 | 42 |
|
38 |
| - ~/src/linux/tools/labs$ make boot |
39 |
| - ARCH=x86 qemu/qemu.sh -kernel zImage.x86 -device virtio-serial \ |
40 |
| - -chardev pty,id=virtiocon0 -device virtconsole,chardev=virtiocon0 \ |
41 |
| - -net nic,model=virtio,vlan=0 -net tap,ifname=tap0,vlan=0,script=no,downscript=no\ |
42 |
| - -drive file=rootfs.img,if=virtio,format=raw --append "root=/dev/vda console=hvc0" \ |
43 |
| - --display none -s |
44 |
| - char device redirected to /dev/pts/19 (label virtiocon0) |
| 43 | + .../linux/tools/labs$ make boot |
45 | 44 |
|
| 45 | +The first run of the ``make boot`` command will compile the kernel image and it |
| 46 | +will take longer. Subsequent runs will only start the QEMU virtual machine, |
| 47 | +with verbose output provided: |
46 | 48 |
|
47 |
| -.. note:: To show the qemu console use "QEMU_DISPLAY=gtk make |
48 |
| - boot". This will show the VGA output and will also give |
49 |
| - access to the standard keyboard. |
| 49 | +.. code-block:: shell |
50 | 50 |
|
51 |
| -.. _vm_interaction_link: |
| 51 | + .../linux/tools/labs$ make boot |
| 52 | + mkdir /tmp/tmp.7rWv63E9Wf |
| 53 | + sudo mount -t ext4 -o loop core-image-minimal-qemux86.ext4 /tmp/tmp.7rWv63E9Wf |
| 54 | + sudo make -C /home/razvan/school/so2/linux.git modules_install INSTALL_MOD_PATH=/tmp/tmp.7rWv63E9Wf |
| 55 | + make: Entering directory '/home/razvan/school/so2/linux.git' |
| 56 | + INSTALL crypto/crypto_engine.ko |
| 57 | + INSTALL drivers/crypto/virtio/virtio_crypto.ko |
| 58 | + INSTALL drivers/net/netconsole.ko |
| 59 | + DEPMOD 4.19.0+ |
| 60 | + make: Leaving directory '/home/razvan/school/so2/linux.git' |
| 61 | + sudo umount /tmp/tmp.7rWv63E9Wf |
| 62 | + rmdir /tmp/tmp.7rWv63E9Wf |
| 63 | + sleep 1 && touch .modinst |
| 64 | + qemu/create_net.sh tap0 |
| 65 | +
|
| 66 | + dnsmasq: failed to create listening socket for 172.213.0.1: Address already in use |
| 67 | + qemu/create_net.sh tap1 |
| 68 | +
|
| 69 | + dnsmasq: failed to create listening socket for 127.0.0.1: Address already in use |
| 70 | + /home/razvan/school/so2/linux.git/tools/labs/templates/assignments/6-e100/nttcp -v -i & |
| 71 | + nttcp-l: nttcp, version 1.47 |
| 72 | + nttcp-l: running in inetd mode on port 5037 - ignoring options beside -v and -p |
| 73 | + bind: Address already in use |
| 74 | + nttcp-l: service-socket: bind:: Address already in use, errno=98 |
| 75 | + ARCH=x86 qemu/qemu.sh -kernel /home/razvan/school/so2/linux.git/arch/x86/boot/bzImage -device virtio-serial -chardev pty,id=virtiocon0 -device virtconsole,chardev=virtiocon0 -serial pipe:pipe1 -serial pipe:pipe2 -netdev tap,id=tap0,ifname=tap0,script=no,downscript=no -net nic,netdev=tap0,model=virtio -netdev tap,id=tap1,ifname=tap1,script=no,downscript=no -net nic,netdev=tap1,model=i82559er -drive file=core-image-minimal-qemux86.ext4,if=virtio,format=raw -drive file=disk1.img,if=virtio,format=raw -drive file=disk2.img,if=virtio,format=raw --append "root=/dev/vda loglevel=15 console=hvc0" --display none -s |
| 76 | + qemu-system-i386: -chardev pty,id=virtiocon0: char device redirected to /dev/pts/68 (label virtiocon0) |
| 77 | +
|
| 78 | +.. note:: To show the QEMU console use |
52 | 79 |
|
53 |
| -Connecting to the VM |
54 |
| --------------------- |
| 80 | +.. code-block:: shell |
55 | 81 |
|
56 |
| -Once the machine is booted you can connect to it on the serial port. A |
57 |
| -link named *serial.pts* is created to the right emulated serial port |
58 |
| -and you can use **minicom**, **picocom** to connect to the virtual |
59 |
| -machine from the host: |
| 82 | + .../linux/tools/labs$ QEMU_DISPLAY=gtk make boot |
60 | 83 |
|
61 |
| -.. code-block:: shell |
| 84 | + This will show the VGA output and will also give |
| 85 | + access to the standard keyboard. |
62 | 86 |
|
63 |
| - $ minicom -D serial.pts |
| 87 | +.. note:: The virtual machine setup scripts and configuration files are located |
| 88 | + in ``tools/labs/qemu/``. |
64 | 89 |
|
65 |
| - Poky (Yocto Project Reference Distro) 2.3 qemux86 /dev/hvc0 |
| 90 | +.. _vm_interaction_link: |
66 | 91 |
|
67 |
| - qemux86 login: root |
68 |
| - root@qemux86:~# |
| 92 | +Connecting to the Virtual Machine |
| 93 | +--------------------------------- |
69 | 94 |
|
70 |
| -Networking is also setup and you can use ssh to connect to the virtual |
71 |
| -machine after finding out the allocated IP address: |
| 95 | +Once the virtual machine is started you can connect to it on the serial port. A |
| 96 | +symbolic link named ``serial.pts`` is created to the emulated serial port |
| 97 | +device: |
72 | 98 |
|
73 | 99 | .. code-block:: shell
|
74 | 100 |
|
75 |
| - $ minicom -D serial.pts |
| 101 | + .../linux/tools/labs$ ls -l serial.pts |
| 102 | + lrwxrwxrwx 1 razvan razvan 11 Apr 1 08:03 serial.pts -> /dev/pts/68 |
| 103 | +
|
| 104 | +On the host you use the ``minicom`` command to connect to the virtual machine |
| 105 | +via the ``serial.pts`` link: |
76 | 106 |
|
| 107 | +.. code-block:: shell |
| 108 | +
|
| 109 | + .../linux/tools/labs$ minicom -D serial.pts |
| 110 | + [...] |
77 | 111 | Poky (Yocto Project Reference Distro) 2.3 qemux86 /dev/hvc0
|
78 | 112 |
|
79 | 113 | qemux86 login: root
|
80 |
| - root@qemux86:~# ifconfig |
81 |
| - eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56 |
82 |
| - inet addr:172.20.0.6 Bcast:172.20.0.255 Mask:255.255.255.0 |
83 |
| - UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 |
84 |
| - RX packets:41 errors:0 dropped:0 overruns:0 frame:0 |
85 |
| - TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 |
86 |
| - collisions:0 txqueuelen:1000 |
87 |
| - RX bytes:7578 (7.4 KiB) TX bytes:1296 (1.2 KiB) |
88 |
| -
|
89 |
| - lo Link encap:Local Loopback |
90 |
| - inet addr:127.0.0.1 Mask:255.0.0.0 |
91 |
| - inet6 addr: ::1%134535719/128 Scope:Host |
92 |
| - UP LOOPBACK RUNNING MTU:65536 Metric:1 |
93 |
| - RX packets:0 errors:0 dropped:0 overruns:0 frame:0 |
94 |
| - TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 |
95 |
| - collisions:0 txqueuelen:1000 |
96 |
| - RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) |
97 |
| -
|
98 |
| - $ ssh root@172.20.0.6 |
99 |
| - The authenticity of host '172.20.0.6 (172.20.0.6)' can't be established. |
100 |
| - RSA key fingerprint is SHA256:CW1opJUHi4LDt1lnKjBVv12kXZ4s+8rreMBm5Jsdm00. |
101 |
| - Are you sure you want to continue connecting (yes/no)? yes |
102 |
| - Warning: Permanently added '172.20.0.6' (RSA) to the list of known hosts. |
103 | 114 | root@qemux86:~#
|
104 | 115 |
|
105 |
| -.. attention:: The Yocto core-image-minimal-qemu does not include an |
106 |
| - SSH server, so you will not able to connect via ssh if |
107 |
| - you are using this image. |
108 |
| -
|
109 |
| -
|
110 |
| -Connecting a debugger to the VM kernel |
111 |
| --------------------------------------- |
112 |
| -
|
113 |
| -You can connect gdb to the running VM kernel and inspect the state of |
114 |
| -the kernel by running the *gdb* target from tools/labs: |
115 |
| -
|
116 |
| -.. code-block :: shell |
117 |
| -
|
118 |
| - $ make gdb |
119 |
| - ln -fs /home/tavi/src/linux/vmlinux vmlinux |
120 |
| - gdb -ex "target remote localhost:1234" vmlinux |
121 |
| - GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1 |
122 |
| - Copyright (C) 2016 Free Software Foundation, Inc. |
123 |
| - License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> |
124 |
| - This is free software: you are free to change and redistribute it. |
125 |
| - There is NO WARRANTY, to the extent permitted by law. Type "show copying" |
126 |
| - and "show warranty" for details. |
127 |
| - This GDB was configured as "x86_64-linux-gnu". |
128 |
| - Type "show configuration" for configuration details. |
129 |
| - For bug reporting instructions, please see: |
130 |
| - <http://www.gnu.org/software/gdb/bugs/>. |
131 |
| - Find the GDB manual and other documentation resources online at: |
132 |
| - <http://www.gnu.org/software/gdb/documentation/>. |
133 |
| - For help, type "help". |
134 |
| - Type "apropos word" to search for commands related to "word"... |
135 |
| - Reading symbols from vmlinux...done. |
136 |
| - Remote debugging using localhost:1234 |
137 |
| - 0xc13cf2f2 in native_safe_halt () at ./arch/x86/include/asm/irqflags.h:53 |
138 |
| - 53asm volatile("sti; hlt": : :"memory"); |
139 |
| - (gdb) bt |
140 |
| - #0 0xc13cf2f2 in native_safe_halt () at ./arch/x86/include/asm/irqflags.h:53 |
141 |
| - #1 arch_safe_halt () at ./arch/x86/include/asm/irqflags.h:95 |
142 |
| - #2 default_idle () at arch/x86/kernel/process.c:341 |
143 |
| - #3 0xc101f136 in arch_cpu_idle () at arch/x86/kernel/process.c:332 |
144 |
| - #4 0xc106a6dd in cpuidle_idle_call () at kernel/sched/idle.c:156 |
145 |
| - #5 do_idle () at kernel/sched/idle.c:245 |
146 |
| - #6 0xc106a8c5 in cpu_startup_entry (state=<optimized out>) |
147 |
| - at kernel/sched/idle.c:350 |
148 |
| - #7 0xc13cb14a in rest_init () at init/main.c:415 |
149 |
| - #8 0xc1507a7a in start_kernel () at init/main.c:679 |
150 |
| - #9 0xc10001da in startup_32_smp () at arch/x86/kernel/head_32.S:368 |
151 |
| - #10 0x00000000 in ?? () |
152 |
| - (gdb) |
153 |
| -
|
154 |
| -Rebuild the kernel image |
155 |
| ------------------------- |
156 |
| -
|
157 |
| -The kernel image is built the first time the VM is started. To rebuild |
158 |
| -the kernel remove the **zImage** file and run the zImage target (or |
159 |
| -start the VM again). |
160 |
| -
|
161 |
| -.. add info about how to update the image |
| 116 | +.. note:: When you connect to the virtual machine, simply enter ``root`` at the |
| 117 | + login prompt and you will get a root console, no password required. |
| 118 | +
|
| 119 | +.. note:: You exit ``minicom`` by pressing ``Ctrl+a`` and then ``x``. You will |
| 120 | + get a confirmation prompt and then you will exit ``minicom``. |
0 commit comments