Linux disk partition details, linux disk partition

Source: Internet
Author: User
Tags ide hard drive

Linux disk partition details, linux disk partition

Installing Linux is the first threshold for beginners. In this process, the biggest confusion is to partition the hard disk. Although Linux of various Release versions already provides a friendly graphic interaction interface, many people still feel unable to start. The main reason for this is that you are not clear about Linux's Partition Rules, and how to use Fdisk, the most effective partition tool under it.

First, we need to have a preliminary understanding of the basic concepts of Hard Disk partitioning. Hard Disk partitioning is mainly divided into two types: Basic partition and extension partition, the sum of the number of basic partitions and extended partitions cannot be greater than four. The basic partition can be used immediately but cannot be partitioned. The expanded partition must be partitioned before it can be used, that is, it must be partitioned twice. So what will be further divided by the expanded partition? It is a logical partition, and there is no limit on the number of logical partitions.

For users who are accustomed to using dos or windows, there are several partitions with several drives, and each partition will get a letter identifier, then you can use this letter to specify the files and directories in the partition. Their file structures are independent and easy to understand. But it is a little annoying for these users who are new to red hat linux. For red hat linux users, no matter how many partitions are allocated to which directory to use, it has only one root directory and an independent and unique file structure. In red hat linux, each partition is used to form a part of the entire file system, because it adopts a processing method called "LOAD, its entire file system contains a complete set of files and directories and associates a partition with a directory. In this case, a partition to be loaded will make its storage space available in a directory.

For windows users, the operating system must be installed in the same partition. It is a commercial software! So you have no choice! For red hat linux, you have a lot of options. You can install the system files in several zones (the loading point must be specified ), it can also be installed in the same partition (the loading point is "/").

We will start from these two aspects to explain the problem that has plagued everyone.

Linux Partition Rules

1. device management

In Linux, each hardware device is mapped to a system file, which is no exception for hard drives, optical drives, and other IDE or SCSI devices. Linux allocates a file consisting of hd prefixes to various IDE devices, while a file consisting of sd prefixes to various SCSI devices.

For an ide hard drive, the drive identifier is "hdx ~", "Hd" indicates the type of the device where the partition is located. This indicates the ide hard disk. "X" is the disk number (a is the basic disk, B is the basic slave disk, c is the auxiliary master disk, d is the auxiliary slave disk), "~" The first four partitions are represented by numbers 1 to 4. They are primary partitions or extended partitions. They are logical partitions starting from 5. For example, hda3 indicates the third primary or extended partition on the first ide hard disk, and hdb2 indicates the second primary or extended partition on the second ide hard disk. For a scsi hard disk, it is marked as "sdx ~", The scsi hard disk uses "sd" to represent the type of the device where the partition is located. The rest are the same as the representation of the ide hard disk.

For example, for the first IDE device, Linux is defined as hda; for the second IDE device, hdb; and so on. The SCSI devices should be sda, sdb, and sdc.

2. Number of partitions

To partition, you must operate on each hardware device. This may be an IDE hard disk or a SCSI hard disk. For each hard disk (IDE or SCSI) device, Linux assigns a serial number ranging from 1 to 16, which indicates the Partition Number on the hard disk.

For example, the first partition of the first IDE Hard Disk maps hda1 in Linux, and the second partition is called hda2. For SCSI hard disks, such as sda1 and sdb1.

3. Functions of each partition

In Linux, it is stipulated that each hard disk device can have a maximum of four primary partitions (including the extended partition). Any extended partition must occupy one primary Partition Number, that is, in a hard disk, there are a maximum of four primary and extended partitions.

For earlier DOS and Windows (versions earlier than Windows 2000), the system recognizes only one primary partition. You can add a logical drive letter (logical partition) to the extended partition, further refine the partition.

A primary partition is used by a computer to start the operating system. Therefore, the boot of each operating system, or a boot program, should be stored in the primary partition.

This is the biggest difference between primary and extended partitions and logical partitions.

This is the best example when we specify the bootloader for Linux installation and boot on the primary partition.

Linux requires that the primary partition (or extended partition) occupies the first four numbers from 1 to 16. Taking the first IDE hard disk as an example, the primary partition (or extended partition) occupies hda1, hda2, hda3, and hda4, while the logical partition occupies 12 numbers from hda5 to hda16.

