磁盘格式化与挂载

简介:

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[root@server02 ~] # cat /etc/filesystems
xfs
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*
[root@server02 ~] # 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

测试示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@server02 ~] # mke2fs -t xfs /dev/sdb2
mke2fs 1.42.9 (28-Dec-2013)
 
Your mke2fs.conf  file  does not define the xfs filesystem  type .
Aborting...
[root@server02 ~] # 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
[root@server02 ~] # blkid /dev/sdb2  
/dev/sdb2 : UUID= "d1873a00-ba11-4635-81af-a1e9bd697f70"  TYPE= "xfs"


二、磁盘挂载

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@server02 ~] # mount /dev/sdb2 /mnt/
[root@server02 ~] # mount /dev/sdb3 /mnt/
mount /dev/sdb3  写保护,将以只读方式挂载
mount : 未知的文件系统类型“(null)”
[root@server02 ~] # 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
[root@server02 ~] # umount /dev/sdb2
[root@server02 ~] # 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命令自动加载配置文件里的配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[root@server02 ~] # 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
[root@server02 ~] # 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里,开机自动执行挂载命令达到挂载的效果。













本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1939163 ,如需转载请自行联系原作者

相关文章
|
关系型数据库 MySQL Java
confluence部署
confluence部署
1464 0
confluence部署
|
9月前
|
机器学习/深度学习 设计模式 API
Python 高级编程与实战:构建 RESTful API
本文深入探讨了使用 Python 构建 RESTful API 的方法,涵盖 Flask、Django REST Framework 和 FastAPI 三个主流框架。通过实战项目示例,详细讲解了如何处理 GET、POST 请求,并返回相应数据。学习这些技术将帮助你掌握构建高效、可靠的 Web API。
|
11月前
|
机器学习/深度学习 供应链 搜索推荐
优化销售预测:6种模型适用的场景与实战案例
不同行业的销售预测采用什么模型比较好?3分钟了解6种销售预测模型,以及适用行业场景。
2993 2
优化销售预测:6种模型适用的场景与实战案例
|
Java
【JVM】双亲委派机制、打破双亲委派机制
【JVM】双亲委派机制、打破双亲委派机制
233 1
|
关系型数据库 MySQL 分布式数据库
PolarDB产品使用问题之如何进行存储容量的扩容
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。
|
监控
关键绩效指标和关键风险指标的区别
【8月更文挑战第31天】
712 0
|
SQL 算法 大数据
深入解析力扣184题:部门工资最高的员工(子查询与窗口函数详解)
深入解析力扣184题:部门工资最高的员工(子查询与窗口函数详解)
|
安全 网络协议 数据挖掘
游戏盾如何隐藏服务器真实IP
游戏盾采用了智能分布式云接入系统,通过部署接入服务,使得游戏客户端不再直接与源服务器建立连接,而是通过游戏盾连接至分布在各地的高防节点。这一架构不仅实现了网络加速,还巧妙地隐藏了源服务器的真实IP地址,使得攻击者难以直接定位到真实的服务器。
爱心代码咯----还缺女朋友吗?(2)
爱心代码咯----还缺女朋友吗?
143 0
|
存储 数据挖掘
Crystal Ball—甲骨文水晶球风险管理软件(概念以及实战——基础案例篇)(下)
Crystal Ball—甲骨文水晶球风险管理软件(概念以及实战——基础案例篇)(下)