41
Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com 1

Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D. 1

Embed Size (px)

Citation preview

Page 1: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

LinuxFilesystem

Last Update 2012.08.241.3.0

Copyright 2000-2012 Kenneth M. Chipps Ph.D. www.chipps.com

1

Page 2: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Objectives of This Section

• Learn– What filesystems are– What filesystems Linux can use

Copyright 2000-2003 Ken Chipps All Rights Reserved 2

Page 3: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of Linux Filesystems

• Linux was cross-developed under the Minix operating system

• Linus Torvalds decided It was easier to share disks between the two systems than to design a new filesystem, so support for the Minix filesystem was built into Linux

• The Minix filesystem was an efficient and relatively bug-free piece of software

Copyright 2000-2003 Ken Chipps All Rights Reserved 3

Page 4: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• However, the restrictions in the design of the Minix filesystem were too limiting, so people started thinking and working on the implementation of new filesystems in Linux

• In order to ease the addition of new filesystems into the Linux kernel, a VFS - Virtual File System layer was developed

Copyright 2000-2003 Ken Chipps All Rights Reserved 4

Page 5: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• The VFS layer was initially written by Chris Provenzano, and later rewritten by Linus Torvalds before it was integrated into the Linux kernel

• VFS also proved to be too limiting so a new filesystem, called the Extended File System was implemented in April 1992 and added to Linux 0.96c

Copyright 2000-2003 Ken Chipps All Rights Reserved 5

Page 6: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• This new filesystem removed the two big Minix limitations– Maximum size of 2 GB– Maximum file name size of 255 characters

• This was an improvement over the Minix filesystem but some problems were still present in it

Copyright 2000-2003 Ken Chipps All Rights Reserved 6

Page 7: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• There was no support for– Separate access– Inode modification– Data modification timestamps

• The filesystem used linked lists to keep track of free blocks and inodes and this produced bad performance

Copyright 2000-2003 Ken Chipps All Rights Reserved 7

Page 8: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• As the filesystem was used, the lists became unsorted and the filesystem became fragmented

• As a response to these problems, two new filesystems were released in the Alpha version of Linux in January 1993– The Xia filesystem– The Second Extended File System

Copyright 2000-2003 Ken Chipps All Rights Reserved 8

Page 9: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• The Xia filesystem was heavily based on the Minix filesystem kernel code and only added a few improvements over this filesystem

• Basically, it provided long file names, support for bigger partitions, and support for the three timestamps

Copyright 2000-2003 Ken Chipps All Rights Reserved 9

Page 10: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• On the other hand, ext2 was based on the ext code with many reorganizations and many improvements

• It had been designed with evolution in mind and contained space for future improvements

• When the two new filesystems were first released, they provided essentially the same features

Copyright 2000-2003 Ken Chipps All Rights Reserved 10

Page 11: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

History of the Linux Filesystem

• Due to its minimal design, xia fs was more stable than ext2

• As the filesystems were used more widely, bugs were fixed in ext2 and lots of improvements and new features were integrated

• ext2 is now very stable and has become the de-facto standard Linux filesystem

Copyright 2000-2003 Ken Chipps All Rights Reserved 11

Page 12: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Structure

• Unlike Windows Linux keeps a single filesystem for all hardware devices

• There is no C: D: E: and so on

Copyright 2000-2003 Ken Chipps All Rights Reserved 12

Page 13: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Inode

• Within a Linux filesystem each file is represented by a structure, called an inode

• Each inode contains the description of the file, as in– File type– Access rights– Owners– Timestamps– Size

Copyright 2000-2003 Ken Chipps All Rights Reserved 13

Page 14: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Inode

– Pointers to data blocks• The addresses of data blocks allocated to

a file are stored in its inode• When a user requests an I/O operation on

the file, the kernel code converts the current offset to a block number, uses this number as an index in the block addresses table and reads or writes the physical block

Copyright 2000-2003 Ken Chipps All Rights Reserved 14

Page 15: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Directories

• Directories are structured in a hierarchical tree

• Each directory can contain files and subdirectories

• Directories are implemented as a special type of file

• Actually, a directory is a file containing a list of entries

Copyright 2000-2003 Ken Chipps All Rights Reserved 15

Page 16: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Directories

• Each entry contains an inode number and a file name

• When a process uses a pathname, the kernel code searches in the directories to find the corresponding inode number

• After the name has been converted to an inode number, the inode is loaded into memory and is used by subsequent requests

Copyright 2000-2003 Ken Chipps All Rights Reserved 16

Page 17: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Files

• Linux itself does not use extensions in file names

• Filenames that begin with a period are hidden

• To see them use ls -a

Copyright 2000-2003 Ken Chipps All Rights Reserved 17

Page 18: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Links

• Like Unix, Linux filesystems implement the concept of links

• Several names can be associated with an inode

• The inode contains a field containing the number associated with the file

Copyright 2000-2003 Ken Chipps All Rights Reserved 18

Page 19: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Links

• Adding a link simply consists of creating a directory entry, where the inode number points to the inode, and in incrementing the links count in the inode.

• When a link is deleted, in other words when one uses the rm command to remove a filename, the kernel decrements the links count and deallocates the inode if this count becomes zero

Copyright 2000-2003 Ken Chipps All Rights Reserved 19

Page 20: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Links

• This type of link is called a hard link and can only be used within a single filesystem

• It is impossible to create cross-filesystem hard links

• Moreover, hard links can only point to files• Another kind of link exists in Linux

