Root File System for
Embedded Systems
-By ALOK PAL
Batch:-Aug-2018,DESD
CDAC HYDERABAD
Agenda
 Introduction
 Types of file system
 Root file system content
 Mounting and unmounting of file system
 Libraries
 Root file system setup
 BusyBox
 Summary
What is Embedded Systems?
 It is a combination of Hardware and Software.
 Embedded = Hardware + Software
 “Embedded” means hidden inside so one can’t see it.
 “System” means hidden multiple components interfaced together for
a common purpose.
Introduction to file systems
 An OS can support more then one file system.
 Home directories for all users to store their personal files.
 Example: – /home/username
 Library file names are either ld* or lib*.so.*
 Examples: – ld-2.11.1.so
 – libncurses.so.5.7
 File systems can be discussed in the following context:
 – Contents
 – Types
 – Partitions
 Two major parts of a file system are User
File –naming system
File access systesm
What is Root File System?
 DATA stored on storage device in binary format as 1s and 0s form.
 It is impossible to understand files/folders from the sea of binary.
 File system was designed as a novel way to organize such data easily understandable by
all users.
 The software which provides the core support for implementing the Operating
System/Kernel.
/
bin lib …………..
dev home etc
Root/Top level
Directory
Types of file systems
 Block-device File Systems
 Flash File Systems
 Flash File Systems II
 In-Memory File system
 User Space File system
 Compressed Read-only File systems
 Linux Virtual File system
Block- device file systems
 Considers storage device as a simple linear collection of blocks or sectors.
 Size of blocks vary (512, 1024 …)
 Have two main operation : Read & Write
 Type of Devices:
 LBA devices (HDDs)
 FTL devices (USB flash drive, SD, SSDs etc).
 In case of bad blocks, the FTL or hardware (for LBA devices) takes care of
hiding from user.
 File system drivers : ext2, ext3, ext4, FAT, NTFS, ReiserFS etc.
Flash File Systems
 Mainly used on Raw Flash Devices
 Linux provides MTD as a primitive translation Layer.
 How are they Different?
 They are not block devices
 Mostly raw NAND / NOR storage media.
 They consist of ERASEBLOCKS
 Have 3 main operation : Read, Write & Erase block
 Each block has limited lifespan (1000s of write cycles)
 Needs write to be spread.
Flash File Systems II
 FTL devices Vs Raw Flash device
 FTL devices has a micro-controller which runs FTL firmware.
 Helps to emulate a block device.
 Why FFS is unique?
 Needs to spread write
 Perform Garbage collection
 Bad blocks handling
 Better reliability compared to FTL (Since FTL is vendor specific)
 E.g. UBIFS, JFFS2 etc.
In-Memory File system
 Uses primary memory e.g. RAM
 Features:
 Has higher I/O performance
 Volatile Memory
 E.g.:- ramfs, tmpfs, ramdisk.
 Why not ramdisk?
 It emulates block device in RAM.
 Block device store recently accessed files in caches. Hence using ramdisk creates a
large memory foot print
 Hard limit on max size of ram disk
User Space File system
 Mainly intended for block devices.
 Resides in the user space.
 Overhead of communicating to and from kernel and User space.
 Distinct Advantage:
 A bad user space file-system can never cause a system crash.
 E.g. ntfs-3g (New Technology File System-3rd generation).
 NTFS-3G supports all operations for writing files: files of any size can be
created, modified, renamed, moved, or deleted on NTFS partitions, it is a
proprietary file system developed by Microsoft.
Compressed Read-only File systems
 Read-only filesystem
 Data Stored in compressed format.
 Especially useful in low memory systems
 E.g.
 Cramfs:
 Metadata not stored (No time stamps or user permissions)
 Possible security issues.
 Max file system size = 256 MB
 Squashfs
 stores metadata information.
 Max filesystem size = 2^64.
Linux Virtual File system
 Role of VFS:
 Register/de-register
 Associate devices and file
