Linux disk partition details

Source: Internet
Author: User
Tags ide hard drive
Installing Linux is the first threshold for beginners. In this process, the biggest confusion is to partition the hard disk. The following describes how to partition a linux disk.

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 reason for this is that we are not clear about Linux's partition rules, and what is the most effective partition tool below it? Fdisk usage.

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;

Copy codeThe code is as follows:
[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 BootStartEndBlocksId System
/Dev/hda1*1765 6144831 7 HPFS/NTFS
/Dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/Dev/hda32806 7751 39728745 5 Extended
/Dev/hda52806 3825 8193118 + 83 Linux
/Dev/hda63826 5100 1024140683 Linux
/Dev/hda75101 5198787153 + 82 Linux swap/Solaris
/Dev/hda85199 6657 1171938683 Linux
/Dev/hda96658 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;


Copy codeThe code is as follows:
[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 BootStartEndBlocksId System
/Dev/sda11 57231 5860452883 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

Copy codeThe code is as follows:
[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;

Example:

Copy codeThe code is as follows:
[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 236M0%/dev/shm

/Dev/sda1 56G22G35G 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.

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: info-contact@alibabacloud.com 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.