Introduction to Linux file systems

Source: Internet
Author: User
Tags uuid

The file system is a very basic knowledge of Linux, but also a prerequisite for learning Linux.

This article will stand in a higher view to understand the Linux file system, mainly including the Linux disk partition and directory, Mount fundamentals, file storage structure, soft link hard links, and the introduction of common directories. I believe that with this knowledge for in-depth study of Linux will have some help. The article is mainly based on the Ubuntu release version.

If there is something wrong, please point out a lot.

1.Linux disk partitioning and directory

There are few differences between Linux distributions, and the differences are mainly in the features of system management and the way software packages are managed. The directory structure is basically the same. The file structure of Windows is a multi-side tree structure, the top of which are different disks (partitions), such as: c,d,e,f, etc.

The file structure of Linux is a single tree structure. You can show it with tree. Installs the tree (sudo apt-get install tree) under Ubuntu and can be viewed by command.

Each time we install the system, we will partition, Linux under the disk partition and directory relationship is as follows:

– Any partition must be mounted on a directory.

– The directory is a logical distinction. Partitioning is a physical distinction.

– The disk Linux partition must be mounted to a specific directory in the directory tree for read and write operations.

– The root directory is where all Linux files and directories reside, and the previous disk partition needs to be mounted.

Here are some of the directory and partitioning relationships we may have:

Figure 1: Directory and partition relationships

Q: How do I view partitions and directories and usage?

–fdisk view hard disk partition table

–DF: Viewing partition usage

–du: Viewing file space usage

Q: Why partition, how to partition?

– Reduce risk by putting different data into separate partitions.

– Large hard drive search range, low efficiency

– Disk mates can only be set for partitions

–/home/var/usr/local are often separate partitions because they are often manipulated and prone to fragmentation.

2.Mount Mount and introduction to NFS

Mount Concept : When you want to use a device, such as to read a formatted partition on the hard disk, CD-ROM or software, such as a device, you must first map these devices to a directory, and this directory is called "mount point", so that you can read these devices, and the corresponding action is "mount". Shields the physical partition details off. The user has only a unified logic concept. Everything is a file. The mount command can be mounted:

Mount [-FNRSVW] [-t vfstype] [-O options] Device dir

Q: All disk partitions must be mounted to be used, so how are the hard disk partitions on our machines mounted?

A: This is primarily the use of/etc/fstab files. Each time the kernel loads it knows where to start the Mount file system. Each system boot is automatically mounted according to the file definition. If not mounted automatically, the partition will not be used. The following is the definition of my/etc/fstab, mainly according to the installed partition:

# <file system> <mount point> <type> <options> <dump> <pass>

PROC/PROC proc Defaults 0 0

#/dev/sda1 is automatically mounted to/

UUID=CB1934D0-4B72-4BBF-9FAD-885D2A8EEEB1/EXT3 Relatime,errors=remount-ro 0 1

#/DEV/SDA5 is automatically mounted to partition/home

Uuid=c40f813b-bb0e-463e-aa85-5092a17c9b94/home ext3 relatime 0 2

#/dev/sda7 is automatically mounted to/work

Uuid=0f918e7e-721a-41c6-af82-f92352a568af/work ext3 relatime 0 2

#分区/dev/sda6 is automatically mounted to swap

uuid=2f8bdd05-6f8e-4a6b-b166-12bb52591a1f None swap SW 0 0

Q: How can I mount a removable hard drive? How do I mount a new partition?

The drive module of the mobile hard drive is mounted automatically, and if you have a new hard disk, partition it and mount it to a folder via the Mount command. If you want to mount it automatically, you can modify the/etc/fstab file.

NFS Introduction: NFS is believed to be widely used in many places and is a very good way to share files. The upload service used by our company is to upload files to a network server, the middle is through NFS implementation.

Server-side files can be accessed transparently by using Client for NFS. NFS is also implemented via Mount, which is implemented via the NFS communication protocol. Basic principle:

Figure 2:nfs Fundamentals

Ubuntu under Ubuntu below example

Service side:

$apt-get Install Nfs-kernel-server

Vi/etc/exports Add NFS Directory:/personal/nfs_share

10.1.60.34 (Rw,sync,no_root_squash)

$sudo Exportfs-r

$sudo/etc/init.d/portmap Start

$sudo/etc/init.d/nfs-kernel-server Start

Client:

$sudo Apt-get Install Nfs-common

$sudo Mount 10.19.34.76:/personal/nfs_share ~/nfsshare Example:

3. File Types

Linux The following file types are mainly:

A) ordinary files : C-Language meta-code, shell scripts, binary executables, and so on. Divided into plain text and binary.

b) catalog files : Directories, the only place where files are stored.

c) linked file : A file that points to the same file or directory.

d) special files : Related to system peripherals, usually under/dev. Divided into block devices and character devices.

You can view information about the type of file by Ls–l, file, Stat, and several commands.

4. File storage structure

Linux Orthodox file systems (such as ext2, ext3) A file consists of directory entries, Inode, and data blocks.

Catalog Entry : includes the file name and inode node number.

Inode: Also known as the file Index node, is the basic information of the file and the data block pointer storage location.

Data Block : The specific contents of the file to be stored.

Linux Orthodox file systems (such as ext2, 3, and so on) partition the hard disk into directories, Inode table chunks, and data block regions. A file consists of a catalog item, an inode, and a data region block. The inode contains the attributes of the file (such as read and write properties, owner, and pointers to the data block), and the data region block is the file content. When you view a file, the file attributes and data points are isolated from the Inode table and the data is read from the data block.

