Home  >  Article  >  Operation and Maintenance  >  How to partition the Linux operating system

How to partition the Linux operating system

angryTom
angryTomOriginal
2019-11-08 09:31:075561browse

How to partition the Linux operating system

How to partition the Linux operating system

1. What is a partition?

Partitioning is to divide a hard disk drive into several logical drives. Partitioning is to use the continuous blocks of the hard disk as an independent magnetic hard drive. The partition table is an index of hard disk partitions, and the partition information will be written into the partition table.

2. Why do we need multiple partitions?

Prevent data loss: If the system has only one partition, then if this partition is damaged, the user will lose all data.

Increase disk space usage efficiency: You can format the partition with different block sizes. If there are many 1K files and the hard disk partition block size is 4K, then 3K space will be wasted for each file stored. . At this time we need to take the average of these file sizes to divide the block size.

Data surge to the limit will not cause system hangs: Separating user data and system data can prevent user data from filling the entire hard disk and causing system hangs.

3. Introduction to the usage of the partition tool fdisk

Introduction to the fdisk command parameters

   p、打印分区表。
   n、新建一个新分区。
   d、删除一个分区。
   q、退出不保存。
   w、把分区写进分区表,保存并退出。

Example:

   [root@localhost ~]# fdisk /dev/hdd

Press " p" key to print the partition table. This hard disk has not been partitioned yet. Press the "n" key to create a new partition. Two menus appear: e represents the extended partition and p represents the primary partition. Press the "p" key and a prompt appears: "Partition number (1-4): "Select the primary partition number

Enter "1" to represent the first one Primary partition. Just press Enter to start partitioning on 1 cylinder. Prompt for last cylinder or size. Enter 5620M and press Enter, indicating that the first partition is 5G space. Press "p" to view the partitions. In this way, a primary partition is divided.

Next, divide the second primary partition and give the remaining space to the second primary partition.

Press the "n" key to add a partition, press the "p" key to set it as the primary partition, enter "2" to set the primary partition number to 2, and press Enter twice to allocate the remaining space to the second partition. primary partition. Press the "p" key to print the partition table

Press the "w" key to save and exit.

Readers can divide the appropriate partitions according to their own hard disk size.

4. Using partitions

Before using the hard disk, the partition must be formatted and mounted.

[root@localhost ~]#mkfs.ext3 /dev/hdd1
[root@localhost ~]#mkfs.ext3 /dev/hdd2

Create the mounting directory

   [root@localhost ~]#mkdir /hdd1 /hdd2
   挂载/dev/hdd1 /dev/hdd2
   [root@localhost ~]#mount /dev/hdd1 /hdd1
   [root@localhost ~]#mount /dev/hdd2 /hdd2

View

   [root@localhost ~]#df -h
   Filesystem            Size  Used Avail Use% Mounted on
   /dev/hda3             7.5G  2.8G  4.3G  40% /
   /dev/hda1              99M   17M   78M  18% /boot
   tmpfs                  62M     0   62M   0% /dev/shm
   /dev/hdd1             2.5G   68M  2.3G   3% /hdd1
   /dev/hdd2             2.5G   68M  2.3G   3% /hdd2

Now write data to the /hdd1 directory and store it in /dev/hdd A hard drive.

Recommended: linux system tutorial

The above is the detailed content of How to partition the Linux operating system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn