Linux operating system File system basics

Source: Internet
Author: User
Tags temporary file storage

first, the Linux file structure
a file structure is a method of organizing files on storage devices such as disks. Mainly embodied in the organization of files and directories.
The directory provides a convenient and effective way to manage files.
Linux uses a standard directory structure that, when installed, has created a file system for the user and a complete and fixed directory composition, specifying the role of each directory and the file types in it.
/root directory

┏━━┳━━━┳━━━┳━━━╋━━━┳━━━┳━━━┳━━━┓
┃┃┃┃┃┃┃┃┃
Bin Home Dev etc lib sbin tmp usr var
┃┃
┏━┻━┓┏━━┳━━┳━━┳━┻━┳━━┓
┃┃┃┃┃┃┃┃
Rc.d cron.d x11r6 src Lib local man bin

┏━━━┳━━┳━┻━┳━━━┓
┃┃┃┃┃
INIT.D rc0.d rc1.d rc2.d ... Linux bin Lib Src
Linux uses a tree-based structure. The top level is the root directory, and all other directories are generated from the root directory. Microsoft DOS and Windows also adopt a tree structure, but in DOS and windows such a tree structure root is the disk partition of the letter, there are several partitions there are several tree structure, the relationship between them is tied. However, in Linux, there is only one directory tree that manages several disk partitions, regardless of the operating system. Structurally, the tree catalogs on each disk partition are not necessarily tied.
If this is not easy to understand, let me cite an example:
  There is a hard disk, divided into 4 partitions,/;/BOOT;/USR and Windows, respectively, the fat