system drivers.
 Generic File operations
 Caching
 Look ups
 Forward File-system specific
operation:
 Read
 Write
 etc
Root file system top-level directories
How to create Root file system?
 First make a directory for this purpose:-
 $ cd ${PRJROOT}/rootfs
 Now create the core root filesystem directories required for your system:-
 $ mkdir bin dev etc lib proc sbin sys tmp usr var
 $chmod 1777 tmp
 After this now you can proceed with this creation of /usr hierarchy:-
 $mkdir usr/bin usr/lib usr/sbin
 To demonstrate more give a command :- $ ls –al /usr
 The last entries to create are in the /var directory:-
 $mkdir var/lib var/lock var/log var/run var/tmp
 Chmod 1777 var/tmp
 The directories we created are the bare minimum required for the normal
operation of most application found in an embedded Linux system.
Mounting and unmounting of file system
 The access of the data are done using a process called as mounting
 A file system must be mounted in order to be usable by the system.
 For example, if you want to mount(access) a CD-ROM to the
directory /mnt/cdrom, you can type a command:-
 $ mount –t iso9660 /dev/cdrom/mnt/cdrom
 After mounting, you can use the cd command to navigate the newly available
file system through the mount point you just made.
 To unmount (remove) the file system from your system command is :-
 $ unmount /dev/cdrom
Libraries
 Shared library archives
 The glibc package contains a number of libraries.
 Glibc :- ${TARGET_PREFIX}/lib to see the entire listr of libraries installed
during the package’s build process.
 Ld:- dynamic linker , it is compulsory needed to use any shared libraries.
 Actual shared libraries formatted as:- libLIBRARY_NAME-GLIBC_VERSION.so
 Many people do not know that .so files are also executable ELF binaries that
can return useful information :- /lib/libc-2.5.so
 Static library archives
 These archives are used by applications that choose to link statically with a
library :- libLIBRARY_NAME.a.
Some more libraries for linux file system
 uClibc
 As with glibc, uClibc contains a number of libraries.it contains the same four
different types of files as the glibc directory.
 uClibc is meant to be a glibc replacement.
 $cd ${PREFIX}/uclibc/lib
 $for file in libuClibc ld-uClibc libc libdl
 Keeping the file system in RAM
 “Tmpfs” :-it is used as a Rootfs via the Initramfs.
 Tmpfs uses the linux page and dentry caches as temporary storage areas, it
saves memory in the common case where the embedded device frequently
uses system software and static data.
Some useful commands
 The DF(disk free) command :- $ df -k
 It displays the disk space usage in kilobytes.
 The Du(disk usage) command :- $ du –h
 It tells the size of root file system .
 And displays number of blocks consumed by each directory .
 A single block may take either 512 Bytes or 1 Kilo Byte depending on your
system.
 For kernel compilation :- arch/x86/boot/bzimage ; is ready command
 File vmlinux
 Vmlinux:- ELF 64_bit LSB executable, x86_64, version1
 If $du –h vmlinux ; command typed it will give size in MBs (45)
Root file system setup
 Characterizing :-
 ->online write support
 ->persistence
 ->power-down reliability
 -> compression
 E.g:- Cramfs
 Cramfs as a filesystem with a bare-minimum feature set, it is a very simple , and sometimes
simplistic, compressed and read-only filesystem aimed at embedded systems. There are no current (.)
or parent(..) directory entries.
 To build the utilities download the package, un-tar the archive, and issue the make command:-
 $ tar zxvf cramfs-1.1.tar.gz
 $cd cramfs-1.1
 $ make; unfortunately, the package Makefile does not provide an install target. Copy the tools in
appropriate directory: $ cp cramfs ${PREFIX}/bin/
 $ cd ${PRJROOT}
 $mkcramfs rootfs/image/cramfs.img
 bin boot dev etc lib linuxrc proc sbin tmp usr
 ‘bin’: addgroup…;
 ‘boot’: boot.b …;
 ‘sbin’: chroot…; in this case compression ratio 50% will be achieved.
