Virtualization Compilation Intro to Project 2 Sarah Diesburg
Virtualization, Compilation, Intro to Project 2 Sarah Diesburg 9/15/2010 COP 4610 / CGS 5765 1
Kernel Coding n The next project requires modification of running kernel code! q Fun but challenging…. 2
A Choice to Make… n n 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 q q q 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
Virtualization 4
Virtual Motivating Factor n Wouldn’t it be great if we could run a test OS in a protected environment inside of our already-installed OS? 5
Virtualization Software n Runs operating systems in full emulated environment q q VMware Virtual. Box Virtual PC Xen 6
Virtualization Terminology n Host OS – running on physical computer q q n Guest OS – running in emulated environment q q n Only one host OS may run at a time “Hosts” the other running operating systems 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
Virtual Machine Files 8
Virtual Machine Advantages n n Can distribute a pre-configured OS Create multiple snapshots q n If something goes wrong, roll-back to a previously saved snapshot Portable q q Run on any host OS Store on portable hard drive or laptop 9
Virtual Machine Advantages n Sandbox q n Does not affect anything on host OS Networked q Can access over the network 10
Class Virtualization Software n VMware Workstation 6. 5. 4 q q n VMware Fusion q n Linux and Windows http: //downloads. vmware. com/d/info/desktop_dow nloads/vmware_workstation/6_5 Mac Academic license will be sent to class in email 11
Project Virtual Machine n May use class virtual machine to complete Project 2 q http: //www. cs. fsu. edu/~cop 4610 t/cop 4610. tar. gz 12
Open the Virtual Machine n Vmware interface: q n File->Open…->COP 4610. vmx Double-click on “COP 4610. vmx” 13
Opened Virtual Machine 14
Virtual Memory Setting n You should set the amount of memory that is allocated to your guest OS q n n Cannot be shared between host and guest Edit Virtual Machine Settings -> Hardware -> Memory Rule of thumb: Give your host at least 1 GB 1. 5 GB, give guest the rest 15
Adjust Virtual Memory 16
Adjust Virtual Memory Slide to blue triangle 17
Start the Machine n Press green start arrow 18
Using the Virtual Machine n To type or use the mouse inside the virtual machine q n Click inside the virtual machine window To type or move the mouse back to the host machine q Press CTRL+ALT 19
Creating a Snapshot n Why would we want to create a snapshot? 20
Create a Snapshot 21
Create a Snapshot n Name it something that describes this moment in time 22
Roll Back to a Snapshot 23
Roll Back to a Snapshot 24
Copy & Paste / File Transfer n Copy & paste from host to guest q q n Will work in default kernel Will not work in kernel you build Preferred method q Use ssh / pretend it is a remote machine 25
Project 2 Virtual Machine n n Username: root Password: root n Username: user Password: user n You can and probably should change these n 26
Lab Machines n n If you sent me your FSU card # and pin #, you now have access to the room Use computers on right half of lab q n All but last row Username/passwords q q q os/os root/root Change these to show your computer is taken! 27
Lab Machines n Must develop directly on bare machines q n Not enough memory to run virtual machine environment! Debian 5. 0 Stable q Same OS as virtual machines 28
Booting 29
Booting Start with this kernel – never modify this kernel! 30
Booting This kernel is only if you really get into trouble… 31
Debian Networking I like to ssh into my virtual machine n To figure out guest’s IP: $>/sbin/ifconfig –a n To restart guest networking (if problem) $>dhclient eth<num> n where num found using the ifconfig command 32
Debian Networking 33
Debian Networking 34
Debian Packaging System Search for a package name $> apt-cache search SEARCH_STRING n Show the details of a package $> apt-cache show PACKAGE_NAME n Download a specific package $> apt-get install PACKAGE_NAME n 35
Debian Packaging System 36
Debian Logging into X n Must use the “user” user q Debian does not allow root X logins 37
Debian Logging into X 38
Disclaimer n But I want to use <X> distro or <X> virtualization software instead…. q n Ok, but… I will not help you with configuration problems! 39
Kernel Compilation 40
Example of Kernel Compilation…. 41
Choosing a Kernel n The next project will involve kernel development q n We all need to be in the same boat… The class version will be 2. 6. 32 42
Kernel Repository n n http: //kernel. org – place to download latest and greatest Linux kernels! Direct download link q n http: //www. kernel. org/pub/linux/kernel/v 2. 6/linux 2. 6. 32. tar. gz Traditional place for kernel is in /usr/src/ 43
Compiling the Kernel n n Compiles based on configuration of. config file located in the kernel source directory How can I correctly configure my kernel? 1. 2. 3. Use the ‘make menuconfig’ command Use the ‘make oldconfig’ command Combination of the two 44
‘make menuconfig’ n Manually select and deselect drivers and options for your kernel q q n * -- 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 q Command ‘lspci’ shows hardware on computer 45
‘make menuconfig’ 46
‘lspci’ 47
General Linux Source Organization n n Memory Management Networking Layer Security Sound Processing n n Architecture-specific Code Disk Drivers Devices File Systems 48
‘make oldconfig’ n Build a new configuration file based on an old working configuration file! Find a working configuration file 1. n 2. 3. 4. Look in /boot for the current kernel’s config file Copy (don’t move) the current kernel’s config file into the new kernel source and rename it to ‘. config’ Issue command ‘make oldconfig’ inside the new kernel source Accept new default changes 49
Combine the Methods n n Can use ‘make oldconfig’ to get a working config file Can use ‘make menuconfig’ to take some unneeded things out of the new kernel q Saves time when compiling 50
Config Example (Inside Source Dir) >$ cp /boot/config-2. 6. 26 -2 -686. config >$ make oldconfig >$ make menuconfig 51
Compiling the Kernel n Issue ‘make’ inside the source directory $> make n Grab some coffee…. 52
Installing the Kernel Install the modules (drivers) 1. q Install the actual kernel 2. q n $> sudo make modules_install $> sudo make install What does ‘sudo’ do? 53
Boot Driver Problem n Suppose you compiled the disk drivers and root file system drivers as modules q q Boot process loads the kernel image Kernel image does not contain disk drivers 54
Boot Driver Solutions n Hard: Figure out all drivers needed to read the root file system and compile into kernel q n May take a few tries… Easy: Create a root file system image file that will load the right modules for you q initramfs 55
initramfs n Create the initramfs image $> cd /boot $> sudo mkinitramfs –o /boot/initrd. img-2. 6. 32 56
Configure the Boot Loader (Grub) n Open up the boot loader configuration file $> sudo <favorite_editor> /boot/grub/menu. lst 57
Configure the Boot Loader (Grub) n Add information about your new kernel q Hint: copy section pertaining to current kernel, substitute kernel numbers title root kernel initrd n n Debian GNU/Linux, kernel 2. 6. 32 (hd 0, 0) /boot/vmlinuz-2. 6. 32 root=/dev/sda 1 ro quiet /boot/initrd. img-2. 6. 32 Save, quit, and reboot! (Default booting kernel is on top of the list) 58
Uh oh…. n If it doesn’t boot, go back into the original kernel q n n Make sure you didn’t skip a step… You may have taken too much out of the kernel… q n Always important to have one working kernel! Start with bloated kernel, take things out one by one Look to additional resources… 59
Additional Resources n n http: //www. cyberciti. biz/tips/compiling-linuxkernel-26. html http: //www. tuxradar. com/content/how-compile -linux-kernel 60
Project 2 n n Investigate system calls Make a simple /proc kernel module q n n /proc from the other side!! Make an elevator Due October 18 th 61
System Calls n Write a program that uses exactly 5 system calls q n Not ANSI C calls, POSIX system calls… How do we know how many system calls are actually being called…? 62
strace [-o output_file] [command [arg…]] n Traces your program and displays all the system calls being called. >$ strace –o out. txt. /myprog 63
Until Next Time n n Finish project 1 Homework 4 assigned tomorrow Study hard for test next week (next Friday) Get your environment set up q n VMware or lab machine Do part 1 of project 2 (system calls) 64
Next Recitation n More on Project 2 q q Create a test module! How /proc works Kernel debugging techniques Elevator 65
- Slides: 65