Disk storage and file system

Partition

Two partition formats: MBR, GPT

MBR partition

The partition table information of MBR partition disk is stored in A total of 512 bytes in the 0th sector of the hard disk track 0
The first 446 bytes are the bootloader
The middle 64 bits are the disk partition table information, each partition information occupies 16 bytes, and a total of 4 partitions are stored. (This paragraph is the data that needs to be backed up)
The last 55AA is the end flag

MBR partition structure

1. Hard disk master boot record MBR consists of 4 parts
2. The main boot program (offset address 0000H–0088H), which is responsible for loading from the active partition and running the
system boot program
3. Error information data area, Offset address 0089H–00E1H is error information, 00E2H–01BDH is all
0 bytes

  1. The partition table (DPT, Disk Partition Table) contains 4 Partition item, offset address 01BEH–01FDH,
    Each partition table item is 16 bytes long, and a total of 64 bytes is partition item 1, partition item 2, partition item 3, and partition item 4
  2. < li>End flag word, the 2 bytes of offset address 01FE–01FF is the end flag 55AA

MBR structure

Disk storage and file system

GPT partition

Support 128 partitions, use 64 bits, support 8Z (512Byte/block) 64Z (4096Byte/block)
Use 128-bit UUID to represent the disk and partition GPT partition table
Automatically back up two copies at the beginning and end, and have CRC check bit
UEFI (Unified Extended Firmware Interface) hardware supports GPT to enable the operating system to start

GPT partition structure

disk storage And file system

Commands for managing partitions

List block devices< /h3>

lsblk

List the information of all available block devices, and also display the dependencies between them
?-a: display all devices
? -b: Display device size in bytes
? -f: Display file system information

Create partition tool

fdisk creates MBR partition

?-l [-u] [device…] View partition

Subcommand

p Partition list
t Change partition type
n Create new partition
d Delete partition
v Verify partition
u Convert unit
w Save and exit
q Exit without saving

gdisk creates GPT partition

?? Fdisk-like GPT partition tool

parted advanced partition operation

h3>

?? The parted operation takes effect in real time, please use it carefully.
?–l: List partition information

Sync partition table

  1. Check whether the kernel has recognized the new partition
    cat /proc/partations
  2. centos6 notifies the kernel to reread the hard disk partition table
    for adding partitions
    partx -a /dev/DEVICE
    kpartx -a /dev/DEVICE -f: force
    Delete partition with
    partx -d –nr MN /dev/DEVICE
  3. CentOS5, 7 use partprobe
    partprobe [/dev/DEVICE]
    Reread the partition table, When the deleted file appears, it still takes up space. Partprobe can reread the partition without restarting.

File system

File system is the method and data structure used by the operating system to identify files on storage devices or partitions; that is, on storage devices Methods of organizing files. The software structure responsible for the management and storage of file information in the operating system is called the file management system, or file system for short. A system for protecting and retrieving stored documents. Specifically, it is responsible for creating files for users, storing, reading, modifying, dumping files, controlling file access, security control, logging, compression, encryption, etc.

Files supported in Linux System

ll /lib/modules/uname –r/kernel/fs

Create a file system

mkfs< br>mkfs.FS_TYPE /dev/DEVICE
?-t: Specify file system

Create ext file system

fs: ext series file system Special management tool

?-t {ext2|ext3|ext4} Specify file system type
?-b {1024|2048|4096} Specify block size
?-L’LABEL’ setting Volume label
? -j is equivalent to -t ext3
?? mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
? -i # is how many words in the data space Section to create an inode; should not be less than the block size
?-N # Specify how many inodes are created in the partition
?-I Disk space occupied by an inode record, 128—4096
?-m # Default 5%, reserved space for managers as a percentage of total space
?-O FEATURE[,…] Enable specified features
?-O ^FEATURE Close specified features

File system tag

blkid: block device attribute information view

?-U UUID Find the corresponding device according to the specified UUID
?- L LABEL finds the corresponding device according to the specified LABEL

e2label: LABEL for managing ext series file system

findfs: Find partition

?findfs [options] LABEL=\

tune2fs: reset the adjustable parameter values ​​of the ext series file system

?- l View the super block information of the specified file system; s uper block
?-L’LABEL’ modify volume label
?-m # modify the percentage of space reserved for administrators
?-j upgrade ext2 to ext3
?-O file system attributes Enable or disable, -O ^has_journal
? -o adjust the default mounting options of the file system, -o ^acl
?-U UUID modify the UUID number

dumpe2fs

< p>Group disk block management
?-h: View super block information, do not display group information

File system detection and repair

Often After a crash or abnormal shutdown, mount the file system marked “no clean”
Note: Do not repair in the mounted state

  1. fsck: File System Check
    ?fsck.FS_TYPE
    ?fsck -t FS_TYPE
    ??-p auto repair errors
    ??-r interactive repair errors
    ?FS_TYPE must be the same as the file type already on the partition
  2. e2fsck: special detection and repair tool for ext series files
    ??-y automatically answers yes
    ??-f mandatory repair

