LECTURE-9 More on Linux Operating System Linux Was Conceived
Total Page:16
File Type:pdf, Size:1020Kb
LECTURE-9 More on Linux Operating System Linux was conceived (tasarlamak) in April 1991, with the first announcement of the project given in August that year. A Finnish computer science student by the name Linus Torvalds. GNU is a Unix-like operating system. That means it is a collection of many programs: applications, libraries, developer tools, even games. The development of GNU, started in January 1984, is known as the GNU Project. Many of the programs in GNU are released under the auspices of the GNU Project; those we call GNU packages. The name “GNU” is a recursive acronym for “GNU's Not Unix.” “GNU” is pronounced g'noo, as one syllable, like saying “grew” but replacing the r with n. The program in a Unix-like system that allocates machine resources and talks to the hardware is called the “kernel”. GNU is typically used with a kernel called Linux. This combination is the GNU/Linux operating system. GNU/Linux is used by millions, though many call it “Linux” by mistake. GNU's own kernel, The Hurd, was started in 1990 (before Linux was started). Volunteers continue developing the Hurd because it is an interesting technical project. Linux is a kernel. – Not an operating system. – Typically run with “GNU” Operating System –So the correct name is actually “GNU/Linux” – But most folks just say “Linux.” GNU project – Started by Richard Stallman – Provides common “userspace” utilities: – ls, make, gcc, emacs 1 Richard Stallman Figure 9-1 represents a generalized high-level architecture of a GNU/Linux System. In reality, the kernel space is a much more complicated concept, containing many more components. Figure 9-1 A High-level GNU/Linux system architecture 2 The applications and system programs, as well as the GNU C library run on top of the kernel in the user-space. Applications refer to programs with a useful function, such as word processing, games, or C applications developed to run on the processor of a Zynq chip. GNU General Public licence is what is known as a copyleft licence. The basis for the project was the creation of an OS that was ‘free. Development Tools and Resources Virtual Machines Those lacking a machine running a Linux distribution but wishing to develop for Linux have the option of using a Virtual Machine (VM). This is a software implementation of an OS, emulated within the existing primary OS of a target machine provided it has enough processing power and memory. A developer wishing to use a VM for the sole purpose of developing applications for Linux may find one of the free options more than suitable for their needs. Someone wishing to deploy a Linux based VM in a business scenario, however, may be required to look at paid alternatives. Table 9-1 Comparison of VMs. 3 Version Control The collaborative nature of development for Linux necessitates the utilisation of some form of version control. 4 Centralised Version Control Systems (CVCSs) utilise a single server that hosts all versioned files. Every user can login to the server and check-out a local copy of the file for editing. When they are finished, they can commit any edits and the server maintains a record of who authored which version of which file and when. However, suppose the basic example of a case where regular full backups of the server have not been made and the hard disk is corrupted; the entire project is lost beyond repair. A Distributed Version Control System (DVCS) mitigates this. Instead of checking-out a single file, each user mirrors the entire repository on the server allowing for recovery of the entire repository should something go wrong. Git Git is one such DVCS, designed by Linus Torvalds for the initial purpose of managing Linux kernel development. It was released in 2005 as a free alternative to a previous, proprietary Version Control System (VCS) that ceased to provide free use. F Figure 9-2: Exemplary Git version history 5 Debugging Linux Code, at some iteration of its development, will likely contain bugs; this is a statement that holds true for all application development, and Linux is no exception In Linux, several tools are at our disposal to identify the nature and location of any bugs. The GNU debugger(gdb) is provided in the user-space in the form of a command line tool or GUI with the purpose of seeking out bugs in user-space programs, or for use in the kernel as the remote host Linux kernel debugger through gdb (kgdb) Table 9-2: Linux debugging tools. 6 There of course exists many other debugging tools available for getting to the root of a bug in a program, and the suggestions above are merely an introduction to the types of bug you may encounter and the debugging options available. The Linux Kernel A kernel is effectively the core of an operating system. It is the part of the operating system that is first to load on boot, and therefore resides in main memory. 7 Figure 9-3: Important components of the Linux kernel System Call Interface A system call is an interaction between an application in the user space and the required service provided by the kernel. The SCI provides this link between the boundary of the user space and kernel space, where direct calls are not possible. Memory Management The truth is that there is a need for more memory than the finite amount available. Virtual memory can help with this problem, making it appear as though there is more memory available in the system than there actually is. 8 Virtual Memory Figure 9-4 represents a simplified visualisation of virtual memory. Two processes, Process A and Process B, each have their own virtual address space and page table. A page is simply a segment of memory, given a unique Page Frame Number (PFN). The page tables therefore contain mapping information allowing the processor to resolve virtual memory addresses into physical ones. Note that Process A has virtual PFN1 mapped to physical PFN3. Figure 9-4: Simplfied representation of virtual memory Process Management As with any other operating system, tasks to be carried out are performed by processes. Consider the fact that any program on an operating system is actually just some instructions, in the format of machine code, stored as an executable image; a process is therefore such a computer program in operation. 9 •As machine code instructions are executed by the system’s processor, processes change and as such are dynamic. •Linux is a multiprocessing OS, and each process has its own rights and responsibilities, meaning a crash of one process will not impact the other processes. •Processes use both a variety of system resources from the CPU for running instructions and physical memory for holding the process and any corresponding data. Linux File Systems Table 9-3: Some supported Linux file systems Linux Device Drivers A Linux device driver, as in any OS, can be considered as a ‘black box’ that provides a level of abstraction between the hardware devices in a system and the programs running in the OS. By utilizing device drivers, a standardized set of calls can be implemented across all programs which are independent of the specific device; these calls correspond to driver specific functions that carry out the required operations. The result is a modular approach allowing the ability to build drivers outside the kernel and add them in as required. 10 Linux Booting The first thing that happens when a Linux system is powered on, or reset, is that the processor will execute code in a predetermined location. For a desktop computer this location is stored in a section of flash memory on the motherboard, known as the Basic Input/Output System (BIOS). As modern day PCs offer such versatility in the range of boot devices, the first thing that the BIOS will do is determine which devices offer bootable options Once the boot device has been determined, the FSBL is loaded into RAM and executed by the processor. The FSBL is a very small section of code — — less than 512 bytes, or a single sector — and its sole purpose is to load the Second-Stage Bootloader (SSBL) into RAM. The SSBLis the stage in the boot process where a boot menu is presented; if you have used Linux before you may have noticed this. This menu presents a list of possible boot options that are available. When a boot option from the list is chosen, the bootloader will load the corresponding OS, which will then decompress and load itself into memory before initialising the kernel. There are other functions that are carried out by the bootloader before the kernel is launched, but we will get to that later. With the required kernel modules successfully launched, the final stage of the boot process is to invoke the first user-space function, init. This function initialises all high-level parts of the system. 11 Figure 9-5: Stages of the desktop Linux boot process 12 .