Difference between revisions of "Operating Systems 2017F Lecture 16"

From Soma-notes
Jump to navigation Jump to search
(Created page with "In Class")
 
Line 1: Line 1:
In Class
In Class
Comp 3000
Lecture 16
Important notes: Tutorial 5:
File system :
 persistent data structure organized around blocks (which are fixed allocation units)
 maps hierarchal names (keys) to values
 provides a file-like API like open,  read, write, close,etc
What does it mean to “make” a file system?
 Initializing a data structure.
 “formatting” a disk
Physical vs Logical : logical size of a file: the size your program see when accessing the file (bytes in a file)
Physical : How much space it takes up on disk , in terms of blocks , fixed units of storage allocation
Physical :
 By default or for multiple of files it is 1K blocks
 Example : Ext4 has 4k blocks
Kernel Programing :
 Warning:
o If you use linux base , you may crash your whole system, just backup before you do so using “rsync”.
Open Stack : log in through the terminal using your instance’s Ip address , but it failed to work . when you ssh to it you must write ssh “Address” –l Ubuntu
 You are required to use sude to add a user name, so u can play around in root.
What is a Kernel module ?
 A way of splitting up kernel functionality so everything does not have to load at boot.
 Modifies a kernel functionality
 Runs in kernel space , is the key thing to think about
o It is more powerful than root and it can do anything
o Access to all kernel memory
o And you can modify everything
 If you miss anything in the kernel development your system will crash
 Kernel machine provides you with a floppy by default which explains why it still exists in Anil’s terminal
 Once you install a module , the module is unstrained
Why do we use modules? Why don’t we load processes instead?
 No new mechanisms
 Increased security (restricted access)
 Makes the kernel less smaller, microkernel design,
o Putting in the functions that are supposed to be in the kernel into processes
o Process do IPC rather than code talking in supervisor mode
 Examples :
• Filesystems
• Drivers
• Networking
• Minix, QNX, GNU, hurd,
 Why is Linux  “monolithics” kernel ?
o Switching between contexts are expensive (context switch)
o How to make microkernels fast can be adopted by monolithics kernels to make them even faster
o Unreal security benefits :
 if you control the file system process, you can control everything
Rebuilding and changing the kernel:
 1)Type “make” : more compilacted than 2401
o Kernel built
 2)Make modules
 3)Sudo make install
 4) sudo make-modules install
 5) Sudo shutdown –r now : for the vm to reboot
 Which configuration would you use to build your own kernel ?
o Don’t do configurations from scratch
o Copy the configurations and use them
o Make localmodconfig : output for ls mod and uses that for configuring your kernel
o Requires time and effort
 Why less /dev/ones doesn’t exist anymore?
o Since reboot occurred
o You must load the modules again
o Head –c 100 /dev/ones to be able to use it again
 Implementing the device file of dev 1 ?
o Implement the file API required
o Teach the kernel what it means to do operations like read, etc
Code from the tutorial ones.c:
 Open ones_read code: file descriptor, file , buffer, amount of bytes to read and offset
o Offset : position in the file
o Fills the buffer with ones
o Why don’t we just set it to 1 instead of putting put_user?
 Char *buf : Pointer for a user space process, in order for the kernel to write to user spacer safely
o Line 46: Why use printk and not printf? Since printf is not defined because the c library is not available in the kernel, how can you can c library when the c library depends on the kernel? Kernel is independent, does not depend on any libraries.
Commands:
Man ls : to see different ls commands
 Ls –las block
 Cat /dev/ones |less : it is like dev u random , but instead of generating random number, it instead generates infinite of number 1
 Ls –mod : displays all the moduls which are currently loaded on the virtual machine
 IBM ps/2 :  series of computers created to control PC, developed the interfaces to have a mouse and keyboard.
 Less readme : to check instructions of how to do a make
 Make menuconfig : options of kernel configurations
 Cat/pro
 Less .config : bad idea to go directly in it , use “make menuconfig “
 /boot : where the kernel got installed.
