[CentOS 7系列]磁盘格式化与挂载

在windows操作系统中,硬盘有fat32和ntfs等多种格式。在linux中同样如此。CentOS 6之前,主要是ext4、ext3和ext2等格式。在CentOS 7这个版本开始,默认的磁盘格式变成了xfs格式。

[[email protected] ~]# cat /etc/filesystems
xfs
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*
[[email protected] ~]# mount  //查看分区的文件系统类型,需要挂载才能看见
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=494380k,nr_inodes=123595,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=100840k,mode=700)


一、磁盘格式化

命令 参数 涵义

mke2fs

-t 
指定格式,不支持xfs;

mkfs.ext4 = mke2fs -t ext4

-b 指定块大小
-m 指定预留空间比(默认5%预留给超级用户)
-i 指定每组的inode数,默认4个块对应1个inode
mkfs.xfs 格式化成xfs

测试示例:

[[email protected] ~]# mke2fs -t xfs /dev/sdb2
mke2fs 1.42.9 (28-Dec-2013)

Your mke2fs.conf file does not define the xfs filesystem type.
Aborting...
[[email protected] ~]# mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[[email protected] ~]# blkid /dev/sdb2  
/dev/sdb2: UUID="d1873a00-ba11-4635-81af-a1e9bd697f70" TYPE="xfs"


二、磁盘挂载

只有格式化的分区才能被挂载。挂载使用mount命令,卸载使用umount命令。使用“-o”可以跟各种选项。默认选项为rw,suid,dev,exec,auto,nouser,和async。

