Knowledge about Disks

Source: Internet
Author: User

Each hard disk is composed of one or more disks. Each disk has two disks that can be read and written.

Logical composition of the hard disk:

Track: the concentric circle of the disc is called the track.

Cylinder: the same track of all disks forms the cylinder. The cylinder is the smallest unit of partition.

Sector: The minimum unit for storing data. Each slice is 512 bytes. The Slice contains user data and some identification information of the slice, such as the ID information such as the head and track in which the slice is located.


MBR: Master Boot Record

MBR is located in 512 bytes of 0 disks, 0 channels, and 0 sectors. MBR is a disk and does not belong to any partition.



MBR has 512 bytes

446 Bytes: Boot Loader (program code), which is used to load the kernel of the operating system through boot loader.

64-byte: Partition Table. A 16-byte table identifies the information of a partition. Up to four partitions can be identified. That is, primary partition + extended partition <= 4. A maximum of one extended partition can be used. An extended partition cannot be directly used and must be converted into a logical partition. For a SCSI disk, there are a maximum of 11 logical partitions, of which 1-4 are the primary and extended partitions. Therefore, for a SCSI disk, the partition range is 1-16. for hard disks with IDE interfaces, there are a maximum of 59 logical partitions in the range of 1-63.

2 bytes: magic number, which indicates whether the MBR is valid.


The file system is a management software that divides the data in a partition into two parts, one of which is called metadata (metadata, similar to the index, the stored non-data itself ), the other is the data storage area (which stores real data ). The data storage area is divided into logical storage units (blocks). Each block is numbered.



Inode bitmap

Block bitmap

Inode

Block


Superblock


Block group



Device Files: Major, minor

A device file is the entry to access a device.


Create a device file: mknod

Format: mknod [Options] Name type [major minor]

Example:

[[email protected] tmp]# mknod -m 644 frame b 100 1[[email protected] tmp]# ls -ltotal 1256-rw-r--r-- 1 root root 641020 Jul 13 22:41 aa-rw-r--r-- 1 root root 641020 Jul 13 22:30 ccbrw-r--r-- 1 root root 100, 1 jul 13 23:09 frame[[email protected] tmp]#



Master ide: master disk hda, slave disk HDB

Slave ide: master disk HDC, slave disk HDD


SCSI/SATA/USB disk: SD

First identified is SDA, followed by SDB, SDC ......


Primary and extended partitions: 1-4

Logical partition: Starting from 5.


The current system has several hard disks: fdisk-l

[[email protected] tmp]# fdisk -lDisk /dev/sda: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00047648   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          26      204800   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              26        1332    10485760   83  Linux[[email protected] tmp]#


View the specified disk information: fdisk-l Disk

Example:

[[email protected] tmp]# fdisk -l /dev/sdaDisk /dev/sda: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00047648   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          26      204800   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              26        1332    10485760   83  Linux[[email protected] tmp]#



View the disks recognized by the kernel: CAT/proc/pratitions

Example:

[[email protected] ~]# cat /proc/partitions major minor  #blocks  name   8        0   41943040 sda   8        1     204800 sda1   8        2   10485760 sda2[[email protected] ~]#


Re-let the kernel identify the Partition Table: partprobe (used in rhel5)

On rhel6, partx-A/dev/SDA is used.

[[email protected] ~]# partx -a /dev/sdaBLKPG: Device or resource busyerror adding partition 1BLKPG: Device or resource busyerror adding partition 2[[email protected] ~]# cat /proc/partitions major minor  #blocks  name   8        0   41943040 sda   8        1     204800 sda1   8        2   10485760 sda2   8        4         31 sda4   8        5    1059932 sda5[[email protected] ~]#


An inode is 128 bytes. During File System formatting, the disk space occupied by metadata has been allocated.

Block Size: 1024 bytes (1 K), 2048 bytes (2 k), 4096 bytes (4 K)

