04.10 Disk Key Knowledge

Keywords: Linux Vmware Database MySQL

Chapter 1 On-line Server Operational Specification

Chapter 2 Mass Creation of User Cases

1. The first method sed

The first method is: sed
[root@Never-downtime ~]# echo stu{01..10}|xargs -n1|sed 's#.*#useradd &;echo 123456|passwd --stdin &#g'
useradd stu01;echo 123456|passwd --stdin stu01
useradd stu02;echo 123456|passwd --stdin stu02
useradd stu03;echo 123456|passwd --stdin stu03
useradd stu04;echo 123456|passwd --stdin stu04
useradd stu05;echo 123456|passwd --stdin stu05
useradd stu06;echo 123456|passwd --stdin stu06
useradd stu07;echo 123456|passwd --stdin stu07
useradd stu08;echo 123456|passwd --stdin stu08
useradd stu09;echo 123456|passwd --stdin stu09
useradd stu10;echo 123456|passwd --stdin stu10
  1. The second method sed reverse reference
[root@Never-downtime ~]# echo stu{01..10}|xargs -n1|sed -r 's#(.*)#useradd \1;echo 123456|passwd --stdin \1#g'
useradd stu01;echo 123456|passwd --stdin stu01
useradd stu02;echo 123456|passwd --stdin stu02
useradd stu03;echo 123456|passwd --stdin stu03
useradd stu04;echo 123456|passwd --stdin stu04
useradd stu05;echo 123456|passwd --stdin stu05
useradd stu06;echo 123456|passwd --stdin stu06
useradd stu07;echo 123456|passwd --stdin stu07
useradd stu08;echo 123456|passwd --stdin stu08
useradd stu09;echo 123456|passwd --stdin stu09
useradd stu10;echo 123456|passwd --stdin stu10
  1. The third method awk
[root@Never-downtime ~]# echo stu{01..10}|xargs -n1|awk '{print "useradd "$NF ";echo 123456|passwd --stdin "$NF}'
useradd stu01;echo 123456|passwd --stdin stu01
useradd stu02;echo 123456|passwd --stdin stu02
useradd stu03;echo 123456|passwd --stdin stu03
useradd stu04;echo 123456|passwd --stdin stu04
useradd stu05;echo 123456|passwd --stdin stu05
useradd stu06;echo 123456|passwd --stdin stu06
useradd stu07;echo 123456|passwd --stdin stu07
useradd stu08;echo 123456|passwd --stdin stu08
useradd stu09;echo 123456|passwd --stdin stu09
useradd stu10;echo 123456|passwd --stdin stu10

Finally, it's all handled by | bash.

Chapter 3 Introduction to Disks

Today, the trend of disk development is smaller, faster, larger capacity and safer use. To achieve these features, our lovely disk design engineers have adopted improved methods: studying more sensitive magnetic heads for reading and writing, more advanced interface types, increasing spindle motor speed, higher storage density disk and more effective data retention technology.

1. Faster
Spindle rotation: 5400/7200/10000/1500 RPM (round per minute how many revolutions per minute)
Interface (connection mode between hard disk and motherboard): ide/scsi/sata/sas/ssd/pci-e/m.2
Disk Cache
Read and write more sensitive magnetic head

2. Disk Summary
(1) The characteristic of Linux system is to use the physical memory that the system does not use as a buffer or buffer (using the commands you have used), so 129 is not the real memory of the system.
(2) The available memory of the real system is 215M.
(3) Buffers are inhalation buffers, and sync writes buffer data to disk.
(4) cache is a buffer for reading data.
(5) Hard disks are mechanical, either writing or reading are too slow, so both reading and writing are using caching and buffering technology.
(6) Portal architecture websites will use caching technology to enable users to write and read as far as possible without touching the disk (read from the cache), or push users'requests forward as possible.
(7) read cache write buffer.

