Disk partitions and mount

(Finishing from "Bird Brother Linux private kitchens" Basics)

 

1. observe the state of the disk partition

1.1lsblk lists all the disks on the system list

lsblk can be seen as the short list block device, meaning that lists all storage devices.

 Let's talk about what information the default output:

• NAME: is the file name of the device Hello! Omit the / dev directory and other leading

• MAJ: MIN: In fact, the core of the device is recognized through these two codes familiar! Are primary: secondary device Code

• RM: whether the removable device (removable device), such as CD-ROM, USB disk, etc.

• SIZE: Capacity

• RO: whether it is a read-only device

• TYPE: disk (disk), partition slots (partition) or read-only memory (rom), etc. Output

• MOUTPOINT: mount point

1.2 BLKID listed device UUID parameters

Although lsblk ready to use -f to list the UUID data file system and device, however, can also be used directly blkid to find UUID device.

1.3 parted listed in the partition table and the type of disk partition information (this command can also be partitioned)

 

2. The disk partition: GDisk / fdisk

Please use the MBR partition table fdisk partition, GPT partition table, please use gdisk partition.

Operation of these two tools is similar, after executing the software instructions may be operated by the internal data of the software.

Below the first to GPT gdisk example:

 

 

 You should first find by lsblk or blkid disk, and then parted / dev / xxx print to find out the partition table type internal use only after gdisk or fdisk to operate the system. On the table can be found gdisk scans the MBR and GPT partition table, but this software is simple to use in GPT partition table is better.

Just press "q" to leave gdisk, then all the actions "will not take effect! "Instead, press the" w "is the action to take effect.

 

 

 Use "p" to list the current partition table information Fengyun disks, the upper half of the information displayed in the status of the entire disk. A total figure of around 40GB of disk capacity, a total of 83,886,080 sectors, each sector has a capacity of 512bytes. Note that now mainly partition sector is the smallest unit. The lower half of the partition table information in the main list of individual items of information for each partition slot. The meaning of each item is as follows:

• Number: partition slot number, number 1 refers to the / dev / vda1 thus calculated.

• Start (sector): start position of each sector number of partition slots

• End (sector): the position of the end sector numbers of each partition, between the start and can calculate the total capacity of the partition slots

• Size: partition tank capacity

• Code: possible file system type of partition in the tank. Linux is 8300, swap 8200. But this project is only a hint of it, really is not necessarily representative of this partition tank file system

• Name: name of the file system, and so on.

 

With gdisk new partition slots

Suppose I need to have the zoning requirements are as follows:

• 1GB of xfs file system (Linux)

• 1GB of vfat file system (Windows)

• 0.5GB 的 swap (Linux swap)

 

 

 重点在『 Last sector 』那一行,那行绝对不要使用默认值!因为默认值会将所有的容量用光!因此它默认选择最大的扇区号码! 因为我们仅要 1GB 而已,所以你得要加上 +1G 这样即可!不需要计算 sector 的数量,gdisk 会根据你填写的数值, 直接计算出最接近该容量的扇区数!每次新增完毕后,请立即『 p 』查看一下结果喔!请继续处理后续的两个分区槽! 最终出现的画面会有点像底下这样才对:

 

 

 那么就直接写入磁盘分区表:

 

 

 因为 Linux 此时还在使用这颗磁盘,为了担心系统出问题,所以分区表并没有被更新!这个时候我们有两个方式可以来处理,其中一个是重新启动,另外一种则是通过 partprobe 这个指令来处理即可

 

 

 

3.磁盘格式化(创建文件系统)

3.1XFS文件系统mkfs.xfs

3.2  EXT4 文件系统 mkfs.ext4

3.3 其他文件系统 mkfs

 

4.文件系统检验

4.1 xfs_repair 处理 XFS 文件系统

 xfs_repair 可以检查/修复文件系统,不过,因为修复文件系统是个很庞大的任务!因此,修复时该文件系统不能被挂载! 所以,检查与修复 /dev/vda4 没啥问题,但是修复 /dev/centos/home 这个已经挂载的文件系统时,若可以卸除,卸除后再处理即可。

4.2 fsck.ext4 处理 EXT4 文件系统

无论是 xfs_repair 或 fsck.ext4,这都是用来检查与修正文件系统错误的指令。注意:通常只有身为 root 且你的文件系统有问题的时候才使用这个指令,否则在正常状况下使用此一指令, 可能会造成对系统的危害。

执行 xfs_repair/fsck.ext4 时, 被检查的 partition 务必不可挂载到系统上!亦即是需要在卸除的状态。

 

