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

前端之家收集整理的这篇文章主要介绍了[CentOS 7系列]磁盘格式化与挂载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

[root@server02~]#cat/etc/filesystems
xfs
ext4
ext3
ext2
nodevproc
nodevdevpts
iso9660
vfat
hfs
hfsplus
*
[root@server02~]#mount//查看分区的文件系统类型,需要挂载才能看见
sysfson/systypesysfs(rw,nosuid,nodev,noexec,relatime,seclabel)
procon/proctypeproc(rw,relatime)
devtmpfson/devtypedevtmpfs(rw,seclabel,size=494380k,nr_inodes=123595,mode=755)
securityfson/sys/kernel/securitytypesecurityfs(rw,relatime)
tmpfson/dev/shmtypetmpfs(rw,seclabel)
devptson/dev/ptstypedevpts(rw,gid=5,mode=620,ptmxmode=000)
tmpfson/runtypetmpfs(rw,mode=755)
tmpfson/sys/fs/cgrouptypetmpfs(ro,mode=755)
cgroupon/sys/fs/cgroup/systemdtypecgroup(rw,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstoreon/sys/fs/pstoretypepstore(rw,relatime)
cgroupon/sys/fs/cgroup/freezertypecgroup(rw,freezer)
cgroupon/sys/fs/cgroup/cpu,cpuaccttypecgroup(rw,cpuacct,cpu)
cgroupon/sys/fs/cgroup/pidstypecgroup(rw,pids)
cgroupon/sys/fs/cgroup/cpusettypecgroup(rw,cpuset)
cgroupon/sys/fs/cgroup/net_cls,net_priotypecgroup(rw,net_prio,net_cls)
cgroupon/sys/fs/cgroup/memorytypecgroup(rw,memory)
cgroupon/sys/fs/cgroup/perf_eventtypecgroup(rw,perf_event)
cgroupon/sys/fs/cgroup/devicestypecgroup(rw,devices)
cgroupon/sys/fs/cgroup/hugetlbtypecgroup(rw,hugetlb)
cgroupon/sys/fs/cgroup/blkiotypecgroup(rw,blkio)
configfson/sys/kernel/configtypeconfigfs(rw,relatime)
/dev/sda3on/typexfs(rw,attr2,inode64,noquota)
selinuxfson/sys/fs/selinuxtypeselinuxfs(rw,relatime)
systemd-1on/proc/sys/fs/binfmt_misctypeautofs(rw,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfson/sys/kernel/debugtypedebugfs(rw,relatime)
hugetlbfson/dev/hugepagestypehugetlbfs(rw,seclabel)
mqueueon/dev/mqueuetypemqueue(rw,seclabel)
/dev/sda1on/boottypexfs(rw,noquota)
tmpfson/run/user/0typetmpfs(rw,size=100840k,mode=700)


一、磁盘格式化

命令 参数 涵义

mke2fs

-t

指定格式,不支持xfs;

mkfs.ext4 = mke2fs -t ext4

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

测试示例:

[root@server02~]#mke2fs-txfs/dev/sdb2
mke2fs1.42.9(28-Dec-2013)

Yourmke2fs.conffiledoesnotdefinethexfsfilesystemtype.
Aborting...
[root@server02~]#mkfs.xfs/dev/sdb2
Meta-data=/dev/sdb2isize=512agcount=4,agsize=131072blks
=sectsz=512attr=2,projid32bit=1
=crc=1finobt=0,sparse=0
data=bsize=4096blocks=524288,imaxpct=25
=sunit=0swidth=0blks
naming=version2bsize=4096ascii-ci=0ftype=1
log=internallogbsize=4096blocks=2560,version=2
=sectsz=512sunit=0blks,lazy-count=1
realtime=noneextsz=4096blocks=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。

[root@server02~]#mount/dev/sdb2/mnt/
[root@server02~]#mount/dev/sdb3/mnt/
mount:/dev/sdb3写保护,将以只读方式挂载
mount:未知的文件系统类型“(null)”
[root@server02~]#df-h
文件系统容量已用可用已用%挂载点
/dev/sda328G1016M27G4%/
devtmpfs483M0483M0%/dev
tmpfs493M0493M0%/dev/shm
tmpfs493M6.8M486M2%/run
tmpfs493M0493M0%/sys/fs/cgroup
/dev/sda1197M109M88M56%/boot
tmpfs99M099M0%/run/user/0
/dev/sdb22.0G33M2.0G2%/mnt
[root@server02~]#umount/dev/sdb2
[root@server02~]#df-h
文件系统容量已用可用已用%挂载点
/dev/sda328G1016M27G4%/
devtmpfs483M0483M0%/dev
tmpfs493M0493M0%/dev/shm
tmpfs493M6.8M486M2%/run
tmpfs493M0493M0%/sys/fs/cgroup
/dev/sda1197M109M88M56%/boot
tmpfs99M099M0%/run/user/0

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

[root@server02~]#cat/etc/fstab

#
#/etc/fstab
#CreatedbyanacondaonSatMay2706:10:332017
#
#Accessiblefilesystems,byreference,aremaintainedunder'/dev/disk'
#Seemanpagesfstab(5),findfs(8),mount(8)and/orblkid(8)formoreinfo
#
UUID=de480d95-018b-4e0b-a874-083a13d8412d/xfsdefaults00
UUID=82044aec-23c6-4e7f-8f05-51a24c0c956a/bootxfsdefaults00
UUID=be771427-d6c1-4d01-a8ab-a473e8df8ac5swapswapdefaults00
[root@server02~]#manfstab
......
DESCRIPTION
ThefilefstabcontainsdescriptiveinformationaboutthevarIoUsfilesystems.fstabisonlyreadbyprograms,andnotwritten;itisthedutyofthesystemadministratortoproperlycreateandmaintainthisfile.Eachfilesystemisdescribedonaseparateline;fieldsoneachlineareseparatedbytabsorspaces.Linesstartingwith'#'arecomments,blanklinesareignored.Theorderofrecordsinfstabisimportantbecausefsck(8),mount(8),andumount(8)sequentiallyiteratethroughfstabdoingtheirthing.

Thefirstfield(fs_spec).//UUID或LABEL
Thisfielddescribestheblockspecialdeviceorremotefilesystemtobemounted.
......

Thesecondfield(fs_file).//挂载点
Thisfielddescribesthemountpointforthefilesystem.Forswappartitions,thisfieldshouldbespecifiedas`none'.Ifthenameofthemountpointcontainsspacesthesecanbeescapedas`\040'.
......

Thethirdfield(fs_vfstype).//分区格式
Thisfielddescribesthetypeofthefilesystem.Linuxsupportslotsoffilesystemtypes,suchasadfs,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,andpossiblyothers.Formoredetails,seemount(8).
......

Thefourthfield(fs_mntops).//可选选项
Thisfielddescribesthemountoptionsassociatedwiththefilesystem.
......

Thefifthfield(fs_freq).//是否备份
Thisfieldisusedforthesefilesystemsbythedump(8)commandtodeterminewhichfilesystemsneedtobedumped.Ifthefifthfieldisnotpresent,avalueofzeroisreturnedanddumpwillassumethatthefilesystemdoesnotneedtobedumped.
......

Thesixthfield(fs_passno).//是否开机检测,不检查为0,检查为2
Thisfieldisusedbythefsck(8)programtodeterminetheorderinwhichfilesystemchecksaredoneatreboottime.Therootfilesystemshouldbespecifiedwithafs_passnoof1,andotherfilesystemsshouldhaveafs_passnoof2.Filesystemswithinadrivewillbecheckedsequentially,butfilesystemsondifferentdriveswillbecheckedatthesametimetoutilizeparallelismavailableinthehardware.Ifthesixthfieldisnotpresentorzero,avalueofzeroisreturnedandfsckwillassumethatthefilesystemdoesnotneedtobechecked.

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

猜你在找的CentOS相关文章