65
1 Virtualization, Compilation, Intro to Project 2 Sarah Diesburg 9/15/2010 COP4610 / CGS5765

Virtualization, Compilation, Intro to Project 2

  • Upload
    adonai

  • View
    53

  • Download
    0

Embed Size (px)

DESCRIPTION

Virtualization, Compilation, Intro to Project 2. Sarah Diesburg 9/15/2010 COP4610 / CGS5765. Kernel Coding. The next project requires modification of running kernel code! Fun but challenging…. A Choice to Make…. - PowerPoint PPT Presentation

Citation preview

Page 1: Virtualization, Compilation, Intro to Project 2

1

Virtualization, Compilation, Intro to Project 2

Sarah Diesburg9/15/2010COP4610 / CGS5765

Page 2: Virtualization, Compilation, Intro to Project 2

Kernel Coding

The next project requires modification of running kernel code! Fun but challenging….

2

Page 3: Virtualization, Compilation, Intro to Project 2

A Choice to Make…

You may either work in the lab (LOV 16) on bare machines or on your own system with a virtual machine

Project 2 will require a live demo Can go down to lab Can bring virtual machine on laptop to my office Can bring virtual machine on portable hard drive

to my office

3

Page 4: Virtualization, Compilation, Intro to Project 2

Virtualization

4

Page 5: Virtualization, Compilation, Intro to Project 2

Virtual Motivating Factor

Wouldn’t it be great if we could run a test OS in a protected environment inside of our already-installed OS?

5

Page 6: Virtualization, Compilation, Intro to Project 2

Virtualization Software

Runs operating systems in full emulated environment VMware VirtualBox Virtual PC Xen

6

Page 7: Virtualization, Compilation, Intro to Project 2

Virtualization Terminology Host OS – running on physical computer

Only one host OS may run at a time “Hosts” the other running operating systems

Guest OS – running in emulated environment Can run multiple guests at the same time Guest thinks it is running on actual hardware

Virtual machine – set of files that make up a guest OS

7

Page 8: Virtualization, Compilation, Intro to Project 2

Virtual Machine Files

8

Page 9: Virtualization, Compilation, Intro to Project 2

Virtual Machine Advantages Can distribute a pre-configured OS Create multiple snapshots

If something goes wrong, roll-back to a previously saved snapshot

Portable Run on any host OS Store on portable hard drive or laptop

9

Page 10: Virtualization, Compilation, Intro to Project 2

Virtual Machine Advantages Sandbox

Does not affect anything on host OS Networked

Can access over the network

10

Page 11: Virtualization, Compilation, Intro to Project 2

Class Virtualization Software VMware Workstation 6.5.4

Linux and Windows http://downloads.vmware.com/d/info/desktop_dow

nloads/vmware_workstation/6_5 VMware Fusion

Mac Academic license will be sent to class in

email

11

Page 12: Virtualization, Compilation, Intro to Project 2

Project Virtual Machine

May use class virtual machine to complete Project 2 http://www.cs.fsu.edu/~cop4610t/cop4610.tar.gz

12

Page 13: Virtualization, Compilation, Intro to Project 2

Open the Virtual Machine

Vmware interface: File->Open…->COP4610.vmx

Double-click on “COP4610.vmx”

13

Page 14: Virtualization, Compilation, Intro to Project 2

Opened Virtual Machine

14

Page 15: Virtualization, Compilation, Intro to Project 2

Virtual Memory Setting

You should set the amount of memory that is allocated to your guest OS Cannot be shared between host and guest

Edit Virtual Machine Settings -> Hardware -> Memory

Rule of thumb: Give your host at least 1GB-1.5GB, give guest the rest

15

Page 16: Virtualization, Compilation, Intro to Project 2

Adjust Virtual Memory

16

Page 17: Virtualization, Compilation, Intro to Project 2

Adjust Virtual Memory

17

Slide to blue triangle

Page 18: Virtualization, Compilation, Intro to Project 2

Start the Machine

Press green start arrow

18

Page 19: Virtualization, Compilation, Intro to Project 2

Using the Virtual Machine

To type or use the mouse inside the virtual machine Click inside the virtual machine window

To type or move the mouse back to the host machine Press CTRL+ALT

19

Page 20: Virtualization, Compilation, Intro to Project 2

Creating a Snapshot

Why would we want to create a snapshot?

