Skip to content

Commit d28b427

Browse files
committed
Refactor VM setup page
Signed-off-by: Sergiu Weisz <sergiu121@gmail.com>
1 parent 4fb5a85 commit d28b427

File tree

2 files changed

+210
-126
lines changed

2 files changed

+210
-126
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
=====================================
2+
Customizing the Virtual Machine Setup
3+
=====================================
4+
5+
Connect to the Virtual Machine via SSH
6+
--------------------------------------
7+
8+
The default Yocto image for the QEMU virtual machine
9+
(``core-image-minimal-qemu``) provides the minimal functionality to run the
10+
kernel and kernel modules. For extra features, such as an SSH connection,
11+
a more complete image is required, such as ``core-image-sato-dev-qemu``.
12+
13+
To use the new image, update the ``YOCTO_IMAGE`` variable in
14+
``tools/labs/qemu/Makefile``:
15+
16+
.. code-block::
17+
18+
YOCTO_IMAGE = core-image-sato-qemu$(ARCH).ext4
19+
20+
When you start the virtual machine the first time using ``make boot`` with the
21+
new image configuration, it will download the image and then boot the virtual
22+
machine. The image is larger (around 400MB) than the minimal image so expect
23+
some time for the download.
24+
25+
You then enter the virtual machine via ``minicom``, determine the IP address of
26+
the ``eth0`` interface an then you can connect to the virtual machine via SSH:
27+
28+
.. code-block:: shell
29+
30+
$ minicom -D serial.pts
31+
Poky (Yocto Project Reference Distro) 2.3 qemux86 /dev/hvc0
32+
33+
qemux86 login: root
34+
root@qemux86:~# ip a s
35+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
36+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
37+
inet 127.0.0.1/8 scope host lo
38+
valid_lft forever preferred_lft forever
39+
inet6 ::1/128 scope host
40+
valid_lft forever preferred_lft forever
41+
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
42+
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
43+
inet 172.213.0.18/24 brd 172.213.0.255 scope global eth0
44+
valid_lft forever preferred_lft forever
45+
inet6 fe80::5054:ff:fe12:3456/64 scope link
46+
valid_lft forever preferred_lft forever
47+
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
48+
link/sit 0.0.0.0 brd 0.0.0.0
49+
50+
$ ssh -l root 172.213.0.18
51+
The authenticity of host '172.213.0.18 (172.213.0.18)' can't be established.
52+
RSA key fingerprint is SHA256:JUWUcD7LdvURNcamoPePMhqEjFFtUNLAqO+TtzUiv5k.
53+
Are you sure you want to continue connecting (yes/no)? yes
54+
Warning: Permanently added '172.213.0.18' (RSA) to the list of known hosts.
55+
root@qemux86:~# uname -a
56+
Linux qemux86 4.19.0+ #3 SMP Sat Apr 4 22:45:18 EEST 2020 i686 GNU/Linux
57+
58+
Connecting a Debugger to the Virtual Machine Kernel
59+
---------------------------------------------------
60+
61+
You can use GDB to connect to the running virtual machine kernel and inspect
62+
the state of the kernel. You run ``make gdb`` in ``tools/labs/``:
63+
64+
.. code-block:: shell
65+
66+
.../linux/tools/labs$ make gdb
67+
ln -fs /home/tavi/src/linux/vmlinux vmlinux
68+
gdb -ex "target remote localhost:1234" vmlinux
69+
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
70+
Copyright (C) 2016 Free Software Foundation, Inc.
71+
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
72+
This is free software: you are free to change and redistribute it.
73+
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
74+
and "show warranty" for details.
75+
This GDB was configured as "x86_64-linux-gnu".
76+
Type "show configuration" for configuration details.
77+
For bug reporting instructions, please see:
78+
<http://www.gnu.org/software/gdb/bugs/>.
79+
Find the GDB manual and other documentation resources online at:
80+
<http://www.gnu.org/software/gdb/documentation/>.
81+
For help, type "help".
82+
Type "apropos word" to search for commands related to "word"...
83+
Reading symbols from vmlinux...done.
84+
Remote debugging using localhost:1234
85+
0xc13cf2f2 in native_safe_halt () at ./arch/x86/include/asm/irqflags.h:53
86+
53asm volatile("sti; hlt": : :"memory");
87+
(gdb) bt
88+
#0 0xc13cf2f2 in native_safe_halt () at ./arch/x86/include/asm/irqflags.h:53
89+
#1 arch_safe_halt () at ./arch/x86/include/asm/irqflags.h:95
90+
#2 default_idle () at arch/x86/kernel/process.c:341
91+
#3 0xc101f136 in arch_cpu_idle () at arch/x86/kernel/process.c:332
92+
#4 0xc106a6dd in cpuidle_idle_call () at kernel/sched/idle.c:156
93+
#5 do_idle () at kernel/sched/idle.c:245
94+
#6 0xc106a8c5 in cpu_startup_entry (state=<optimized out>)
95+
at kernel/sched/idle.c:350
96+
#7 0xc13cb14a in rest_init () at init/main.c:415
97+
#8 0xc1507a7a in start_kernel () at init/main.c:679
98+
#9 0xc10001da in startup_32_smp () at arch/x86/kernel/head_32.S:368
99+
#10 0x00000000 in ?? ()
100+
(gdb)
101+
102+
Rebuild the Kernel Image
103+
------------------------
104+
105+
The kernel image is built the first time the VM is started. To rebuild the
106+
kernel remove the kernel image file defined by the ``ZIMAGE`` variable in
107+
``tools/labs/qemu/Makefile``:
108+
109+
.. code-block::
110+
111+
ZIMAGE = $(KDIR)/arch/$(ARCH)/boot/$(b)zImage
112+
113+
Typically the full path of the kernel is ``arch/x86/boot/bzImage``.
114+
115+
Once removed the kernel image is rebuild by using:
116+
117+
.. code-block:: shell
118+
119+
~/src/linux/tools/labs$ make zImage
120+
121+
or simply starting the virtual machine
122+
123+
.. code-block:: shell
124+
125+
~/src/linux/tools/labs$ make boot

Documentation/teaching/info/vm.rst

Lines changed: 85 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -4,158 +4,117 @@
44
Virtual Machine Setup
55
=====================
66

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.
910

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:
1513

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``
1922

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:
2525

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``
2731

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``.
2834

29-
Starting the VM
30-
---------------
35+
Starting the Virtual Machine
36+
----------------------------
3137

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``:
3540

3641
.. code-block:: shell
3742
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
4544
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:
4648

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
5050
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
5279
53-
Connecting to the VM
54-
--------------------
80+
.. code-block:: shell
5581
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
6083
61-
.. code-block:: shell
84+
This will show the VGA output and will also give
85+
access to the standard keyboard.
6286
63-
$ minicom -D serial.pts
87+
.. note:: The virtual machine setup scripts and configuration files are located
88+
in ``tools/labs/qemu/``.
6489
65-
Poky (Yocto Project Reference Distro) 2.3 qemux86 /dev/hvc0
90+
.. _vm_interaction_link:
6691
67-
qemux86 login: root
68-
root@qemux86:~#
92+
Connecting to the Virtual Machine
93+
---------------------------------
6994
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:
7298
7399
.. code-block:: shell
74100
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:
76106
107+
.. code-block:: shell
108+
109+
.../linux/tools/labs$ minicom -D serial.pts
110+
[...]
77111
Poky (Yocto Project Reference Distro) 2.3 qemux86 /dev/hvc0
78112
79113
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.
103114
root@qemux86:~#
104115
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

Comments
 (0)