How does Linux partition the disk and mount it?

Source: Internet
Author: User

How is Linux going to partition a piece of disk partition and use it? Processes such as

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3C/20/wKioL1PA5fvj5VhvAADvlciwNEs674.jpg "title=" The process of formatting a disk partition. png "alt=" wkiol1pa5fvj5vhvaadvlciwnes674.jpg "/>

1. Partitioning

(1), first , know whether a disk has space is not partitioned?

Partitioning is based on the cylinder (cylinders), there is no remaining cylinder can be partitioned again, otherwise it is not possible.

However, it is important to note that:

We can divide up to 4 primary partitions, and if we look at the remaining cylinders (cylinders) on the disk, we are no longer partitioning. Which means the remaining cylinders

is no longer able to use it. Unless partitions are re-partitioned on the disk.

To see if there are any remaining cylinders:

[[EMAIL PROTECTED] ~]# FDISK  -L /DEV/SDADISK /DEV/SDA: 85.9 GB,  85899345920 bytes255 heads, 63 sectors/track, 10443 cylindersunits =  cylinders of 16065 * 512 = 8225280 bytesSector size  ( logical/physical): 512 bytes / 512 bytesi/o size  (minimum/optimal):  512 bytes / 512 bytesdisk identifier: 0x00088117   device  boot      start         end       Blocks   Id  System/dev/sda1   *            1           26      204800   83  Linux/dev/sda2               26        7859     62914560   8e  Linux LVM/dev/sda3             7859        8120      2103516   83  Linux                       |            |             \|/         \|/             Start cylinder for disk partitions     end cylinder for disk partitions

Description

You can use the above method to see if a disk is idle. Because the disk partition is based on "cylinder cylinders",

Therefore, if the end of the last partition is less than the total number of cylinders on the disk, it indicates that the disk has no broken cylinders.

If the end cylinder number of the last partition equals the total number of cylinders on the disk, all cylinders of the disk are partitioned.

(2), using the tool : "fdisk" "Sfdisk" "parted" partitioning.

"Fdisk" is an interactive disk partitioning tool.

[[email protected] ~]# fdisk /dev/sda --> after entering the "Fdisk" interface, use the following command to complete the disk partitioning operation                         m          See Help for Fdisk        p          list disk Partitions        n          Create a new partition       d           Delete Partitions                        t           specifies what system is used for the partition is mainly corresponding to the file system.       w          Save Exit        q          Do not save exit

This completes the partition creation of the disk. The kernel itself does not recognize the partition that was just created. We're going to install the software on the newly created partition (that is, the format partition, which is the file system),

The kernel must be aware of the partition. Otherwise, the file system cannot be created on the partition.

2. Let the kernel recognize the partition , the CentOS 5 version and the CentOS 6 version use the same tool.

CentOS 5 uses "partitions" CentOS 6 with "Partx" or "Kpartx"

(1), How to know if the kernel recognizes the disk and partition it? Some information about the kernel work can be/proc by providing an interface to the user space through the kernel.

[[email protected] ~]# cat /proc/partitionsmajor  minor   #blocks   name   8         0   83886080 sda   8        1      204800 sda1   8         2   62914560 sda2   8         3    2103516 sda3 253        0    20971520 dm-0 253        1     2097152 dm-1 253        2   10485760  dm-2 253        3   20971520 dm-3 

Description: The disk partition identified by the kernel is identified above. If the partition you just created is not listed, you should notify the kernel.

(2), how to notify the kernel to identify the newly created partition

"Kpartx" is an upgraded version of "Partx"

Partx-a devoce kpartx-a devoce kpartx-f devoce kpartx-fa Devoce

If the kernel recognizes the partition you just created, you can create the specified file system on that partition.

3. Format (create file system)

(1), select File System .

File system is also a software, it is the role of direct management of the files on the disk. The software is different from the usual software, it is directly to do the kernel, it is usually made into a kernel module. There are many software that can implement the same kind of functions, such as: the software (file system) that manages the files on disk: Ext2, ext3, Ext4, XFS, UFS, Ceph, Htrfs, etc.

Each of these file systems has its own characteristics, and they have different performance capabilities in different scenarios. Therefore, we have to choose the software (filesystem) that manages our disk according to the actual application. This must first understand what their characteristics are. According to the actual application, select the file system that best meets the needs of the application. For example: one file that we want to store is usually 16M, so choose a file system that supports large file storage. Some file system supported disk blocks (block), very large. If we set the block size when we created the file system 8m,2 block can save a file. If we create a file system, the block size is 2M.