Therefore, each Hard Disk in Linux has a total of 16 partitions.

For logical partitions, Linux requires that they must be built on extended partitions (also in DOS and Windows systems), rather than on the primary partition.

Therefore, we can see that the extended partition provides a more flexible partition mode, but it cannot be used as a boot for the operating system. Apart from the differences between the above partitions, we can simply treat them equally.

4. Partition indicators

For each Linux partition, the partition size and type are the most important indicators. The size of the capacity is easy to understand, but the partition type is not so easy to accept. The partition type specifies the format of the file system above the partition.

Linux supports a variety of File System formats, including our familiar FAT32, FAT16, NTFS, HP-UX, and a variety of Linux Native and Linux Swap partition types.

In Linux, you can use the partition type number to differentiate these partitions. Various types of numbers will be introduced when introducing the usage of Fdisk.

5 common partitions

/Boot partition, which contains the kernel of the operating system and the files to be used during system startup. It is necessary to create this partition, because most PCs are subject to bios restrictions, moreover, if you have a separate/boot partition, the computer can still start even if the primary root partition has a problem. The partition size is about 50 mb-100mb. However, if you want to use lilo to start the red hat linux system, the partitions containing/boot must be completely less than cylindrical 1023. Because the data after 8 GB cannot be read by lilo, red hat linux should be installed within 8 GB.

/Usr partition: the place where the software is stored in red hat linux. If possible, allocate the maximum space to it.

/Home partition is the location of your home directory. The size of this partition depends on the number of users. If multiple users use a computer together, this partition is completely necessary. Moreover, root users can also control the use of computers by common users, such as using hard disks for users or user groups, restrict common users to which files to access. In fact, it is necessary for a single user to establish this partition. If this partition is not available, you can only log on to the system as the root user. This is dangerous, because the root user has absolute right to use the system, once you misoperate the system, the trouble will arise.

/Var/log partition is the System log Record Partition. If this independent partition is set up, even if the system log file has a problem, they also do not affect the primary partitions of the operating system.

/Tmp partition, used to store temporary files. This is necessary for multi-user systems or network servers. In this way, even if a large number of temporary files are generated during the running of the program, or the user has performed wrong operations on the system, other parts of the file system are still safe. Because this part of the file system is still subject to read and write operations, it usually occurs faster than other parts.

/Bin partition, which stores standard system utilities.

/Dev partition to store device files.

/Opt partition, which stores optional installed software.

/Sbin partition, which stores standard system management files.

This section describes several common partitions. Generally, we need a swap partition, A/boot partition, A/usr partition, A/home partition, and A/var/log partition. Of course, there is no rule. It is determined by yourself. But remember that there must be at least two partitions, one swap partition and one/partition.

Fdisk Usage Details

The following describes how to use Fdisk to consolidate the knowledge about Linux partitions.

Fdisk is the most commonly used partition tool in various Linux releases and is defined as an Expert-level partition tool, which makes beginners a little discouraged.

1. Fdisk parameter description

When running Fdisk, the welcome page is displayed first. You can operate Fdisk by entering command parameters in this interface. Enter "m" as prompted to display the description of each parameter of the Fdisk command. You can see that Fdisk has many parameters, but it is often used. If you are familiar with these parameters, You can smoothly use Fdisk to partition Linux hard disks. First, we will briefly introduce the meaning of each parameter, and then describe several key parameters in detail.

When users partition in Linux, the most common parameters are d, l, m, n, p, q, t, w, etc.

2. Use Fdisk for partitioning

In the Linux partition process, the p parameter is usually used to display the hard disk partition table information, and then the future partition is determined based on the information. If you want to completely change the partition format of the hard disk, you can use the d parameter to delete the existing hard disk partitions one by one.

For example, d1 and d2. After deletion, you can use the n parameter to add a new partition. After pressing "n", we can see the newly added partition. Select the new partition type, primary partition or extended partition, and then select p or e. Their differences are described above. Then, set the partition size. Note that if there are extended partitions on the hard disk, only logical partitions can be added, but no extended partitions can be added. When the partitions are added, their types are all default Linux Native, if you want to change some of the partitions to other types, such as Linux Swap or FAT32, you can use the command t to change them. When you press t to change the partition type, the system prompts the partition to be changed and the type of the partition (if you want to know the partition type supported by the system, type l ). For details about the partition type numbers supported by Linux and their corresponding partition types, refer to Table 2 (these information can be obtained by using the l command ). After changing the partition type, you can press "w" to save and exit. If you do not want to save it, you can select "q" to exit.

