Thursday, July 30, 2009

Linux file system layout

Subdirectories of the root directory
DirectoryContent
/binCommon programs, shared by the system, the system administrator and the users.
/bootThe startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
/devContains references to all the CPU peripheral hardware, which are represented as files with special properties.
/etcMost important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
/homeHome directories of the common users.
/initrd(on some distributions) Information for booting. Do not remove!
/libLibrary files, includes files for all kinds of programs needed by the system and the users.
/lost+foundEvery partition has a lost+found in its upper directory. Files that were saved during failures are here.
/miscFor miscellaneous purposes.
/mntStandard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/netStandard mount point for entire remote file systems
/optTypically contains extra and third party software.
/procA virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail.
/rootThe administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
/sbinPrograms for use by the system and the system administrator.
/tmpTemporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!
/usrPrograms, libraries, documentation etc. for all user-related programs.
/varStorage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.

How can you find out which partition a directory is on? Using the df command with a dot (.) as an option shows the partition the current directory belongs to, and informs about the amount of space used on this partition:



icts@09cpu0161:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 67282996 12299376 51565796 20% /
tmpfs 1025328 0 1025328 0% /lib/init/rw
varrun 1025328 104 1025224 1% /var/run
varlock 1025328 0 1025328 0% /var/lock
udev 1025328 252 1025076 1% /dev
tmpfs 1025328 92 1025236 1% /dev/shm
/dev/sda3 53263504 67636 53195868 1% /media/D-Drive


Every partition has its own file system. By imagining all those file systems together, we can form an idea of the tree-structure of the entire system, but it is not as simple as that. In a file system, a file is represented by an inode, a kind of serial number containing information about the actual data that makes up the file: to whom this file belongs, and where is it located on the hard disk.

Every partition has its own set of inodes; throughout a system with multiple partitions, files with the same inode number can exist.

Each inode describes a data structure on the hard disk, storing the properties of a file, including the physical location of the file data. When a hard disk is initialized to accept data storage, usually during the initial system installation process or when adding extra disks to an existing system, a fixed number of inodes per partition is created. This number will be the maximum amount of files, of all types (including directories, special files, links etc.) that can exist at the same time on the partition. We typically count on having 1 inode per 2 to 8 kilobytes of storage.

At the time a new file is created, it gets a free inode. In that inode is the following information:

  • Owner and group owner of the file.

  • File type (regular, directory, ...)

  • Permissions on the file

  • Date and time of creation, last read and change.

  • Date and time this information has been changed in the inode.

  • Number of links to this file

  • File size

  • An address defining the actual location of the file data.

The only information not included in an inode, is the file name and directory. These are stored in the special directory files. By comparing file names and inode numbers, the system can make up a tree-structure that the user understands. Users can display inode numbers using the -i option to ls. The inodes have their own separate space on the disk.


icts@09cpu0161:/$ ls -i
3432449 bin 843777 lib64 2293761 srv
1540097 boot 11 lost+found 1 sys
12 cdrom 3956737 media 2367489 tmp
1268 dev 1105921 mnt 3284993 usr
2588673 etc 1114113 opt 1335297 var
3416065 home 1 proc 16 vmlinuz
15 initrd.img 1736705 root 13 vmlinuz.old
14 initrd.img.old 376833 sbin
3457025 lib 1843201 selinux

No comments:

Post a Comment