Linux Development 8.02.2016 Lecture 7. Schedule Linux Root Filesystem.

Slides:



Advertisements
Similar presentations
Basic Unix system administration
Advertisements

Linux Booting Procedure
Linux can be generally divided into four major components: 1. KERNEL – OS, ultimate boss The kernel is the core program that runs programs and manages.
Introduction to Unix (CA263) File System
Exploring the UNIX File System and File Security
Linux Intro Linux, the do it yourself OS Linux, successor to MINIX Linux, Unix for the masses (PC users) History:
GNU/Linux Filesystem 1 st AUT GNU/Linux Festival Computer Engineering & IT Department Bahador Bakhshi.
Linux Linux File System.
The UNIX File System.
Guide To UNIX Using Linux Third Edition
Linux-MVME Targets Using Motorola Board Support
DELTA TAU Data Systems, Inc. 1 UMAC TurboTurbo PMAC PCIGeo Drive Single Source Machine Control motion logic data Power PMAC as a Linux Computer January.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
File System and Directory Structure in Linux. What is File System In a computer, a file system is the way in which files are named and where they are.
Guide To UNIX Using Linux Fourth Edition
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux.
Introduction to Linux Installing Linux User accounts and management Linux’s file system.
Manage Directories and Files in Linux
Chapter 8. Disks and Filesystems. Ordinary Files u What is a file? –a container for ordered data –persistent (stays around) and accessible by name u Unix.
Operating Systems  A collection of programs that  Coordinates computer usage among users  Manages computer resources  Handle Common Tasks.
1 Project 3: An Introduction to File Systems CS3430 Operating Systems University of Northern Iowa.
Porting Operating Systems Phan Duy Hùng (PhD) ES Lecturer – Hanoi FPT University.
Chapter Two Exploring the UNIX File System and File Security.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Linux Administration. Pre-Install Different distributions –Redhat, Caldera, mandrake, SuSE, FreeBSD Redhat Server Install –Check HCL –Significant issues.
COMPUTER SYSTEM LABORATORY Lab6 - Root Filesystem.
Unit - VI. Linux and Real Time: Real Time Tasks Hard and Soft Real Time Tasks Linux Scheduling Latency Kernel Preemption Challenges in Kernel Preemption.
Linux Architecture Overview 1. Initialization Uboot – hardware init, loads kernel Kernel – remaining initialization, calls “init” Init – 1 st process,
UNIX (Linux) Introduction Module-1. OS Kernel In computing, the kernel is the central component of OS. It is a bridge between applications and the actual.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Manage Directories and Files in Linux. 2 Objectives Understand the Filesystem Hierarchy Standard (FHS) Identify File Types in the Linux System Change.
Chapter Two Exploring the UNIX File System and File Security.
Review Please hand in any homework and practicals Vim Scripting Inter-device communication.
System Administration – Part 2. Devices in UNIX are files: A device can be accessed with different file names All device files are stored in /dev or its.
Linux Commands C151 Multi-User Operating Systems.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop V Files and the File System Part B – File System.
Chapter 10: File-System Interface Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 File-System Interface.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
SUSE Linux Enterprise Desktop Administration Chapter 7 Manage Directories and Files.
Linux Architecture Overview.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Lab 8 Department of Computer Science and Information Engineering National Taiwan University Lab8 - Root Filesystem 2015/11/10/ 22 1.
Lab 5 Department of Computer Science and Information Engineering National Taiwan University Lab5 - OS Kernel 2014/10/21/ 16 1.
Implementation Method Linux-USB Gadget Framework –The Linux-USB Gadget Framework makes it easy for peripherals and other devices embedding GNU/Linux system.
Embedded Software Design Week II Linux Intro Linux Kernel.
LINUX Zhengli Zhu, School of Life Sciences. Outline 1. ABC of Linux 2. Basic orers of Linux 3. Bash Programming.
ORAFACT The Linux File System. ORAFACT Filesystem Support Support for dozens of filesystem types including: Minix, ext2, MS-DOS, UMSDOS, VFAT, NTFS, NFS,
Linux Administration – Finding You Way on the Command Line The Linux File Directory or Tree.
Getting Started with Linux
Filesystem Hierarchy Operating systems I800
Filesystem Management and Backups
Linux 101 Training Module Linux Basics.
File System Implementation
UNIT-V EMBEDDED LINUX.
Welcome to Linux Chap#1 Hanin Abdulrahman.
UBUNTU INSTALLATION
Linux file system "On a UNIX system, everything is a file;
Chapter 6 File Systems CSNB113 SYSTEM ADMINISTRATION
Basic Commands ls cp ls –l (in detail format) echo ls –a
C151 Multi-User Operating Systems
Structure of Unix OS.
9 Linux on the Desktop.
Project 3: An Introduction to File Systems
Exploring the UNIX File System and File Security
Operating Systems Lecture 4.
Linux Architecture Overview.
Computer System Laboratory
Welcome to Linux Chap#1 Hanin Abdulrahman.
Welcome to Linux Chap#1.
Presentation transcript:

