Linux Training Tutorial Linux Disk Partitioning Detailed Explanation


In the process of learning Linux, installing Linux is the first threshold for every beginner. In the middle of this process, the biggest confusion is partitioning the hard disk. Although various Linux distributions have provided a friendly graphical interface, many people still feel that they have no idea where to start. The main reason for this is that it is not clear about the partition rules of Linux, and the use of Fdisk, the most effective partition tool under it.

  Brothers Linux Training

Tutorial : First of all, we need to have some preliminary understanding of the basic concepts of hard disk partitions. Hard disk partitions are mainly divided into two types: primary partitions and extension partitions

.
and cannot be greater than four. And the basic partition can be used immediately but cannot be re-partitioned. The extended partition must be partitioned before it can be used, that is to say, it must be partitioned twice. So what is further divided by the extended partition? It is the logical partition

(logical partition)
, and there is no limit to the number of logical partitions.

  For users who are accustomed to using dos or windows, there are several drives in several partitions, and each partition is given a letter identifier, which can then be used to specify the files and directories on this partition, Their file structures are independent and very easy to understand. But for these first-time users of red hat linux, it can be a bit annoying. Because for red hat linux users, no matter how many partitions there are and which directory they are assigned to, in the final analysis, there is only one root directory, an independent and unique file structure. Each partition in red hat linux is used to form a part of the entire file system, because it adopts a processing method called "loading", and its entire file system contains a complete set of files and directories, and will A partition is associated with a directory. A partition to be loaded at this time will have its storage space available in a directory.

  For windows users, the operating system must be installed in the same partition, it is commercial software! So you have no choice! For redhat linux, you have a larger choice, you can divide the system files into several It can be installed in the same partition (the load point must be specified), or it can be installed in the same partition (the load point is "/").

  Let's start from these two aspects to explain this problem that troubles everyone.

  Linux partition regulations

  1. Device management

  In Linux, every hardware device is mapped to a system file, and IDE or SCSI devices such as hard disks and CD-ROMs are no exception. Linux assigns various IDE devices a file consisting of the hd prefix; and for various SCSI devices, assigns a file consisting of the sd prefix.

  For IDE hard disk, the drive identifier is "hdx~", where "hd" indicates the type of the device where the partition is located, here refers to 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), "~" represents the partition, the first four partitions are represented by numbers 1 to 4, which are Primary or extended partitions, starting from 5 are logical partitions. For example, hda3 is represented as the third primary or extended partition on the first IDE hard disk, and hdb2 is represented as the second primary or extended partition on the second IDE hard disk. For scsi hard disks, it is marked as "sdx~", scsi hard disks use "sd" to indicate the type of the device where the partition is located, and the rest are the same as IDE hard disks.

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

  2. Number of partitions

  To partition, it is necessary to operate for each hardware device, which may be an IDE hard disk or a SCSI hard disk. For each hard disk (IDE or SCSI) device, Linux assigns a serial number from 1 to 16, which represents the partition number on the hard disk.

  For example, the first partition of the first IDE hard disk is mapped to hda1 under Linux, and the second partition is called hda2. For SCSI hard disks it is sda1, sdb1, etc.

  3. The role of each partition

  In Linux, it is stipulated that each hard disk device can have up to 4 main partitions (including extended partitions), and any extended partition must occupy a main partition number, that is, in a hard disk, the main partition The total number of partitions and extended partitions is up to 4.

  For early DOS and Windows (versions before Windows 2000), the system only recognizes one primary partition, and the partition can be further refined by adding a logical drive letter (logical partition) to the extended partition.

  The role of the primary partition is that the computer is used to start the operating system, so the startup of each operating system, or the boot program, should be stored on the primary partition.

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

  When we specify the bootloader to install and guide Linux, we must specify it on the primary partition, which is the best example.

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

  Therefore, each hard disk under Linux has a total of up to 16 partitions.

  For logical partitions, Linux stipulates that they must be created on extended partitions (as is the case on DOS and Windows systems), not primary partitions.

  Therefore, we can see that the extended partition can provide a more flexible partition mode, but cannot be used as a boot for the operating system. Removing the differences between the various partitions above, we can simply treat them as the same.

  4. Partition indicators

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

  Linux supports a variety of file system formats, including the familiar FAT32, FAT16, NTFS, HP-UX, and various Linux-specific Linux Native and Linux Swap partition types.

  In Linux systems, these different types of partitions can be distinguished by their partition type numbers. Various types of numbers will be introduced when introducing the use of Fdisk.

  5 Common partition

  /boot partition, which contains the kernel of the operating system and the files used in the process of starting the system. It is necessary to build this partition, because most PCs are currently restricted by bios, and if there are With a separate /boot boot partition, even if the main root partition fails, the computer can still boot. The size of this partition is about 50mb-100mb. But if you want to use lilo to start the red hat linux system, the partition containing /boot must be completely below the cylinder 1023. And because the data lilo after 8gb cannot be read, so red hat linux should be installed within the area of ​​8gb.

  The /usr partition is where the software is stored in the red hat linux system. If possible, the maximum space should be allocated to it.

  The /home partition is where the user's home directory is located. The size of this partition depends on how many users there are. If multiple users use a computer together, this partition is absolutely necessary, and the root user can also control the use of the computer by ordinary users, such as limiting the use of hard disks to users or user groups, and restricting which files ordinary users can access. Wait. In fact, it is necessary for a single user to establish this partition, because without this partition, you can only log in to the system as the root user, which is dangerous, because the root user has absolute right to use the system, but once you have access to the system If you make a mistake, trouble will come.

  The /var/log partition is the system log recording partition. If this separate partition is set up, even if there is a problem with the system's log files, they will not affect the main partition of the operating system.

  The /tmp partition is used to store temporary files. This is necessary for multi-user systems or web servers. In this way, even if a large number of temporary files are generated when the program is running, or the user performs wrong operations on the system, the rest of the file system is still safe. Because this part of the filesystem is still subject to read and write operations, it usually breaks down faster than other parts.

  The /bin partition holds standard system utilities.

  The /dev partition is used to store device files.

  The /opt partition holds optional installed software.

  The /sbin partition holds standard system management files.

  Several commonly used partitions are introduced above. Generally speaking, we need a swap partition, a /boot partition, a /usr partition, a /home partition, and a /var/log partition. Of course, there are no rules, it is entirely up to you. But remember to have at least two partitions, a swap partition and a / partition.

  The use of Fdisk is explained in detail.

  The following introduces the use of Fdisk to consolidate the knowledge about Linux partitions learned above.

  Fdisk is the most commonly used partitioning tool in various Linux distributions. It is defined as an Expert-level partitioning tool, which makes it a little prohibitive for beginners.

  1. Fdisk parameter description When

  running Fdisk, the first thing that catches the eye is the welcome interface. Users can operate Fdisk by entering command parameters in this interface. The user can display the description of each parameter of the Fdisk command by typing "m" at the prompt. Readers can see that Fdisk has many parameters, but only a few are often used. If readers are proficient in these parameters, they can smoothly use Fdisk to partition Linux hard disks. We first briefly introduce the meaning of each parameter, and then explain several key parameters in detail.

  When users partition in Linux, the most commonly used parameters are d, l, m, n, p, q, t, w and so on.

  2. Partitioning with Fdisk

  In the Linux partitioning process, the hard disk partition table information is generally displayed first through the p parameter, and then the future partitions are determined according to the information. If you want to completely change the partition format of the hard disk, you can delete the existing hard disk partitions one by one through the d parameter.

  For example d1, d2. After the deletion is completed, you can add a new partition through the n parameter. When "n" is pressed, we can see the newly added partition. Here to select the new partition type, is the primary partition or extended partition; then select p or e. Their differences have been explained above. Then is to set the size of the partition. It should be reminded that if there are extended partitions on the hard disk, you can only add logical partitions, not extended partitions. When adding partitions, the type is the default Linux Native. If you need to change some of the partitions For other types, such as LinuxSwap or FAT32, it can be changed by command t. When pressing "t" to change the partition type, the system will prompt which partition to change and what type to change (if you want to know the partitions supported by the system type, type l). For the partition type numbers supported by Linux and their corresponding partition types, please refer to Table 2 (the information can be obtained with the l command). After changing the partition type, you can press "w" to save and exit. If you don't want to save, you can select "q" to exit directly.

  fdisk is a powerful disk operation tool, from the util-linux software package, here we only talk about how to view the disk partition table and partition structure; parameter -l, through the -l parameter, you can get the number of all disks in the machine , can also list all disk partitions;

  copy the code as follows:

  [root@localhost beanan]#fdisk -l

  Disk /dev/hda: 80.0 GB,80026361856 bytes

  255 heads, 63 sectors/track,9729 cylinders

  Units = cylinders of 16065* 512 = 8225280 bytes</p> <p>Device BootStartEndBlocksId System

  / dev / hda1 7HPFS 6144831 * 1765 / the NTFS

  / dev / hda2 766 2805 16386300c the FAT32 W95 (the LBA)

  / dev / Extended hda32806 7751 397 287 455

  / dev / hda52806 + 83 3825 8,193,118 the Linux

  / dev / hda63826 51,001,024,140,683 the Linux

  / dev / hda75101 5198787153+ 82 Linux swap / Solaris

  /dev/hda85199 66571171938683 Linux

  /dev/hda96658 7751 8787523+83 Linux

  in the above Blocks, represents the size of the partition, the unit of Blocks is byte, we can convert it into M, such as the first partition/ If the size of dev/hda1 is converted into M, it should be 6144831/1024=6000M, which is about 6G. In fact, it is not so troublesome. If you move the decimal point three places forward, you will know the approximate size;

  System Indicates the file system, such as /dev/hda1 is in NTFS format; /dev/hda2 represents the file system in fat32 format;.

  In this example, we should pay special attention to the /dev/hda3 partition, which is an extended partition; There are logical partitions under him. In fact, this partition is equivalent to a container; the ones belonging to her are hda5, hda6, hda7, hda8, hda9;

  We also noticed that there is no hda4? Why is hda4 not included in the extended partition? A disk has at most four primary partitions; hda1-4 are all primary partitions; hda4 cannot be included in the extended partition, and the extended partition is also Count 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 when I partitioned it at the time;

  after careful statistics, let's see if this disk is Isn't there still room? hda1+hda2+hda3=the actual volume of the partition, so we can calculate hda1+hda2+hda3=6144831+16386300+39728745 = 62259876 (b), convert it into M units, and move the decimal point forward by three places , so the volume occupied by the partitions that have been divided so far is 62259.876(M). In fact, the most accurate calculation is 62259876/1024=60800.67(M); and the size of this disk is 80.0 GB (80026361856byte), in fact, the actual size is 78150.744(M). ); Through our series of calculations, we can conclude that the hard disk still has space in use; there is still about 18G of unpartitioned space;

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

  copy code As follows:

  [root@localhost beinan]#fdisk -l /dev/sda</p> <p>Disk /dev/sda: 60.0 GB, 60011642880 bytes

  64 heads, 32 sectors/track,57231 cylinders

  Units = cylinders of 2048 * 512 = 1048576 bytes</p> <p>Device BootStartEndBlocksId System

  /dev/sda11 57231 5860452883Linux From

  the above situation, we can know that there is only one partition in the /dev/sda disk; the usage is almost 100%;

  we can also view /dev/

  hda code is as follows:

  [ root@localhost beanan]#fdisk -l /dev/hda

  Try it yourself?

  We can also view all disks and partitions in the current machine through: cat/proc/partitions

  df command;

  df comes from the coreutils package, when the system is installed , it comes with it; we can use this command to view the disk usage and the location where the file system is mounted;

  for example:

  copy the code as follows:

  [root@localhost beanan]# df-lh</p> <p>Filesystem Capacity Used Available % Mount Point</p> <p>/dev/hda8 11G 6.0G 4.4G 58% /</p><p>/dev/shm 236M 0 236M0% /dev/shm</ p> <p>/dev/sda1 56G22G35G39% /mnt/sda1

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

  other For the parameters, please refer to man df


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326469907&siteId=291194637