Merge pull request #3692 from GHLandy/master

[完成翻译] Part 4 - LFCS: Partitioning Storage Devices, Formatting Filesystems and Configuring Swap Partition;[开始翻译] Part 5 - LFCS: How to Mount/Unmount Local and Network (Samba & NFS) Filesystems in Linux
This commit is contained in:
Xingyu.Wang 2015-12-31 00:06:00 +08:00
commit 49845562ae
3 changed files with 198 additions and 194 deletions

View File

@ -1,193 +0,0 @@
GHLandy Translating
Part 4 - LFCS: Partitioning Storage Devices, Formatting Filesystems and Configuring Swap Partition
================================================================================
Last August, the Linux Foundation launched the LFCS certification (Linux Foundation Certified Sysadmin), a shiny chance for system administrators to show, through a performance-based exam, that they can perform overall operational support of Linux systems: system support, first-level diagnosing and monitoring, plus issue escalation if needed to other support teams.
![Linux Foundation Certified Sysadmin Part 4](http://www.tecmint.com/wp-content/uploads/2014/10/lfcs-Part-4.png)
Linux Foundation Certified Sysadmin Part 4
Please aware that Linux Foundation certifications are precise, totally based on performance and available through an online portal anytime, anywhere. Thus, you no longer have to travel to a examination center to get the certifications you need to establish your skills and expertise.
Please watch the below video that explains The Linux Foundation Certification Program.
youtube 视频
<iframe width="720" height="405" frameborder="0" allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/Y29qZ71Kicg"></iframe>
This post is Part 4 of a 10-tutorial series, here in this part, we will cover the Partitioning storage devices, Formatting filesystems and Configuring swap partition, that are required for the LFCS certification exam.
### Partitioning Storage Devices ###
Partitioning is a means to divide a single hard drive into one or more parts or “slices” called partitions. A partition is a section on a drive that is treated as an independent disk and which contains a single type of file system, whereas a partition table is an index that relates those physical sections of the hard drive to partition identifications.
In Linux, the traditional tool for managing MBR partitions (up to ~2009) in IBM PC compatible systems is fdisk. For GPT partitions (~2010 and later) we will use gdisk. Each of these tools can be invoked by typing its name followed by a device name (such as /dev/sdb).
#### Managing MBR Partitions with fdisk ####
We will cover fdisk first.
# fdisk /dev/sdb
A prompt appears asking for the next operation. If you are unsure, you can press the m key to display the help contents.
![fdisk Help Menu](http://www.tecmint.com/wp-content/uploads/2014/10/fdisk-help.png)
fdisk Help Menu
In the above image, the most frequently used options are highlighted. At any moment, you can press p to display the current partition table.
![Check Partition Table in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Show-Partition-Table.png)
Show Partition Table
The Id column shows the partition type (or partition id) that has been assigned by fdisk to the partition. A partition type serves as an indicator of the file system, the partition contains or, in simple words, the way data will be accessed in that partition.
Please note that a comprehensive study of each partition type is out of the scope of this tutorial as this series is focused on the LFCS exam, which is performance-based.
**Some of the options used by fdisk as follows:**
You can list all the partition types that can be managed by fdisk by pressing the l option (lowercase l).
Press d to delete an existing partition. If more than one partition is found in the drive, you will be asked which one should be deleted.
Enter the corresponding number, and then press w (write modifications to partition table) to apply changes.
In the following example, we will delete /dev/sdb2, and then print (p) the partition table to verify the modifications.
![fdisk Command Options](http://www.tecmint.com/wp-content/uploads/2014/10/fdisk-options.png)
fdisk Command Options
Press n to create a new partition, then p to indicate it will be a primary partition. Finally, you can accept all the default values (in which case the partition will occupy all the available space), or specify a size as follows.
![Create New Partition in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-New-Partition.png)
Create New Partition
If the partition Id that fdisk chose is not the right one for our setup, we can press t to change it.
![Change Partition Name in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Change-Partition-Name.png)
Change Partition Name
When youre done setting up the partitions, press w to commit the changes to disk.
![Save Partition Changes](http://www.tecmint.com/wp-content/uploads/2014/10/Save-Partition-Changes.png)
Save Partition Changes
#### Managing GPT Partitions with gdisk ####
In the following example, we will use /dev/sdb.
# gdisk /dev/sdb
We must note that gdisk can be used either to create MBR or GPT partitions.
![Create GPT Partitions in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-GPT-Partitions.png)
Create GPT Partitions
The advantage of using GPT partitioning is that we can create up to 128 partitions in the same disk whose size can be up to the order of petabytes, whereas the maximum size for MBR partitions is 2 TB.
Note that most of the options in fdisk are the same in gdisk. For that reason, we will not go into detail about them, but heres a screenshot of the process.
![gdisk Command Options](http://www.tecmint.com/wp-content/uploads/2014/10/gdisk-options.png)
gdisk Command Options
### Formatting Filesystems ###
Once we have created all the necessary partitions, we must create filesystems. To find out the list of filesystems supported in your system, run.
# ls /sbin/mk*
![Check Filesystems Type in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Filesystems.png)
Check Filesystems Type
The type of filesystem that you should choose depends on your requirements. You should consider the pros and cons of each filesystem and its own set of features. Two important attributes to look for in a filesystem are.
- Journaling support, which allows for faster data recovery in the event of a system crash.
- Security Enhanced Linux (SELinux) support, as per the project wiki, “a security enhancement to Linux which allows users and administrators more control over access control”.
In our next example, we will create an ext4 filesystem (supports both journaling and SELinux) labeled Tecmint on /dev/sdb1, using mkfs, whose basic syntax is.
# mkfs -t [filesystem] -L [label] device
or
# mkfs.[filesystem] -L [label] device
![Create ext4 Filesystems in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-ext4-Filesystems.png)
Create ext4 Filesystems
### Creating and Using Swap Partitions ###
Swap partitions are necessary if we need our Linux system to have access to virtual memory, which is a section of the hard disk designated for use as memory, when the main system memory (RAM) is all in use. For that reason, a swap partition may not be needed on systems with enough RAM to meet all its requirements; however, even in that case its up to the system administrator to decide whether to use a swap partition or not.
A simple rule of thumb to decide the size of a swap partition is as follows.
Swap should usually equal 2x physical RAM for up to 2 GB of physical RAM, and then an additional 1x physical RAM for any amount above 2 GB, but never less than 32 MB.
So, if:
M = Amount of RAM in GB, and S = Amount of swap in GB, then
If M < 2
S = M *2
Else
S = M + 2
Remember this is just a formula and that only you, as a sysadmin, have the final word as to the use and size of a swap partition.
To configure a swap partition, create a regular partition as demonstrated earlier with the desired size. Next, we need to add the following entry to the /etc/fstab file (X can be either b or c).
/dev/sdX1 swap swap sw 0 0
Finally, lets format and enable the swap partition.
# mkswap /dev/sdX1
# swapon -v /dev/sdX1
To display a snapshot of the swap partition(s).
# cat /proc/swaps
To disable the swap partition.
# swapoff /dev/sdX1
For the next example, well use /dev/sdc1 (=512 MB, for a system with 256 MB of RAM) to set up a partition with fdisk that we will use as swap, following the steps detailed above. Note that we will specify a fixed size in this case.
![Create-Swap-Partition in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-Swap-Partition.png)
Create Swap Partition
![Add Swap Partition in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Enable-Swap-Partition.png)
Enable Swap Partition
### Conclusion ###
Creating partitions (including swap) and formatting filesystems are crucial in your road to Sysadminship. I hope that the tips given in this article will guide you to achieve your goals. Feel free to add your own tips & ideas in the comments section below, for the benefit of the community.
Reference Links
- [About the LFCS][1]
- [Why get a Linux Foundation Certification?][2]
- [Register for the LFCS exam][3]
--------------------------------------------------------------------------------
via: http://www.tecmint.com/create-partitions-and-filesystems-in-linux/
作者:[Gabriel Cánepa][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/gacanepa/
[1]:https://training.linuxfoundation.org/certification/LFCS
[2]:https://training.linuxfoundation.org/certification/why-certify-with-us
[3]:https://identity.linuxfoundation.org/user?destination=pid/1

View File

@ -1,3 +1,5 @@
GHLandy Translating
Part 5 - LFCS: How to Mount/Unmount Local and Network (Samba & NFS) Filesystems in Linux
================================================================================
The Linux Foundation launched the LFCS certification (Linux Foundation Certified Sysadmin), a brand new program whose purpose is allowing individuals from all corners of the globe to get certified in basic to intermediate system administration tasks for Linux systems, which includes supporting running systems and services, along with overall monitoring and analysis, plus smart decision-making when it comes to raising issues to upper support teams.
@ -229,4 +231,4 @@ via: http://www.tecmint.com/mount-filesystem-in-linux/
[2]:http://www.tecmint.com/how-to-setup-nfs-server-in-linux/
[3]:https://training.linuxfoundation.org/certification/LFCS
[4]:https://training.linuxfoundation.org/certification/why-certify-with-us
[5]:https://identity.linuxfoundation.org/user?destination=pid/1
[5]:https://identity.linuxfoundation.org/user?destination=pid/1

View File

@ -0,0 +1,195 @@
GHLandy Translated
LFCS 系列第四讲:分区存储设备、格式化文件系统和配置交换分区
================================================================================
去年八月份Linux 基金会发起了 LFCSLinux Foundation Certified SysadminLinux 基金会认证系统管理员)认证,给所有系统管理员一个展现自己的机会。通过基础考试后,他们可以胜任在 Linux 上的整体运维工作:包括系统支持、一流水平的诊断和监控以及在必要之时向其他支持团队提交帮助请求等。
![Linux Foundation Certified Sysadmin Part 4](http://www.tecmint.com/wp-content/uploads/2014/10/lfcs-Part-4.png)
LFCS 系列第四讲
需要注意的是Linux 基金会认证是非常严格的,通过与否完全要看个人能力。通过在线链接,你可以随时随地参加 Linux 基金会认证考试。所以,你再也不用到考试中心了,只需要不断提高自己的专业技能和经验就可去参加考试了。
请看一下视频,这里将讲解 Linux 基金会认证程序。
youtube 视频
<iframe width="720" height="405" frameborder="0" allowfullscreen="allowfullscreen" src="//www.youtube.com/embed/Y29qZ71Kicg"></iframe>
本讲是《十套教程》系列中的第四讲。在本讲中,我们将涵盖分区存储设备、格式化文件系统和配置交换分区等内容,这些都是 LFCS 认证中的必备知识。
### 分区存储设备 ###
分区是一种将单独的硬盘分成一个或多个区的手段。一个分区只是硬盘的一部分,我们可以认为这部分是独立的磁盘,里边包含一个单一类型的文件系统。分区表则是将硬盘上这些分区与分区标识符联系起来的索引。
在 Linux 中IBM PC 兼容系统里边用于管理传统 MBR最新到2009年分区的工具是 fdisk。对于 GPT2010年至今分区我们使用 gdisk。这两个工具都可以通过程序名后面加上设备名称如 /dev/sdb进行调用。
#### 使用 fdisk 管理 MBR 分区 ####
我们先来介绍 fdisk
# fdisk /dev/sdb
然后出现提示说进行下一步操作。若不确定如何操作,按下 “m” 键显示帮助。
![fdisk Help Menu](http://www.tecmint.com/wp-content/uploads/2014/10/fdisk-help.png)
fdisk 帮助菜单
上图中,使用频率最高的选项已高亮显示。你可以随时按下 “p” 显示分区表。
![Check Partition Table in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Show-Partition-Table.png)
显示分区表
Id 列显示由 fdisk 分配给每个分区的分区类型(分区 id。一个分区类型代表一种文件系统的标识符简单来说包括该分区上数据的访问方法。
请注意,每个分区类型的全面都全面讲解将超出了本教程的范围——本系列教材主要专注于 LFCS 测试,因能力为主。
**下面列出一些 fdisk 常用选项:**
按下 “l”小写 L选项来显示所有可以由 fdisk 管理的分区类型。
按下 “d” 可以删除现有的分区。若硬盘上有多个分区fdisk 将询问你要删除那个分区。
键入对应的数字,并按下 “w” 保存更改(将更改写入分区表)。
在下图的命令中,我们将删除 /dev/sdb2然后显示p分区表来验证更改。
![fdisk Command Options](http://www.tecmint.com/wp-content/uploads/2014/10/fdisk-options.png)
fdisk 命令选项
按下 “n” 后接着按下 “p” 会创建新一个主分区。最后,你可以使用所有的默认值(这将占用所有的可用空间),或者像下面一样自定义分区大小。
![Create New Partition in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-New-Partition.png)
创建新分区
若 fdisk 分配的分区 Id 并不是我们想用的,可以按下 “t” 来更改。
![Change Partition Name in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Change-Partition-Name.png)
更改分区类型
全部设置好分区后,按下 “w” 将更改保存到硬盘分区表上。
![Save Partition Changes](http://www.tecmint.com/wp-content/uploads/2014/10/Save-Partition-Changes.png)
保存分区更改
#### 使用 gdisk 管理 GPT 分区 ####
下面的例子中,我们使用 /dev/sdb。
# gdisk /dev/sdb
必须注意的是gdisk 可以用于创建 MBR 和 GPT 两种分区表。
![Create GPT Partitions in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-GPT-Partitions.png)
创建 GPT 分区
使用 GPT 分区方案,我们可以在同一个硬盘上创建最多 128 个分区,单个分区最大以 PB 为单位,而 MBR 分区方案最大的只能 2TB。
注意fdisk 与 gdisk 中大多数命令都是一样的。因此,我们不会详细介绍这些命令选项,而是给出一张使用过程中的截图。
![gdisk Command Options](http://www.tecmint.com/wp-content/uploads/2014/10/gdisk-options.png)
gdisk 命令选项
### 格式化文件系统 ###
一旦创建完需要的分区,我们就必须为分区创建文件系统。查询你所用系统支持的文件系统,请运行:
# ls /sbin/mk*
![Check Filesystems Type in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Check-Filesystems.png)
检查文件系统类型
选择文件系统取决于你的需求。你应该考虑到每个文件系统的优缺点以及其特点。选择文件系统需要看的两个重要属性:
- 日志支持,允许从系统崩溃事件中快速恢复数据。
- 安全增强式 LinuxSELinux支持按照项目 wiki 所说,“安全增强式 Linux 允许用户和管理员更好的把握访问控制权限”。
在接下来的例子中,我们通过 mkfs 在 /dev/sdb1上创建 ext4 文件系统(支持日志和 SELinux标卷为 Tecmint。mkfs 基本语法如下:
# mkfs -t [filesystem] -L [label] device
或者
# mkfs.[filesystem] -L [label] device
![Create ext4 Filesystems in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-ext4-Filesystems.png)
创建 ext4 文件系统
### 创建并启用交换分区 ###
要让 Linux 系统访问虚拟内存则必须有一个交换分区当内存RAM用完的时候将硬盘中指定分区即 Swap 分区当做内存来使用。因此当有足够的系统内存RAM来满足系统的所有的需求时我们并不需要划分交换分区。尽管如此是否使用交换分区取决于管理员。
下面列出选择交换分区大小的经验法则:
物理内存不高于 2GB 时,取两倍物理内存大小即可;物理内存在 2GB 以上时,取一倍物理内存大小即可;并且所取大小应该大于 32MB。
所以,如果:
M为物理内存大小S 为交换分区大小,单位 GB那么
若 M < 2
S = M *2
否则
S = M + 2
记住,这只是基本的经验。对于作为系统管理员的你,才是决定是否使用交换分区及其大小的关键。
要配置交换分区,首先要划分一个常规分区,大小像我们之前演示的那样来选取。然后添加以下条目到 /etc/fstab 文件中其中的X要更改为对应的 b 或 c
/dev/sdX1 swap swap sw 0 0
最后,格式化并启用交换分区:
# mkswap /dev/sdX1
# swapon -v /dev/sdX1
显示交换分区的快照:
# cat /proc/swaps
关闭交换分区:
# swapoff /dev/sdX1
下面的例子,我们会使用 fdisk 将 /dev/sdc1512MB系统和内存为 256MB来设置交换分区下面是我们之前详细提过的步骤。注意这种情况下我们使用的是指定大小分区。
![Create-Swap-Partition in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Create-Swap-Partition.png)
创建交换分区
![Add Swap Partition in Linux](http://www.tecmint.com/wp-content/uploads/2014/10/Enable-Swap-Partition.png)
启用交换分区
### 结论 ###
在你的系统管理员之路上,创建分区(包括交换分区)和格式化文件系统是非常重要的一部。我希望本文中所给出的技巧指导你到达你的管理员目标。随时在本讲评论区中发表你的技巧和想法,一起为社区做贡献。
参考链接
- [About the LFCS][1]
- [Why get a Linux Foundation Certification?][2]
- [Register for the LFCS exam][3]
--------------------------------------------------------------------------------
via: http://www.tecmint.com/create-partitions-and-filesystems-in-linux/
作者:[Gabriel Cánepa][a]
译者:[GHLandy](https://github.com/GHLandy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/gacanepa/
[1]:https://training.linuxfoundation.org/certification/LFCS
[2]:https://training.linuxfoundation.org/certification/why-certify-with-us
[3]:https://identity.linuxfoundation.org/user?destination=pid/1