for/and/boot or/and/usr, they are dependent, and for/boot and/usr are side-by-side relationships.
If I mount the FAT partition under Windows to/mnt/winc, (Mount?? Oh, don't worry, hehe, I'll talk about it in a minute. For/mnt/winc and/usr or/mnt/winc and/boot, they are two branches that do not have any relationship to the directory tree.
Because Linux is a multi-user system, developing a fixed directory plan can help unify the management of system files and different user files. But that's what makes many beginners who go from Windows to Linux feel headache. The following lists the functions of some of the main directories under Linux.
/bin binary Executable command
/dev Device Special files
/etc system administration and configuration files
/ETC/RC.D startup configuration files and scripts
The base point of the home user directory, such as the user's home directory is/home/user, can be represented by ~user
/lib Standard Programming Library, also known as dynamic Link shared library, acts like a. dll file in Windows
/sbin System Management commands, which are stored in the hypervisor used by the system administrator
/tmp Common temporary file storage point
/root system Administrator's home directory (hehe, privileged Class)
The/MNT system provides this directory to allow users to temporarily mount other file systems.
/lost+found This directory is usually empty, the system is not properly shut down and leave the "homeless" files (what is called under Windows. chk) right here.
/proc a virtual directory, which is a mapping of system memory. This directory can be accessed directly to obtain system information.
/var overflow area for some large files, such as log files for various services
/usr The largest directory, the applications and files to be used almost all in this directory. These include:
/USR/X11R6 the directory where x window is stored
/usr/bin a multitude of applications
/usr/sbin Some management programs for super users
/usr/doc Linux Documentation
/usr/include the header files needed to develop and compile applications under Linux
/usr/lib Common dynamic-link libraries and package profiles
/usr/man Help Documentation
/USR/SRC source code, the Linux kernel source is placed in the/usr/src/linux
/usr/local/bin Local Add-on command
/usr/local/lib local additions to the library
  Second, the Linux file system
the file system refers to the physical space in which a file exists, and each partition in a Linux system is a file system with its own directory hierarchy.    Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. An operating system can not operate without the operation of the file, so it is necessary to own and maintain their own file system.
the Llinux file system uses an index node to log file information that acts like a Windows file allocation table.
An index node is a structure that contains information such as the length of a file, creation and modification times, permissions, affiliation, location on disk, and so on. A file system maintains an array of index nodes, each of which corresponds to the only element in an array of index nodes. The system assigns a number to each index node, which is the index number of the node in the array, called the index node number.
The Linux file system saves both the file index node number and the filename in the directory. So, the directory is just a table that combines the name of the file with its index node number, and each pair of file names and index nodes in the directory is called a connection.
for a file, there is a unique index node number corresponding to it, for an index node number, but can have more than one file name corresponding. Therefore, the same file on the disk can be accessed through a different path.
you can use the LN command to create a new connection to an already existing file without copying the contents of the file. The connection has the soft connection and the hard connection cent, the soft connection is also called the symbolic connection. Each of them is characterized by:
Hard connect: Both the original file name and the connection file name point to the same physical address.
Directories cannot have hard connections, hard connections cannot span file systems (cannot span different partitions)
The file has only one copy on the disk, saving hard disk space;
because deleting a file succeeds when the same index node belongs to a unique connection, you can prevent unnecessary accidental deletions.
Symbolic connection: Establishing a symbolic connection for a file with the Ln-s command is a special file of Linux, and as a file, its data is the pathname of the file it is connected to. Like a shortcut under Windows.
can delete the original file and save the connection file, there is no prevention of accidental deletion function.
This paragraph of the content is too abstract, but also the node is an array, I have tried to popular again, and not good examples for demonstration. If you are still foggy, I have no way, only first remember, in the future in the practical application of slowly experience, understanding. This is also my study of a method.
Third, Mount file system
  As we know from the previous section, each partition in a Linux system is a file system with its own directory hierarchy. Linux will form the overall directory hierarchy of a system in a way that is divided into separate file systems that belong to different partitions. The word "in a certain way" means the mount.
Hang the top-level directory of one file system on a subdirectory of another file system, making them a whole, called mounts. Refer to this subdirectory as a mount point.
Let's take an example:
Root partition:
/root directory

┏━━━━┳━━━━━┳━━━━━┳━━━━━╋━━━━━┳━━━━━┳━━━━━┳━━━━━┓
┃┃┃┃┃┃┃┃┃
Bin Home Dev etc lib sbin tmp usr var

┏━┻━┓
┃┃
RC.D CRON.D

┏━━━┳━━━┳━┻━┳━━━━┓
┃┃┃┃┃
INIT.D rc0.d rc1.d rc2.d ...
/usr partition:
Usr

┏━━━━┳━━━╋━━━┳━━━┳━━━┓
┃┃┃┃┃┃
X11R6 src Lib local man bin
┃┃
┃┏━━━╋━━━┓
┃┃┃┃
Linux bin Lib Src
After mounting, it forms the diagram at the beginning of the article. Does it look like it's hung up?
Note: 1, mount point must be a directory.
2, a partition is mounted on an existing directory, this directory can not be empty, but the contents of the previous directory will not be available after mounting.
This is true for the mounting of file systems created by other operating systems. However, it is necessary to understand that the format of the file system used by the CD, floppy disk, and other operating systems is not the same as the file system format used by Linux. The disc is ISO9660, the floppy disk is FAT16 or Ext2;windows NT is FAT16, NTFS;WINDOWS98 is FAT16, fat32;windows2000 and WindowsXP are FAT16, FAT32, NTFS. Before mounting, see if Linux supports the file system format that you want to mount.
Mount with mount command:
Format: Mount [-parameter] [device name] [Mount Point]
Among the parameters commonly used are
-t specifies the file system type of the device, which is common:
Minix Linux The earliest file system used
EXT2 Linux currently used file system
Msdos MS-DOS FAT, is FAT16
VFAT Windows98 commonly used FAT32
NFS Network File System
ISO9660 CD-ROM standard file system
NTFS file system for Windows NT 2000
HPFS OS/2 File System
Auto automatically detects the file system
-o Specifies the option to mount the file system. Some are also available in/etc/fstab. Commonly used to have
CODEPAGE=XXX code page
Iocharset=xxx Character Set
RO mount in read-only mode
RW mount in read-write mode
Nouser makes it impossible for ordinary users to mount
User can mount a device to a normal user
As a reminder, the Mount command does not have a mount point feature, so you should ensure that the mount point already exists when you execute the Mount command. (Don't understand?) The point is that you want to mount the file system, first of all to build a directory. Is that OK? )
Example: Windows98 is installed in the HDA1 partition, and there are floppy disks and discs on the computer that need to be mounted.
# Mk/mnt/winc
# Mk/mnt/floppy
# Mk/mnt/cdrom
# mount-t Vfat/dev/hda1/mnt/winc
# mount-t Msdos/dev/fd0/mnt/floppy
# mount-t Iso9660/dev/cdrom/mnt/cdrom
It is now possible to read and write these file systems into directories such as/mnt/winc.
To ensure that the last two lines of the command are not wrong, make sure that there is a disk in the floppy drive and optical drive. (If the disk disc of the hard disk can be replaced frequently at any time, I think I will not make such a mistake:->)
If you have a Chinese file name in your Windows98 directory, a bunch of garbled characters are displayed when you mount it using the command above. This will use the CodePage iocharset option in the-o parameter. CODEPAGE specifies the code page of the file system, the Chinese code is 936;iocharset specified character set, Simplified Chinese is generally used cp936 or gb2312.
Mount must have an error when mounting file system Linux is not supported, such as Windows2000 's NTFS file system. You can recompile the Linux kernel to gain support for the file system. About recompiling the Linux kernel, that's not the point.
   Iv. Automatic Mounting
  It's obviously too cumbersome to run the Mount command every time you access the Windows partition, why not use the Mount command to access other Linux partitions?
In fact, Linux automatically mounts the Linux partitions that need to be mounted on each boot. So can we set Linux to mount the partitions we want to mount, such as Windows partitions, when booting up, to automatically mount the file system?
This is perfectly possible. There is a fstab file in the/etc directory, which lists the list of file systems that are automatically mounted when Linux is powered on. My/etc/fstab file is as follows:
/DEV/HDA2/EXT3 Defaults 1 1
/dev/hda1/boot ext3 Defaults 1 2
None/dev/pts devpts gid=5,mode=620 0 0
NONE/PROC proc Defaults 0 0
NONE/DEV/SHM TMPFS Defaults 0 0
/dev/hda3 swap swap defaults 0 0
/dev/cdrom/mnt/cdrom iso9660 noauto,codepage=936,iocharset=gb2312 0 0
/dev/fd0/mnt/floppy Auto Noauto,owner,kudzu 0 0
/dev/hdb1/mnt/winc vfat defaults,codepage=936,iocharset=cp936 0 0
/dev/hda5/mnt/wind vfat defaults,codepage=936,iocharset=cp936 0 0
In the/etc/fstab file, the first column is the device name of the mounted file system, the second column is the mount point, the third column is the mounted file system type, the fourth column is the Mount option, and the options are separated by commas. The 56th column does not know what to mean, but also looks at the expert pointing.
The last two lines are the c;d disks that I added manually under Windows, plus the codepage=936 and iocharset=cp936 parameters to support Chinese filenames. The parameter defaults actually contains a set of default parameters:
RW is mounted in read/write mode
SUID Open User ID and group ID setting bit
Dev interprets character or block devices on a file system
EXEC executable binary file
Auto Mount automatically
Nouser makes it impossible for ordinary users to mount
Async performs a file system's input-output operation in an unsynchronized manner
  As you can see in this list, the optical drive and floppy drive are not mounted automatically and the parameters are set to Noauto. (If you want to set the automatic mount, you have to make sure that every time you turn on the CD-ROM drive and floppy disk, hehe.) )

Linux operating system File system basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.