BusyBox
 BusyBox implements most linux commands through a single executable that is less than
1 MB (statically linked with glibc) or less then 500KB(statically linked with uClibc)
 BusyBox is available under the GNU GPL
 By default BusyBox is dynamically linked with the C library.
 The project’s location is:- https://www.busybox.net this website includes
documentation , downloads , links, and a mailing list archive.
 After downloading and extracting the package, move into directory for the rest setup:
$cd ${PRJROOT}/sysapps/busybox-1.29.3 (latest stable version released on
9sep2018).
 Give a command : $ make help , it explains all the available Makefil targets, such as
make clean, make mrproper, and make install.
 Compilation:- by setting CONFIG_STATIC=y for BusyBox after configuration
 Now you can compile and install it When linking the glibc, use the command :- $ make
ARCH=ppc CROSS_COMPILE=powerpc-linux- >CONFIG_PREFIX=${PRJROOT}/rootfs install
 To build BusyBox with uClibc instead of the GNU C library, command is:-
 $ make ARCH=ppc CROSS_COMPILE=power-uclibc- 
 >CONFIG_PREFIX=${PRJROOT}/rootfs install , BusyBox is now installed on your target’s
root filesystem and ready to be used.
Summary
 Root file system can be volatile or non volatile in nature .
 If root file is present in RAM then it will be not persistence , because when power
goes Off it will be vanished, but if it present in the ROM then it will be always
persistence.
 E.g:- init ram fs can act as a root file system created by user inside the volatile
memory but it will not be present there after the system power Off.
 So the file system will implement three objects:-
 ->Files-that hold persistence data
 ->Open files:- that allows to access(mount)files
 ->Directories:- that name the files.
 You can create your own root file system ,some commands are :-
 $ ls ; to check the rootfile is present or not
 $bin linuxrc sbin usr
 $du –h :- tells size of the root file system
 $ ls etc/proc
 $ ls –al
 BusyBox init:- sysinit, respawn, askfirst,wait once, ctrlaltdel,shutdown, restart
Root file system for embedded systems

