In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the method of linux hard disk partition, formatting, and mounting". In daily operation, I believe that many people have doubts about the method of linux hard disk partition, formatting, and mounting. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "what is the method of linux hard disk partition, formatting, and mounting?" Next, please follow the editor to study!
I. Division and classification
MBR: the full name is Master Boot Record, that is, the master boot record of the hard disk.
GPT: the partition mode uses GUID partition tables, which is a newer standard for disk partition table structure derived from the EFI standard. Compared with the commonly used master boot record (MBR) partitioning scheme, GPT provides a more flexible disk partitioning mechanism.
1. Overview of MBR
Partition number: primary partition 1-4, logical partition 5. . Up to 4 primary partitions
LINUX states that logical partitions must be based on extended partitions, not on primary partitions
Zoning function:
Primary partition: it is mainly used to boot the operating system, it is mainly put the operating system boot or boot program, / boot partition is best placed on the primary partition
Extended partition cannot be used, it only exists as a container of logical partition; what we really store data is primary partition and logical partition, and a large amount of data is placed in logical partition.
This is a schematic diagram of the hard disk partition using the MBR partition scheme (a hard disk). The respective meanings of primary partition, extended partition and logical partition will be explained later.
MBR is a traditional partition table, and if you are using an older computer, it is more likely that the hard disk of the computer will use the MBR partition scheme. Below, we list some important features of the MBR partitioned table:
1. The MBR partition scheme uses 64 bytes in the first physical sector of the hard disk as the space of the partition table to store the hard disk partition information, and the information of each partition takes up 16 bytes. Therefore, the MBR partition table can only hold partition information for up to four partitions.
2. In the MBR partition scheme, there are three types of partitions: primary partition, extended partition and logical partition. Extended partitions and logical partitions appear in order to break the limit that only 4 partitions can be saved in the partition table.
3. The partition information saved in the MBR partition table is the partition information of the main partition and the extended partition, and the extended partition cannot be used directly. It needs to be divided into one or more logical partitions in the extended partition before it can be used. The partition information of logical partitions is saved in the extended partition rather than in the MBR partition table, thus breaking the limit that the MBR partition table can only hold four partitions.
4. 16-byte partition information contains partition activity status flag, file system identification, start and stop column number, magnetic head number, sector number, starting sector location (4 bytes), total number of sectors (4 bytes) and so on. The most important thing here is that the starting sector position of the partition and the total number of sectors of the partition are represented by 4 bytes.
5, generally, the capacity of each sector is 512 bytes, and the maximum capacity that a 4-byte sector can represent is 2TB. As can be seen from 4, in the MBR partition table, the starting position of the partition cannot be greater than 2TB, and the maximum capacity of the partition can not be greater than 2TB. Therefore, it is not suitable to use MBR partition scheme for physical hard disks with more than 2TB capacity.
If you are an average user who is not so interested in technical details, there are only two things you need to keep in mind about MBR partitioning:
1. Originally, the MBR partition table can only hold information about four partitions, but by expanding the use of partitions and logical partitions, MBR breaks through this limitation.
2. In the MBR partition table, the parameter indicating the address is only 4 bytes, so in the MBR partition scheme, the starting position of the partition cannot be greater than 2TB, and the maximum capacity of the partition cannot be greater than 2TB. Therefore, it is not suitable to use MBR partition scheme for physical hard disks with more than 2TB capacity.
two。 Check hard disk devices and partitions [root@centos7] # ls / dev/sda*/dev/sda / dev/sda1 / dev/sda2 / dev/sda3 / dev/sda4 / dev/sda5
Naming method: / dev/sd [a murz] n
Where: a murz represents the serial number of the hard disk, such as sda represents the first scsi hard disk, sdb is the second.
N represents the partition number of each disk
3. Use the partition tool fdisk to operate, partition and format the disk (key)
Fdisk: disk partitioning, the most commonly used partitioning tool in Linux distributions
Usage: fdisk [option] device
Common option:-l View hard disk Partition Table
Case study: create a partition on an SDB disk with a size of 1G
Brw-rw----. 1 root disk 8, 0 Feb 23 01:02 / dev/sdabrw-rw----. 1 root disk 8, 1 Feb 23 01:02 / dev/sda1brw-rw----. 1 root disk 8, 2 Feb 23 01:02 / dev/sda2brw-rw----. 1 root disk 8, 3 Feb 23 01:02 / dev/sda3brw-rw----. 1 root disk 8, 4 Feb 23 01:02 / dev/sda4brw-rw----. 1 root disk 8, 5 Feb 23 01:02 / dev/sda5brw-rw----. 1 root disk 8, 16 Feb 23 01:02 / dev/sdbWelcome to fdisk (util-linux 2.23.2). Changes will remain in memory only Until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0xeb311dde.Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition # g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types # display partition type m print this menu printing help n add a new partition add New partition o create a new empty DOS partition table p print the partition table shows partition table q quit without saving changes does not save exit s create a new empty Sun disklabel t change a partition's system id change partition table type u change display/entry units v verify the partition table w write table to disk and exit save operation and exit x extra functionality (experts only) Disk / dev/sdb: 8526 MB 8526585856 bytes, 16653488 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: P primary (0 primary, 0 extended, 4 free) e extendedPartition number (1-4, default 1): 1 First sector (2048-16653487, default 2048): Using default value 2048Last sector, + sectors or + size {K Jing M Jing G} (204816653487) Default 16653487): 1G Value out of range.Partition 1 of type Linux and of size 1 GiB is setThe partition table has been altered calling ioctl () to re-read partition table.Syncing disks./dev/sdb / dev/sdb1 [root@centos7 ~] #
Let the new partition take effect
[root@centos7 ~] # partx-a / dev/sdbpartx: / dev/sdb: error adding partition 1
Format the partition and mount it for use
Filesystem Size Used Avail Use% Mounted ondevtmpfs 733M 0733M 0% / devtmpfs 748M 0748M 0% / dev/shmtmpfs 748M 9.5m 739m 2% / runtmpfs 748M 0748M 0% / sys/fs/cgroup/dev/sda2 10G 4.5G 5.6G 45% / / dev/sda5 52G 111M 52G 1% / home/dev/sda1 197M 146M 52m 75% / boottmpfs 150M 20K 150M 1% / run/user/0/dev/sr0 57M 57M 0100% / run/media/root/VBox_GAs_6.1.2/dev/sdb1 976M 2.6M 907M 1% / root/data4. Write to the configuration file and let it power on and mount automatically
Method 1:
Write to the configuration file and let it boot and mount automatically: / etc/fstab
# # / etc/fstab# Created by anaconda on Sat Feb 22 09:25:14 2020 Accessible filesystems, by reference, are maintained under'/ dev/disk'# See man pages fstab (5), findfs (8) Mount (8) and/or blkid (8) for more info#UUID=b2af0e57-3f99-40b9-a621-6697301e4b88 / xfs defaults 0 0UUID=dd56dea7-8797-4fef-aa8e-ef2a8adf2f29 / boot xfs defaults 0 0UUID=c05c7778-3202-44c8-810e-23f9e711cf8f / home xfs defaults 0 0UUID=c26caf1e-444a-4445-8f91-49af5b828113 swap swap Defaults 0 0/dev/sdb1 / root/data ext4 defaults 0 0Filesystem Size Used Avail Use% Mounted ondevtmpfs 733M 0733M 0% / devtmpfs 748M 0 748M 0% / dev/shmtmpfs 748M 9.5M 739m 2% / runtmpfs 748M 0748M 0% / sys/fs/cgroup/dev/sda2 10G 4.5G 5.6G 45% / / dev/sda5 52G 111M 52G 1% / home/dev/sda1 197M 146M 52M 75% / boottmpfs 150M 20K 150m 1% / run/user/0/dev/sr0 57M 57M 0% / run/media/root/VBox_GAs_6.1.2/dev/sdb1 976M 2.6M 907m 1% / root/data
Explain each column of the configuration file
/ dev/sdb1
/ sdb1
Ext4
Defaults
0
0
Partition device to be mounted
Mounting point
File system Typ
Mounting option
Whether to back up
Whether to detect or not
Method 2:
Use the uuid mount of the device to avoid unplugging the hard disk and changing the partition number to mount the wrong hard disk:
/ dev/sr0: UUID= "2020-01-13-11-26-32-82" LABEL= "VBox_GAs_6.1.2" TYPE= "iso9660" / dev/sda1: UUID= "dd56dea7-8797-4fef-aa8e-ef2a8adf2f29" TYPE= "xfs" / dev/sda2: UUID= "b2af0e57-3f99-40b9-a621-6697301e4b88" TYPE= "xfs" / dev/sda3: UUID= "c26caf1e-444a-4445-8f91-49af5b828113" TYPE= "swap" / dev/sda5: UUID= "c05c7778-3202-44c8-810e-23f9e711cf8f" "TYPE=" xfs "/ dev/sdb1: UUID=" 911fc7a2-bc67-407d-9517-ed2992e54b3a "TYPE=" ext4 "GPT partition scheme
Compared to MBR,GPT, which is a new generation of partitioning scheme, if you are using a new computer, it is possible that the hard drive on that computer uses the GPT partitioning scheme.
GPT is more complex than MBR. Let's briefly explain the technical details of GPT. If you are not technical control and are not interested in these technical details, you can skip this part and read the important features of GPT directly.
First of all, you will notice that LBA 0 and LBA 1 are used to indicate the address on the hard disk. This is because in the past, the hard disk is generally addressed by chs, but now it is generally addressed by LBA. Readers who do not understand and are interested in specialized research on chs and LBA can consult the relevant information on their own. For the above picture, LBA 0 refers to the first sector with a physical serial number of 0. LBA 1 refers to the second sector with a physical serial number of 1, and so on.
The following is compared with the picture above to explain the GPT partitioning scheme.
1. Keep the partition scheme of MBR,GPT. The first physical sector of the hard disk is still a MBR mentioned earlier. This MBR is mainly for the sake of software compatibility, but it doesn't make any sense to the GPT partition scheme itself.
2. The GPT partition header, after retaining the MBR, that is, occupies the second physical sector, the GPT partition header, defines the number of partitions. Basically, you can think that the number of GPT partitions is unlimited.
3. The GPT partition table, starting from the third sector, is the actual partition table. Please note that each sector can hold 4 partition information, indicating that the partition information of each partition occupies 128 bytes of space.
4, from 3, we know that the information of each partition occupies 1/4 sectors, that is, 128byte space, compared with the MBR partition scheme, the information of each partition is only 16 bytes, so GPT partition scheme, there is sufficient space to store the starting position of the partition and the total capacity, basically, do not consider the limitation on the capacity of the partition.
5. From 3, we know that the number of partitions in the GPT partition scheme depends on how much partition information there is in the partition table. However, the actual situation is not like this, in fact, as shown in the figure: if you use the windows operating system, usually GPT partition table occupies 32 sectors of space, can save 128partition information, unused space will be reserved, how much partition information is actually used and how much partition information is retained is set in the GPT partition header in 2. Our computers usually have no more than 10 partitions, so more than 90% of the space in the GPT partition table is reserved, which is actually wasted.
6. The next two parts, which are very simple, are the backup of the GPT partition table and the GPT partition header.
The above is the general content of the GPT partition scheme, but it is not complicated. For ordinary users, in fact, the most important feature of GPT is: using GPT partition scheme, there is no hard disk capacity can not exceed the limit of 2TB size, this is the difference between GPT and MBR features and advantages!
Now, you may feel how to use MBR and GPT: use MBR or GPT when the hard disk capacity is less than or equal to 2TB, and use GPT when the hard disk capacity is greater than 2TB. This is true, but the actual situation is more complicated than this. Because, to use MBR or GPT correctly, you need to know something else: such as BIOS and EFI.
The 1.gdisk disk partitioning tool is similar to the fdisk tool
Gdisk is mainly used to partition hard drives with a capacity greater than 2T, which cannot be handled by fdisk larger than 2T.
Two types of partition tables: GPT and MBR; MBR does not support more than 4T
GPT partition: GPT, global unique identification partition table (GUID Partition Table), which uses 128bit GUID to uniquely identify each disk and partition. Unlike MBR, which has a single point of failure, GPT provides redundancy of partition table information, one at the head of the disk and the other at the end of the disk; it detects errors and corruption in the GPT header and partition table through the CRC checksum; by default, a hard disk supports 128partitions
Example: create a sdb1 by partitioning sdb into gpt
Brw-rw----. 1 root disk 8 16 Feb 23 01:37 / dev/sdb [root@centos7 ~] # [root@centos7 ~] # gdisk / dev/sdbGPT fdisk (gdisk) version 0.8.10Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present***Found invalid GPT and valid MBR Converting MBR to GPT formatin memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit bytyping 'q' if you don't want to convert your MBR partitionsto GPT formatting deleted bback up GPT data to a filecchange a partition's nameddelete a partition # delete partition ishow detailed information on a partitionllist known partition typesnadd a new partition # add a Ocreate a new empty GUID partition table (GPT) pprint the partition table # print partition table qquit without saving changes # exit do not save rrecovery and transformation options (experts only) ssort partitionstchange a partition's type codevverify diskwwrite table to disk and exit # write to partition table and exit xextra functionality (experts only)? print this menuCurrent type is' Linux filesystem'Changed type of partition to 'Linux filesystem'Disk / dev/sdb: 16653488 sectors 7.9 GiBLogical sector size: 512 bytesDisk identifier (GUID): E08228E1-79AB-4AC8-8A82-782A795B9AFFPartition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 16653454Partitions will be aligned on 2048-sector boundariesTotal free space is 14556269 sectors (6.9 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!OK Writing new GUID partition table (GPT) to / dev/sdb.The operation has completed successfully.mkfs.xfs: / dev/sdb1 appears to contain an existing filesystem (ext4). Mkfs.xfs: Use the-f option to force overwrite. [root@centos7 ~] # mkfs.xfs-f / dev/sdb1 # format meta-data=/dev/sdb1 isize=512 agcount=4, agsize=65536 blks = sectsz=512 attr=2 Projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0, rtextents=0
Other mount views are the same as MBR partitions. I will not repeat them here. You can also use fdisk-l to view disk partition mounts.
Disk / dev/sda: 68.7 GB, 68719476736 bytes 134217728 sectors Units = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00060ad4 Device Boot Start End Blocks Id System/dev/sda1 * 2048 411647 204800 83 Linux/dev/sda2 411648 21383167 10485760 83 Linux/dev/sda3 21383168 25577471 2097152 82 Linux swap / Solaris/dev/ Sda4 25577472 134217727 54320128 5 Extended/dev/sda5 25579520 134217727 54319104 83 LinuxWARNING: fdisk GPT support is currently new And therefore in an experimental phase. Use at your own discretion.Disk / dev/sdb: 8526 MB, 8526585856 bytes, 16653488 sectors Units = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: gptDisk identifier: E08228E1-79AB-4AC8-8A82-782A795B9AFF# Start End Size Type Name 1 2048 2099199 1G Linux filesyste Linux filesystem 2 2099200 16653454 7G Linux filesyste Linux filesystem The study on "what is the method of partitioning, formatting and mounting linux hard disk" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.