In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the example analysis of disks and disk partitions in Linux, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Why should there be multiple partitions?
Prevent data loss: if the system has only one partition, then the partition is corrupted and the user will lose all the data.
Increase disk space efficiency: partitions can be formatted with different block sizes. If there are many 1K files and the hard disk partition block size is 4K, 3K space will be wasted for each file stored. At this point, we need to take the average of these file sizes to divide the block size.
The surge of data to the limit will not cause the system to hang: separating the user data from the system data can prevent the tie hang caused by the user data filling the entire hard disk.
Disk classification
The more common disk types are SCSI hard drives used in servers, SATA hard drives in the consumer market, and, of course, all kinds of solid state drives that are hot these days.
SCSI hard disk
SCSI hard disk is a hard disk with SCSI interface. Because of its good performance and high stability, it is widely used in the server. At the same time, it is also expensive, and it is rare to see it on ordinary PC because of its high price. The SCSI hard disk uses a 50-pin interface, which is similar to the ordinary hard disk interface (the following figure is from the Internet):
SATA hard disk
The hard disk of SATA (Serial ATA) port is also called serial port hard disk. Serial ATA adopts serial connection mode, and serial ATA bus uses embedded clock signal, which has stronger error correction ability. Compared with the past, its biggest difference is that it can check the transmission instructions (not only data), and automatically correct if errors are found, which greatly improves the reliability of data transmission. The serial interface also has the advantages of simple structure and hot-swappable support (the following figure is from the Internet):
Solid state hard disk
Solid state hard disk (Solid State Disk), commonly known as SSD hard disk, is made of solid-state electronic memory chip array, which is composed of control unit and memory unit (FLASH chip, DRAM chip). Its main feature is that there is no mechanical structure of the traditional hard disk, and the reading and writing speed is very fast (the following picture is from the Internet):
The representation of disk device under Linux
In Linux systems, the naming rules for disk device files are:
Primary device number + secondary device number + disk partition number
For today's common disks, it is generally expressed as:
Sd [a Murz] x
The main equipment number represents the type of equipment, and the same main equipment number represents the same type of equipment. Currently, the main setting number of common disks is sd.
The secondary device number represents the serial number of the same kind of equipment and is denoted by "amurz". For example, / dev/sda represents the first disk, and / dev/sdb represents the second disk.
X represents the disk partition number. There may be multiple partitions on each disk, and for each partition, Linux is represented by / dev/sdbx, where x represents the x partition of the second disk.
As shown in the following figure:
There are four disks / dev/sda,/dev/sdb,/dev/sdc and / dev/sdd in the system. Three partitions are created on / dev/sda, and there is only one partition / dev/sdb1 on / dev/sda1,/dev/sda2,/dev/sda5;/dev/sdb. On the other hand, / dev/sdc and / dev/sdd are not yet partitioned (or there can be only one partition with the same name as the disk).
Disk partition
Disk partitions are created for the following purposes:
Improve the security of data (data corruption in one partition will not affect data in other partitions)
Support to install multiple operating systems
There is a performance improvement for multiple small partitions compared to a large partition.
Better organize data
The partition of a disk consists of a primary partition, an extended partition and a logical partition. The maximum number of primary partitions on a disk is 4, where the extended partition is also a primary partition, and there can be at most one extended partition, but multiple logical partitions can be created on the extended partition. Therefore, the range of the primary partition (including the extended partition) is 1-4, and the logical partition starts at 5. For logical partitions, Linux states that they must be built on extended partitions, not on primary partitions.
The primary partition is used to boot the operating system, and mainly stores the boot or boot programs of the operating system. Therefore, it is recommended that the bootstrap of the operating system be placed on the primary partition, such as the / boot partition of Linux, preferably on the primary partition:
Extended partitions are simply "containers" of logical partitions. In fact, only primary and logical partitions are used for data storage, so the data can be centrally stored in the logical partition of the disk.
We can view the disk partition information through the fdisk command:
$sudo fdisk-l / dev/sda
The first few lines of the output are the basic information of the disk, such as the total size of 80g, the total number of sectors (sector), the size of each sector, and so on. What is in the red box is the partition information that we are more concerned about:
The first column, Device, shows the device file name for the disk partition.
The second column Boot shows whether it is a boot partition, and the / dev/sda1 in the figure above is the boot partition.
The third column, Start, represents the starting position of the disk partition.
The fourth column, End, represents the end of the disk partition.
The fifth column, Sectors, represents the number of sectors occupied by the partition.
The sixth column, Size, shows the size of the partition.
The seventh column and the eighth column show the same content, respectively, the numeric ID and its text description. The Id column shows the ID corresponding to the disk partition, and the corresponding ID number varies from partition to partition. Under Linux, 83 represents primary partition and logical partition, 5 represents extended partition, 8e represents LVM partition, 82 represents swap partition, and 7 represents NTFS partition.
The information in the figure above shows that / dev/sda1 is a primary partition and is used as a boot partition; / dev/sda2 is an extended partition with only one logical partition, / dev/sda5, which can be proved by the same size of both partitions.
Using fdisk to partition disk
Fdisk is a powerful disk partition management tool in Linux system, which can be used to observe the usage of hard disk and to manage disk partition. This article only describes how to create a new disk partition using fdisk.
Suppose we add a new disk to our Linux system, and the corresponding device name is / dev/sdd. Let's partition this disk with the fdisk command.
$sudo fdisk / dev/sdd
Enter the command n to create a new partition:
Based on the above prompts, we select p to create the primary partition, and then prompt us to enter the partition number:
The number of the main partition is 1-4, and here we enter 1. Next is to set the size of the partition:
The size of the partition is set by setting the sector at the beginning and end of the partition. Here, if you enter twice, the entire disk will be divided into a partition, that is, the container of the entire disk will be assigned to a partition. Such a simple partition is almost complete. Note that the partition information has not been written to disk at this time, and you can go back on it here. If you confirm to execute the partition above, execute the w command:
At this point, the partition operation is complete, and we can view the results of the partition with the following command:
$sudo fdisk-l / dev/sdd
If you find the above execution troublesome, you can use the following command to have the same effect:
$(echo n; echo p; echo 1; echo; echo; echo w) | sudo fdisk / dev/sdd
Change the type of partition
The partition type created above defaults to 83 (Linux). What if you want a partition of type 8e (Linux LVM)? We can continue to use the fdisk command to change the type of partition, this time by entering the t command to change the type of partition:
Next, you can choose the partition number to modify. We only have one partition, so the default is 1.
Below we can view the partition types supported by the fdisk command through the L command:
We need to create a LVM, so we use the type code 8e of LVM:
Finally, enter the w command to confirm the change. Check the partition information of / dev/sdd again, and the partition type has changed to Linux LVM:
The above is all the contents of the article "sample Analysis of disks and disk partitions in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.