filesystems

Copyright 2000-2003 Ken Chipps All Rights Reserved 20

Page 21: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Links

• Symbolic links are simply files which contain a filename

• When the kernel encounters a symbolic link during a pathname to inode conversion, it replaces the name of the link by its contents

• In other words. the name of the target file, then it restarts the pathname interpretation

Copyright 2000-2003 Ken Chipps All Rights Reserved 21

Page 22: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Links

• Since a symbolic link does not point to an inode, it is possible to create cross-filesystem symbolic links

• Symbolic links can point to any type of file, even to nonexistent files

• Symbolic links are very useful because they don't have the limitations associated with hard links

Copyright 2000-2003 Ken Chipps All Rights Reserved 22

Page 23: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

ext2

• The current filesystem standard• The second extended file system• First appeared in the 2.2 kernel• Although some are moving to ext3

Copyright 2000-2003 Ken Chipps All Rights Reserved 23

Page 24: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

ext3

• ext3 is a journaling filesystem developed by Stephen Tweedie

• It is compatible with the ext2 filesystems• Basically it can be seen as an ext2

filesystem with a journal file• The journaling capability means no more

waiting for fsck to run or worrying about metadata corruption

Copyright 2000-2003 Ken Chipps All Rights Reserved 24

Page 25: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

ext3

• What is most noticeable is that you can switch back and forth between ext2 and ext3 on a partition without any problem

• It is just a matter of giving the mount command the right filesystem type

• From kernel version 2.4.16 on ext3 is included in the standard kernel

Copyright 2000-2003 Ken Chipps All Rights Reserved 25

Page 26: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

ext3

• Before a partition can be mounted as an ext3 filesystem the journal file must be created

• The easiest way to do it is to type– tune2fs -j /dev/hdaX

• This can be done on an unmounted or on a mounted filesystem

• If the journal is created on a mounted filesystem a file named .journal file will be seen

Copyright 2000-2003 Ken Chipps All Rights Reserved 26

Page 27: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

ext3

• Don't try to delete this and don't back this up or restore it from backup

• If tune2fs -j is run on an unmounted partition an invisible journal file will be created

• Now the filesystem can be mounted as ext3 using– mount -t ext3 /dev/hdaX /mnt/somewhere

Copyright 2000-2003 Ken Chipps All Rights Reserved 27

Page 28: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 28

Standard System Directories

• /– The root directory– Generally in Linux, unlike other operating

systems, this directory holds no files– It only has other directories below it

• /bin– Holds standard commands and utilities

Page 29: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 29

Standard System Directories

• /boot– Holds the kernel image files and modules

loaded when the system boots• /dev

– Holds the file interfaces for devices such as printers

• /etc– This directory and its subdirectories holds

system configuration files

Page 30: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Standard System Directories

• /home– Holds user home directories

• /initrd– This directory is empty, but is used as a

critical mount point during the boot process• /lib

– Shared libraries and kernel modules

Copyright 2000-2003 Ken Chipps All Rights Reserved 30

Page 31: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 31

Standard System Directories

• /lost+found– Used by fsck to place orphaned files, such as

files without names• /misc

– Normally not used• /media

– On modern Linux systems this contains the mount points fore removable media

Page 32: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 32

Standard System Directories

• /mnt– On older Linux systems this contains the

mount points fore removable media• /opt

– Holds software applications that have been added

• /proc– Used to show running processes

Page 33: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Standard System Directories

• /root– The home directory of the superuser

• /sbin– Holds specialized system programs

• /tmp– For temporary files

• /usr– Hold files and commands directly related to

users of the systemCopyright 2000-2003 Ken Chipps All Rights Reserved 33

Page 34: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 34

Standard System Directories

• /usr/bin– User oriented commands and utilities

• /usr/doc– Documentation

• /usr/lib– Holds libraries for programming languages

Page 35: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 35

Standard System Directories

• /use/local– Locally installed software

• /usr/sbin– Holds system administration commands

• /usr/share– Stuff to be used by several programs

• /usr/share/doc– Holds Linux documentation

Page 36: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 36

Standard System Directories

• /usr/share/man– Holds the man pages

• /usr/spool– Holds spooled files, such as print spooling

• /usr/src– Holds source files– For example /usr/src/linux holds the kernel

source files

Page 37: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 37

Standard System Directories

• /usr/X11R6– X Window applications and libraries

• /var– Holds files that vary a lot in size

• /var/cache– Application cache data

• /var/lib– State information for applications

Page 38: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Standard System Directories

• /var/lock– Holds locks for files that are locked

• /var/log– Holds kernel and system log files

• /var/spool– Holds application spool data as well as print,

cron, and at jobs

Copyright 2000-2003 Ken Chipps All Rights Reserved 38

Page 39: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 39

Standard System Directories

• /var/tmp– Holds temporary files that need to be retained

during a system reboot

Page 40: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 40

Links

• Some files in Linux systems are not files• Instead they are links to files• These show up as

– l• in the first position when the

– ls• command is issued

Page 41: Linux Filesystem Last Update 2012.08.24 1.3.0 Copyright 2000-2012 Kenneth M. Chipps Ph.D.  1

Copyright 2000-2003 Ken Chipps All Rights Reserved 41

Links

• Basically a symbolic link is just another way to indicate a path

• Symbolic links then differ from hard links• Hard links are actual files• To remove a file, just remove the hard

links• The symbolic links will then fail, as the file

is no longer there