translated by liujing97

This commit is contained in:
liujing97 2019-04-09 16:59:46 +08:00
parent ad59536e87
commit 70bb708a2c

View File

@ -7,21 +7,20 @@
[#]: via: (https://opensource.com/article/19/4/create-filesystem-linux-partition)
[#]: author: (Kedar Vijay Kulkarni (Red Hat) https://opensource.com/users/kkulkarn)
How to create a filesystem on a Linux partition or logical volume
如何在 Linux 分区或逻辑卷中创建文件系统
======
Learn to create a filesystem and mount it persistently or
non-persistently in your system.
学习在你的系统中创建一个文件系统,并且长期挂载或者非长期地挂载它
![Filing papers and documents][1]
In computing, a filesystem controls how data is stored and retrieved and helps organize the files on the storage media. Without a filesystem, information in storage would be one large block of data, and you couldn't tell where one piece of information stopped and the next began. A filesystem helps manage all of this by providing names to files that store data and maintaining a table of files and directories—along with their start/end location, total size, etc.—on disks within the filesystem.
在计算技术中,文件系统控制如何存储和检索数据,并且帮助组织存储媒介中的文件。如果没有文件系统,信息将被存储为一个大数据块,而且你无法知道一条信息在哪结束,下一条信息在哪开始。文件系统通过为存储数据的文件提供名称,并且在文件系统中的磁盘上维护文件和目录表以及它们的开始和结束位置,总的大小等来帮助管理所有的这些。
In Linux, when you create a hard disk partition or a logical volume, the next step is usually to create a filesystem by formatting the partition or logical volume. This how-to assumes you know how to create a partition or a logical volume, and you just want to format it to contain a filesystem and mount it.
在 Linux 中,当你创建一个硬盘分区或者逻辑卷之后,接下来通常是通过格式化这个分区后逻辑卷来创建文件系统。本文向你展示如何去创建一个分区或一个逻辑卷,并且你想要用文件系统格式化并挂载它。
### Create a filesystem
### 创建文件系统
Imagine you just added a new disk to your system and created a partition named **/dev/sda1** on it.
假设你为你的系统添加了一块新的硬盘并且在它上面创建了一个叫 **/dev/sda1** 的分区。
1. To verify that the Linux kernel can see the partition, you can **cat** out **/proc/partitions** like this:
1. 为了验证 Linux 核可以发现这个分区,你可以 **cat****/proc/partitions** 的内容,就像这样:
```
[root@localhost ~]# cat /proc/partitions
@ -40,7 +39,7 @@ major minor #blocks name
```
2. Decide what kind of filesystem you want to create, such as ext4, XFS, or anything else. Here are a few options:
2. 决定你想要去创建的文件系统种类,比如 ext4, XFS或者其他的一些。这里是一些选项
```
[root@localhost ~]# mkfs.<tab><tab>
@ -48,7 +47,7 @@ mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
```
3. For the purposes of this exercise, choose ext4. (I like ext4 because it allows you to shrink the filesystem if you need to, a thing that isn't as straightforward with XFS.) Here's how it can be done (the output may differ based on device name/sizes):
3. 为了这次练习的目的,选择 ext4。我喜欢 ext4 因为如果你需要的话,它可以允许你去压缩文件系统,这对于 XFS 并不简单。)这里是完成它的方法(输出可能会因设备名称或者大小而不同):
```
[root@localhost ~]# mkfs.ext4 /dev/sda1
@ -74,15 +73,15 @@ Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
```
4. In the previous step, if you want to create a different kind of filesystem, use a different **mkfs** command variation.
4. 在上一步中,如果你想去创建不同的文件系统,请使用不同变种的 **mkfs** 命令。
### Mount a filesystem
### 挂载文件系统
After you create your filesystem, you can mount it in your operating system.
当你创建好文件系统后,你可以在你的操作系统中挂载它。
1. First, identify the UUID of your new filesystem. Issue the **blkid** command to list all known block storage devices and look for **sda1** in the output:
1. 首先,识别出新文件系统的 UUID 号。使用 **blkid** 命令列出所有可识别的块存储设备并且在输出信息中查找 **sda1**
```
[root@localhost ~]# blkid
@ -95,7 +94,7 @@ After you create your filesystem, you can mount it in your operating system.
```
2. Run the following command to mount the **/dev/sd1** device :
2. 运行下面的命令挂载 **/dev/sd1** 设备:
```
[root@localhost ~]# mkdir /mnt/mount_point_for_dev_sda1
@ -113,11 +112,11 @@ tmpfs 93M 0 93M 0% /run/user/0
/dev/sda1 2.9G 9.0M 2.7G 1% /mnt/mount_point_for_dev_sda1
[root@localhost ~]#
```
The **df -h** command shows which filesystem is mounted on which mount point. Look for **/dev/sd1**. The mount command above used the device name **/dev/sda1**. Substitute it with the UUID identified in the **blkid** command. Also, note that a new directory was created to mount **/dev/sda1** under **/mnt**.
命令 **df -h** 显示了每个文件系统被挂载的挂载点。查找 **/dev/sd1**。上面的挂载命令使用的设备名称是 **/dev/sda1**。用 **blkid** 命令中的 UUID 号替换它。注意,在 **/mnt** 下一个被新创建的目录挂载了 **/dev/sda1**。
3. A problem with using the mount command directly on the command line (as in the previous step) is that the mount won't persist across reboots. To mount the filesystem persistently, edit the **/etc/fstab** file to include your mount information:
3. 直接在命令行下使用挂载命令(就像上一步一样)会有一个问题,那就是挂载不会在设备重启后存在。为使永久性地挂载文件系统,编辑 **/etc/fstab** 文件去包含你的挂载信息:
```
UUID=ac96b366-0cdd-4e4c-9493-bb93531be644 /mnt/mount_point_for_dev_sda1/ ext4 defaults 0 0
@ -125,7 +124,7 @@ UUID=ac96b366-0cdd-4e4c-9493-bb93531be644 /mnt/mount_point_for_dev_sda1/ ext4 de
4. After you edit **/etc/fstab** , you can **umount /mnt/mount_point_for_dev_sda1** and run the command **mount -a** to mount everything listed in **/etc/fstab**. If everything went right, you can still list **df -h** and see your filesystem mounted:
4. 编辑完 **/etc/fstab** 文件后,你可以 **umount /mnt/mount_point_for_fev_sda1** 并且运行 **mount -a** 命令去挂载被列在 **/etc/fstab** 文件中的所有文件。如果一切顺利的话,你可以使用 **df -h** 列出并且查看你挂载的文件系统:
```
root@localhost ~]# umount /mnt/mount_point_for_dev_sda1/
@ -141,7 +140,7 @@ tmpfs 93M 0 93M 0% /run/user/0
/dev/sda1 2.9G 9.0M 2.7G 1% /mnt/mount_point_for_dev_sda1
```
5. You can also check whether the filesystem was mounted:
5. 你也可以检测文件系统被挂载在何处:
```
[root@localhost ~]# mount | grep ^/dev/sd
@ -150,7 +149,7 @@ tmpfs 93M 0 93M 0% /run/user/0
Now you know how to create a filesystem and mount it persistently or non-persistently within your system.
现在你已经知道如何去创建文件系统并且长期或者非长期的挂载在你的系统中。
--------------------------------------------------------------------------------