Disk Management File System under Linux Create Partitions in One Word Absolutely! !

1. Disk structure

1. Physical structure of hard disk

Platter: The hard disk has multiple platters, each platter has 2 sides

Magnetic head: One magnetic head per side

2. Data structure of hard disk

Sector: The disk is divided into multiple sector areas, each sector stores 512 bytes of data, the smallest storage unit of the hard disk

Track: Concentric circles with different radii on the same disk are circular tracks drawn by the magnetic head on the surface of the disk

Cylinder: A cylindrical surface composed of different disks with the same radius, composed of multiple tracks of the same radius circle
Hard disk storage capacity = magnetic head Number × number of tracks (cylinders) × number of sectors per track × number of bytes per sector
You can use cylinders/heads/sectors to uniquely locate each area disk on the disk a>
Interface type:

IDE (the parallel port data cable connects the motherboard and the hard disk. Its anti-interference performance is too poor, and the cable takes up a lot of space, which is not conducive to the internal heat dissipation of the computer. It has been gradually replaced by SATA.)

SATA (strong anti-interference, supports hot swap and other functions, fast speed, strong error correction ability.)

SCSI (Small Computer System Interface, scsI hardware is widely used in workstation-level personal computers and servers. It has low CPU usage during data transmission, fast rotation speed, and supports hot swapping, etc.)

SAS (is a new generation of sCs1 technology, which is the same as SATA hard disk. It adopts serial technology to obtain higher transmission speed, which can reach 6Gb/s.)

Fiber Channel (Learn About)

3. Disk partition structure

  • The number of primary partitions in the hard disk is only 4
  • The serial numbers of primary partitions and extended partitions are limited to 1~4
  • Extended partition is divided into logical partitions
  • Logical partition serial numbers will always start from 5

 

 

 2. MBR and GPT disk partitions

1. Introduction to partitions

Reason for partitioning:

Optimize I/O performance
Implement disk space quota limits
Improve repair speed
Isolate systems and programs< /span> Use different file systems
Install multiple os

Advantages of 1.2 partitioning:

Easy to manage
Optimize read and write performance

Disadvantages of 1.3 partitioning:

Once created, it cannot be modified. If you want to modify it, you can only infer reconstruction, reformatting, and data loss
It is not flexible enough. The space can only come from one hard disk and must be continuous. Space
There is no backup redundancy function, there is no backup, and you need to rely on engineers for manual backup

1.4 Types of partitions:

Primary partition: The partition table stores the distribution range, starting from where and ending     Use partition number 1-4 directly < /span> 


Extended partition: The range of the logical partition is stored        cannot be used directly, it must be in the extended partition It can be used only if it is divided into logical partitions on the basis of (use its first sector to store the partition table). It is a special primary partition  Partition number 1-4


Logical partition: can be used directly, but it must depend on the extended partition partition number 5+< /span>

2.MBR partition (can only be divided into 4 areas at most, and can only partition hard disks smaller than 2T)

①MBR is located in the first physical sector of the hard disk
②MBR contains the main boot program of the hard disk and the hard disk partition table
③The partition table has 4 Each partition recording area occupies 16 bytes
④MBR is located in the first physical sector of the hard disk
⑤MBR contains the master boot of the hard disk Program and hard disk partition table
⑥The partition table has 4 partition recording areas, each partition recording area occupies 16 bytes

3.GPT partition (can be divided into 128 areas)

Use 128-bit UUID (Universally Unique Identifier) ​​to represent disks and partitions. GPT partition tables are automatically backed up in the first and last copies, and have CRC check bits. UEFI (Unified Extensible Firmware Interface) hardware supports GPT, making the operating system Can start

3. File system type

1.XFSX file system

①Partition to store file and directory data
②High-performance log file system, especially good at processing large files, can support millions of TB of storage space.
③The file system used by default in CentOS 7 system

Supplement: ext4 centos6 default file system

 2.SWAP, swap file system

