csc 256/456: operating systems qemu and the · revision control tools ... permits you to revert to...

26
CSC 256/456: Operating Systems QEMU and the Linux Kernel John Criswell University of Rochester 1

Upload: others

Post on 10-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

CSC 256/456: Operating Systems

QEMU and the Linux Kernel

John Criswell!University of Rochester

1

Page 2: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Outline❖ Useful tools!

❖ Compiling the Linux Kernel!

❖ QEMU!

❖ Linux Kernel Details

2

Page 3: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Useful Tools

3

Page 4: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

screen❖ Virtual console!

❖ Allows you to leave a session running after logout!

❖ screen : Starts a new screen!

❖ screen -ls : Lists active screens!

❖ screen -d -r : Re-connects to existing default screen!

❖ screen -d -r <screen_name> : Re-connects to existing screen

4

Page 5: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

cscope❖ Source code browser!

❖ cscope -R in top-level source code directory!

❖ Available at http://cscope.sourceforge.net!

❖ Allows you to find:!

❖ C structures by name!

❖ Functions!

❖ Functions called by/calling other functions!

❖ Doesn’t handle indirect function calls

5

Page 6: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Revision Control Tools❖ Tracks change that you make!

❖ Permits you to revert to previous version!

❖ Helps merge changes made by multiple developers!

❖ Well-known tools!

❖ git!

❖ Subversion (svn)

6

Page 7: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Linux Kernel

7

Page 8: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Unpacking the Linux Kernel❖ xzcat linux-2.6.32.63.tar.xz | tar -xvf -

8

Page 9: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Kernel Compile Overview❖ make mrproper!

❖ make menuconfig!

❖ make

9

Page 10: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Configuring the Linux Kernel❖ make mrproper: Required step!

❖ make menuconfig : Configures the Linux kernel!

❖ Load alternative configuration file csc256.config!

❖ Exit and save the new configuration

10

Page 11: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Compiling the Linux Kernel❖ make!

❖ Compiles the Linux kernel!

❖ Use the -j option to compile files in parallel!

❖ Kernel located in arch/x86_64/boot/bzImage!

❖ Initial compile may take up to 2 hours!

❖ Subsequent compiles should be much shorter (~2 mins)!

❖ Writing header files will increase compile time

11

Page 12: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

QEMU

12

Page 13: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

About QEMU❖ A processor emulator!

❖ Emulates code for target CPU on host CPU

Host System

Guest System

13

Page 14: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Other Potential VMs❖ Emulators (i.e., slow but useful for debugging)!

❖ Bochs!

❖ Fast solutions!

❖ KVM (part of Linux)!

❖ VMWare!

❖ VirtualBox!

❖ Hyper-V (Windows)

14

Page 15: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Why QEMU?❖ Allow you to change the kernel!

❖ Privileged operation!

❖ Isolate kernel changes from the real machine!

❖ Make programming and debugging easier

15

Page 16: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Contents QEMU Package❖ QEMU: QEMU executables and related files!

❖ openwrt-x86-generic-combined-ext2.img: File containing hard disk image of OpenWRT Linux distribution

16

Page 17: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Quick Start❖ Get the files you need at!

❖ http://www.cs.rochester.edu/courses/256/fall2014/QDGL/index.html!

❖ Approximate space requirements!

❖ QEMU Image: 53 MB!

❖ Kernel source and object code: 4 GB!

❖ Everything: About 4 GB of disk space

17

Page 18: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Fire It Up!❖ Start QEMU and default Debian installation!

❖ cd install!

❖ ./bin/qemu-system-x86_64 -m 64M -L ./qemu/share/qemu/ -curses -hda openwrt-x86-generic-combined-ext2.img!

❖ No password!

❖ Use halt command to shutdown!

❖ Kill qemu from different window

18

Page 19: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Start Up a New Kernel❖ ./bin/qemu-system-x86_64 -m 64M -L ./qemu/share/

qemu/ -curses -hda openwrt-x86-generic-combined-ext2.img -kernel ~/bzImage -append "root=/dev/sda2 rootfstype=ext2”!

❖ When QEMU boots, use uname -a to check if you booted the correct kernel image

19

Page 20: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Getting Files on to the VM❖ Networking doesn’t work (sorry!)!

❖ No compiler, either (keeps image small)!

❖ Make files look like hard disks!

❖ Add -hdb <filename> to QEMU command line!

❖ Boot the kernel!

❖ dd if=/dev/sdb of=<FileName> bs=<FileSize> count=1

20

Page 21: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Mini Homework #1❖ Build the Linux kernel!

❖ Boot the QEMU image with the Linux kernel!

❖ Report output of the procedure!

❖ uname -a!

❖ recipe from boot scripts

21

Page 22: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

How to Train Your Linux Kernel

22

Page 23: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Adding a System Call❖ Implement a function for your new system call

#include <linux/kernel.h>!!asmlinkage long newsyscall (struct prinfo * p) {!! printk (“CSC256: Hi!\n”);!! return 0;!}

23

Page 24: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Adding a New System Call❖ Add the function pointer in arch/x86/kernel/syscall_table_32.S!

❖ .long newsyscall /* 181 */!

❖ Add the system call number in include/asm-x86/unistd_64.h!

❖ #define __NR_newsyscall 181!

❖ Replace getpmsg with your system call in ./arch/x86/include/asm/unistd_64.h!

#define __NR_newsyscall 181!

__SYSCALL(__NR_newsyscall, newsyscall)

24

Page 25: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Using Your New System Call❖ Run the following program within QEMU

25

#include <linux/unistd.h>!#include <sys/syscall.h>!!int main (int argc, char ** argv) {!! syscall (181, NULL);!! return 0;!}

Page 26: CSC 256/456: Operating Systems QEMU and the · Revision Control Tools ... Permits you to revert to previous version! Helps merge changes made by multiple developers! Well-known tools!

Credits❖ Previous semester project setup!

❖ Konstantinos Menychtas for previous QEMU setup!

❖ Hongzhou Zhao!

❖ Zhuan Chen!

❖ Li Lu!

❖ Slides!

❖ Li Lu

26