Then we need 8 pieces of disk to store 16M of data. These 8 blocks need not be contiguous on disk, so "asynchronous IO" is generated. The speed is certainly much slower than storing a file on a block of disk.

However, the file system we choose to support large disk blocks is possible.

We have chosen the file system that best suits the current application and the operating system support is available. Because the file system is managed by the kernel. So how do we know if the operating system we are using supports it? With CentOS 6

For example:

[[email protected] ~]# cat /proc/filesystemsnodev    sysfsnodev   rootfsnodev   bdevnodev    procnodev   cgroupnodev   cpusetnodev   tmpfsnodev    devtmpfsnodev   binfmt_miscnodev   debugfsnodev    securityfsnodev   sockfsnodev   usbfsnodev   pipefsnodev    anon_inodefsnodev   inotifyfsnodev   devptsnodev    ramfsnodev   hugetlbfs        iso9660nodev    pstorenodev   mqueuenodev   selinuxfs         ext4nodev   rpc_pipefsnodev   autofs 

With this approach, we can tell if CentOS 6 supports the file system we choose.

The user is through, VFS (virtual file system), dealing with many of the underlying file systems. VFS are an abstraction layer of these file systems at the bottom. So, we can think of this as long as the VFS supports the file system. Linux systems are supported.

Note: Sometimes we have this situation: through the official Linux, know to support the file system, but CentOS does not support. What is the reason for this?

Because, when compiling the Linux kernel source code, the function that supports the file system is closed. If we want to use the file system again, we only have to recompile the kernel.

We can see how the file /boot/config-2.6.32-358.el6.i686 is configured when the kernel is compiled. We can also refer to this configuration file, and then re-compile the kernel after the functionality of the file system is enabled.

(2), use the tool to install the file system (format). "Mkfs" or "MKE2FS"

Formatting will organize sectors (512) into blocks, and when we store data, we store it in blocks, such as: our block size is 2M, and we want to store 5M size files. Then we need to use 3 disk blocks (block) to store the file. The remaining 1M idle is not used to store other file data. It occupies 1M of storage space (waste) So, we partition the time according to the actual need to set the size of blocks (block).

If our partition disk space is fully used, it becomes awkward when the system administrator makes maintenance. So we have to make room for the administrator to perform maintenance operations.

In Windows systems, different disks can be named differently. Linux systems are also available, but they are called "volume labels." However, the calculation identifies the partition or is based on the device number. It's just a sign.

"MKE2FS" the command is highly customizable to the file system, so choose this command to customize the file system that fits our needs.

USAGE:MKE2FS OPTIONS ...    Device-c the detection block. Create file system-t {EXT2,EXT3,EXT4} Specify file system-B {1024,2048,4096} specify block Size-l LABEL Specifies the volume label-j equivalent to-t ext3-i # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Create Innode 5% of space. Reserved block count reserved blocks. Default Reservation 5%

4. Mounting

In the Linux system, the new partition format is not ready to use directly, you need to "mount" to use. This is not like Windows. Linux hierarchical inverted-tree structure to manage directory files,

All directory files belong to the root (/), of course, we have access to a directory file is usually root (/), first-level access. such as: Visit the process of/var/log/message . It can be seen that we visit a file several times to check the Inode table. To increase the speed of the table, the system caches the Innode table in the memory buffer. The speed of accessing the memory is much faster than accessing the disk. It is also common to cache the corresponding relationship between the directory files accessed by the user and the inode. The next time you access the data, you can go directly to the disk and fetch the data. This data is usually stored in buffer and cached.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3C/23/wKiom1PA6bfSOJAvAAIYxpo04ZM476.jpg "title=" The process of locating a file. png "alt=" wkiom1pa6bfsojavaaiyxpo04zm476.jpg "/>

We visit a file to go through a lot of search procedures, especially when the file is located in a deep directory. So, if our file

The closer to the root (/) in the Linux directory tree, the quicker it is to access the file.

Since we have only one (root) access to the file entry on the disk, we want to associate the newly formatted partition with a directory under the root (/). Let it belong to a member of the root (/). Then the directory is

