disk storage

Equipment type

block device

  Store and read in blocks, equivalent to batch storage and batch reading

character device

  Read and write in units of one byte or one character.

    cp -a / dev / sda / data / sda

    mknod /data/sda b 8 1 create a special type of file

Hard disk structure

  1. The head moves from the inside to the outside on the platter - left and right

  2. The platter rotates at high speed

  3. Track The gap between the circle and the circle (similar to the runway of the playground) How many sectors each track is divided into needs to occupy 6 bits to store, the maximum value is 2^6=64

  4. Sector Each sector is 512 bytes, and each track is divided into multiple sectors

  5. Cylinder The same tracks between different platters form a cylinder

Hard disk usage

  1. Partition

  2. Create a file system (format)

  3. Mount (associate the device name with the directory name)

  4. If the hard disk is not formatted, when storing and reading data on the hard disk, it can only be performed in binary (0 and 1) mode, and cannot be accessed in the form of files.

  5. hexdump -C /dev/sda | less directly reads the data on the hard disk in binary or relative format.

disk partition

 Why partition

  Optimize I/O performance

  Implement disk space quota limits

  Improve repair speed

  Isolate systems and procedures

  Install multiple OS

  using different file systems

Partitioning

  Partitions must be in a contiguous space

  4 primary partitions or 3 primary partitions + 1 extended partition + N logical partitions

    1. MBR partition

      1). hexdump -C /dev/sda -n 512 View the first 512 bytes of content on the disk

      2). dd if=/dev/sda of=/data/mbr_bak bs=1 count=512 Read the binary file content, read one byte at a time, read a total of 512 bytes

      3). dd if=/dev/zero of=/dev/sda bs=1 count=512 Use 0 device to read data to other binary files, write one byte at a time, and write a total of 512 bytes

      4). dd if=/data/mbr_bak of=/dev/sda bs=1 count=512 restore binary file content

      5). dd if=/dev/zero of=/dev/sda bs=1 count=2 seek=510 clear the 511th and 512th bytes to 0

   2. GPT partition

      4 areas: EFI information area (GPT header), partition table, GPT partition, backup area

Partitioning tools fdisk and gdisk 

gdisk /dev/sdb GPT partition tool like fdisk

fdisk -l [ -u] [device...] view partitions

fdisk /dev/sdb management partition

  Subcommand:

p partition list

t Change the partition type

n create a new partition

d delete partition

v parity partition

u Conversion unit

w save and exit

q do not save and exit

Manage partitions

   List block devices lsblk

   fdisk creates MBR partition

   gdisk creates GPT partition 

   parted advanced partition operations 

   Partprobe sync memory and partition table information on disk invalid on centos6

   partx -a /dev/DEVICE centos6 sync new partitions

   partx -d /dev/DEVICE centos6 delete partitions synchronously

The partition table is stored in two places, one in memory and one on disk.

   fdisk Views the partition table information on the disk
   Other commands such as lsblk view the partition table information on the memory

Sync partition table

See if the kernel has recognized the new partition: cat /proc/partations

centos6 notifies the kernel to re-read the hard disk partition table

add partition

partx -a /dev/DEVICE

kpartx -a /dev/DEVICE -f: force

Delete the partition with partx -d --nr MN /dev/DEVICE

CentOS 5, 7: use

partprobe partprobe [/dev/DEVICE]

File system

File system classification

Depending on whether it supports the "journal" function: Journaled filesystems: ext3, ext4, xfs, ...

Non-journaled filesystems: ext2, vfat

Components of the file system: Modules in the kernel: ext4, xfs, vfat

User space management tools: mkfs.ext4, mkfs.xfs, mkfs.vfat

Linux Virtual File System: VFS

File systems supported before checking: cat /proc/filesystems

    The software structure in the operating system responsible for managing and storing file information is called a file management system, or file system for short.

    If there is no file system, then we can only access the contents of the disk in the form of 0 and 1 binary, and cannot access the disk data in the form of a file.

Supported filesystems: /lib/modules/`uname –r`/kernel/fs

  Distributed file system

     Break up a file and store it evenly on different machines. It has the function of file backup and fault tolerance.

 journaled file system

     The function of the log is to record all the operations of the user on the data

     If there is no log system, after the user transfers the data from the disk into the memory for modification, if an exception occurs when the system has not started writing from the memory to the disk, only the modification of the memory will be lost.

     The original data on the disk is not damaged.

     If an exception occurs while the system has already started writing from memory to disk, the data in memory will be lost and the original file contents on the disk will be damaged.

     The log system will open up a separate space on the hard disk for log storage (journal). The log and the file are separated, and the log can avoid system abnormality and cause damage to the file and ensure the stability of the system.

buffer和cache

   1. When a user accesses a file, the disk will first store the file in the disk cache, and then the memory will read the data from the disk cache.

   2. The buffer is to improve the performance of writing data. First, the data that needs to be written to the disk in the memory is stored in the buffer, and then written to the disk in batches.

   3. The cache is to improve the performance of reading data. First, the data to be read is stored in the cache, and the next time it is read, it is directly read from the cache.

cluster file system

       By default, when multiple servers access the same file on the same disk at the same time, the data of the file will be corrupted. The cluster file system is to solve this problem

  Basic concepts of block groups and clusters (windows)

       The smallest unit that the file system allocates to a file, and the smallest amount of disk space a file needs to occupy, no matter how small it is.

Create a file system

  mkfs command:

    (1) mkfs.FS_TYPE /dev/DEVICE ext4 xfs btrfs vfat

     (2) mkfs -t FS_TYPE /dev/DEVICE -L 'LABEL': set volume label

    

    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324767721&siteId=291194637