o Ls –lah : to see the size
 Less/ etc/modules
 Modul init: what function should be called when loaded and when it is unloaded
 Modul exit:
 Creating a device file : defining a file which has special semantics, define a struct and functions which should be called to explain each file operation, open , read, release(like closing but not really)
 What happens if you start running to the file ? permission are read only, not writing
o Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.

Revision as of 15:08, 7 November 2017

In Class Comp 3000 Lecture 16 Important notes: Tutorial 5: File system :  persistent data structure organized around blocks (which are fixed allocation units)  maps hierarchal names (keys) to values  provides a file-like API like open, read, write, close,etc What does it mean to “make” a file system?  Initializing a data structure.  “formatting” a disk Physical vs Logical : logical size of a file: the size your program see when accessing the file (bytes in a file) Physical : How much space it takes up on disk , in terms of blocks , fixed units of storage allocation

Physical :  By default or for multiple of files it is 1K blocks  Example : Ext4 has 4k blocks

Kernel Programing :  Warning: o If you use linux base , you may crash your whole system, just backup before you do so using “rsync”. Open Stack : log in through the terminal using your instance’s Ip address , but it failed to work . when you ssh to it you must write ssh “Address” –l Ubuntu  You are required to use sude to add a user name, so u can play around in root. What is a Kernel module ?  A way of splitting up kernel functionality so everything does not have to load at boot.  Modifies a kernel functionality  Runs in kernel space , is the key thing to think about o It is more powerful than root and it can do anything o Access to all kernel memory o And you can modify everything  If you miss anything in the kernel development your system will crash  Kernel machine provides you with a floppy by default which explains why it still exists in Anil’s terminal  Once you install a module , the module is unstrained Why do we use modules? Why don’t we load processes instead?  No new mechanisms  Increased security (restricted access)  Makes the kernel less smaller, microkernel design, o Putting in the functions that are supposed to be in the kernel into processes o Process do IPC rather than code talking in supervisor mode  Examples : • Filesystems • Drivers • Networking • Minix, QNX, GNU, hurd,  Why is Linux “monolithics” kernel ? o Switching between contexts are expensive (context switch) o How to make microkernels fast can be adopted by monolithics kernels to make them even faster o Unreal security benefits :  if you control the file system process, you can control everything




Rebuilding and changing the kernel:  1)Type “make” : more compilacted than 2401 o Kernel built  2)Make modules  3)Sudo make install  4) sudo make-modules install  5) Sudo shutdown –r now : for the vm to reboot  Which configuration would you use to build your own kernel ? o Don’t do configurations from scratch o Copy the configurations and use them o Make localmodconfig : output for ls mod and uses that for configuring your kernel o Requires time and effort  Why less /dev/ones doesn’t exist anymore? o Since reboot occurred o You must load the modules again o Head –c 100 /dev/ones to be able to use it again  Implementing the device file of dev 1 ?

o Implement the file API required o Teach the kernel what it means to do operations like read, etc Code from the tutorial ones.c:  Open ones_read code: file descriptor, file , buffer, amount of bytes to read and offset o Offset : position in the file o Fills the buffer with ones o Why don’t we just set it to 1 instead of putting put_user?  Char *buf : Pointer for a user space process, in order for the kernel to write to user spacer safely o Line 46: Why use printk and not printf? Since printf is not defined because the c library is not available in the kernel, how can you can c library when the c library depends on the kernel? Kernel is independent, does not depend on any libraries.


Commands: Man ls : to see different ls commands  Ls –las block  Cat /dev/ones |less : it is like dev u random , but instead of generating random number, it instead generates infinite of number 1  Ls –mod : displays all the moduls which are currently loaded on the virtual machine  IBM ps/2 : series of computers created to control PC, developed the interfaces to have a mouse and keyboard.  Less readme : to check instructions of how to do a make  Make menuconfig : options of kernel configurations  Cat/pro  Less .config : bad idea to go directly in it , use “make menuconfig “  /boot : where the kernel got installed. o Ls –lah : to see the size  Less/ etc/modules  Modul init: what function should be called when loaded and when it is unloaded  Modul exit:  Creating a device file : defining a file which has special semantics, define a struct and functions which should be called to explain each file operation, open , read, release(like closing but not really)  What happens if you start running to the file ? permission are read only, not writing o Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.