Access to the partition device, but it still belongs to the root (/). This makes the hierarchy of this hierarchy (partitions belong to the first layer of the file tree). Mount using the Mount command:

mount [option]... [-t fstype] [-o option]  Equipment   mount points                      Specify file System    Option parameters for the device-t       fstype     specify the file system type (typically not required, auto-identify)-R        readonly    read-only Mount-w        read and  write    read-Write mount-l        specifies the device as a volume label,  mount -L MYDATA  mount point-u        Specify the device in uuid  mode    mount uuid= ' UUID '   mount point-a        automatically mount all (defined in/etc/fstab file) Support for automatic mounting of all devices-n        mount, do not update/etc/mtab files-o   option     is actually the act of specifying the data to be manipulated on the device.      async                Asynchronous i/o  is asynchronous when it writes data to the partition. Data is temporarily stored in memory                            then synchronize the data once to disk. Although this improves the                 of write operation in certain procedure            performance, but it is directly considered for applications with high data security.      sync                  Sync i/o      atime/noatime         whether files and directories are updated when the most recent access timestamp is more busy system see                            Close. Because, updates need to be written, additional work is added. If you can ignore it, you can ban                            stop.                          auto/noauto           Whether the device supports "mount -a" auto mount. Device written in  /etc/fstab  file                            You can use this method to mount automatically. The     diratime/nodiratime   directory is accessed when the last access timestamp is updated     dev/nodev              whether to support the use of devices on this device      exec/noexec           whether the binary program files on this device are allowed to execute      suid/nosuid           whether to support the use of suid   on files on this device   remount               re-mount, Typically used to reload the specified Mount option when not uninstalled     ro                     Read Only      rw                     Read     acl   Write                  whether this device supports the use of FACL , which is not supported by default.

Note: You can not specify options when mounting, as long as the default options match the requirements of your current system application, what are the default options?

Defaults Use default OPTIONS:RW, suid, Dev, exec, auto, Nouser, Async,and relatime.

Obviously, if we need to use the ACL function, we can not use the default.

The Linux system identification device relies on the device number to view the device files in the/dev directory (one access entry for the device). The system is more user-friendly, using a string to identify the device, such as: SDA1 represents the first partition of the first disk. But the system identifies the SDA1 device or depends on the device number. Like we can also create a volume label for a partition to identify the partition. So when we mount the device, there are a number of ways to identify the device that is mounted.

As follows:

Use UUID numbers to identify devices

[[email protected]/]# mount-o ACL uuid= "47b2cb89-20de-4adb-8cc5-e45e172d0028"/mydata[[email protected]/]# Mount | grep "\<sda3\>"/dev/sda3 on/mydata type EXT4 (RW,ACL) [[email protected]/]# Mount-o acl-u 47b2cb89-20de-4adb-8cc5 -e45e172d0028/mydata[[email protected]/]# Mount | grep "\<sda3\>"/dev/sda3 on/mydata type Ext4 (RW,ACL)

mount a device using the device name

[Email protected]/]# mount-o acl/dev/sda3/mydata[[email protected]/]# Mount | grep "\<sda3\>"/dev/sda3 on/mydata type Ext4 (RW,ACL)

To mount a device using a custom volume label

[Email protected] mydata]# mount-l mydata/mydata[[email protected] ~]# Mount | grep "\<sda3\>"/dev/sda3 on/mydata type EXT4 (rw)

Description: Although they can all identify the device and mount it successfully, they are different in the case of a host of many disks. It is best to mount it using the UUID method.

The UUID is a unique device identifier and will not be duplicated. is the lifetime sign of the device. As our * * *.


Add:

"Blkid" View information for a specified block device

[Email protected] ~]# blkid/dev/sda1/dev/sda1:uuid= "12e178c7-8a7e-4d2e-a33b-b3b17f8ef842" type= "Ext4"

To modify the parameters properties of a partition:

Tune2fs-j ext2 upgrade to ext3. Note: You can only upgrade non-degraded.      However, we can explicitly specify that the log function is not used when mounting.      -L LABEL Modify volume label-M # Modify reservation percent-O [^]feature enable the specified attribute, the attribute is pre-added ^, which indicates that this feature is turned off. -O [^]mount-options to start or close the specified mount option


This article is from the "Linux" blog, so be sure to keep this source http://9528du.blog.51cto.com/8979089/1437388

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.