[Linux] hard disk partition Mount __linux

Source: Internet
Author: User
Tags uuid web hosting ide hard drive

Last week in doing the expansion of the log machine, found that yun-dimensional students will be a hard disk mount point is not consistent with the previous log machine, considering this will bring trouble to future maintenance, and then try to modify, at the same time, review the log machine before the Mount configuration, found that there is a chance to drop the pit at any time ... As for what pits, I will explain at the end of the text.

So, it feels simple, maybe a command to fix things, however, many children's shoes may be unknown, pure copy paste online command, it is easy to dig pits buried thunder, today to talk about the disk partition, mount the problem of Linux, the length of the limit, will not chat too low-level, pure when the popular Science bar ~ 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 generally use only two partitions, one is the primary partition (Primary partion) is an extended partition (extended partition), the primary partition can be used immediately, but can not be partitioned, The extended partition must be partitioned again before it can be used, meaning it must be partitioned two times. So what is divided by the extended partition?  It is a logical partition (Logical partion), and logical partitions are not limited in number. 1.2 Meaning of drive markings

For students who are accustomed to using DOS or Windows, several partitions have several drives, and each partition gets an alphabetic identifier, which can then be used to specify the files and directories on the partition, and their file structure is independent and very well understood. But for Red Hat Linux novices, it's a bit annoying. Because for Linux users, regardless of a few partitions, are scored to the directory use, it ultimately has only a root directory, a separate and unique file structure. Each partition in Red Hat Linux is used to make up the entire filesystem, because it employs a processing method called mount point, which contains a complete set of files and directories and links a partition to a directory. A partition to load is obtained under a directory in the Linux storage space.
Now let's look at how Red Hat Linux drives are identified. For IDE hard drives, the drive identifier is "hdx1", where "HD" indicates the type of device the partition is in, and this is the IDE hard drive. "X" is the disk number (A is the base disk, B is the basic subordinate disk, C is the secondary master disk, D is the secondary slave disk, "1" represents the partition, the first four partitions are numbers 1 through 4, they are primary or extended, and the logical partitions begin at 5. Example, Hda3 is represented as the third primary or extended partition on the first IDE hard disk, HDB2 as the second primary partition or extended partition on the second IDE hard disk. The SCSI hard drive is identified as "sdx1", the SCSI hard drive is "SD" to indicate the type of device the partition is located in, and the rest is the same as the IDE hard disk presentation, no longer repeat.
As we can see from the above, Red hat Linux partitions are different from other operating system partitions, and its partition format is commonly used in EXT3 and swap two kinds, Ext3 for system files, swap as Red Hat Linux swap partitions (equivalent to virtual memory files in Windows). Now we can see that red Hat Linux requires at least two dedicated partitions (Linux Native (local) and Linux swap). Red Hat Linux cannot be installed on the dos/windows partition. In general, we install Red Hat Linux with one or more hard disk partitions of the type "Linux Native", but each partition in Red Hat Linux has to specify a mount point, which tells Red Hat Linux to start up , which partition to use for this directory. For a "Swap" partition, it is generally defined, and it is not necessary to define a mount point.
Let's start with a preliminary understanding of "Linux Native" and "Linux Swap".
A swap partition is a switched partition of the Linux storage data, which mainly saves the data temporarily from the main memory, redeployment the memory when it is needed, and does not specify the "Mout point" (Mount) for the partition used as swap, since it acts 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 where system files are stored, generally used EXT3 partition type, for Red Hat Linux, there is a larger choice, you can put the system files in several areas to install (must be described mount point), can also be installed in the same partition (mount point is "/").1.3 Why do you want to customize multiple partitions?

Several areas are divided into the following purposes:
In the case of no loss of data reload system, such as The independent set up/home mount point, reload the system directly marked back to/home, the data will not have any loss. Allocate appropriate file systems for different mount points to properly perform performance, such as using ReiserFS for/var, using XFS for/home, and/or using EXT4. Turn on different mount options for different mount points, such as whether immediate synchronization is required, whether the log is turned on, and whether compression is enabled. Large hard drive search range, inefficient disk quotas can only be set on partitions/home,/var,/usr/local are often separate partitions, because often operate, easy to produce debris 2, Mount point directory Introduction 2.1 Common Mount directory structure

Each hard disk is divided into partitions, each of which has its own file system. Windows assigns a single letter to each of these file systems. However, Gnu/linux uses a unique tree structure to manage files, and each file system is mounted at a location in the tree structure.
Just as Windows requires 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 of the tree structure. Any directory under the root structure can be a mount point, and you can also mount the same file system at different mount points.
The mount point is actually the entry directory for the disk file system in Linux
2.2 Common Mount directory descriptions

Directory content

