Linux disk and partition detailed

Source: Internet
Author: User
Tags uuid web hosting

1. Introduction to Linux partitioning 1.1 primary partition VS Extended Partition

The hard disk partition table can store up to four partitions, but we are generally divided into two partitions, one is the primary partition (Primary partion) is an extended partition (extended partition), the primary partition can be used immediately but no longer partition, The extended partition must be partitioned before it can be used, meaning it must also be partitioned two times. So what's the extension partition going to do? It is a logical partition (Logical partion), and there is no limit on the number of logical partitions.

1.2 Meaning of drive marking

For those of you who are accustomed to using DOS or Windows, there are several partitions that have several drives, and each partition will have a letter identifier, and then you can use that letter to specify the files and directories on this partition, and their file structures are independent and very well understood. For Red Hat Linux novices, however, it's a bit annoying. Because for Linux users, regardless of a few partitions, scored for the directory use, it is ultimately only a root directory, a separate and unique file structure. Each partition in Red Hat Linux is part of the entire file system because it uses a processing method called "mount point", which contains a full set of files and directories in the entire file system, and links a partition to a directory. At this point a partition to be loaded is available in a directory on the storage space of Linux.
Let's start by looking at how Red Hat Linux drives are identified. For IDE hard drives, the drive identifier is "hdx1", where "HD" indicates the type of device on which the partition is located, which refers to the IDE hard disk. The "X" is the disk number (A is the base disk, B is the base slave, C is the secondary primary, D is the secondary slave), "1" represents the partition, the first four partitions are represented by the numbers 1 to 4, they are the primary or extended partition, and the logical partition starts from 5. Example, Hda3 is represented as the third primary or extended partition on the first IDE hard disk, and HDB2 is represented as the second primary or extended partition on the second IDE hard disk. The SCSI hard disk is identified as "sdx1", the SCSI hard disk is "SD" to indicate the type of device the partition is located, and the rest is the same as the representation of the IDE hard disk, no longer repeat.
We can see from the above that the Red hat Linux partition is different from other operating system partitions, its partition format is commonly used in EXT3 and swap two kinds, EXT3 for storing system files, swap as Red hat The Swap partition for Linux (equivalent to a virtual memory file in Windows). So now we can see that red Hat Linux requires at least two dedicated partitions (Linux Native (local) and Linux Swap (swap)). Because Red Hat Linux cannot be installed on the dos/windows partition. In general, we will install Red Hat Linux with one or more hard disk partitions of type "Linux Native", but each partition in Red Hat Linux must specify a mount point, which tells Red Hat Linux to start , which partition to use for this directory. For a "Swap" partition, it is generally defined, and it does not necessarily define the load point.
Let's start with a preliminary understanding of "Linux Native" and "Linux Swap".

      • Swap partition is Linux temporarily stored data exchange partition, it is mainly to save the main memory temporarily unused data, when needed to redeployment in memory, and the partition used as swap does not specify "Mout point" (load points), since it as a swap partition, We should certainly give it a size that is at least equal to the amount of actual memory on the system, which in general is one to twice times the size of memory. Alternatively you can create and use more than one swap partition, up to 16.
      • Linux native is the place to store system files, generally with the EXT3 partition type, for Red Hat Linux, there is a large choice, you can put the system files in several areas to install (must specify the mount point), can also be installed in the same partition (mount point is "/").
1.3 Why do I need to customize multiple partitions?

There are several purposes for the division of multiple zones:

    • The system can be re-installed without loss of data, such as setting up the/home mount point independently, and marking it back to//when reloading the system without any loss of data.
    • Assign appropriate file systems to different mount points for proper performance, such as using ReiserFS for/Var, using XFS for/home, and/or using EXT4.
    • Different mount options are turned on for different mount points, such as whether immediate synchronization is required, whether the log is turned on, or whether compression is enabled.
    • Large hard drive search range, low efficiency
    • Disk quotas 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 point directory Introduction 2.1 Common Mount directory structure

Each disk is divided into partitions, each of which has its own file system. Windows specifies a letter for each of these file systems. However, Gnu/linux uses a unique tree structure to manage the files, and each file system is mounted somewhere in the tree structure.
Just as Windows needs a C: drive, Gnu/linux must be able to mount the root file system on the root (/) of the file tree. When the root mount is complete, you can mount additional file systems on various mount points in the tree structure. Any directory under the root structure can be used as a mount point, and you can also mount the same file system on different mount points at the same time.
The mount point is actually the entry directory for the disk file system in Linux

2.2 Common Mount Directory descriptions

Catalog Content