[[email protected] ~]# mount /dev/sdb2 /mnt/
[[email protected] ~]# mount /dev/sdb3 /mnt/
mount: /dev/sdb3 写保护,将以只读方式挂载
mount: 未知的文件系统类型“(null)”
[[email protected] ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G 1016M   27G    4% /
devtmpfs        483M     0  483M    0% /dev
tmpfs           493M     0  493M    0% /dev/shm
tmpfs           493M  6.8M  486M    2% /run
tmpfs           493M     0  493M    0% /sys/fs/cgroup
/dev/sda1       197M  109M   88M   56% /boot
tmpfs            99M     0   99M    0% /run/user/0
/dev/sdb2       2.0G   33M  2.0G    2% /mnt
[[email protected] ~]# umount /dev/sdb2
[[email protected] ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G 1016M   27G    4% /
devtmpfs        483M     0  483M    0% /dev
tmpfs           493M     0  493M    0% /dev/shm
tmpfs           493M  6.8M  486M    2% /run
tmpfs           493M     0  493M    0% /sys/fs/cgroup
/dev/sda1       197M  109M   88M   56% /boot
tmpfs            99M     0   99M    0% /run/user/0

通过mount命令挂载的分区只在当前有效,当系统重启之后,分区将会消失。将分区挂载卸载/etc/fstab文件中,可以使系统启动时默认挂载。可以使用mount -a命令自动加载配置文件里的配置。

[[email protected] ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sat May 27 06:10:33 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=de480d95-018b-4e0b-a874-083a13d8412d /        xfs     defaults        0 0
UUID=82044aec-23c6-4e7f-8f05-51a24c0c956a /boot    xfs     defaults        0 0
UUID=be771427-d6c1-4d01-a8ab-a473e8df8ac5 swap     swap    defaults        0 0
[[email protected] ~]# man fstab
......
DESCRIPTION
       The  file  fstab  contains  descriptive information about the various file systems.  fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file.  Each filesystem is described on a separate line; fields on each line are separated by tabs or spaces.  Lines starting with  ‘#‘ are  comments, blank lines are ignored. The order of records in fstab is important because fsck(8), mount(8), and umount(8) sequentially iterate through fstab doing their thing.

The first field (fs_spec). //UUID或LABEL
    This field describes the block special device or remote filesystem to be mounted.
......

The second field (fs_file). //挂载点
    This  field  describes  the  mount  point for the filesystem.  For swap partitions, this field should be specified as `none‘. If the name of the mount point contains spaces these can be escaped as `\040‘.
......

The third field (fs_vfstype). //分区格式
    This field describes the type of the filesystem.  Linux supports lots of filesystem types, such as adfs, affs, autofs, coda, coherent, cramfs, devpts, efs, ext2, ext3, hfs,hpfs,  iso9660,  jfs,  minix,  msdos,  ncpfs,  nfs, ntfs, proc, qnx4, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs, and possibly others. For more details, see mount(8).
......

The fourth field (fs_mntops). //可选选项
    This field describes the mount options associated with the filesystem.
......

The fifth field (fs_freq).  //是否备份
    This field is used for these filesystems by the dump(8) command to determine which filesystems need to be dumped.  If the fifth field is not present, a  value  of  zero  is returned and dump will assume that the filesystem does not need to be dumped.
......

The sixth field (fs_passno).  //是否开机检测,不检查为0,检查为2
    This  field  is  used  by  the  fsck(8)  program  to determine the order in which filesystem checks are done at reboot time.  The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2.  Filesystems within a drive will be checked sequentially, but filesystems on different  drives  will  be checked at the same time to utilize parallelism available in the hardware.  If the sixth field is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked.

另外一种开机自动挂载的方法是将mount命令写在/etc/rc.local里,开机自动执行挂载命令达到挂载的效果。

时间: 2024-08-08 06:59:40

[CentOS 7系列]磁盘格式化与挂载的相关文章

centos、linux查找未挂载磁盘格式化并挂载?

centos.linux查找未挂载磁盘格式化并挂载? df -h 查看当前linux服务器硬盘: fdisk -l /dev/sda   第一块硬盘 /dev/sdb   第二块硬盘 依此类推 以/dev/sdb为新增硬盘为例,需要进行以下操作方可正常使用 1.分区 fdisk /dev/sdb 依次输入 n,回车 p,回车1,回车 回车 2.格式化 mkfs -t ext4 -c /dev/sdb1 3.挂载(挂载目录可自行定义) mount /dev/sdb1 /opt [[email pr

磁盘格式化、挂载与卸载及分区表 fstab

一.磁盘的格式化 我们用 fdisk 命令将磁盘分好区之后,磁盘还是不能够直接使用的,需要将磁盘进行格式化,而格式化的本质就是为磁盘安装文件系统 我们使用命令:mke2fs 来为CentOS系统安装文件系统,下面来看看 mak2fs 的常用选项: -b:分区时设定每个数据块占用空间的大小,目前支持的每个块的大小是1024.2048.4096 -i:设定inode(文件元信息的存储域)的大小 -N:设定inode的数量(在默认的inode数量不够用的情况下) -c:在格式化前检测一下磁盘是否有问题

2017-12-29 3周5次课 磁盘格式化、挂载、手动增加swap空间

4.5/4.6 磁盘格式化  ·linux支持的文件系统格式: [[email protected] ~]# cat /etc/filesystems xfs ext4 ext3 ext2 nodev proc nodev devpts iso9660 vfat hfs hfsplus * ·CentOS7 默认系统:xfs ·查看分区文件系统:mount [[email protected] ~]# mount ##在结果中,只需要关注/dev/开头的行,例如: /dev/sda1 on /b

day15:磁盘格式化和挂载

4.5: 磁盘格式化 1.在linux下支持文件系统的格式如下: [[email protected] ~]# cat /etc/filesystemsxfsext4ext3ext2hfsplus 查看linux当前系统的文件分区格式,则用mount命令: 语法:   mke2fs     [选项]      [参数]                ===   mkfs         [选项]      [参数] 选项:-L:label,预设该分区的标签-t:用来指定文件系统的类型(xfs.e

磁盘格式化、挂载及增加swap空间

磁盘格式化 查看磁盘: lsblk命令用于列出所有可用块设备的信息,而且还能显示他们之间的依赖关系,但是它不会列出RAM盘的信息.块设备有硬盘,闪存盘,cd-ROM等等.lsblk命令包含在util-linux-ng包中,现在该包改名为util-linux.这个包带了几个其它工具,如dmesg.要安装lsblk,请在此处下载util-linux包.Fedora用户可以通过命令sudo yum install util-linux-ng来安装该包. 格式化磁盘:1.查看当前系统支持的文件系统格式:

centos查找未挂载磁盘格式化并挂载

查看当前linux服务器分区 df -h 查看当前linux服务器硬盘: fdisk -l /dev/sda   第一块硬盘 /dev/sdb   第二块硬盘 依此类推 以/dev/sdb为新增硬盘为例,需要进行以下操作方可正常使用 1.分区 fdisk /dev/sdb 依次输入 n,回车 p,回车 1,回车 回车 w 2.格式化 mkfs -t ext4 -c /dev/sdb1 3.挂载(挂载目录可自行定义) mount /dev/sdb1 /opt [[email protected]6

[CentOS 7系列]磁盘分区

在宴会上,厨师做菜,往往会将做好的菜,分别放在一个个小盘里呈上.面对这一桌的菜,我们不妨思考下,为什么不全部放在一个大盘里呢?首先是串味问题,放在一起的多种菜肴,酸甜苦辣咸混在一起,会彼此之间影响口味.而后当厨师摆盘的时候,如果一个菜摆的不好,会影响大盘中的其他菜的视觉体验.还有,使用小盘时,每个菜肴都有独特的名字,如果觉得口味上佳,可以让厨师再上一份同样的.最后,如果菜肴不多,使用大盘就有点浪费.举这个不太恰当的例子,是要告诉读者,磁盘分区的意义和菜肴分盘的意义相似. 1.df 查看磁盘分区状

Linux 的磁盘格式化、挂载、磁盘检验、等管理功能

df:列出文件系统的整体磁盘使用量du:检查磁盘空间使用量fdisk:用于磁盘分区 一.df命令列出系统的整体磁盘使用量 df命令参数功能:检查文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息.语法:df [-ahikHTm] [目录或文件名]选项与参数:-a :列出所有的文件系统,包括系统特有的 /proc 等文件系统:-k :以 KBytes 的容量显示各文件系统:-m :以 MBytes 的容量显示各文件系统:-h :以人们较易阅读的 GByt

Linux CentOS 7 磁盘格式化mke2fs、mkfs.ext4、磁盘挂载及手动增加swap空间

一. 磁盘格式化 查看系统支持的分区类型: cat /etc/filesystems [[email protected] ~]# cat /etc/filesystems  xfs ext4 ext3 ext2 nodev  procnodev  devpts iso9660 vfat hfs hfsplus* [[email protected] ~]# mountsysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)proc o