/root directory, system commands and user data, etc. (if there are no separate partitions on the mount point below, they will all be in the root directory partition)
/boot boot loader Static link file that holds programs related to Linux startup
/home user directory, storing data for ordinary users
/tmp Temporary file
/usr is where the red Hat Linux system stores the software and, if possible, the maximum space should be allocated to it
/usr/local is installed from the Setup program here
/var constantly changing data, some of the server's services, logs are placed below.
/OPT (option optional) add-on application packages

/bin Basic Command Execution file
/dev Device files
/ETC host-specific system configuration
/lib Basic shared libraries and kernel modules
/media mount point for Mobile Media
/MNT for temporary mounting of file systems or other hardware devices (such as optical drive, floppy drive)
/proc System Information virtual directories (2.4 and 2.6 cores), which are generated in memory by the system itself.
/root Root User's Directory
/sbin Basic System Command execution file
/sys virtual Directory of System information (2.6 kernel)
Data provided by the/SRV system for service
/usr/x1186 x-windows directory, storing some x-windows configuration files
/usr/include system header files, storing some C-language header files
/USR/SRC Linux kernel source code, Linux system installed kernel source code are saved here
Some additions to the/bin catalogue by/usr/bin
Some additions to the/sbin catalogue by/usr/sbin
/lost+found This directory is empty in most cases. But if you're working on a sudden blackout, or if you don't shut down normally, when you restart the machine, some files won't find where they should be, and the system will put them in this directory.
/boot:/etc,/bin,/sbin,/lib, and/dev must always be physically included, otherwise you will not be able to start the system.
/home: Each user will place his private data in the subdirectory of this directory.
/tmp: Most of the temporary data created by the program is stored in this directory.
/usr: Contains all the user programs (/usr/bin), library files (/usr/lib), Documents (/usr/share/doc), and so on.
/var: All variable data, such as newsgroup articles, emails, web sites, databases, caching of package systems, and so on, will be placed in this directory. The size of this directory depends on the purpose of your computer, but for most people, it will be used primarily for the management tools of the package system. If you do server space should be as large as possible. The actual division of my server and the actual use of the size, has not actually put into use. So the/var directory doesn't use that much. The directory of the general Web hosting Web pages is the directory where the/var/www,postfix mail is stored:/var/mail,var/log, is the system logging partition,/var/spool: Some mail, news, print queues, etc.
/OPT: Storage of optional installed software.

The above describes several mount points, generally we need at least two partitions (of course, as long as one/partition also can), need a swap partition, and a "/" partition, but put some 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 is no regulation, it is entirely in accordance with the need to decide. We can use the HDD management tool disk Druid provided by Red Hat Linux to complete the partition and mount point settings.

In contrast to the above diagram and catalog introduction, you can think of the Linux system mount point as a tree
/For the tree's roots
/derivative of other mount points for the branches of this tree
The file under the mount point is a leaf
2.3 Why does Linux partition need to mount this action?

If you have read the Linux series I wrote before, then you should remember that I once marked a sentence: Linux under all documents. In other words, the Linux OS manages everything in the system as a file. Our common hardware devices in Windows (printers, network cards, sound cards ...). , disk partitions, etc., are all considered as files in Linux, access to equipment, partitions is read and write the corresponding files. 3, actual combat partition Mount 3.1 Temporary Mount

A chestnut, the original partition is as follows:

[root@sg-sl-data]# df-h
filesystem            Size  Used avail use% mounted on
/dev/sda2              20G  5.6G   13G  31%/
/dev/sda6             996M   35M  910M   4%/data
/dev/sda5             426G  199M  404G   1%/disk1
/dev/sda1             996M   46M  899M   5%/boot
tmpfs                 7.9G     0  7.9G   0%/dev/shm
3.1.1 Uninstall the partition first:Umount/disk1
Umount/data
3.1.2 Hang again:Mount/dev/sda5/data
Mount/dev/sda6/disk1
Note: As mentioned earlier, 2 partitions cannot be mounted at the same time to/data
3.2 Permanent mount: Mount automatically

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

Label=/data/data ext3 Defaults 1 2
Label=/disk1/disk1 ext3 Defaults 1 2
Modified to:
/dev/sda5/data ext3 Defaults 1 2
/dev/sda6/disk1 ext3 Defaults 1 2

Description: Fstab is the file System Allocation table configuration file, the file has a strict syntax format restrictions, similar to crontab, save will also be your input format for verification, please use caution, otherwise there will be unexpected problems occur. A total of 6 fields, spaces separated, specific meaning of each field please refer to here, no longer repeat: http://diamonder.blog.51cto.com/159220/282542
3.3 Below is added HDD & partition & Mount (high-risk operation, novice cautious use.) )

Friendship Tip: Zoning operation is high-risk operation, especially novice students do not try at random in the production environment, or the consequences of the ego.

For more detailed zoning tutorials, see:

Linux disk Partitions fdisk command detailed http://linux008.blog.51cto.com/2837805/548711

Fdisk/dev/sdb
 
