440 likes | 556 Views
教育部顧問式嵌入式軟體聯盟. Embedded filesystem. Outline. Introduction to the file system Hard link and soft link Elementary management Embedded Linux file system Virtual files ystem The role of the virtual file system. Introduction to the file system.
E N D
教育部顧問式嵌入式軟體聯盟 Embedded filesystem
Outline • Introduction to the file system • Hard link and soft link • Elementary management • Embedded Linux file system • Virtual files ystem • The role of the virtual file system
Introduction to the file system • One of the last operations conducted by the Linux kernel during system startup is mounting the rootfilesystem • The root filesystem has been an essential component of all Unix systems from the start • In the Linux, the root filesystem will be mounted under this dictionary “/” • There are some sub-dictionaries and files under /, and these sub-dictionary also have their own sub-dictionaries and files and recursion
Introduction to the file system • The whole file system is like the branches • Root is the beginning, and then branches again and again • This structure is called the hierarchy structure • The following table contains the top level dictionaries of the root filesystem • It is very useful for those apprentices who want to understand the Linux filesystem to be conversant with what are in those dictionaries
Introduction to the file system • Anything which is used by filesystem appears as the type of file, including the dictionaries • The dictionary is one kind of special filesystem • For all the hardware devices, there are corresponding files on the filesystem • For example :/dev/fd0 is the first floppy disk of the system, and vice versa
Introduction to the file system • Terminology you should know first • Block: • Files is stored in the blocks with fixed size of the disk • The size of the block is usually the power of two • Superblock: • Stores information concerning a mounted filesystem • For disk-based filesystems, this object usually corresponds to a filesystem control block stored on disk • You may not be able to get the data form the disk if the superblock is damaged
Introduction to the file system • Inode: • Stores general information about a specific file • For disk-based filesystems, this object usually corresponds to a file control block stored on disk • Each inode object is associated with an inode number which uniquely identifies the file within the filesystem
Hard link and soft link • What is the symbolic link? • There are two kinds of link on the Linux﹕ • hard link • soft link • The second one is also called symbolic link • We will discuss the difference between the hard link and soft link
Hard link and soft link • What is hard link • You must get an inode if you want to store a file on the disk, and then inode will record where the file located in the disk • If you use the hard link, all file will use the same inode. It will point to the same location as the original file • This inode will renew its link count, and the more hard links, the more link counts • All the hard links are equivalent, and you must remove all the hard links associated with this file if you want to remove this file
Hard link and soft link • What is hard link • For instance:the disk space of file A is still there if I make a hard link as file B for file A and remove file A later. It is because that the disk space is still associated with file B • This disk space will be released if I remove the file B then • We could regard all the files as hard links, and different hard links point to different disk spaces • It is also allowed that different hard links reference to the same disk space
Hard link and soft link • What is soft link (also called symbolic link) • The difference from hard link is that soft link will make another inode, but it just points to the original name, not the same disk space • This soft link will become ownerless if the original inode was deleted and it is called the dead link • Hard link must be established on the same partition, and it could not be used on dictionaries • Soft link could be established on different partitions, and it could be used on both files and dictionaries
Elementary management • pwd • It means that 「Print Working Directory」, and it stands that where you are in the file system • cd .. • The function of this utility is that changing directory to upper directory • If you enter 「cd」in the console but no any path, you would go back your home dirctory • You could go to the absolute path which you want to if you add the absolute path behind the cd instruction
Elementary management • mkdir dir_name • The result of this instruction will make a new directory under current directory, and the name of the directory is the dir_name which you enter
Elementary management • rmdir dir_name • Remove the directory named dir_name • If you want to use this command, the directory you want to remove must contain no file, link and directory • You could use the 「rm」command to delete the files within the directory which you want to remove • You could use the 「rm -rf」command to delete all the files within the directory compulsorily
Elementary management • For instance • This command will copy the test to generate a new file named test2.copy • If we replace the 「cp」 command with 「mv」, we just change the name of test to test2.copy • The original file will disappear and there is only the new file named test2.copy cp test test2.copy
Elementary management • ls • 「ls」command means that list • If the target of this command is the directory, and the content of this directory will be listed • If you want to get the information of the directory it own , you could use the 「-d」parameter ls –d /root
Elementary management • chmod 1 • Change the permission mode of the file • You could see some information about the file • You could get some prosperities in the first ten columns • If the first one is 『-』, it means it is a regular file • If the first one is 『d』, it means it is a directory • If the first one is 『l』, it means it is a link ls -l
Elementary management • chmod 2 • The following 9 letters were grouped into three • 『 user 』 • 『 group 』 • 『 others 』 • They stand for the permission of these three group • Every group has such permission • 『 r 』 stands for readable • 『 w 』stands for writable • 『 x 』stands for executable
Elementary management • chmod 3 • The next number stands for the count of the hard links referenced to this file • The following next two columns stand for who is the user and the group of the user • User column means that one of the users within the system and it usually stands for the one who creates this file • Group column means that which group the user belongs
Elementary management • chmod 4 • The follows are the file size and the modified date, and the last one is the name of the file • The following is the screenshot of 「ls -l」
Embedded Linux file system • In most embedded Linux systems, where there are no users and no administrators, the rules to build a root filesystem can be loosely interpreted • This doesn't mean that all rules can be violated, but it does mean that breaking some rules will have little to no effect on the system's proper operation • Interestingly, even mainstream commercial distributions for workstations and servers do not always adhere to the established rules for root filesystems.
Embedded Linux file system • All the directories that pertain to providing a multiuser extensible environment, such as /home, /mnt,/opt, and /root, can be omitted • This discussion does not revolve around size issues, but rather functionality • In fact, omitting a directory entry changes little to the resulting size of the root filesystem
Embedded Linux file system • Depending on your bootloader and its configuration, you may not need to have a /boot directory • This will depend on whether your bootloader can retrieve kernel images from your root filesystem before your kernel is booted
Embedded Linux file system • At the extreme, you could omit /proc, which is useful only for mounting the virtual filesystem that has the same name • If you are very tight for space, you can configure your kernel without /proc support, but I encourage you to enable it whenever possible • /usr and /var, have a predefined hierarchy of their own, much like that of the root directory
Embedded Linux file system • For the purposes of most embedded Linux systems, nonetheless, the three directories in the /usr we created will suffice • /usr/bin • /usr/lib • /usr/sbin • The directories we created are the bare minimum required for the normal operation of most applications found in an embedded Linux system
Embedded Linux file system • BusyBox • BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc • Enthusiasm for BusyBox stems from the functionality it provides while still remaining a very small-sized application
Embedded Linux file system • BusyBox • Although BusyBox does not support all the options provided by the commands it replaces, the subset it provides is sufficient for most typical uses • See the docs directory of the BusyBox distribution for the documentation in a number of different formats
Embedded Linux file system • Usage of BusyBox • As expected, only one executable was installed, /bin/busybox • This is the single binary with support for all the commands configured using Config.h • This binary is never called directly • Instead, symbolic links bearing the original commands' names have been created to /bin/busybox
Embedded Linux file system • Usage of BusyBox • Such symbolic links have been created in all the directories in which the original commands would be found, including /bin, /sbin, /usr/bin, and /usr/sbin
Embedded Linux file system • Usage of BusyBox • When you type a command during the system's normal operation, the busybox command is invoked via the symbolic link • In turn, busybox determines the actual command you were invoking using the name being used to run it • /bin/ls, for instance, points to /bin/busybox
Embedded Linux file system • Usage of BuxyBox • Although this scheme is simple and effective, it means you can't use arbitrary names for symbolic links • Creating a symbolic link called /bin/dir to either /bin/ls or /bin/busybox will not work, since busybox does not recognize the dir command.
Embedded Linux file system • More data • Official website:http://www.busybox.net/
Embedded Linux file system • Device files • Following Unix tradition, every object in a Linux system is visible as a file, including devices • All the device files (device nodes) in a Linux root filesystem are located in the /dev directory • In the embedded Linux system only the entries required for the system's proper operation should be created
Embedded Linux file system • Basic device entries
Embedded Linux file system • Basic device entries
Embedded Linux file system • In addition to the basic device files, there are a few compulsory symbolic links that have to be part of your /dev directory
Embedded Linux file system • Congratulation we have now prepared a basic /dev directory for our target
Virtual file system • One of the keys for Linux to success is its ability to coexist comfortably with other systems • By using the concept called the Virtual Filesystem • Linux manages to support multiple disk types in the same way other Unix variants do • The idea behind the VFS is to put a wide range of information in the kernel to represent many different types of filesystems
Virtual file system • The five standard Unix file types • Regular files • Directories • Symbolic links • Device files • Pipes • This chapter will discuss the first three entries • The device files will be discussed in chapter 13 • The pipes will be discussed in chapter 19
The role of the virtual file system • The Virtual Filesystem (also known as Virtual Filesystem Switch or VFS) is a kernel software layer that handles all system calls related to a standard Unix filesystem • Its main purpose is providing a common interface to several kinds of filesystems
The role of the virtual filesystem Hard disk of ext2 format VFS CP Floppy of MS-DOS
The role of the virtual filesystem • An example for the using of VFS • Use the “cp” utility,copy the data to the disk of ext2 format from the floppy of MS-DOS format • This operation embraces two kinds of filesystem and two different storage devices , which are held together by VFS
The role of the Virtual Filesystem • Data writing process Write() function of filesystem write() sys_write() filesystem real storage device User level VFS The VFS is an abstraction layer between the application program and the filesystem implementations. User level requests the write() function and it must goes through the VFS to get the write() function supported by filesystem to write the data into the real storage device