<! -- [If! SupportLists] --> 1.1 <! -- [Endif] --> Linux File System Structure
Linux has some fixed directories. Although the directory structures of various Linux distributions are not the same, they are not very different. Knowing the functions of these directories not only helps you plan disk partitions, but also makes your daily maintenance work easier.
The main directory of the Ubuntu file system is shown in Table 2.2.
Table 2.2 Main directories of the UbuntuLinux File System
Contents |
Full English name |
Chinamoocs |
/ |
/ |
The starting point of the entire directory structure. All other files and directories are under it |
/Bin |
Binaries |
Used to store the most common binary commands |
/Boot |
Boot |
Contains the main Linux boot files, such as grub and kernel files. |
/Dev |
Devices |
All devices are in this directory, including hard disks and monitors. |
/Etc |
Etc |
All configuration files of the system are placed under it |
/Home |
Home |
Stores users' HOME directories ($ HOME) and their files and configurations. |
/Lib |
Libraries |
System library Files, a bit like Windows's Program Files |
/Lost + found |
Lost + found |
Stores files lost in case of system exceptions (such as sudden downtime) to facilitate recovery |
/Media |
Media |
Attach various media, such as optical disks and floppy disks. |
/Mnt |
Mount |
Load various file systems |
/Opt |
Optionally |
Used to store the "optional" programs for Installation |
/Proc |
Processes |
Contains process and other information. It is a memory ing, not a real directory. |
/Root |
Root |
This directory is the root directory of the root user |
/Sbin |
System-only binaries |
Stores system-specific binary commands |
/Sys |
System |
Store system information |
/Tmp |
Temporary files |
Store temporary files |
/Usr |
User |
Stores applications, library files, and documents of common users. |
/Var |
Variable files |
Files that change frequently in time, size, and content |
You should be familiar with the usage of various directories in Table 2.2. Only by understanding the usage of various directories can you avoid making large errors when partitioning hard disks.
<! -- [If! SupportLists] --> 1.2 <! -- [Endif] --> "partition" and "mount point"
We often confuse the concepts of "Mount Points" and "partitions" when discussing "partitions" in Linux. In fact, as long as everyone can understand it, there is no need to fill in words. However, as a Linux system administrator, we should still understand the differences between the two concepts.
What we usually call "/var partition" is actually "partitions mounted on/var", while "/var" is just a mount point. So what is "partition?
In Linux, "partitions" are devices one by one and placed in the/dev directory. The names of IDE hard disks should be/dev/hda1 and/dev/hda2, their names are/dev/sda1 and/dev/sda2.
<! -- [If! SupportLists] --> 1.3 <! -- [Endif] --> hard disk partition Representation Method
So What Are hda and sda? They are short for Hard Driver Number A and SCSI Driver Number A, that is, hd and sd indicate the Hard disk interface type, and a is the serial Number, indicating the Hard disk. 1st IDE Hard Disks are hda, 2nd IDE Hard Disks are hdb, and so on. 1st SCSI hard disks are represented by sda, so 2nd SCSI disks are represented by sdb, and so on, in the future, sdc and sdd are used.
In fact, sd is not just a SCSI device. In addition to IDE devices, storage devices for interfaces such as SCSI, SATA, USB, and Firewire are all represented by sd.
Now you know that/dev/sdb2 refers to 2nd partitions of 2nd SCSI hard disks, while/dev/hda5 refers to 1st partitions of 5th IDE hard disks.
Table 2.3 Linux hard disk partition Representation
|
IDE interface hard drive |
SCSI interface Hard Disk |
Representation of the entire hard disk |
/Dev/hda /Dev/hdb /Dev/hdc ...... |
/Dev/sda /Dev/sdb /Dev/sdc ...... |
Hard Disk Partition Representation |
/Dev/hda1,/dev/hda2... /Dev/hdb1,/dev/hdb2... /Dev/hdc1,/dev/hdc2... |
/Dev/sda1,/dev/sda2... /Dev/sdb1,/dev/sdb2... /Dev/sdc1,/dev/sdc2... |
In the earlier version of Linux kernel, all IDE-related driver code is not only too complex, but also has many problems. As a result, Linux Kernel developers have provided libata-based PATA drivers starting from Kernel 2.6.19, so that IDE devices can be used as SCSI devices.
Therefore, in Ubuntu, whether you are using an IDE or SATA hard disk, the devices you see are/dev/sdx instead of/dev/hdx. Since then,/dev/hdx no longer exists.
Note that there is another Representation Method for hard disk Partitioning in Linux, which is used in grub. Grub originated from Grand uniied Bootloader and is a general computer boot tool that supports multiple boot modes for multiple operating systems. In grub, all storage devices of any interface are represented by hdx, where x is a number and starts from 0. For example, the 1st partitions of 1st hard disks are (hd0, 0 ).
<! -- [If! SupportLists] --> 1.4 <! -- [Endif] --> Linux partition Guide
In any Linux system, there must be at least two partitions: one is the root partition, represented by "/", and the other is the swap partition. Therefore, the simplest partitioning method is to create a swap partition first, and allocate all the remaining space to the root partition "/".
The size of the swap partition. The minimum size should be the same as the memory size. The maximum size is generally no more than twice the memory size.
The swap partition is like the Windows virtual memory swap file pagefile. sys. The system uses it as the virtual memory when needed. For example, when running a large program, when the memory is optimized, or when the system is sleeping. When the system sleep, the data in the entire memory is written to the swap partition, which is why the size of your swap partition should be at least the same as that of the memory.
In addition, it is best to create/boot separately in one partition. Because the files in this directory are important, the system may fail to start in case the partition is damaged. If a partition is created separately, damage to other partitions will not affect it, thus improving system stability. In general, the/boot partition does not need to be too large, and MB is enough.
As for other partitions, it depends on your actual needs.
For example, if your server has many users logging on to put files, it is best to separate/home partitions and provide enough space.
For example, if your server is to be stored in a database, the database may become very large./var should be partitioned separately and given enough space. Because the database is stored under/var by default.
The same is true for Web servers, because Web pages are stored under/var by default. Therefore, if you think someone will upload a large number of files, you 'd better partition/var separately and give enough space.
Prompt: As a server, Hiweed also recommends using/tmp as a separate partition. Most applications write temporary files to this directory. Although this directory is cleared every time Ubuntu restarts, no one will restart the server.
<! -- [If! SupportLists] --> 1.5 <! -- [Endif] --> Linux partition case
When Hiweed helped a friend's company build a system architecture, he built a development server inside the company, where there were Web servers and database servers.
The development server is used by company Developers to store a large number of files in the home directory. At ordinary times, when their workstation is started, it will automatically mount its own "home directory" on the Development Server to the local. Therefore, the/home of this server is the most used and requires a large space.
In addition, because it is a development server, we also need a source code repository for version management, which is placed under/var. Although the source code file size is not very large and requires no extra space, these codes are very important, so we need to protect them like protection/boot.
Therefore, for this development server, our partitioning solution (the server hard disk has a total of 80 GB [10 GB], and the memory is 1 GB [512 MB]), see Table 2.4.
Table 2.4 Development Server partition Solution
File System |
Mount point |
Big and small |
Partition format |
/Dev/sda1 |
/Boot |
254 MB [254] |
Ext2 |
/Dev/sda2 |
/ |
10 GB [2] |
Ext4 |
/Dev/sda5 |
(None) |
2 GB [768] |
Swap |
/Dev/sda6 |
/Var |
20.3 GB [2] |
Ext4 |
/Dev/sda7 |
/Home |
46.8 GB [4.3] |
Ext4 |
/Dev/sda8 |
/Tmp |
2 GB [768] |
Ext4 |
The preceding partition scheme is just a reference. The actual partition scheme should be based on your actual situation.
<! -- [If! SupportLists] --> 1.6 <! -- [Endif] -->/etc/fstab Introduction
All static file systems in Linux are described in the/etc/fstab file. Fstab is short for File System Table, that is, "File System Table ". When the system starts, each partition is mounted through the information in fstab. The file system entry of fstab has six fields, as shown in Table 2.5.
Table 2.5 fstab format
Backup |
Mount point |
Lattice |
Mount options |
Backup? |
Check order |
/Dev/sdb2 |
/Home |
Ext4 |
Ults |
0 |
2 |
The following describes the meaning of each field, as shown in Table 2.6.
Table 2.6 meaning of each fstab Field
Segment |
Description |
Device |
Name or UUID of the storage device (partition) |
Mount point |
Name of the destination folder to be mounted. After mounting, you can access the device from this folder. |
Format |
File System format, for example, ext4 |
. Mount options |
Mounting options. The options are the same as those of the mount command. For details, refer to man mount. |
Backup? |
Enable/disable dump backup |