Mkfs-T ext2 = mkfs. ext2mkfs-T ext3 = mkfs. ext3mke2fs: commands used to create the ext file system. There are many parameters to choose from. -N: Not really creating a file system, but finding the location of the backup superblock. -L: Set the label-B of the file system: Specify the block size of the file system. Valid values: 1024, 2048, 4096-t: Specifies the file system type, such as ext2, ext3, ext4, the default is ext2-c: Check whether the file system has bad block. -C: checks the file system in read/write mode. -E: extension options. -J: Create an ext2 file system with the log function, that is, ext3.-F: Force create a file system, even if the file system has been attached. -I: specifies the number of bytes of an inode. -G: specifies the number of blocks in a block group. -G: specifies the number of block groups. -I: Specifies the inode size. -M #: the percentage of blocks to be retained. The default value is 5%. If the value is 3%, the value is-m 3. -M: Specifies the last Mount directory. -N: Number of inode. -U: Specifies the uuid of the file system. You can use blkid to view the UUID. Uuidgen command is used to generate UUID. -V: view the mke2fs version.
Blkid: view the file system UUID, file system type, and label example: [[email protected] ~] # Blkid/dev/sda1: UUID = "4d6d0163-a389-4bbc-ac23-ec99adcf1_c" type = "ext4"/dev/sda2: UUID = "uid" type = "ext4"/dev/sda5: UUID = "2cbaad52-8080-4bd2-ad53-010b9dfadbbb" type = "ext2" label = "mydata" [email protected] ~] #
E2label: view or define the label syntax format: e2label device [New-label] example: [email protected] ~] # E2label/dev/sda5mydata [[email protected] ~] # E2label/dev/sda5 mydata [[email protected] ~] # E2label/dev/sda5mydata [[email protected] ~] #
Tune2fs: adjusts the attributes of the file system. -J: Update ext2 to the ext3 File System lossless. -C: Maximum number of mounts. If it is 0 or-1, it will not be detected by e2fsck or kernel. -C: How many times of mounting will be checked by e2fsck at the next startup. -I # d | M | W: check interval. D is day, M is month, and W is week. 0 or-1 disable this function. -L: list the superblock information of the file system. Equivalent to dumpe2fs-H device-L: set the label. -M: Set the percentage of reserved blocks. -M: Modify the last mounted directory. -O: Mount Option. ACL is commonly used. -R: set the number of reserved blocks. -T: Set the last time e2fsck was used to check the file system. The time format is yyyymmdd [HH [mm [ss]. If it is now, it is the current time. -U: Set the username or uid-U of the user who can use the reserved Block Space: Modify the UUID. Note:-C or-I may need to disable the self-check function of the file system for the disk where the database is located. Example: [[email protected] ~] # Tune2fs-C 0/dev/sda5tune2fs 1.41.12 (17-may-2010) Setting maximal Mount count to-1 [email protected] ~] # Tune2fs-I-1/dev/sda5tune2fs 1.41.12 (17-may-2010) Setting interval between checks to 18446744073709465216 seconds [[email protected] ~] #
Set label: [[email protected] ~] # Blkid/dev/sda5/dev/sda5: UUID = "2cbaad52-8080-4bd2-ad53-010b9dfadbbb" type = "ext2" label = "mydata" [email protected] ~] # E2label/dev/sda5mydata [[email protected] ~] # Tune2fs-l mydata/dev/sda5tune2fs 1.41.12 (17-may-2010) [[email protected] ~] # E2label/dev/sda5mydata [[email protected] ~] #