[root@CentOS7 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        562M        715M         11M        707M        1.2G
Swap:          1.0G          0B        1.0G

Chapter IV Types of Disk Interface

1. Type of disk structure:
The disk interface is the connecting part between the disk and the host system. Its function is to transfer data between the disk cache and the host memory. Different disk interfaces determine the speed of connection between disk and computer. In the whole system, the quality of disk interfaces directly affects the speed of program running and the performance of the system. From the overall point of view, the disk interface is divided into IDE, SATA, SCSI, SAS, PCI-E and optical fiber FC channels. IDE interface disks were mostly used in household products in the early days, some of them were used in servers, while SCSI interface disks were mainly used in the server market in the early days, while optical fiber channel was only used in high-end servers (dedicated storage emc), which is expensive. SATA is a new kind of disk interface. Types have gradually replaced IDE and SCSI interfaces, and are becoming more and more popular in the home market and server market.

** Information comparison of mainstream disks in enterprise production environment:
Popularity of Enterprise Production Scenarios: SAS > SATA > SSD
Performance and price per unit capacity: SSD > SAS > SATA
Buying Disk Capacity at Unit Price: SATA > SAS > SSD**

2. ssd disk:
Solid State Drive (SSD), IDE ELASH DISK (IDE ELASH DISK) is composed of control unit and storage unit (FLASH chip). Simply speaking, the disk is made of solid state electronic storage chip array. The interface specification, definition, function and usage method of SSD are the same as that of ordinary disk, and the product shape and size are also the same as that of ordinary disk. The working temperature range of the chip is very wide (- 40 ~ 85 C). At present, it is widely used in military, vehicle, industrial control, video surveillance, network monitoring, network terminals, power, medical, aviation, navigation equipment and other fields. Although the cost is high at present, it is also gradually popularizing to DIY market.

3. SSD Solid State Hard Disk Interface Type

4. SSD Solid State Disk Disadvantages:

5. The advantages and disadvantages of SSD solid-state disk compared with traditional mechanical disk:

Chapter 5 Types of Server Hard Disks

1. Enterprise SAS hard disk (default)
DELL,HP, IBM and so on, among which DELL and HP are the mainstream servers of Internet companies, the two brands of servers, the two brands of servers, the comprehensive cost-effective ratio of the two brands of servers is relatively high. Baidu uses many IBM servers. Current server market: the mainstream disks are SAS, SATA, SSD.
The most common SAS hard disk in an enterprise is 15,000 rpm (spindle speed here). Current mainstream 300G, 600G, 1000G, from the specific business needs and cost-effective considerations.
Purpose: Business servers for general external services on production lines (working environment online environment): database services, storage services, image services and related high concurrency services (web http cache services) on production lines. Generally speaking, if there is no special business needs, SAS disk is the preferred disk configuration for production environment.

2. Enterprise SATA Hard Disk
Enterprise SATA hard disk 7200-10000 rpm, the common capacity is 1T 2T 4T 6T, the advantages are economic, large capacity, cost-effective.
Data storage and business access that do not provide services offline are not very large business applications. For example, the site program and database, image offline backup and so on.
Characteristic: High capacity cost performance, generally 2T SATA disk is better. Hard disk

Chapter 6 Summary of Disk Purchase

(1) Online business, using SAS disk.
(2) Offline business, using SATA disks, tape libraries
(3) Online high concurrency, small capacity (many people want to see pictures) business, SSD disk.
(4) Cost idea: According to the heat of data access, only hierarchical storage can be analyzed. SATA+SSD

Chapter 7 Disk-related Terms

1. Translation of Disk Nouns

2. Disk head
Each disk of the disk has a read-write head for each valid disk (number of heads = number of disks = number of disks*2)
The boot program of the system is 446 Bytes in the first sector of 0 cylindrical 0 track 1.
MBR 0 head 0 track 1 sector front 446 (bytes) Bytes

3. Computation of Disks

Method 1
[root@Never-downtime ~]# python
>>> 63*1305*255*512
10733990400

Method 2
[root@Never-downtime ~]# echo 255*63*1305*512|bc
10733990400

Method 3
[root@Never-downtime ~]# awk 'BEGIN{print 255*63*1305*512}'
10733990400

4. Cylindrical surface of disk
The circular track of the same track with the same radius on all disks of a disk forms a cylinder from top to bottom, which is called a cylinder.
The number of cylinders = the number of tracks

5. Sector of Disk
Operating system stores information on hard disk in the unit of Sector. Normally, the size of each sector is 512 bytes. There are two main parts in a sector: the identification of the place where the data is stored and the data segment where the data is stored.

6. Summary of key points
(1) A disk has 2-14 disks, each disk has two sides. Each face corresponds to a read-write head. The number of disks is the number of disks. The number of disks*2 = the number of disks (the number of disks).
(2) On the same disk, with the center of the disk as the center, each circular trajectory with different radius (different hula hoops) is a track.
(3) Tracks on different disks are divided into several sectors, each of which is a sector.
(4) A column contains more than one track, and a track contains more than one sector.
(5) Data information record can be expressed as three conditions: a magnetic head, a track and a sector.

Chapter 8 Computing Method of Disk Capacity

# bit (b)
# 1 byte = 8 bits
 # byte (B)
# 1KB=1024 bytes (B)
#1MB=1024KB=1024^2(B)
#1GB=1024MB=1024^2 KB=1024^3 B
#1TB=1024^4 B 

Hard Disk Capacity Size = Sector Number * 512 = Sector Number * 512 * Cylindrical Number * Head Number

Chapter 9 RAID Arrays

1. Significance of RAID
RAID is a group of independent physical disks assembled at different RAID levels to form a disk group. Logically, RAID is a large disk that can provide higher storage performance than a single physical disk. At the same time, it can provide a technology of data redundancy backup at different levels.
(1) Provide data security.
(2) Improving data read-write performance.
(3) Provide a larger single logical disk data storage capacity.

RAID Levels Key advantages Key shortcomings Practical application scenarios
RAID 0 Speed of reading and writing No redundancy Node RS of MYSQL slave cluster
RAID 1 100% Redundant Mirror Read-write performance is general and cost is high. Business with important data and no downtime
RAID 5 Has certain performance and redundancy can damage a piece Writing performance is not high General business is available
RAID 10 Read and write fast, 100% redundancy High cost Performance and redundancy require good business. Data Master Library and Storage Master Node

1. RAID0
It has the highest storage performance of all RAID levels (no waste of disk capacity, fast read and write).
The principle of RAID 0 to improve storage performance is to distribute continuous data to multiple disks for access, so that data requests can be executed by multiple disks in parallel. Each disk executes its own part of the data requests. This parallel operation on data can make full use of the bus bandwidth and significantly improve the overall disk access performance.

To make RAID 0, you need at least one physical disk, such as a dell server with a raid card. If you don't make raid, you can't use the disk unless you connect the disk directly to the motherboard, so you can use a disk as RAID 0.

Focus describe
capacity It is the capacity of five disks combined and has the highest storage performance at all RAID levels. The principle is to distribute continuous data to multiple disks for access.
performance In theory, the speed of disk reading and writing is five times faster than that of single disk, but due to the influence of bus bandwidth and other factors, the actual rate of increase will certainly be theoretical value. However, compared with serial transmission, the effect of speed increase is obvious, and the more the disk, the smaller the multiple.
redundancy Without any redundancy, a bad disk, the entire RAID can not be used.
occasion Suitable for large-scale concurrent reads and writes, but the data security requirements are not high, such as MySQL Slave (database slave), cluster node RS
Characteristic Fast speed, no redundancy, no loss of capacity.

2. RAID1
RAID 1 is also called mirror image. Its purpose is to maximize the availability and repairability of user data. The operation mode is to automatically copy the data written by users to another hard disk 100 percent, so as to realize the storage of double data.

Only two disks are supported, and the entire RAID size is equal to the smallest of the two disks, so it's better to use disks of the same size. It can write the cool disk at the same time to achieve data backup, but it reduces the write performance relatively, but it can read the data concurrently, which is equivalent to the reading efficiency of two RAID 0.

Focus describe
capacity Loss of 50% of data capacity.
performance It can't improve the storage performance. In theory, the write performance is not much different from that of a single disk.
redundancy Among all RAID levels, RAID 1 provides the highest data security guarantee with 100% redundancy.
occasion It is suitable for storing important data, such as server system partition and data storage with insufficient performance requirements.
Characteristic 100% redundancy and half capacity loss.

3. RAID5
RAID 5 is a storage solution that considers storage performance, data security and storage cost.
RAID 5 needs three or more physical disks. It can provide parity check for heating backup disks. It has high reliability. Only two disks damaged at the same time can damage data. Only one disk is damaged. The system will reconstruct data according to the stored parity check bits and provide temporary services. At this time, if there is a hot backup, the system will automatically reconstruct the data on the failed disks on the hot backup disks.

Focus describe
capacity Loss of a disk's data capacity of 10*600G 9*66G
performance RAID 5 and RAID 10 have the same data reading speed, but only one more parity information.
redundancy Losable disk, RAID 5 data security is lower than RAID 1 and disk space utilization is higher than RAID 1.
occasion RAID 5 can be understood as a compromise between RAID 0 and RAID 1. It is suitable for situations where there are certain requirements for performance and redundancy, but neither is very high. MySQL master and slave libraries can be used, storage can also be used. Ordinary servers can do RAID 5 in order to reduce maintenance costs and maintain redundancy and read performance.
Characteristic Capacity loss is a disk, write data through parity check, RAID 0 and RAID 1 compromise scheme.

4. RAID10
Minimum 4 disks, equivalent to RAID 0 and RAID 1, 100% redundancy

5. RAID Summary

RAID Levels Minimum disk requirements Key advantages Key shortcomings Practical application scenarios
RAID 0 1 pieces Speed of reading and writing No redundancy MySQL Slave
RAID 1 2 pieces (only) 100 Redundant Mirrors Read-write performance is general and cost is high. Separately, data is important and cannot be downtime business
RAID 5 3 pieces Has certain performance and redundancy, can damage a disk, good reading performance Writing performance is not high General business can be used
RAID 10 4 pieces Read and write fast 100 redundancy High cost Performance and redundancy require good business, database master and storage master node.

Chapter 10 Focus on Disk Partition mbr

1. Disk Partitioning Tool
(1) The essence of partitioning the disk is to set the partition table of 64 bytes after the first 446 bytes of the above-mentioned 0-head 0-track 1 sector. That is to say, the starting and ending magnetic head number, sector number and cylinder number are mainly divided.
(2) The tools for partitioning disk include fdisk (suitable for partitioning less than 2T, suitable for mbr partition table), parted (good at partitioning larger than 2T, partitioning smaller than 2T, suitable for gpt partition table), preferred fdisk, only when greater than 2T to select parted.
(3) The partition table of a disk is only 64 bytes in size. The partition table of each primary partition/extended partition takes 16 bytes. Therefore, a disk only supports four partition table information, that is, the total number of primary partition+extended partition is not more than 4.
(4) Disk partitions are divided by cylinders (understandable from the point of view of disk read-write principle).
(5) Extended partitions can not be used directly, and logical partitions need to be created on the basis of extended partitions.
(6) Extended partitions have their own partition table, so there can be multiple logical partitions under extended partitions. Disks usually need to be partitioned before they are used. Of course, it is not a problem if partitions are not formatted directly, but this is not a common case. Disk partition can be divided into primary partition, extended partition and logical partition. A disk can have up to four partition table information (disk limitation). The location of one main partition can be replaced by one extended partition, and a hard disk can only have one extended partition (operating system limitation). Within this extended partition, multiple logical partitions can be partitioned (IDE disk logical partition number may be 5-63). SATA (No. 5-15)

2. Business case
A server 6 600 G disks, raid5, the total size of 3T, at this time can not install the system? Why?

Method 1: After making raid5, do not reboot the system, but reboot the raid interface and continue to divide it into a small virtual disk vd200G. Using this 200G virtual disk to install the system, the remaining 2.8T partitions are parted after the system is loaded.

Method 2: First take one raid 0, and then make five raid 5. Install the system on raid0.

Method 3: When installing the system, the system can be installed by default by changing the partition table to gpt.

3. Notes for Disk Partitioning
Main partition: There are only four main partitions at most, and the partition table is limited to 64 bytes. / dev/sda1/dev/sda2/dev/sda3/dev/sda4
Extended partition: If more partitions are divided, the extended partition must be created, not used directly, and then the logical partition can be created to use.
The maximum number of primary partitions + extended partitions is 4.

P-primary primary primary partition
E-extended extended partition
L-logical Logical Partitioning

A hard disk can only be partitioned in one of the following combinations:
(1) Any number of primary partitions, but the number of primary partitions is less than or equal to 4. For example, a hard disk can be divided into four primary partitions, three primary partitions, two primary partitions or one primary partition.
(2) Extended partitions can be combined with primary partitions, but the number of primary partitions + extended partitions is less than 4.
For example, three main partitions:
Three primary partitions + one extended partition
2 primary partitions + 1 extended partition
1 primary partition + 1 extended partition
When the total number of partitions is more than 4, an extended partition must be advanced, and the maximum number of extended partitions can only be one.
P+P+P+P
P+P+P+E

5. Large Portal Website (for Creation and Extension)
/ boot 200M main partition
swap 1.5 times primary partition
/ 50-200G main partition
Remaining space is not partitioned, reserved, which will be used in the future, according to their own needs to re-divide, ===== extended partition under logical partition.

6. Website nodes (data is not very important)
/ boot 200M main partition
Main partition within 8 G swap 1.5 times
/ Give all primary partitions

7. Building data partitions separately (data is important)
/ boot 200M main partition
swap 1.5 times primary partition
/ 40-200G main partition
/ All remaining data

8. Device name of disk partition
In Linux system, the device name is used to access the device, and the device name is stored in the / dev directory.
The rules for defining device names are as follows. Other partitions can be analogized as follows:

## The first hard disk of the IDE interface of the system is called / dev/had.
## The second hard disk of the IDE interface of the system is called / dev/hdb.
## The first hard disk of the SCSI interface of the system is called / dev/sdb.
## The second disk of the SCSI interface of the system is called / dev/sdb.

SATA, SAS are all the beginning of sd.
Each partition is represented by a disk name plus a corresponding number, such as:

## The first partition hard disk of the first IDE interface of the system is called / dev/had1.
## The fifth partition hard disk of the system's first IDE interface is called / dev/hdb5.
## The first partition hard disk of the second SCSI interface of the system is called / dev/sdb1.
## The fifth partition disk of the second SCSI interface of the system is called / dev/sdb5.

9. Business case
If I have a SAS hard disk and I want to divide the disk into six usable disk partitions, what is the number of each disk partition under the Linux system?

(1)P+E
sda1 sda5 sda6 sda7 sda8 sda9
(2)P+P+E
sda1 sda2 sda5 sda6 sda7 sda8
(3)P+P+P+E
sda1 sda2 sda3 sda5 sda6 sda7

Chapter 11 fdisk partitioning tools

1. Creating an environment

Virtual Machine Add Hard Disk Specify Disk Type SCSI Set Disk Space Size Add Completion Restart reboot

2. View Disk Information

[root@Never-downtime ~]# fdisk -l 
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00073277

//System main hard disk sda
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         124      786432   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             124        1306     9493504   83  Linux

//System second hard disk sdb
[root@Never-downtime ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7e1aac90.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7e1aac90

   Device Boot      Start         End      Blocks   Id  System

3. Check Help h

Command (m for help): h
h: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

4. Display partition condition p

Command (m for help): p

Disk /dev/sdc: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders, total 417792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdba2afab

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): p

Disk /dev/sdc: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders, total 417792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdba2afab

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048       43007       20480   83  Linux

5. Add primary partition sdb1

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-102, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-102, default 102): +10M

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7e1aac90

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          11       11248   83  Linux