20

Page 21: Virtualization, Compilation, Intro to Project 2

Create a Snapshot

21

Page 22: Virtualization, Compilation, Intro to Project 2

Create a Snapshot

Name it something that describes this moment in time

22

Page 23: Virtualization, Compilation, Intro to Project 2

Roll Back to a Snapshot

23

Page 24: Virtualization, Compilation, Intro to Project 2

Roll Back to a Snapshot

24

Page 25: Virtualization, Compilation, Intro to Project 2

Copy & Paste / File Transfer Copy & paste from host to guest

Will work in default kernel Will not work in kernel you build

Preferred method Use ssh / pretend it is a remote machine

25

Page 26: Virtualization, Compilation, Intro to Project 2

Project 2 Virtual Machine

Username: root Password: root

Username: user Password: user

You can and probably should change these

26

Page 27: Virtualization, Compilation, Intro to Project 2

Lab Machines

If you sent me your FSU card # and pin #, you now have access to the room

Use computers on right half of lab All but last row

Username/passwords os/os root/root Change these to show your computer is taken!

27

Page 28: Virtualization, Compilation, Intro to Project 2

Lab Machines

Must develop directly on bare machines Not enough memory to run virtual machine

environment! Debian 5.0 Stable

Same OS as virtual machines

28

Page 29: Virtualization, Compilation, Intro to Project 2

Booting

29

Page 30: Virtualization, Compilation, Intro to Project 2

Booting

30

Start with this kernel – never modify this

kernel!

Page 31: Virtualization, Compilation, Intro to Project 2

Booting

31

This kernel is only if you really get into

trouble…

Page 32: Virtualization, Compilation, Intro to Project 2

Debian Networking

I like to ssh into my virtual machine To figure out guest’s IP:

$>/sbin/ifconfig –a

To restart guest networking (if problem)

$>dhclient eth<num>

where num found using the ifconfig command

32

Page 33: Virtualization, Compilation, Intro to Project 2

Debian Networking

33

Page 34: Virtualization, Compilation, Intro to Project 2

Debian Networking

34

Page 35: Virtualization, Compilation, Intro to Project 2

Debian Packaging System

Search for a package name

$> apt-cache search SEARCH_STRING

Show the details of a package

$> apt-cache show PACKAGE_NAME

Download a specific package

$> apt-get install PACKAGE_NAME

35

Page 36: Virtualization, Compilation, Intro to Project 2

Debian Packaging System

36

Page 37: Virtualization, Compilation, Intro to Project 2

Debian Logging into X

Must use the “user” user Debian does not allow root X logins

37

Page 38: Virtualization, Compilation, Intro to Project 2

Debian Logging into X

38

Page 39: Virtualization, Compilation, Intro to Project 2

Disclaimer

But I want to use <X> distro or <X> virtualization software instead…. Ok, but…

I will not help you with configuration problems!

39

Page 40: Virtualization, Compilation, Intro to Project 2

Kernel Compilation

40

Page 41: Virtualization, Compilation, Intro to Project 2

Example of Kernel Compilation….

41

Page 42: Virtualization, Compilation, Intro to Project 2

Choosing a Kernel

The next project will involve kernel development We all need to be in the same boat…

The class version will be 2.6.32

42

Page 43: Virtualization, Compilation, Intro to Project 2

Kernel Repository

http://kernel.org – place to download latest and greatest Linux kernels!

Direct download link http://www.kernel.org/pub/linux/kernel/v2.6/linux-2

.6.32.tar.gz Traditional place for kernel is in /usr/src/

43

Page 44: Virtualization, Compilation, Intro to Project 2

Compiling the Kernel

Compiles based on configuration of .config file located in the kernel source directory

How can I correctly configure my kernel?1. Use the ‘make menuconfig’ command

2. Use the ‘make oldconfig’ command

3. Combination of the two

44

Page 45: Virtualization, Compilation, Intro to Project 2

‘make menuconfig’

Manually select and deselect drivers and options for your kernel * -- compiled directly into kernel M – compiled into a module (driver) that can be

dynamically added Can be tough to figure out what you need

and don’t need Command ‘lspci’ shows hardware on computer

45

Page 46: Virtualization, Compilation, Intro to Project 2

‘make menuconfig’

46

Page 47: Virtualization, Compilation, Intro to Project 2