input m---n---p---1--carriage return---carriage return---p---w
 
mkfs.ext3/dev/sdb1
 
mkdir/disk2
 
mount/dev/sdb1/ disk2/
 
Add in/etc/fstab:
/dev/sdb1            /disk2                  ext3    defaults        1 2
4, through the Fstab set boot mount of the pit

Fstab files are well known to all, and Linux starts by mounting each partition through the information in the fstab, a typical partition entry like this:

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

/DEV/SDA4 is the partition that needs to be mounted, SDA4 is the Linux detection of hard disk in order to name the partition, generally speaking, this name will not change, but if you have more than one hard drive, the computer in the order of the change in the sequence, the same name may represent different hard disk partitions, if you are from the USB Device startup, and the insertion order with other USB devices can also lead to difficulty in partitioning the identification.

Therefore, the above 3.2 section of the configuration directly write/dev/sda6 is a great hidden trouble, the order of the hard drive after the restart may change, such as you put the Nginx user log on a separate partition, then after the reboot although set the Fstab, However, due to the fact that the same partition number may represent different partitions of the hard disk, the data services on some partitions will become unusable.

PS: The beginning of the article said in review before the classmate's mount configuration found buried a ray, it is the above problem. )

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

To mount the partition in Fstab with a UUID, it looks like this:
Uuid=1234-5678/mnt/usb vfat utf8,umask=0 0 0
You can mount the partitions correctly by filling in the corresponding UUID values for the partition after uuid=.
So, how do we know the UUID of a partition?
There are 3 different ways:
4.1 By browsing the device file information under/dev/disk/by-uuid/ # ls-l/dev/disk/by-uuid/
------
lrwxrwxrwx 1 root 10-13 09:14 0909-090b->. /.. /sdb5
lrwxrwxrwx 1 root 10-13 09:13 7c627a81-7a6b-4806-987b-b5a8a0a93645->. /.. /sda4
.....
4.2 through vol_id command # VOL_ID/DEV/SDB5
Id_fs_usage=filesystem
Id_fs_type=vfat
Id_fs_version=fat32
id_fs_uuid=0909-090b
id_fs_uuid_enc=0909-090b
Id_fs_label=swap
Id_fs_label_enc=swap
Id_fs_label_safe=swap
4.3 through blkid command # BLKID/DEV/SDB5
/dev/sdb5:label= "SWAP" uuid= "0909-090b" type= "VFAT"
These three methods can be used to obtain the partition's uuid,uuid depending on the partition, the length and format are different.

For example, I finally put the/dev/sdb mount in the/data1 directory (not reassuring to restart or generate file test, see the space of the Mount Partition is occupied):

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-t uuid=0c685e8b-dbb3-4a1c-a106-3f1716ab34dd/ext4 defaults,noatime 1 1 Uuid=2d7f1bcf-06d1-486e-87df-404ba670fcd9/boot ext4 defaults,noatime 1 2 uuid=248e7a99-b459-480 0-BBD3-354047E49A2F swap swap defaults,noatime 0 0 tmpfs/dev/ SHM tmpfs defaults,nosuid,noexec,nodev 0 0 devpts/dev/pts devpts gid=5,mode=62                                        0 0 0 Sysfs/sys sysfs defaults 0 0 proc /proc proc defaults 0 0 uuid=870ebaf6-727f-48d3-b60c-f 203339d94ac/data1 EXT4 defaults,noatime 0 0 
5. FAQ:The mount point must be a directory. A partition is mounted on an existing directory that may not be empty, but the previous contents of this directory will not be available when it is mounted. This is also true for file systems that are built by other operating systems, and after uninstalling, the files before the directory are still there without any loss. The directory only takes up an inode in the disk and holds information such as file attributes. Any one of the partitions must be mounted to a directory. The 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 of the Linux files and directories are located, and you need to mount the previous disk partition. A partition can be hung in multiple directories, but in turn a directory can only be a mount point for one partition. 6, refer:

[1] One of Linux introductory notes: System partition and mount point http://newthink.blog.51cto.com/872263/223795/

[2] mount point http://wiki.linuxdeepin.com/index.php?title=%E6%8C%82%E8%BD%BD%E7%82%B9

[3] What is called "Mount", "mount point". The concept http://bbs.csdn.net/topics/380197703 in Linux file system

[4] Introduction to Linux file Systems http://alicsd.iteye.com/blog/816268

[5] The eighth chapter, Linux disk and file system Management http://vbird.dic.ksu.edu.tw/linux_basic/0230filesystem.php

[6]/etc/fstab detailed http://diamonder.blog.51cto.com/159220/282542 http://dikar.iteye.com/blog/361659

[7] How to add a new hard drive using Fdisk under CentOS http://343308530.blog.51cto.com/7202597/1251558

[8] Multi-disk partition management Fdisk http://blog.fens.me/linux-fdisk/

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.