Create a swap partition for Linux system
-== Generally set to 1.5~2 times of physical memory.==

3. Other file system types supported by Linux

EXT4 FAT32, NTFS, LVM

EXT4 error warning function, disk self-healing function and log function, single file 64GB

FAT32 FAT16 and can only support a maximum partition of 32GB, and a single file can only support a maximum of 4GB

4. Detect and confirm the new hard drive

Other file system types supported**

•EXT4 FAT32, NTFS, LVM

5. Detect and confirm the new hard drive

fdisk command    View or manage disk partitions (can only be divided into hard disks below 2T)

View or manage disk partitions
fdisk -L [disk device] fdisk [disk device] fdisk/dev/sdb (hard disk name)

6. Commonly used commands in interactive mode (mostly used and important)

 6.1 Commands
 

 

6.2.gdisk: Partitioning disks above 2T

6.3.parted (not recommended, effective immediately)

6.4partprobe: Partition cannot be refreshed

Reason: The partition in memory is not transferred to the system

 7. Check the disk partition status

fdisk -l [disk device]

Device (device): The device file name of the partition.
Boot: Whether it is a boot partition. If so, there will be a "*" mark.
start: The starting position (number of cylinders) of the partition in the hard disk.
End: The end position of the partition on the hard disk (number of cylinders)
Blocks: The size of the partition, in Blocks (blocks), the default block The size is 1024 bytes.
Id: The system ID number corresponding to the partition. For example, 83 represents the XFS partition or EXT4 partition in Linux, and 8e represents the LM logical volume.
82 represents the swap file system, which is swap
System: partition type.
As shown in the picture

4. View command

1.blkid: View UUID

Permanent 挂载 Using UUID

2.lsblk: View partition status

3.df: Check the mounting status

df-th humanized view

5. Disk partition experiment

1. Preparation:

  

 2.The first step

Before managing disk partitions, you need to create a new disk. You cannot directly use the system disk for management, otherwise it will cause the computer system to crash.

3. Steps to create partitions 

 fdisk /dev/sdb                 #Edit and manage hard disk sdb
n                                 #New partition
Enter                      #Default primary partition
Enter                           #Default partition number
                                                              #Default starting sector                                                                                #Set the partition size to 5G p                                     #Print View w                             #Save and exit mkfs.xfs  /dev/sdb1               #Format Establish file system mount /dev/sdb1 /mnt #Mount sdb1 to the /mnt directory lsblk





df -ht ​ ​ ​ ​ ​

 

4. Create extended partition 

Note that the option to create an extended partition is "e". The partition space can be larger because the subsequent logical partitions are separated from the extended partition.

fdisk /dev/sdb                                                                                                                                                                                                                                                     ; #Create extended partition Enter #Set the partition size to 10G p#Print View W#Save exit






(You can also not save it and then do the logic)

 

 

5. Create logical partitions

Note that the option to create a logical partition is "l", and other operations are the same as creating a primary partition before. Also note that logical partitions all start from "5".

 fdisk /dev/sdb                   #Edit and manage hard disk sdb
n                               #New partition
l                                  #Create a new logical partition
Enter       #Print View w                                                                           Save and exit mkfs.xfs /dev/sdb5                                                                                                                                                                                             Save and exit mkfs. lsblk                                                                                                                                                                                                                                                                                    







 

 

 

6. Create partition and format

After the partition is divided, it cannot be used directly. The disk needs to be formatted before it can be used.. For formatting, you only need to format the xfs format, that is, the primary partition. There are two formatting methods, one is: mkfs -t xfs /dev/sdb1 and the other is: mkfs.xfs /dev/sdb1 Note:It is best to restart the system after partitioning. Or execute the "partprobe" command to enable the operating system to detect the new partition table to prevent the existing data in the hard disk from being damaged when formatting the partition.
Use the mkfs -t xfs /dev/sdb1 command to format the sdb1 partition. The xfs in this command means that the file system type of partition 1 is xfs.

Command format 

mkfs -t file system type partition device mkfs -t xfs /dev/sdb1

or mkfs. (partition type) partition device mkfs.xfs /dev/sdb1  

 

 After the format is ready, it cannot be used directly. It still needs to be mounted. The mounting place is the mount point.​ 

! ! ! Problems you may encounter when creating partitions, formatting, and establishing file systems! ! !
Display: dev/sdb5: No such file or directory
Solution: partprobe #Refresh, re-read partition information
 

 

7. Mount

Change to the root directory and create a new directory

Because mnt is already used by the disk

Then mount /dev/sdb1 to /data1

 

 

5. Create file system swap partition

Create a swap file system
Before creating swap, the target partition should first set the partition type ID number to 82 through the fdisk tool

 1. Change the ID type after partitioning

t #Fill in the type
2 #Fill in the partition number
82 #Fill in the ID of the swap partition
p # Print and view
w #Save and exit

2. Format the swap partition

mkswap /dev/sdc2

3Enable swap partition

free -h             
#View the memory usage of the current system
 
swapon /dev/sdc2    
#Open swap partition
 
free -h             
#View the memory usage of the current system and compare it with the previous one

4. Close the swap partition:

swapoff -a

#Close all swap partitions

6. Mounting, unmounting and permanent mounting

1.mount: mount

Mount: Mount the file system and ISO image to the specified folder

Format:

mount [-t type] Storage device mount point directory
mount -o loop ISO image file mount point directory

-t: used to specify the file system type, which can usually be omitted and automatically recognized by the system.

-o: Mount parameter list, separated by English commas; if used to describe special devices, specify it with loop

2.umount: Unmount

umount: Unmount a mounted file system 

Prerequisite for uninstallation: The mounted device or directory is not in use. You must exit the mounting directory first.

Format:

umount storage device location
umount mount point directory

umount [-lf] storage device directory or mount point directory

-l means to unblock a busy file system

-f means force

3. Permanent mounting

blkid                 #View UUID number
vim /etc/fstab     #Permanently mounted
 
UUID=? /Mounted directory File format defaults 0 0
 

4. Check disk usage

Direct mount command

df [options]

-h: Display the capacity unit of the partition

-T: Display the type of file system

-i: Display the number of inode numbers of the partition

 5. Set up automatic mounting of the file system

The Linux operating system will automatically read the contents of the /etc/fstab file and automatically mount the specified file system every time it is booted. (One or two can be mounted manually, but in many cases it is a waste of time, so automatic mounting is required)

Order

vim /etc/fstab

/dev/sdb1 /opt xfs defaults 0 0

/dev/sr0 /mnt iso9660 defaults 0 0

 

 

Field 1: Device name or device volume name. (partition)

Field 2: The location of the file system’s mount point directory. (mount point)

Field 3: File system type, such as xfs, swap, etc. (file system type)

Field 4: Mount parameters, which are parameters that can be used after the "-o" option of the mount command. For example, defaults (default parameters), rw (readable and writable), ro (read-only), noexec (execution program disabled). (Mount parameters)

Field 5: Indicates whether the file system requires dump backup (dump is a backup tool). Generally, when set to 1, it means required, and when set to 0, it will be ignored by dump. (backup)

Field 6: This number determines the order in which disk checks are performed during system startup. 0 means no inspection, 1 means inspection first, and 2 means inspection second. The root partition should be set to 1 and other partitions to 2. (disk check sequence)

After entering the correct format, restart after wq, and the two written mounts will be automatically mounted during the restart.

Every time the Linux operating system is powered on, it will automatically read the contents of the /etc/fstab file and automatically mount the specified file system. So you need to save the files that need to be automatically mounted in this file.

After saving "wq", use the "init 6" command to restart, also restart the virtual machine, and then reconnect and find that the two files have been automatically mounted.

 

6.Soft raid

mdadm

-C create

-v show process

-f uninstall

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_52269501/article/details/128126092