Use the mount command to mount the file system

Mount: The behavior of establishing an association between an additional file system and an existing directory of the root file system, thereby making this directory an entry for other files< br>Associate the device with the mount point: mount Point
??mount
When unmounting: you can use the device or the mount point
??umount device name|mount point
mount Click the original file to be temporarily hidden after the mount is completed
The mount point directory is generally empty

mount

By viewing /etc The /mtab file displays all currently mounted devices

Common command options

-t vsftype ?? Specify the file system type on the device to be mounted
-r readonly ,?? Read-only mount
-w read and write, ?? Read-write mount
-n ?? Do not update /etc/mtab, mount is not visible
-a ?? Automatically mount Load all devices that support auto-mounting (defined in the /etc/fstab file, and auto function in the mount option)
-L’LABEL’ ?? Specify the mount device with the volume label
-U ‘UUID’ ?? Specify the device to be mounted by UUID
-B, –bind ?? Bind the directory to another directory
View all mounted devices tracked by the kernel?? cat / proc/mounts
-o options:?? (options for mounting the file system), multiple options are separated by commas

ync ?? ?? ?? asynchronous mode
sync ?? ?? ?? Synchronous mode, when memory changes, write to disk at the same time
atime/noatime ?? Contains directories and files
diratime/nodiratime ?? Directory access timestamp
auto/noauto ?? Support for automatic mounting, do you support the -a option
exec/noexec?? Do you support running applications on the file system
dev/nodev?? Do you support using device files on this file system
suid/ nosuid ?? Does it support suid and sgid permissions?
remount ?? ?? Remount
ro ?? ?? ?? Read only
rw?? ?? ?? Read and write
user/nouser ?? Whether to allow ordinary users to mount this device, /etc/fstab use
acl ?? ?? Enable the acl function on this file system
loop ?? ?? ?? Use loop device
_netdev ?? ?? Only mount network resources when the network is available, such as: NFS file system
defaults ?? ?? Equivalent to rw, suid, dev, exec, auto, nouser, async

< /blockquote>

umount

Mount command

  1. Check the mounting situation
    findmnt MOUNT_POINT|device
  2. View the processes that are accessing the specified file system
    lsof MOUNT_POINT
    fuser -v MOUNT_POINT
  3. Terminate all processes that are accessing the specified file system
    fuser -km MOUNT_POINT
  4. Uninstall
    umount DEVICE
    umount MOUNT_POINT

Example

Mount sdb1
Disk storage and file system
Judge whether to mount
disk Storage and file system
Disk storage and file system
Remount
Disk storage and file system
mknod create device file
disk storage and file system
Uninstall sdb2

Disk storage and file system
If it is in use, it cannot be unmounted
disk storage and file system
View The user process that is using the mounted device
disk storage and file system
Disk storage and file system
Forcibly stop using the mount point
disk Storage and file system

File mounting configuration file

Each line of etc/fstab defines a file system to be mounted

1, the device to be mounted or pseudo file system
device file
LABEL: LABEL=””
UUID: UUID=””
Pseudo file system name: proc, sysfs
2, mount point
3, file system type: ext4, xfs, iso9660, nfs, none
4, mount options: defaults, acl, bind
5. Dump frequency: 0: no backup 1: daily dump 2: dump every other day
6, the order of the file system checked by fsck: the allowed number is 0 1 2
0: No self-checking
1: First self-checking; generally only rootfs use
2: Non-rootfs use

swap swap partition

< The pre>swap swap partition is a supplement to the system RAM, and the swap partition supports virtual memory. When there is not enough RAM to store the data processed by the system, data will be written to the swap partition.
When the system lacks swap space, the kernel will terminate the process due to the exhaustion of RAM memory. Configuring too much swap space will cause the storage device to be allocated but idle, causing waste. Too much swap space will also cover up memory leaks.

Enable swap partition

swapon [OPTION]. .. [DEVICE]
-a: Activate all swap partitions
-p PRIORITY: Specify priority
??/etc/fstab In the fourth column: pri=value

Disable swap partition

swapoff [OPTION]… [DEVICE]

Swap priority

 You can specify the priority of swap partition from 0 to 32767, the larger the value, the higher the priority
If the user does not specify, then the kernel will automatically assign a priority to swap. This priority starts from -1, and each time a new one is added For swaps that do not have a user-specified priority, this priority will be reduced by one. The default priority of the swap added first is relatively high, unless the user specifies a priority, and the user-specified priority (a positive number) Always higher than the default priority specified by the kernel (it is a negative number)
Optimizing performance: distributed storage, high-performance disk storage

Leave a Comment

Your email address will not be published.