‘lspci’

47

Page 48: Virtualization, Compilation, Intro to Project 2

General Linux Source Organization Memory Management Networking Layer Security Sound Processing

Architecture-specific Code

Disk Drivers Devices File Systems

48

Page 49: Virtualization, Compilation, Intro to Project 2

‘make oldconfig’

Build a new configuration file based on an old working configuration file!1. Find a working configuration file

Look in /boot for the current kernel’s config file

2. Copy (don’t move) the current kernel’s config file into the new kernel source and rename it to ‘.config’

3. Issue command ‘make oldconfig’ inside the new kernel source

4. Accept new default changes

49

Page 50: Virtualization, Compilation, Intro to Project 2

Combine the Methods

Can use ‘make oldconfig’ to get a working config file

Can use ‘make menuconfig’ to take some unneeded things out of the new kernel Saves time when compiling

50

Page 51: Virtualization, Compilation, Intro to Project 2

Config Example (Inside Source Dir)>$ cp /boot/config-2.6.26-2-686 .config

>$ make oldconfig

>$ make menuconfig

51

Page 52: Virtualization, Compilation, Intro to Project 2

Compiling the Kernel

Issue ‘make’ inside the source directory

$> make

Grab some coffee….

52

Page 53: Virtualization, Compilation, Intro to Project 2

Installing the Kernel

1. Install the modules (drivers) $> sudo make modules_install

2. Install the actual kernel $> sudo make install

What does ‘sudo’ do?

53

Page 54: Virtualization, Compilation, Intro to Project 2

Boot Driver Problem

Suppose you compiled the disk drivers and root file system drivers as modules Boot process loads the kernel image Kernel image does not contain disk drivers

54

Page 55: Virtualization, Compilation, Intro to Project 2

Boot Driver Solutions

Hard: Figure out all drivers needed to read the root file system and compile into kernel May take a few tries…

Easy: Create a root file system image file that will load the right modules for you initramfs

55

Page 56: Virtualization, Compilation, Intro to Project 2

initramfs

Create the initramfs image

$> cd /boot

$> sudo mkinitramfs –o /boot/initrd.img-2.6.32 2.6.32

56

Page 57: Virtualization, Compilation, Intro to Project 2

Configure the Boot Loader (Grub) Open up the boot loader configuration file

$> sudo <favorite_editor> /boot/grub/menu.lst

57

Page 58: Virtualization, Compilation, Intro to Project 2

Configure the Boot Loader (Grub) Add information about your new kernel

Hint: copy section pertaining to current kernel, substitute kernel numbers

title Debian GNU/Linux, kernel 2.6.32root (hd0,0)kernel /boot/vmlinuz-2.6.32 root=/dev/sda1 ro quietinitrd /boot/initrd.img-2.6.32

Save, quit, and reboot! (Default booting kernel is on top of the list)

58

Page 59: Virtualization, Compilation, Intro to Project 2

Uh oh….

If it doesn’t boot, go back into the original kernel Always important to have one working kernel!

Make sure you didn’t skip a step… You may have taken too much out of the

kernel… Start with bloated kernel, take things out one by

one Look to additional resources…

59

Page 60: Virtualization, Compilation, Intro to Project 2

Additional Resources

http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html

http://www.tuxradar.com/content/how-compile-linux-kernel

60

Page 61: Virtualization, Compilation, Intro to Project 2

Project 2

Investigate system calls Make a simple /proc kernel module

/proc from the other side!! Make an elevator Due October 18th

61

Page 62: Virtualization, Compilation, Intro to Project 2

System Calls

Write a program that uses exactly 5 system calls Not ANSI C calls, POSIX system calls…

How do we know how many system calls are actually being called…?

62

Page 63: Virtualization, Compilation, Intro to Project 2

strace

strace [-o output_file] [command [arg…]]

Traces your program and displays all the system calls being called.

>$ strace –o out.txt ./myprog

63

Page 64: Virtualization, Compilation, Intro to Project 2

Until Next Time

Finish project 1 Homework 4 assigned tomorrow Study hard for test next week (next Friday) Get your environment set up

VMware or lab machine Do part 1 of project 2 (system calls)

64

Page 65: Virtualization, Compilation, Intro to Project 2

Next Recitation

More on Project 2 Create a test module! How /proc works Kernel debugging techniques Elevator

65