Standing in the 2w ft view, the file storage structure is probably as follows:

Figure 3: File storage structure 2w ft view

The structure of the catalog entries is as follows (the directory entries for each file are stored in the file contents of the directory to which the files belong):

Figure 4: Catalog Item structure

The inode structure of the file is as follows (the file information contained in the Inode can be viewed through stat filename):

Figure 5:inode Structure

The above only reflects the general structure, the Linux file system itself is evolving. But the above concepts are basically unchanged. And, such as Ext2, ext3, Ext4 file systems are also very different, if you want to see the specific file system introduction.

5. Soft connection, hard link

Soft links and hard links are two of our common concepts:

Hard Connect : is to give a copy of the file while establishing a connection between the two. Modify one, and the file to which it is connected is modified at the same time. If you delete [color=red] any of the remaining files [/color] will not be affected.

Soft Connection : Also called symbolic connection, he just set up a "shortcut (borrow a wondows common word)" in the new location of the source file, so when the source file is deleted, the symbol connection file will become water without-----only the left filename, of course, delete this connection, Also does not affect the source file, but the use of the connection file, reference is directly called the source file.

The specific relationship can be seen:

Figure 5: Soft links and hard links

The difference between a hard link and a soft link can be seen from the diagram:

1: The inode number of the hard link original file and the new file is the same. and soft links are different.

2: Deleting the original file causes soft links to be unavailable, and hard links are not affected.

3: The original file modification, soft and hard link file content is also modified, because all points to the same file content.

6. file Directory management commands

Disk and file space

Fdisk DF du

File directory and Management

cd pwd mkdir rmdir LS CP RM MV

View File Contents

Cat:cat [file] To view the contents of the file. Full-concatenate meaning, the file content is continuously output to the screen. The first line is displayed on the last line. Tac:tac [file] and cat are just the opposite of viewing from the last line to the first row.

Cat has a relatively bad place when the file is not able to see the big time, this time can be used more or less command.

More:more [File] If you use a command such as grep or find, you can use the more page-by-page view. If you see half of you want to quit, you can exit by typing ' q '. less:less [file] Less is more resilient than more and can page up and down.

If you want to read only the first few lines of a file or the end of a file, you can use head or tail. head–n [file]: reads the first n rows of a file. tail–n [file]: reads the end of the file n rows.

The above commands are used to view character files, binary files are garbled, to see the contents of the binary file, you can use the OD command, such as viewing the contents of a MP3 file: od shijiemori.mp3

File directories and Permissions

chmod chown chgrp Umask

File Lookup

Which:which [filename] This command is used to query the path path to find an executable file within that route. For example: which passwd: Find executable passwd Whereis:whereis [-bmsu] [keyword] This command is used to list the files and directories of related words. (Linux will record files in a file database, the command type from the database to query, so faster, Linux will update the database every day)

locate:locate [filename] This command is used to list the files and directories of related words. Finding data is particularly fast and is queried by database methods. But the database is updated once a week, so there may be some data that cannot be found. can go to modify the configuration file.

find:find [path] [parameter] [keyword] This command is used to locate the file under the specified path. It is not queried by the data, so the speed is slower.

7. Common Directory interpretation

The directory structure of various Linux distributions is basically the same, each directory is briefly described as follows:

Directory

Describe

/

root directory

/bin

The most basic command required to be a basic system is to put it here. such as LS, CP, mkdir and other commands; functions and/usr/bin are similar, the files in this directory are executable, commands that ordinary users can use.

/boot

The Linux kernel and the files required for the boot system program, such as the Vmlinuz initrd.img files, are located in this directory. In general, the GRUB or LILO system Boot Manager is also located in this directory, starting the Mount file storage location, such as Kernels,initrd,grub. is generally a separate partition.

/dev

Some of the necessary equipment, sound cards, disks and so on. And like/dev/null. /dev/console/dev/zero/dev/full and so on.

/etc

The system's configuration file is stored in the location. Some server configuration files are also here, such as user account and password configuration file;

/etc/opt:/opt the corresponding configuration file

/etc/x11:xwindows System Configuration File

/etc/xml:xml configuration file

......

/home

User working directory, and personal profile, such as personal environment variables, all accounts are assigned a working directory. is generally a separate partition.

/lib

Repository file storage location. Bin and sbin required library files. Windows-like DLLs.

/media

Removable media mount point, such as CD-ROMs, mobile hard disk, USB drive, the system will be mounted here by default.

/mnt

Temporarily mount the file system. This directory is generally used to store mounted storage devices, such as the CDROM directory. You can see the definition of/etc/fstab.

/opt

An optional application package.

/proc

When the operating system is running, the process (running program) information and kernel information (such as CPU, hard disk partition, memory information, etc.) are stored here. /proc directory masquerading file system proc mount directory, Proc is not a real file system, its definition can be see/etc/fstab.

/root

Root user's working directory

/sbin

Similar to Bin, is some executable files, but not all users need, generally is the system management needs to be used.

/tmp

System temporary files, general system restarts will not be saved.

/usr

Contains the system user tools and programs.

/usr/bin: Non-mandatory ordinary user can execute command

/usr/include: Standard header file

Library files for/usr/lib:/usr/bin/and/usr/sbin/

/usr/sbin: A non-mandatory executable file

/USR/SRC: Kernel source

/usr/x11r6:x Window System, Version one, Release 6.

/srv

This directory holds data that needs to be extracted after some services are started

Original source: http://www.iteye.com/topic/816268

Introduction to Linux file systems

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.