Linux Storage Management: hard disk, partition and file system, linux partition

Source: Internet
Author: User

Linux Storage Management: hard disk, partition and file system, linux partition
Storage Management: 1. Hard disks, partitions, and file systems

Ii. Hard Disk Quota Restrictions

I. Hard Disk, partition, and file system
Physical Concept of a hard disk: the hard disk is actually composed of many circular hard disks. The hard disk is divided into single disks (one hard disk contains only one hard disk) according to the data volume that the hard disk can accommodate) or multiple disks (one hard disk contains multiple hard disks.
The hard disk contains a bone head (head) on the hard disk to read and write, the head is fixed on the arm of the manipulator, the arm of the manipulator has multiple heads, you can read. When the head is not fixed (assuming that the mechanical arm is not moving), the circle drawn from the hard disk is the magnetic track. A hard disk may have multiple hard disks. The tracks with the same radius on all disks form a cylindrical disk.
The same track on two hard disks is a cylindrical disk. This cylinder is also the smallest unit for partitioning. If you want to draw a straight line from the center of the circle, you can further split the track into sectors, and the sector is the smallest storage physical quantity on the disk. Generally, the size of a slice is 512 bytes. These are the basic components of the hard disk.
When calculating the storage capacity of the entire hard disk, the simple formula is: cylindrical * head * sector * 512 bytes
Partition: Why partition? Because we must tell the operating system that the area accessible to this hard disk is from column A to Column B, so that the operating system can control the disk head to ~ If the A-B cylinder is not specified as a partition or the D-E cylinder is a partition, the operating system does not know where to access the data, the main points of the partition size is: start and end cylinders.
Where is the information about the start and end columns of a partition stored? It is the MBR (Master Boot Recorder) Main Boot area, which is on the 0th rail of the hard disk. This is the first area that must be read first when the computer starts to use the hard disk! It records all the partition information and the location where the boot program can be written at startup. When the MBR of a hard disk breaks down, the partition information is lost, and the hard disk can be said to be dead.
MRB is generally 512 bytes, so mrb can only provide memory for up to 4 partitions, which is the primary partition P (primary) and Extended partition E (Extended) there can be a maximum of four reasons. If there are more than four partitions, 3 P + E should be used: 3 primary partitions + 1 extended partition, then, an extended partition is divided into several logical partitions.
Here is a command to back up the hard disk MBR: dd if/dev/sda/mbr bs = 512 count = 1 back up the mbr of the sda hard disk to the/mbr File

Mbr is the first area of the hard disk. Its size is 512 B. The dd command can be used to back up the disk based on the device. bs = 512 indicates the size of a block planned for the backup. If no value is specified, the default value is, count = 1 refers to the number of bs. Only mbr is backed up here, so you only need to back up the first B area. If you want to back up the entire partition: dd if/dev/sda5/sda5, if input file, of output file.

Here, a block is planned to be 4 K by default, so the mbr file occupies a block size, which wastes 4096B-512B space.
File System: After the start and end cylinders of the system partition in higher vocational colleges, then you need to format the partition as "the file system that can be recognized by the operating system" because the file systems that can be recognized by each operating system are different (windows: fat, fat32, ntfs... linux: ext2, ext3 ...), for example, windows cannot identify linux File Systems by default. Different file systems have different data reading methods.
In the final analysis, data must be stored in the hard disk. The smallest unit of data stored in the hard disk (partition) is the sector. The slice size is only 512 B. When the head is reading, it needs to move one slice and one slice. In this way, how many slice will be allocated to a GB hard disk, when reading data, the head moves one slice and one slice, which is too inefficient. To solve this problem, the concept of Logical block emerged. The block capacity is based on the size of the slice, which is an integer multiple of the slice size, 512 integer times 512, 1024, 2096...
Run the dumpe2fs-h/dev/sda command to view the block.

A file or directory is stored in one or more blocks. Assume that the block size is 2048B and the size of a file is 512B, the file occupies a block, and the capacity of 2048-512B is wasted. Therefore, when partitioning, you must plan the block Size Based on the Data Type used.
Now that block is the smallest unit in a partition, the first block in the partition records all the block, indoe, and file association information in the partition, the first block in this partition is called the super block, which is similar to the mbr area in the hard disk.

File and Directory Index and file time
Files are divided into two elements in the operating system. One is indoe, the other is block, and the other is a pointer to record the file content, while the block is the real content of the file. When reading a file, the operating system first needs to find the file's indoe, and then read the real file content according to the location of the block content of the file recorded on the indoe.
The directory is similar to a file and has two indoe and blockelements. The indoe of the Directory records the location of the block in the directory, the directory block records the indoe location information of the files in the directory. In this way, when the operating system needs to access a file, it will first find the indoe of the directory where the file is located, and find the block of the Directory through the indoe of the directory, find the indoe of the file under the directory from the block in the directory, and then know the location of the block of the file from the indoe in the file, then, read the block content of the file to read the content of the file. For example, when we cut a file in the same partition (no matter how large), the speed is much faster, and the file cut between different partitions is much slower. Why, because the block of a file exists in the same partition, changing the file location only changes the position of the indoe pointer pointing to the block, so it is very fast. However, it is slow to cut a file to another partition because the other partition does not have the block and indoe of this file.
Basically, the number of indoe files corresponds to the number of files. When the file is too large, for example, when the size of a file occupies multiple blocks, the indoe of this file points to multiple blocks. This is the reason that the operating system is installed each time and there will be less space in the air separation zone. On the one hand, the system automatically creates an indoe table to occupy space, on the one hand, the system has some reserved space by default to prevent temporary files from being generated when the application starts when the space is insufficient.
The file or directory has three time periods: Access-time, Modify-time, and Change-time.
Linux-suse: // # stat/test
Access: 06:42:14. 000000000-0400 last Object Access time
Modify: 06:42:14. 000000000-0400 last modification time of the file content
Change: 06:42:14. 000000000-0400 last modification time of file Properties
Access-time is the last Access time of the file. For example, if you have accessed the file using test restart, vi test, or cat test, the Access time changes regardless of whether the content changes.
Modify-time is the last modification time of the file content. For example, when vi is used to add or Modify the file content
Change-time is the last modification time of the file attribute. For example, if the File Permission, location (indoe changed), and group Change occur, the Change will Change.
Touch is the command for creating files. However, if you run touch test on an existing file, the three time periods of test are changed to the current time. It is mostly used for running system files generated by timestamps, service failure and other faults.
The file time displayed in ls-l is Modify-time.

Partition operations
Use fdisk in linux for disk partition planning and other operations
Use the command fdisk/dev/sda (disk device)
Go to the fdisk command interface and press h to view help
Main Parameter: p view Partition
N create a partition P for the primary partition and E for the logical Partition
D. delete a partition.
W save
Q: exit and do not save
L view the ID number of the file system
For example, create a master partition of MB and a 1 GB logical partition.
1. Add a hard disk

2. Use fdisk to open the hard disk
3. n create primary partitions and logical partitions (create from extended partitions)
4. Check the created partition for confirmation.
5. Save w

The First sector is the start and Last sector is the end of the partition. The number of the cylinder determines the partition size. The total number of cylinders in this partition can be 2048-10485759 (which should be 5 Gb). The first 2048 should be used in the indoe table, therefore, the space cylinder can be used from 2048. This disk has a total of 10485759 so many cylinders, But we generally do not know how many GB or M a cylinder is, therefore, when we start to use a cylindrical disk again, it will start from 2048 by default (it can also be used from 3048 and 5987, but this will lead to low efficiency in reading data from spatial discontiguous disks ), during the Last sector operation, we can use capacity to increase the capacity by MB, so that the system can calculate the number of cylinders and allocate 1 GB space. Remove "+" to indicate the maximum space.

6. Refresh the kernel to identify new partitions. (If you delete a partition, delete the cache record in the kernel and refresh it)
Partprobe or partx-a/dev/sdb
When you delete an existing partition and create a new partition, use partx-d/dev/sdb and then partx-a/dev/sdb.
Man's explanation for partprobe or partx:
1. partprobe is a program that informs the operating system kernel of par-tition table changes, by requesting that the operating system re-read the partition table.
2. partx-tell the Linux kernel about the presence and numbering of on-disk partitions

8. Mount and use

9. Start mounting

Supplement: 1. Hard Disk detection bad track command: fsck/dev/sdb and
2. Install the data in the memory back to the hard disk sync. You need to execute the command several times before shutdown to ensure that the data will not return to the hard disk in the memory and the data will not be lost due to power failure.

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: 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.