Fdisk is a powerful disk operation tool from util-linux. Here we only talk about how to view the disk partition table and partition structure. The parameter-l is passed through the-l parameter, you can obtain the number of all disks on the machine and list all disk partitions;

[Root @ localhost beinan] # fdisk-l

Disk/dev/hda: 80.0 GB, 80026361856 bytes

255 heads, 63 sectors/track, 9729 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/hda1*1 765 6144831 7 HPFS/NTFS

/Dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)

/Dev/hda3 2806 7751 39728745 5 Extended

/Dev/hda5 2806 3825 8193118 + 83 Linux

/Dev/hda6 3826 5100 10241406 83 Linux

/Dev/hda7 5101 5198 787153 + 82 Linux swap/Solaris

/Dev/hda8 5199 6657 11719386 83 Linux

/Dev/hda9 6658 7751 8787523 + 83 Linux

In the above Blocks, it indicates the partition size, and the unit of Blocks is byte. We can convert it to M. For example, if the size of the first partition/dev/hda1 is converted to M, it should be 6144831/1024 = 6000 M, that is, about 6 GB. In fact, it is not so troublesome. Let's take a rough look at moving the decimal point forward to three digits and we will know the approximate size;

System indicates the file System. For example,/dev/hda1 is in NTFS format;/dev/hda2 indicates a file System in fat32 format ;.

In this example, we should pay special attention to the/dev/hda3 partition, which is an extended partition. It contains a logical partition, which is actually equivalent to a container; from her own hda5, hda6, hda7, hda8, hda9;

We also noticed that there is no hda4. Why? Why is hda4 not included in the extended partition? A disk can have up to four primary partitions; A hda1-4 is regarded as the primary partition; hda4 cannot be included in the extended partition, and the extended partition is also considered the primary partition; in this example, there is no hda4 partition, of course, we can set one of the partitions as the primary partition, but I didn't do this at the time;

Let's take a closer look at the statistics and see if there is space on this disk? Hda1 + hda2 + hda3 = actually partitioned volume, so we can calculate hda1 + hda2 + hda3 = 6144831 + 16386300 + 39728745 = 62259876 (B) and convert it into M units, the decimal point is shifted to three places, so the size of the partition that has been divided is about 62259.876 (M). In fact, the most accurate calculation is 62259876/1024 = 60800.67 (M ); the size of this disk is 80.0 GB (80026361856 bytes). In fact, the actual size is 78150.744 (M). Through a series of calculations, we can see that there is still space for this hard disk; there is about 18 GB unpartitioned space;

You can also specify fdisk-l to view the partition of one of the hard disks;

[Root @ localhost beinan] # fdisk-l/dev/sda

Disk/dev/sda: 60.0 GB, 60011642880 bytes

64 heads, 32 sectors/track, 57231 cylinders

Units = cylinders of 2048*512 = 1048576 bytes

Device Boot Start End Blocks Id System

/Dev/sda1 1 57231 58604528 83 Linux

We can see from the above situation that there is only one partition in the/dev/sda disk; The usage is almost;

We can also view/dev/hda's

[Root @ localhost beinan] # fdisk-l/dev/hda

Try it yourself?

You can also use cat/proc/partitions to view all disks and partitions on the current machine.

Df command;

Df comes from the coreutils software package and comes with it during system installation. We can use this command to view the disk usage and the location where the file system is mounted;


[Root @ localhost beinan] # df-lh

Filesystem capacity in use available % mount point

/Dev/hda8 11G 6.0G 4.4G 58%/

/Dev/shm 236 M 0 236 M 0%/dev/shm

/Dev/sda1 56G 22G 35G 39%/mnt/sda1

We can see that the system is installed in/dev/hda8; there is also a 56 GB disk partition/dev/sda1 mounted in/mnt/sda1;

For other parameters, see man df.

Through the above two aspects of learning, I believe that for beginners, partition is no longer a stumbling block in the Linux advanced.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.