Linux Development Lecture 7

Schedule Linux Root Filesystem

Principle and solution Filesystems are organized as hierarchy In Unix systems application and user see a single global hierarchy of files and directories Filesystems are mounted in a specific location in this hierarchy of directories The content of this directory reflects the content of a storage device The start point of a mounted directory is called start point The principle of work leads to easy access

How to mount a device 1. Create directory in /mnt/ called usbstorage 2. Plug a USB flash device in your system and check where it is (using ls /dev or fdisk -l) 3. Mount the device using # mount /dev/sdxXX /mnt/usbstorage 4. ls /mnt/usbstorage

How to unmount device # umount /mnt/usbstorage

Deeper in mount command # mount –t [type] [device] [mountpoint] -t is argument for specifying the device type (also called format e.g. FAT, FAT32, HFS+, NTFS) [type] – the system type – vfat, ntfs, ext3, ext4, auto [device] – specify the device (our device was /dev/sdb) [mountpoint] – the folder that will be our mount folder (in our case it was /mnt/usbstorage) Check the –o option in the internet

Task 1 Format a flash drive to fat32 format on your host OS Mount it to Linux Make few directories/files Unmount it Connect to your host FS and check if everything is ok

Root filesystem The filesystem mounted on / is called root filesystem It is the core filesystem for linux and cannot be unmounted It is mounted directly to the kernel When no root filesystem is available the kernel panics (the problem from Lecture 4) It is commonly called rootfs

Rootfs mouting locations From harddisk From USB drive From SD card From NAND From network (using NFS) From memory, uploaded through the bootloader

Rootfs over network (just FYI) Host NFS server NFS client build into the kernel

NFS server installation $ sudo apt-get install nfs-kernel-server $ Add the export directory to your /etc/exports file: ~/rootfs xxx.xxx(rw, no_root_sqash,no_subtree_check) xxx.xxx is the client IP address rw, no_root_squash,no_subtree_check are the NFS server options for this directory export Start the NFS servier suing sudo/etc/init.d/nfs-kernel-server start

NFS client The kernel must be compiled with: CONFIG_NFS_FS=y CONFIG_IP_PNP=y CONFIG_ROOT_NFS=y The kernel must be booted with the following parameters root=/dev/nfs Ip= xxx.xxx # target IP Nfsroot= xxx.xxx:/home/user/rootfs # NFS server details, where xxx.xxx are the numbers of the host IP address, and /user/ must be changed with your user name

Rootfs in memory: initramfs The rootfs can be integrated into the kernel image It is loaded to the system with the kernel The mechanism is called initramfs It can be make in one image with the kernel Also it can be loaded separately by the bootloader Useful for: Booting in small systems As an intermediate step before switching to the real root(installing a new system, network system install)

Rootfs in memory: initramfs Kernel image (zImage, bzImage, etc) Kernel core and data Root file system stored as a compressed archive

Rootfs in memory: initramfs The content is defined in the kernel configuration using the parameter CONFIG_INIT_RAMFS_SOURCE option. It can be the path to the filesystem located somewhere on your PC, cpio archive, ca be a text describing the content of initramfs (described in Documentation/filesystems/) The kernel build will automatically integrate the fs in your kernel image Details can be fount at: Documentation/fylesystems/ramfs-rootfs-initramfs.txt Documentation/early-userspace/README

Questions ?

Filesystem content

Root fs organization The Linux rootfs organization in well-defined bt Filesystem Hierarchy Standart Most of the Linux systems use this specification Application expect this organization It is easier for developers to and users to have the same organization in all systems

Important directories /bin – basic programs /boot – Kernel image (only when kernel is loaded from a filesystem, non common on non-x86 architectures) /dev – devices /etc – system-wide configurations /home – user directories /lib – basic libraries /media – mount points for removable media

Important directories /mnt – mount point for static media /proc – mount point for the proc virtual fs /root – home directory for the root user /sbin – basic system programs /sys – mount point for sysfs virtual fs /tmp – temporary files /usr – user programs, libraries /var – variable data files – logging data, temporary files

Separation of programs and libraries Basic programs are installed in /bin and /sbin and basic libraries in /lib All other programs are installed under /usr/bin and user/sbin, libraries /usr/lib

Questions ?

Devices

One of the most important kernel role is to allow application to access hardware devices In the most linux systems device types is divided to Character device Block device Internally the kernel identifies the device by three characteristics Type (char or block) Major number (Category of device) Minor number (identifier of device)

Device types Block device HDD, SD card, SSD, Flash drive, etc. Char devices Serial devices The stream of information has no beginning and no end, no size

Devices represented as files The devices in unix are represented as files This allows API protocols to be used for development (as open, write, read, close, etc) All device files are store in /dev directory

Devices represented as files A simple C program that writes a message to a serial device int fd; fd = open(“dev/ttyS0”, O_RDWR); write(fd, “Hello it’s me”, 13); close(fd);

Creating device files On a basic linux system the device files have to be made manually using mknod command mknod /dev/ [c|b] major minor Since kernel version a lot of the Linux systems create the device files automatically Devtmpfs – vitual file system udev – daemon for creating and destroing device files

Questions ?

Pseudo file systems

/proc /proc fs allows The kernel to expose statictics about running processes in the system The user to adjust at runtime various system parameters about process management, memory management etc. /proc is needed by the mass of the userspace application More information – Documentation/filesystems/proc.txt in the kernel sources

/proc A directory holds information about each process that runs on the linux machine It contains information about the files opened by the process, the CPU and memory usage Can be mounted by making directory proc in root and then # mount –t proc none /proc

/proc /proc/interrupts, /proc/devices, /proc/iomem,/proc/ioportts contain general device related information /proc/cmdline contains the kernel command line /proc/sys conations many files that can be written to adjust kernel parameters – more information available at Documentation/sysctl/

sysfs Integrated since kernel 2.6 Allows to represent in user space the cision that the kernel has of the buses, devices and drivers in the system Used in various user space applications All application expect sysfs to be mounted in /sys directory Can be mounted by making directory sys in “/” and then # mount –t sysfs none /sys

Questions ?

Minimal file system

Basic Applications In order Linux to work, a Linux system needs at least a few applications init application – first userspace application that is started by the kernel after mounting the rootfs Kernel looks for it in /sbin/, /bin/, /etc/, /bin/sh It initialize all other userspace applications and services

Basic applications shell application – to allow user to interact with the system Basic unix apps like mv, cp, mkdir, cat, etc. These commands must be integrated in the rootfs to make it usable

Bootloader (loads kernel to ram and stat it) Bootloader (loads kernel to ram and stat it) Rootfs Kernel – initialize devices, mounts rootfs /sbin/init - starts other userspace services and apps /sbin/init - starts other userspace services and apps shell Other apps Overall booting process

Kernel – initialize devices, mounts rootfs Booting process with initramfs Bootloader (loads kernel to ram and stat it) Bootloader (loads kernel to ram and stat it) /sbin/init - starts other userspace services and apps /sbin/init - starts other userspace services and apps /init – starts early userspace commands, loads drivers to access the final rootfs, mounts rootfs and start it

Busybox

In order to work properly Linux system needs few basic sets of programs: An init program A shell Various basic utilities for file manipulation For easier setup and run of a rootfs with all the needed basic components there is Busybox. It is used for compiling all the needed basic programs.

Busybox Provides simple implementation of init program A single configuration file - /etc/inittab Allows to run services at start and to make sure that certain services are always running on the system See examples/inittab in Busybox for details on the configuration

Busybox setup 1. Get busybox source untar it 3. Configure it with defconfig (do not forget the ARCH and CROSS_COMPILE) 4. Configure it with menuconfig and check Busybox Settings  Options -> Build as a static binary

Busybox setup 5. make ARCH=….... CROSS_COMPILE= Install 6. After make we need to compress the whole folder _install to a rootfs.img, this happens using $ cd _install $ find. | cpio –o --format=newc >../rootfs.img xq

Final Task 1. Build kernel for versatilepb 2. Build busybox 3. $ qemu-system-arm –M versatilepb –kernel zImage –initrd rootfs.img –append “root=/dev/ram rdinit=/bin/sh console=ttyAMA0,115200” –nographic # (for people with GUI change –nographic with –serial stdio) 4. mount /proc 5. mount /sys

Homework task 1 1. Modify rootfs directory by adding folders proc sys dev etc etc/init.d 2. Make a script inside etc/init.d/ to mount proc and sys when the system starts 3. Post the qemu command line start string (e.g. qemu-system- arm –M versatilepb –kernel zImage … )

Homework task 2(optional) Find a way to load rootfs over network. This task is optional