/root directory, store system commands and user data, etc. (if the following mount points do not have separate partitions, they will be in the partition of the root directory)
/boot boot loader static link file for Linux boot-related programs
/home User directory, storing data for ordinary users
/ tmp temp file
/ usr is where the Red Hat Linux system holds the software and, if possible, the maximum space should be allocated to it
/usr/local the self-installed program is installed here
/var constantly changing data, some server services, logs are placed below.
/opt (option optional) additional application package

/bin Basic Command Execution file
/dev Device files
/etc host-specific system configuration
/lib Basic shared libraries and kernel modules
/media mount point for moving media
/MNT for temporary mounting of file systems or other hardware devices (such as optical drives, floppy drives)
A virtual directory of/proc System Information (2.4 and 2.6 cores), which is generated in memory by the system itself.
/root Root User's Directory
/sbin Basic System Command execution file
/sys virtual directory for System Information (2.6 cores)
/SRV System-supplied data for service
/usr/x1186 x-windows directory, storing some x-windows configuration files
/usr/include System header file, storing some C-language header files
/USR/SRC Linux kernel source code, Linux system installed kernel source code are stored in this
/usr/bin some additions to the/bin catalogue
/usr/sbin some additions to the/sbin catalogue
/lost+found This directory is empty in most cases. But if you have a sudden power outage at work, or if you don't shut down normally, some files will not find where they should be when you restart the machine, for these files, the system puts them in this directory.
/boot: You must always physically include/etc,/bin,/sbin,/lib, and/dev, or you will not be able to start the system.
/home: Each user will place his private data in a subdirectory of this directory.
/tmp: The temporary data created by the program is mostly stored in this directory.
/usr: contains all user programs (/usr/bin), library files (/usr/lib), Documents (/usr/share/doc), and so on.
/var: all mutable data, such as newsgroup articles, e-mails, websites, databases, cache of package systems, etc., will be put into this directory. The size of this directory depends on the purpose of your computer, but for most people, it will be used primarily as a management tool for package systems. If you make a server, space should be as large as possible. My server's actual division and actual use of the size, has not actually put into use. So the/var directory doesn't use that much. The general Web hosting Web page directory is/var/www,postfix mail storage directory is:/var/mail,var/log, is the system logging partition,/var/spool: Store some mail, news, print queue and so on.
/OPT: Storage of optional installed software.

There are several mount points described above, in general we need at least two partitions (of course, as long as A/partition can also), need a swap partition, and a "/" partition, but some of the common, important mount points to other partitions, so easy to manage. General one/partition, one/usr partition, one/home partition, one/var/log partition. Of course, there are no rules, it is entirely in accordance with the needs of the set. We can use Disk Druid, which is provided by Red Hat Linux, to complete the partitioning and mount point settings.

Comparison and catalogue introduction, you can think of the Linux system mount point as a tree
/As the root of a tree
/derivative of the other mount point for the branch of this big tree
The file under the mount point is a leaf

2.3 Why is the Linux partition required to mount this action?

If you have read my previous article on the Linux series, then you should remember that I used to mark a word:Linux under All Files! in other words, the Linux operating system manages everything in the system as a file. Our common hardware devices in Windows (printers, network cards, sound cards ...) ), disk partitions and so on, all are considered as files in Linux, access to devices, partitions is to read and write the corresponding files.

3, actual combat partition Mount 3.1 temporary mount

To raise a chestnut, the original partition is as follows:

[Email protected]]# DF-hfilesystem            Size  used Availuse% mountedon/dev/sda2              20G  5. 6G   13G  //dev/sda6             996M   35M  910M   4/data /dev/sda5             426G  199M  404G   1/disk1/dev/sda1             996M   46M  899M   5%/boottmpfs                 7. 9G     0  7. 9G   0 %/DEV/SHM

3.1.1 Unmount the partition first:
Umount//data

3.1.2 and then hang up again:
MOUNT/DEV/SDA5//dev/sda6/disk1


Note: As mentioned earlier, 2 partitions cannot be mounted to/data at the same time

3.2 Permanent mount: Auto mount on Boot

The method in the above steps is only temporary work, the disk partition will not be visible after the boot or mount before the appearance, want to be permanent, also need to modify the/etc/fstab, will

Label=/data             /data                   ext3    defaults        12LABEL=/disk1            / Disk1                  ext3    defaults        12


Modified to:

/dev/sda5             /data                   ext3    defaults        12/dev/sda6             /disk1                  ext3    Defaults        12

Description: Fstab is the file System Allocation table configuration file, the file has strict syntax format restrictions, similar to crontab, save your input format will be verified, please use it carefully, otherwise there will be unexpected problems. A total of 6 fields, space-delimited, specific meaning of each field please refer to here, no longer repeat: http://diamonder.blog.51cto.com/159220/282542