6. Add extended partition sdb2

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (12-102, default 12): 
Using default value 12
Last cylinder, +cylinders or +size{K,M,G} (12-102, default 102): 
Using default value 102

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7e1aac90

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          11       11248   83  Linux
/dev/sdb2              12         102       93184    5  Extended
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@Never-downtime ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00073277

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         124      786432   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             124        1306     9493504   83  Linux

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7e1aac90

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          11       11248   83  Linux
/dev/sdb2              12         102       93184    5  Extended

7. The system reads the partition again

Using partprobe, you can create new partitions with fdisk tools without restarting the system.
[root@Never-downtime ~]# partprobe /dev/sdc

8. Format and create file systems

[root@Never-downtime ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25896 inodes, 103424 blocks
5171 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1992 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

9. Cancel Automatic File Check

[root@Never-downtime ~]# tune2fs -c -1 -i -1 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 18446744073709465216 seconds

10. Temporarily mount and view

[root@Never-downtime ~]# mount -t ext4 /dev/sdb1 /mnt/
[root@Never-downtime ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       8.8G  1.6G  6.8G  19% /
tmpfs           931M     0  931M   0% /dev/shm
/dev/sda1       190M   38M  142M  22% /boot
/dev/sdb1        94M  1.6M   88M   2% /mnt

Chapter 12 Partied Partitioning Tools

1. View the newly added disk

[root@Never-downtime ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  211MB   210MB   primary  ext4            boot
 2      211MB   1016MB  805MB   primary  linux-swap(v1)
 3      1016MB  10.7GB  9721MB  primary  ext4

2. Create partition tables

[root@Never-downtime ~]# parted /dev/sdc 
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) h                                                                
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  check NUMBER                             do a simple check on the file system
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on partition NUMBER
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system
  move NUMBER START END                    move partition NUMBER
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free
        space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resize NUMBER START END                  resize partition NUMBER and its file system
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of
        GNU Parted
(parted) mklabel gpt
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted)                                                                

3. Create partition tables and view them

(parted) mkpart primary 0 5M
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  5000kB  4983kB               primary

(parted) mkpart primary 5 10M
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  5000kB  4983kB               primary
 2      5000kB  10.5MB  5469kB               primary

(parted) q                                                                
Information: You may need to update /etc/fstab.                           

4. Delete partitions and create a partition

(parted) rm 
Partition number? 1
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 2      5000kB  10.5MB  5469kB               primary

(parted) rm                                                               
Partition number? 2                                                       
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary 0 10M                                            
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I                                                          
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  10.5MB  10.5MB  ext4         primary

5. The system reads the partition again

[root@Never-downtime ~]# partprobe /dev/sdc1

6. Format and create file systems

[root@Never-downtime ~]# mkfs.ext4 /dev/sdc1 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
2560 inodes, 10204 blocks
510 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks: 
    8193

Writing inode tables: done                            
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

7. Cancel File System Auto-Check

[root@Never-downtime ~]# tune2fs -c -1 -i -1 /dev/sdc1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 18446744073709465216 seconds

8. Temporary mount and view

[root@Never-downtime ~]# mount /dev/sdc1 /tmp/
[root@Never-downtime ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       8.8G  1.6G  6.8G  19% /
tmpfs           931M     0  931M   0% /dev/shm
/dev/sda1       190M   38M  142M  22% /boot
/dev/sdc1        94M  1.6M   88M   2% /tmp
/dev/sdb1        94M  1.6M   88M   2% /tmp

Chapter 13 Start-up Automatic Mounting

Method 1:
Place mount /dev/sdb1 /mnt in / etc/rc.local, suitable for network file system, NFS,MFS,GFS.

Method 2:
Add the above mount information in fstab format. / etc/fstab, suitable for local disk.

Equipment to be hung
UUID=c66c5981-de35-454a-9634-179b07cbdbfd /                       xfs     defaults        0 0
UUID=a7c3eb19-e720-44ab-94a1-b40c534e91f8 /boot                   xfs     defaults        0 0
UUID=83334dcd-fe5e-4312-aac2-43ac2c2999d7 swap                    swap    defaults        0 0
/dev/sdb1                                                         /mnt    xfs             0 0

Chapter 14 Differences between fdisk and parted

  1. Traditional MBR (Master Boot Record) partitioning has one limitation:
    Unable to support partitions of hard disks that exceed 2TB (or partitions that exceed 2TB in a single partition)
    If greater than 2T, use the concept of GPT (Globally Unique Identifier Partition Table Format) partitioning
    GPT partition table can solve the limitation of traditional MBR that can not exceed 2TB very well.
    But in Linux system, the traditional fdisk command can not support gpt partitioning.

  2. Parted operations are real-time, that is to say, if you execute a partition command, it will be partitioned in real time, not as fdisk does, need to execute the w command to write the modifications made, so the testing of parted must be careful not in the production environment!!!

  3. parted supports gpt partition tables, which can partition disks larger than 2T.

  4. The parted partition takes effect directly and does not need to use commands to write to disk, preferably partprobe/dev/sdb.

  5. fdisk is used for disks less than 2TB.

  6. Format mounts and so on are no different from fdisk.

Chapter 15 java Enterprise Cases

swap virtual memory
Swap (swap partition) in Linux is similar to virtual memory in Windows. When there is insufficient memory, Swap uses part of the hard disk space as memory to solve the problem of insufficient memory. Android is a Linux-based operating system, so Swap partition can also be used to improve system efficiency [1].
Exchange partition, in English, is swap, meaning "exchange" and "physical transaction". Its function is that when memory is insufficient, the operating system first stores the data temporarily unused in memory into the swap space of the hard disk to free up memory for other programs to run, which is the same function as the virtual memory (pagefile.sys) of Windows.

SWAP is the virtual memory partition under LINUX. Its function is to virtual disk space (that is, SWAP partition) into memory for use after physical memory is used up.
It acts like a Windows exchange file, but it is a continuous disk space and is invisible to users.
It should be noted that although this SWAP partition can act as "virtual" memory, it is much slower than physical memory, so if you need faster speed, you can't count on SWAP, the best way is still to increase physical memory. SWAP partitioning is only a temporary solution.

java environment has plenty of memory but swap?

[root@oldboyedu-35 ~]# dd if=/dev/zero of=/tmp/swap bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB) copied, 2.87742 s, 46.6 MB/s
[root@oldboyedu-35 ~]# mkswap /tmp/swap
mkswap: /tmp/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 131068 KiB
no label, UUID=c075a67b-4c8a-4a57-afb5-ef5a711c29b0
[root@oldboyedu-35 ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          980M       415M       564M       252K        15M       265M
-/+ buffers/cache:       135M       845M
Swap:         868M         0B       868M
[root@oldboyedu-35 ~]# swapon /tmp/swap
[root@oldboyedu-35 ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          980M       415M       564M       252K        15M       265M
-/+ buffers/cache:       135M       845M
Swap:         996M         0B       996M 
[root@Never-downtime ~]# umount /dev/sdb1
[root@Never-downtime ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       8.8G  1.5G  6.9G  18% /
tmpfs           931M     0  931M   0% /dev/shm
/dev/sda1       190M   38M  142M  22% /boot
[root@Never-downtime ~]# mkswap /dev/sdb1 
Setting up swapspace version 1, size = 103420 KiB
no label, UUID=efb60fab-8c4f-4a7f-a982-7c48eac251ce
[root@Never-downtime ~]# free -l
             total       used       free     shared    buffers     cached
Mem:       1906280     142744    1763536        256      23052      29076
Low:       1906280     142744    1763536
High:            0          0          0
-/+ buffers/cache:      90616    1815664
Swap:       786428          0     786428
[root@Never-downtime ~]# swapon /dev/sdb1 
[root@Never-downtime ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3       8.8G  1.5G  6.9G  18% /
tmpfs           931M     0  931M   0% /dev/shm
/dev/sda1       190M   38M  142M  22% /boot
[root@Never-downtime ~]# free -l
             total       used       free     shared    buffers     cached
Mem:       1906280     142992    1763288        256      23064      29096
Low:       1906280     142992    1763288
High:            0          0          0
-/+ buffers/cache:      90832    1815448
Swap:       889848          0     889848

Creating swap using general physical partitions
Create swap using files
Enterprise case: insufficient memory in java environment
Swap in the work, especially in the java environment, program writing problems, memory leaks will occur, may occupy swap.
Coordination allows the development and modification of programs, and operation and maintenance can temporarily increase swap.

Posted by zang8027 on Fri, 14 Jun 2019 21:26:34 -0700