Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux Development 8.02.2016 Lecture 7. Schedule Linux Root Filesystem.

Similar presentations


Presentation on theme: "Linux Development 8.02.2016 Lecture 7. Schedule Linux Root Filesystem."— Presentation transcript:

1 Linux Development 8.02.2016 Lecture 7

2 Schedule Linux Root Filesystem

3

4 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

5 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

6 How to unmount device # umount /mnt/usbstorage

7 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

8 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

9 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

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

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

12 NFS server installation $ sudo apt-get install nfs-kernel-server $ Add the export directory to your /etc/exports file: ~/rootfs 192.168.xxx.xxx(rw, no_root_sqash,no_subtree_check) 192.168.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

13 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=192.168.xxx.xxx # target IP Nfsroot=192.168.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

14 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)

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

16 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

17 Questions ?

18 Filesystem content

19 Root fs organization The Linux rootfs organization in well-defined bt Filesystem Hierarchy Standart http://linuxfoundation.org/collaborate/workgroups/lsb/fhs 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

20 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

21 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

22 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

23 Questions ?

24 Devices

25 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)

26 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

27 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

28 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);

29 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 2.6.32 a lot of the Linux systems create the device files automatically Devtmpfs – vitual file system udev – daemon for creating and destroing device files

30 Questions ?

31 Pseudo file systems

32 /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

33 /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

34 /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/

35 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

36 Questions ?

37 Minimal file system

38 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

39 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

40 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

41 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

42 Busybox

43 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.

44 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

45 Busybox setup 1. Get busybox source - https://www.busybox.net/downloads/busybox-1.24.1.tar.bz2 https://www.busybox.net/downloads/busybox-1.24.1.tar.bz2 2. 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

46 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

47 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

48 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 …...........)

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


Download ppt "Linux Development 8.02.2016 Lecture 7. Schedule Linux Root Filesystem."

Similar presentations


Ads by Google