5.文件系统挂载与卸载

要进行挂载前,你最好先确定几件事:

•        单一文件系统不应该被重复挂载在不同的挂载点(目录)中;

•        单一目录不应该重复挂载多个文件系统;

•   要作为挂载点的目录,理论上应该都是空目录才是。

那么挂载了文件系统之后,原目录下的东西就会暂时的消失,这只是暂时的,等卸载了之后又会出来。

挂载——mount命令

卸载——umount命令

 

6 磁盘/文件系统参数修订

你可能要修改 Label name , 或者是 journal 的参数,或者是其他磁盘/文件系统运作时的相关参数,使用mknod命令。

 

7.设置开机挂载

直接到 /etc/fstab 里面去修改。

但是系统挂载的一些限制:

•        根目录 / 是必须挂载的﹐而且一定要先于其它 mount point 被挂载进来。

•        其它 mount point 必须为已建立的目录﹐可任意指定﹐但一定要遵守必须的系统目录架构原则 (FHS)

•  所有 mount point 在同一时间之内﹐只能挂载一次。

•        所有 partition 在同一时间之内﹐只能挂载一次。

•  如若进行卸除﹐您必须先将工作目录移到 mount point(及其子目录) 之外。

 

 

 这个文件的内容共有六个字段, 各个字段的总结数据与详细数据如下:

[装置/UUID等]  [挂载点]  [文件系统]  [文件系统参数]  [dump]  [fsck]

o   第一栏:磁盘装置文件名/UUID/LABEL name:

这个字段可以填写的数据主要有三个项目:

§  文件系统或磁盘的装置文件名,如 /dev/vda2 等

§  文件系统的 UUID 名称,如 UUID=xxx

§  文件系统的 LABEL 名称,例如 LABEL=xxx

这三个任意一个都可以。

o   第二栏:挂载点 (mount point)::

就是挂载点啊,一定是目录。

o   第三栏:磁盘分区槽的文件系统:

在手动挂载时可以让系统自动测试挂载,但在这个文件当中我们必须要手动写入文件系统才行!包括 xfs, ext4, vfat, reiserfs, nfs 等等。

o   第四栏:文件系统参数:

这里我们利用表格的方式再汇整一下参数:

参数

内容意义

async/sync

异步/同步

设定磁盘是否以异步方式运作!预设为 async(效能较佳)

auto/noauto

自动/非自动

当下达 mount -a 时,此文件系统是否会被主动测试挂载。预设为 auto。

rw/ro

可擦写/只读

让该分区槽以可擦写或者是只读的型态挂载上来,如果你想要分享的数据是不给用户随意变更的, 这里也能够设定为只读。则不论在此文件系统的文件是否设定 w 权限,都无法写入喔!

exec/noexec

可执行/不可执行

限制在此文件系统内是否可以进行『执行』的工作?如果是纯粹用来储存数据的目录, 那么可以设定为 noexec 会比较安全。不过,这个参数也不能随便使用,因为你不知道该目录下是否默认会有执行档。

举例来说,如果你将 noexec 设定在 /var ,当某些软件将一些执行文件放置于 /var 下时,那就会产生很大的问题喔! 因此,建议这个 noexec 最多仅设定于你自定义或分享的一般数据目录。

user/nouser

允许/不允许使用者挂载

是否允许用户使用 mount 指令来挂载呢?一般而言,我们当然不希望一般身份的 user 能使用 mount 啰,因为太不安全了,因此这里应该要设定为 nouser 啰!

suid/nosuid

具有/不具有 suid 权限

该文件系统是否允许 SUID 的存在?如果不是执行文件放置目录,也可以设定为 nosuid 来取消这个功能!

defaults

同时具有 rw, suid, dev, exec, auto, nouser, async 等参数。 基本上,预设情况使用 defaults 设定即可!

o   第五栏:能否被 dump 备份指令作用:

dump 是一个用来做为备份的指令,不过现在有太多的备份方案了,所以这个项目可以不要理会,可以直接输入 0

o   第六栏:是否以 fsck 检验扇区:

早期开机的流程中,会有一段时间去检验本机的文件系统,看看文件系统是否完整 (clean)。 不过这个方式使用的主要是透过 fsck 去做的,我们现在用的 xfs 文件系统就没有办法适用,因为 xfs 会自己进行检验,不需要额外进行这个动作,所以可以直接填 0 。

Guess you like

Origin www.cnblogs.com/ericz2j/p/12044657.html
Recommended