溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

磁盤格式化與掛載

發(fā)布時(shí)間:2020-07-14 22:25:43 來源:網(wǎng)絡(luò) 閱讀:1029 作者:Grodd 欄目:系統(tǒng)運(yùn)維

    在windows操作系統(tǒng)中,硬盤有fat32和ntfs等多種格式。在linux中同樣如此。CentOS 6之前,主要是ext4、ext3和ext2等格式。在CentOS 7這個(gè)版本開始,默認(rèn)的磁盤格式變成了xfs格式。

[root@server02 ~]# cat /etc/filesystems
xfs
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*
[root@server02 ~]# mount  //查看分區(qū)的文件系統(tǒng)類型,需要掛載才能看見
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)


一、磁盤格式化

命令參數(shù)涵義

mke2fs 

-t 

指定格式,不支持xfs;

mkfs.ext4 = mke2fs -t ext4

-b指定塊大小
-m指定預(yù)留空間比(默認(rèn)5%預(yù)留給超級(jí)用戶)
-i指定每組的inode數(shù),默認(rèn)4個(gè)塊對(duì)應(yīng)1個(gè)inode
mkfs.xfs
格式化成xfs

測(cè)試示例:

[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"


二、磁盤掛載

    只有格式化的分區(qū)才能被掛載。掛載使用mount命令,卸載使用umount命令。使用“-o”可以跟各種選項(xiàng)。默認(rèn)選項(xiàng)為rw,suid,dev,exec,auto,nouser,和async。

[root@server02 ~]# mount /dev/sdb2 /mnt/
[root@server02 ~]# mount /dev/sdb3 /mnt/
mount: /dev/sdb3 寫保護(hù),將以只讀方式掛載
mount: 未知的文件系統(tǒng)類型“(null)”
[root@server02 ~]# df -h
文件系統(tǒng)        容量  已用  可用 已用% 掛載點(diǎn)
/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
文件系統(tǒng)        容量  已用  可用 已用% 掛載點(diǎn)
/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命令掛載的分區(qū)只在當(dāng)前有效,當(dāng)系統(tǒng)重啟之后,分區(qū)將會(huì)消失。將分區(qū)掛載卸載/etc/fstab文件中,可以使系統(tǒng)啟動(dòng)時(shí)默認(rèn)掛載。可以使用mount -a命令自動(dòng)加載配置文件里的配置。

[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). //掛載點(diǎn)
    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). //分區(qū)格式
    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). //可選選項(xiàng)
    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).  //是否開機(jī)檢測(cè),不檢查為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.

另外一種開機(jī)自動(dòng)掛載的方法是將mount命令寫在/etc/rc.local里,開機(jī)自動(dòng)執(zhí)行掛載命令達(dá)到掛載的效果。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI