How to manage disks in linux operation and maintenance examples

Preface

The storage medium in any computer system has always been a disk for storage. The mainstream storage medium is now divided into ssd and hdd. In the production environment, ssd and hdd are mixed.
RAID is a commonly used disk array in servers for a large number of reads and writes. storage

1. Disk structure

Common hard disks are divided into two types, solid-state hard drives (ssd) and mechanical hard drives (hdd). Solid-state drives are not as secure as mechanical drives, so I will briefly introduce mechanical drives.
The biggest difference between solid-state hard drives and traditional mechanical hard drives is that they no longer use disks for data storage, but use memory chips for data storage. The storage chips of solid-state hard disks are mainly divided into two types: one uses flash memory as the storage medium; the other uses DRAM as the storage medium. At present, solid-state hard drives that use flash memory as storage media are mainly used.
There are three main forms of ssd. STAT M.2 PCIE
Insert picture description here
mechanical hard disk is mainly composed of disk platters, magnetic heads, spindles and transmission shafts. The data is stored in the disk platters.
Insert picture description here
Insert picture description here
There are three conceptual
sectors here : the platters are divided into multiple A sector area, 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 head on the surface of the disk.
Cylinder: A cylindrical surface composed of different disks with the same radius, composed of multiple tracks with the same radius.

Storage capacity and interface

The storage capacity of the hard disk = the number of heads, the number of tracks and the number of sectors per track * the number of bytes per sector (512 bytes).
Cylinders/heads/sectors can be used to uniquely locate each area
on the disk. The interface is mainly used STAT and SCSL types used IDE types in the early days,
and now there are SAS and Fibre Channel.
Insert picture description here

Second, the hard disk partition steps and commands

1. MBR and partition representation

MBR translated Chinese master boot record first physical sector located at the MBR of the hard disk containing the master boot program and a partition table of the hard disk
partition table recording area has four partitions, each partition recording region occupies 16 bytes
in Devices such as hard disks and partitions in Linux are represented by files.
Insert picture description here
/dev/sda3 is the hard disk file, where /dev indicates the directory where the hardware device file is located. hd indicates the IDE device sd indicates the SCSI device a indicates the order of the hard disk. 3 indicates the order
of the partitions. The number of primary partitions in the disk is only 4 primary partitions and extended partitions. The serial number is limited to 1-4. The
extended partition can be divided into logical partitions. The logical partition number always starts from 5.

2 Add hard disk and partition operation

First add 1-2 hard disks to the virtual machine
and then use the fdisk command to view it. It
Insert picture description here
can be seen that there is a 40gb hard disk but there is no partition, so it cannot be used now.

Continue to refer to the fdisk command format as fdisk disk name
Insert picture description here
Insert picture description here

Because it is a new disk, choose New Partition
Insert picture description here
. It shows whether you want to create a logical partition or a primary partition. Choose p primary partition. The
Insert picture description here
partition number is one. The
Insert picture description here
partition size is 20GB.
Insert picture description here
You can change the disk type. The default Linux type can be changed without changing the
Insert picture description here
partition. Remember to save it. The partition will not take effect,
Insert picture description here
you can see that the partition has been created

Format partition and mount

After the partition is completed, the disk cannot be used directly and needs to be formatted and mounted.
First, the formatting
instruction is mkfs, which is used to create a file system (formatting). The
format is mkfs -t file type partition device. The
Insert picture description here
formatting is complete and the
formatting is complete. It can be used after
mounting. Mounting can mirror the file system iso to the specified folder. The
instruction is mount [-t type] The storage device mount point directory. The
Insert picture description here
Insert picture description here
disk partition has been mounted in the data directory. The
file system can be unmounted with the command umount
The format is umount storage device -lf force unmount

Automount

Since it is troublesome to mount manually every time after restarting, it is necessary to set up automatic mount.
After auto-mounting is enabled, you can boot up and mount the file system yourself.
To enter the fstab file in the /etc directory, use vim to edit the text

Insert picture description here
Insert picture description here

Insert picture description here
The first field is the mounted device, the second field is the mount point, the third field is the file type, the fourth field is the mount parameter defaults is the default rw is readable and writable, ro is read-only, noexec is not executable, and the fifth field is whether or not Need to dump backup 1 to need 0 to ignore the order of the disk check of the sixth field when the system starts.

Insert picture description here
Boot to mount automatically

Guess you like

Origin blog.csdn.net/weixin_49172531/article/details/113640174