Root file system for embedded systems

  • 1.
    Root File Systemfor Embedded Systems -By ALOK PAL Batch:-Aug-2018,DESD CDAC HYDERABAD
  • 2.
    Agenda  Introduction  Typesof file system  Root file system content  Mounting and unmounting of file system  Libraries  Root file system setup  BusyBox  Summary
  • 3.
    What is EmbeddedSystems?  It is a combination of Hardware and Software.  Embedded = Hardware + Software  “Embedded” means hidden inside so one can’t see it.  “System” means hidden multiple components interfaced together for a common purpose.
  • 4.
    Introduction to filesystems  An OS can support more then one file system.  Home directories for all users to store their personal files.  Example: – /home/username  Library file names are either ld* or lib*.so.*  Examples: – ld-2.11.1.so  – libncurses.so.5.7  File systems can be discussed in the following context:  – Contents  – Types  – Partitions  Two major parts of a file system are User File –naming system File access systesm
  • 5.
    What is RootFile System?  DATA stored on storage device in binary format as 1s and 0s form.  It is impossible to understand files/folders from the sea of binary.  File system was designed as a novel way to organize such data easily understandable by all users.  The software which provides the core support for implementing the Operating System/Kernel. / bin lib ………….. dev home etc Root/Top level Directory
  • 6.
    Types of filesystems  Block-device File Systems  Flash File Systems  Flash File Systems II  In-Memory File system  User Space File system  Compressed Read-only File systems  Linux Virtual File system
  • 7.
    Block- device filesystems  Considers storage device as a simple linear collection of blocks or sectors.  Size of blocks vary (512, 1024 …)  Have two main operation : Read & Write  Type of Devices:  LBA devices (HDDs)  FTL devices (USB flash drive, SD, SSDs etc).  In case of bad blocks, the FTL or hardware (for LBA devices) takes care of hiding from user.  File system drivers : ext2, ext3, ext4, FAT, NTFS, ReiserFS etc.
  • 8.
    Flash File Systems Mainly used on Raw Flash Devices  Linux provides MTD as a primitive translation Layer.  How are they Different?  They are not block devices  Mostly raw NAND / NOR storage media.  They consist of ERASEBLOCKS  Have 3 main operation : Read, Write & Erase block  Each block has limited lifespan (1000s of write cycles)  Needs write to be spread.
  • 9.
    Flash File SystemsII  FTL devices Vs Raw Flash device  FTL devices has a micro-controller which runs FTL firmware.  Helps to emulate a block device.  Why FFS is unique?  Needs to spread write  Perform Garbage collection  Bad blocks handling  Better reliability compared to FTL (Since FTL is vendor specific)  E.g. UBIFS, JFFS2 etc.
  • 10.
    In-Memory File system Uses primary memory e.g. RAM  Features:  Has higher I/O performance  Volatile Memory  E.g.:- ramfs, tmpfs, ramdisk.  Why not ramdisk?  It emulates block device in RAM.  Block device store recently accessed files in caches. Hence using ramdisk creates a large memory foot print  Hard limit on max size of ram disk
  • 11.
    User Space Filesystem  Mainly intended for block devices.  Resides in the user space.  Overhead of communicating to and from kernel and User space.  Distinct Advantage:  A bad user space file-system can never cause a system crash.  E.g. ntfs-3g (New Technology File System-3rd generation).  NTFS-3G supports all operations for writing files: files of any size can be created, modified, renamed, moved, or deleted on NTFS partitions, it is a proprietary file system developed by Microsoft.
  • 12.
    Compressed Read-only Filesystems  Read-only filesystem  Data Stored in compressed format.  Especially useful in low memory systems  E.g.  Cramfs:  Metadata not stored (No time stamps or user permissions)  Possible security issues.  Max file system size = 256 MB  Squashfs  stores metadata information.  Max filesystem size = 2^64.
  • 13.
    Linux Virtual Filesystem  Role of VFS:  Register/de-register  Associate devices and file system drivers.  Generic File operations  Caching  Look ups  Forward File-system specific operation:  Read  Write  etc
  • 14.
    Root file systemtop-level directories
  • 15.
    How to createRoot file system?  First make a directory for this purpose:-  $ cd ${PRJROOT}/rootfs  Now create the core root filesystem directories required for your system:-  $ mkdir bin dev etc lib proc sbin sys tmp usr var  $chmod 1777 tmp  After this now you can proceed with this creation of /usr hierarchy:-  $mkdir usr/bin usr/lib usr/sbin  To demonstrate more give a command :- $ ls –al /usr  The last entries to create are in the /var directory:-  $mkdir var/lib var/lock var/log var/run var/tmp  Chmod 1777 var/tmp  The directories we created are the bare minimum required for the normal operation of most application found in an embedded Linux system.
  • 16.
    Mounting and unmountingof file system  The access of the data are done using a process called as mounting  A file system must be mounted in order to be usable by the system.  For example, if you want to mount(access) a CD-ROM to the directory /mnt/cdrom, you can type a command:-  $ mount –t iso9660 /dev/cdrom/mnt/cdrom  After mounting, you can use the cd command to navigate the newly available file system through the mount point you just made.  To unmount (remove) the file system from your system command is :-  $ unmount /dev/cdrom
  • 17.
    Libraries  Shared libraryarchives  The glibc package contains a number of libraries.  Glibc :- ${TARGET_PREFIX}/lib to see the entire listr of libraries installed during the package’s build process.  Ld:- dynamic linker , it is compulsory needed to use any shared libraries.  Actual shared libraries formatted as:- libLIBRARY_NAME-GLIBC_VERSION.so  Many people do not know that .so files are also executable ELF binaries that can return useful information :- /lib/libc-2.5.so  Static library archives  These archives are used by applications that choose to link statically with a library :- libLIBRARY_NAME.a.
  • 18.
    Some more librariesfor linux file system  uClibc  As with glibc, uClibc contains a number of libraries.it contains the same four different types of files as the glibc directory.  uClibc is meant to be a glibc replacement.  $cd ${PREFIX}/uclibc/lib  $for file in libuClibc ld-uClibc libc libdl  Keeping the file system in RAM  “Tmpfs” :-it is used as a Rootfs via the Initramfs.  Tmpfs uses the linux page and dentry caches as temporary storage areas, it saves memory in the common case where the embedded device frequently uses system software and static data.
  • 19.
    Some useful commands The DF(disk free) command :- $ df -k  It displays the disk space usage in kilobytes.  The Du(disk usage) command :- $ du –h  It tells the size of root file system .  And displays number of blocks consumed by each directory .  A single block may take either 512 Bytes or 1 Kilo Byte depending on your system.  For kernel compilation :- arch/x86/boot/bzimage ; is ready command  File vmlinux  Vmlinux:- ELF 64_bit LSB executable, x86_64, version1  If $du –h vmlinux ; command typed it will give size in MBs (45)
  • 20.
    Root file systemsetup  Characterizing :-  ->online write support  ->persistence  ->power-down reliability  -> compression  E.g:- Cramfs  Cramfs as a filesystem with a bare-minimum feature set, it is a very simple , and sometimes simplistic, compressed and read-only filesystem aimed at embedded systems. There are no current (.) or parent(..) directory entries.  To build the utilities download the package, un-tar the archive, and issue the make command:-  $ tar zxvf cramfs-1.1.tar.gz  $cd cramfs-1.1  $ make; unfortunately, the package Makefile does not provide an install target. Copy the tools in appropriate directory: $ cp cramfs ${PREFIX}/bin/  $ cd ${PRJROOT}  $mkcramfs rootfs/image/cramfs.img  bin boot dev etc lib linuxrc proc sbin tmp usr  ‘bin’: addgroup…;  ‘boot’: boot.b …;  ‘sbin’: chroot…; in this case compression ratio 50% will be achieved.
  • 21.
    BusyBox  BusyBox implementsmost linux commands through a single executable that is less than 1 MB (statically linked with glibc) or less then 500KB(statically linked with uClibc)  BusyBox is available under the GNU GPL  By default BusyBox is dynamically linked with the C library.  The project’s location is:- https://www.busybox.net this website includes documentation , downloads , links, and a mailing list archive.  After downloading and extracting the package, move into directory for the rest setup: $cd ${PRJROOT}/sysapps/busybox-1.29.3 (latest stable version released on 9sep2018).  Give a command : $ make help , it explains all the available Makefil targets, such as make clean, make mrproper, and make install.  Compilation:- by setting CONFIG_STATIC=y for BusyBox after configuration  Now you can compile and install it When linking the glibc, use the command :- $ make ARCH=ppc CROSS_COMPILE=powerpc-linux- >CONFIG_PREFIX=${PRJROOT}/rootfs install  To build BusyBox with uClibc instead of the GNU C library, command is:-  $ make ARCH=ppc CROSS_COMPILE=power-uclibc-  >CONFIG_PREFIX=${PRJROOT}/rootfs install , BusyBox is now installed on your target’s root filesystem and ready to be used.
  • 22.
    Summary  Root filesystem can be volatile or non volatile in nature .  If root file is present in RAM then it will be not persistence , because when power goes Off it will be vanished, but if it present in the ROM then it will be always persistence.  E.g:- init ram fs can act as a root file system created by user inside the volatile memory but it will not be present there after the system power Off.  So the file system will implement three objects:-  ->Files-that hold persistence data  ->Open files:- that allows to access(mount)files  ->Directories:- that name the files.  You can create your own root file system ,some commands are :-  $ ls ; to check the rootfile is present or not  $bin linuxrc sbin usr  $du –h :- tells size of the root file system  $ ls etc/proc  $ ls –al  BusyBox init:- sysinit, respawn, askfirst,wait once, ctrlaltdel,shutdown, restart