Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial and Demos on Linux Virtual Machine

Similar presentations


Presentation on theme: "Tutorial and Demos on Linux Virtual Machine"— Presentation transcript:

1 Tutorial and Demos on Linux Virtual Machine
CSC 4320/ Operating Systems Summer 2015

2 Outline How to install Virtual Machine(VM)?
How to install a Linux Operating using VM? Install Guest Addition for Linux. Demo: linux Kernel module

3 How to install Virtual Machine?(1)
Install a virtual machine, e.g. Virtual Box. Download Virtual Box from website . (Note:Please choose the right platform package for your host OS). Install Virtubal Box in your computer.

4 How to install Virtual Machine?(2)
Once the installation is done, you can find a similar GUI for Virtual Box as follows……

5 How to install Virtual Machine?(2)
Once the installation is done, you can find the GUI for Virtual Box.

6 How to install a Linux system using VM?(1)
Install Ubuntu System using Virtual Box Download the latest Ubuntu system from website Follow the tutorial to install Ubuntu. Note: Please install a new Ubuntu instead try Ubuntu. The installation takes about 20 minutes.

7 How to install a Linux system using VM?(2)
Once the installation is done, you can login in it and the system is as follows……

8

9 Install Guest Addition for Linux(1)
Goal: enable other strong features(e.g. folder sharing with host , screen enlarging). Steps: In menu bar, choose Devices -> Insert Guest addition CD Image. Click Yes when asked to start VBOXADDITIONS. Authenticate the installation. The installation opens a terminal and displays the procedure. Press Return when it is finished. Log out and then log in.

10 Install Guest Addition for Linux(2)
Share folders with host OS. Steps: Create a folder on Host computer. (e.g. shareName) Open Virtual Box and your Ubuntu System. In Menu Bar, select Devices-> Shared folder settings.

11 Install Guest Addition for Linux(3)
Click at right most of popped up window to add a folder. Machine Folders are permanent folders that will be shared until you remove them, while Transient Folders are temporary and will be removed when the virtual machine restarts or shuts down.

12 Install Guest Addition for Linux(4)
Select the folder path and choose Auto-mount and Make Permanent.

13 Install Guest Addition for Linux(5)
Click Ok to finish the settings.

14 Install Guest Addition for Linux(6)
Open a terminal Open the dash, type “terminal”, select Terminal from the appeared results. Type the following command sudo adduser $USER vboxsf Note: you have to add current user into group vboxsf by above command, otherwise you will be warned permission denied when access to the shared folder.

15 Install Guest Addition for Linux(7)

16 Install Guest Addition for Linux(8)
Shut down Ubuntu, then reboot Virtual Box and Ubuntu. Find the shared folder sf_shareName in /media.

17 Demo: Linux Kernel Modules
List all kernel modules loaded currently. $lsmod Module Size Used by Vboxsf ………… ………. …..

18 Demo: Linux Kernel Modules -----Part I (1)
Create a Kernel Module “simple”. (Page ) Create a program named simple.c (prints appropriate messages when the kernel module is loaded and unloaded). Create a Makefile for compiling the program.

19 simple.c #include <linux/init.h> #include <linux/module.h>
/* Macros for registering module entry and exit points. */ #include <linux/kernel.h> module_init( simple_init ); /* This cis called when the module is loaded. */ module_exit( simple_exit ); int simple_init(void) MODULE_LICENSE("GPL"); { MODULE_DESCRIPTION("Simple Module"); printk(KERN_INFO "Loading Module\n"); MODULE_AUTHOR("SGG"); return 0; } /* This function is called when the module is removed. */ void simple_exit(void) { printk(KERN_INFO "Removing Module\n");

20 Makefile Note: Makefile should be in the same directory as simple.c
obj-m += simple.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Note: Makefile should be in the same directory as simple.c

21 Demo: Linux Kernel Modules -----Part I (2)
Compile kernel module simple.c $make Note: if the compiling succeeds, several files are produced.

22 Demo: Linux Kernel Modules -----Part I (3)
Load Kernel Module $sudo insmod simple.ko Check out contents in kernel log buffer. $dmesg

23 Demo: Linux Kernel Modules -----Part I (4)
Remove Kernel Module $sudo rmmod simple Check out contents in kernel log buffer. $dmesg

24 Demo 1

25 Demo: Linux Kernel Modules -----Part II
Create a Kernel Module “simple-solution”.(Page ) Create a program named simple-solution.c. In the module entry point, create a linked list containing five struct birthday elements and traverse the linked list. The name of first struct birthday element should be your own name. In the module exit point, remove the elements from the linked list and return the free memory back to the kernel Create a Makefile for compiling the program.

26 simple-solution.c (incomplete version )
#include <linux/init.h> /* Create a linked list containing five struct birthday elements*/ #include <linux/module.h> #include <linux/kernel.h> #include <linux/list.h> /* Traverse the linked list */ #include <linux/slab.h> } struct birthday void simple_exit(void) { { int month; /* Remove the elements from the linked list and return the free memory back to the kernel */ int day; int year; char *name; struct list_head list; }; module_init( simple_init ); module_exit( simple_exit ); static LIST_HEAD(birthday_list); MODULE_LICENSE("GPL"); int simple_init(void) MODULE_DESCRIPTION("Kernel Data Structures"); MODULE_AUTHOR("SGG");

27 Makefile obj-m += simple-solution.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Note: Makefile should be in the same directory as simple_solution.c

28 Demo 2

29 Practice project1 to-do list
See Project 1 requirement from D2L. Download files from D2L and follow the steps. For Part II: Add codes in simple-solution.c based on the instruction in Project Part 2 (Page ) of textbook. Compile simple-solution.c and then try to load and remove kernel module. Use dmesg to check out the kernel log content right after loading and removing kernel module. Save the kernel log contents into screenshots.

30 What to submit? A complete version of simple-solution.c
Project report including required screenshots and source code of simple-solution.c (a sample is provided in D2L).


Download ppt "Tutorial and Demos on Linux Virtual Machine"

Similar presentations


Ads by Google