View ext2, ext3, ext4 file system information: dumpe2fs-h: View superblock information. It is equivalent to tune2fs-L. If the block information is discrete, fragments are generated.
Fsck: Check and fix the file system. -T fstype: Specifies the file system type. -A: Automatic repair. Duplicate y is not required. -Y: equivalent to-A. In some file systems,-y is required. E2fsck: used to check and fix the ext file system. -A: Automatic repair. Duplicate y is not required. -F: force check, even if the file system is clean. -B backup-superblock: uses the backup superblock to repair damaged superblocks. You can use mke2fs-N device to view the backup superblock. Note: When you perform e2fsck or fsck checks on the file system, You Need To uninstall the file system. Example: [[email protected] ~] # E2fsck-F/dev/sda5e2fsck 1.41.12 (17-may-2010) pass 1: Checking inodes, blocks, and sizespass 2: Checking directory structurepass 3: Checking directory connectivitypass 4: checking reference countspass 5: Checking group summary informationmydata: 11/66384 files (0.0% non-contiguous), 4503/264983 blocks [[email protected] ~] #
Mount: Associate the new file system with the current root file system. Unmount: unassociate a new file system from the current root file system. Mount: Mount. Syntax format: Mount device mount point device: Device File: for example,/dev/sda5 volume label: Label = "XXX" UUID: UUID = "XXXX" mount point: directory. Requirements: 1. This directory must exist in advance. 2. The directory is not used by other processes. 3. If a file exists in the directory, the original file will be temporarily hidden. If mount is used directly, you can view all mounted devices in the system. Example: [[email protected] ~] # Mount/dev/sda2 on/type ext4 (RW) proc on/proc type proc (RW) sysfs on/sys type sysfs (RW) devpts on/dev/PTS type devpts (RW, gid = 5, mode = 620) tmpfs on/dev/SHM type tmpfs (RW) /dev/sda1 on/boot type ext4 (RW) None on/proc/sys/fs/binfmt_misc type binfmt_misc (RW)/dev/sda5 on/Backup Type ext4 (RW) [[email protected] ~] # Example: [[email protected] ~] # Blkid/dev/sda5/dev/sda5: Label = "mydata" UUID = "f2871de8-1e3d-4540-a3a8-30565c82fbec" type = "ext4" [[email protected] ~] # Tune2fs-C-1-I-1/dev/sda5tune2fs 1.41.12 (17-may-2010) setting maximal Mount count to-1 setting interval between checks to 18446744073709465216 seconds [[email protected] ~] # Mkdir/backup [[email protected] ~] # Mount/dev/sda5/backup [[email protected] ~] # DF-hfilesystem size used avail use % mounted on/dev/sda2 9.9g 7.3g 2.1g 78%/tmpfs 245 M 0 245 m 0%/dev/SHM/dev/sda1 194 m 28 m 156 m 16%/boot/dev/sda5 1019 M 34 m 934 M 4%/backup [email protected] ~] # Uninstall: umount format: umount device umount Mount POint Description: uninstall yes, no process uses this file system. Example: [[email protected] backup] # umount/dev/sda5umount:/backup: device is busy. (In some cases useful info about processes that use the device is found by lsof (8) or Fuser (1) [[email protected] backup] # umount/backupumount:/backup: device is busy. (In some cases useful info about processes that use the device is found by lsof (8) or Fuser (1) [[email protected] backup] #
Mount syntax format: Mount [Options] [-O options] device Mount-pointoptions:-A: All file systems mounted in the/etc/fstab file. -N: by default, the mount command writes information to the/etc/mtab file every time a device is mounted. Use the-n option to write the mounting information to the/etc/mtab file. -T fstype: specifies the type of the file system on the device to be mounted. If this option is not specified, mount will call blkid to obtain the file system type. -R: Read-Only mounting. -W: read/write mounting. -O: specify additional mounting options, that is, specify the attributes enabled by the file system. Async: writes data to the hard disk asynchronously. First save to memory, and then save to hard disk. Sync: synchronize data to the hard disk. Atime: atime is updated for each write. Each atime generates an IO. Noatime: Do not update atime. Auto: can be automatically mounted by option-. Noauto: automatic mounting is not allowed. Defaults: use the default mount option. RW, SUID, Dev, exec, auto, nouser, async, and relatime. Dev: allows the existence of device files in the file system. Nodev: The file system cannot contain device files. Exec: allows the execution of the binary program noexec: does not allow the execution of the binary program. _ Netdev: Specify the mounted device as the device on the network. If the device on the network is unavailable, it will not try to mount it all the time. SUID: allows the file system to have suid or sgid files, which may affect the file system. Remount: Try to remount a mounted file system. For example, Mount-O remount and rwrw are mounted in read/write mode. RO: Read-Only mounting. Quota: Start the quota function. -- BIND: Additional mount to another directory. Sync and async Performance Comparison: Note: The default mount option is async. [[Email protected] backup] # Time CP-r/etc /*. real0m19.830suser0m0.029ssys0m5.395s [[email protected] backup] # rm-RF * [[email protected] backup] # Mount-O remount, sync/dev/sda5 [[email protected] backup] # Time CP-r/etc /*. real2m34.755suser0m0.048ssys0m4.754s [[email protected] backup] #



This article is from the "Hezhang" blog, please be sure to keep this source http://hezhang.blog.51cto.com/1347601/1438219

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.