3.3 Below is add HDD & partition & Mount (high-risk operation, novice use caution!) )

Friendly tip: partition operation is high-risk operation, especially novice students do not try in the production environment, otherwise the consequences of their own!

For a more detailed partitioning tutorial, see:

Linux disk partition fdisk command details http://linux008.blog.51cto.com/2837805/548711

fdisk/dev/SDB input m---n---p---1--Enter---Enter---p---/dev///dev/sdb1/disk2 /Added in /etc/fstab:/dev/sdb1            /disk2                  ext3    defaults        12

4, through the fstab set up the pit of the boot mount

Fstab file Everyone is familiar with Linux at boot time through the information in the fstab to mount each partition, a typical partition entry is like this:

/dev/sdb4/mnt/usb vfat utf8,umask=0 0 0

/DEV/SDA4 is required to mount the partition, SDA4 is the Linux detection hard disk in order to the partition naming, generally speaking, this name does not change, but if you have more than one hard disk, hard disk in the computer in order to change the time, the same name may represent different hard disk partitions, if you are from the USB Device startup, and the insertion Order of other USB devices can also cause difficulty in zoning recognition.

Therefore, the above 3.2 section of the configuration directly write/dev/sda6 is a big risk, the reboot after the order of the hard disk may change, for example, you put Nginx user log on a separate partition, then after restarting although set Fstab, However, because the sequence changes the same partition number may represent a different hard disk partition, this will cause the data service on some partitions to be unavailable.

(PS: At the beginning of the article said in the review before the load configuration of the students found a buried thunder, it is the above problem. )

This time the UUID comes in handy, the UUID is universally unique Identifier, that is, each partition has a unique UUID value, so there is no problem of partition recognition confusion.

Mount the partition with a UUID in Fstab, which looks like this:
Uuid=1234-5678/mnt/usb vfat utf8,umask=0 0 0
You can mount the partition correctly by filling in the appropriate UUID values for the partition after the uuid=.
So how do we know the UUID of a partition?
There are 3 ways to do this:

4.1 By browsing the device file information under/dev/disk/by-uuid/
# ls-l/dev/disk/by-uuid/------1-:  0909-090b. /.. /1-7c627a81-7a6b-: 4806 -987b-b5a8a0a93645. /.. /

4.2 via vol_id command
# vol_id/dev/sdb5id_fs_usage=Filesystemid_fs_type=vfatid_fs_version=fat32id_fs_ UUID=0909-090bid_fs_uuid_enc=0909-090bid_fs_label=Swapid_fs_label _enc=Swapid_fs_label_safe=swap

4.3 via blkid command
# blkid/dev/sdb5/dev/sdb5:label="SWAP" uuid="0909-090b  "type="vfat "


All three methods can be used to obtain the uuid,uuid of the partition according to the partition, the length and format are different.

For example, I finally put the/DEV/SDB in the/data1 directory (not reassuring to restart or generate files under test, see Mount Partition space is occupied not):

File system       Type   capacity  used  available% mount point /dev/sda3      ext4   518G  2. 7G  489G    1%/tmpfs          tmpfs   16G     0   16G    0/dev/SHM /dev/sda1      ext4  1008M   61M  896M    7/boot/dev/sdb       ext4   1. 8T  1. 1G  1. 7T    1/data1

Grep-v'#'/etc/fstab |column-Tuuid=0C685E8B-DBB3-4A1C-A106-3F1716AB34DD/EXT4 Defaults,noatime1  1UUID=2d7f1bcf-06d1-486e-87df-404ba670fcd9/boot Ext4 Defaults,noatime1  2UUID=248e7a99-b459-4800-BBD3-354047E49A2F Swap swap Defaults,noatime0  0Tmpfs/dev/shm Tmpfs Defaults,nosuid,noexec,nodev0  0devpts/dev/pts devpts gid=5, mode=620                0  0Sysfs/sys SYSFS Defaults0  0proc/PROC proc Defaults0  0UUID=870ebaf6-727f-48d3-b60c-f203339d94ac/data1 Ext4 Defaults,noatime0  0
5. FAQ:
    • The mount point must be a directory.
    • A partition is mounted on an existing directory, and this directory may not be empty, but the previous content in this directory will not be available after mounting. The same is true for the mounting of file systems created by other operating systems, and after uninstallation, the previous files of the directory are still there and there will be no loss.
    • The directory occupies only one inode in the disk, storing information such as file attributes.
    • Any partition must be mounted on a directory.
    • A directory is a logical distinction. Partitioning is a physical distinction.
    • Disk Linux partitions 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.
    • A partition can be hung in multiple directories, but in turn a directory can only be a mount point for a partition.

Linux disk and partition detailed

Related Article

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.