Chinaunix首页 | 论坛 | 博客
  • 博客访问: 335464
  • 博文数量: 127
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 333
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-27 14:44
个人简介

兴趣是最好的学习契机!

文章分类

全部博文(127)

文章存档

2017年(1)

2016年(3)

2015年(54)

2014年(58)

2013年(11)

我的朋友

分类: LINUX

2015-04-28 15:32:56

本章节用到的命令主要有:mkfsmke2fstune2fsblkide2labelbc

一、mkfs 命令

前文中介绍了如何给磁盘分区,那么分好了区的磁盘,如何使用呢?首先需要对分区进行格式化。格式化分区非常重要,它是用来创建文件系统的,其命令为mkfs,意为make file system

创建文件系统时需要指定具体的类型,故mkfs命令可以与-t选项结合使用,其格式为:

mkfs -t FileSystemType /dev/part

注意,扩展分区是不能格式化的

 

RHEL4及以前的版面,默认支持的文件系统未ext2RHEL5默认使用的是ext3RHEL6建议使用ext4。事实上RHEL56能够支持各种不同的文件系统,但是否可以真正使用这些文件系统,要看内核编译时能否支持(内核编译将在后文中介绍)。这里我们将/dev/sdb3格式化为ext4类型的文件系统,可以进行如下操作:

 

[root@localhost ~]# mkfs -t ext4 /dev/sdb3  

注意,这一步须反复确认以保证正确书写,因为格式

# 操作会删除磁盘分区上的所有数据,须谨慎操作!

 

——————————————运行结果————————————————— 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
  
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

今后如果想要查看某个磁盘分区的文件系统类型,可以使用 blkid DEVICE 命令,如:

 

[root@localhost ~]# blkid /dev/sdb3

1
/dev/sdb3: UUID="259690de-5ec4-4356-b590-02ba11c31730" TYPE="ext4"

这里可以看到/dev/sdb3这个设备的UUID号和文件系统类型。之所以要为磁盘分区生成UUID(全局唯一识别标识),是因为在实际生产环境中,一台服务器上可以挂载的磁盘分区可以达到成千上万台,故需要使用UUID对其进行区分。

 

二、mke2fs 命令

在命令行中敲mkfs命令后连敲两下tab键补全命令,可以看到所有以mkfs开头的命令:

[root@localhost ~]# mkfs

1
mkfs  mkfs.cramfs   mkfs.ext2  mkfs.ext3  mkfs.ext4  mkfs.ext4dev  mkfs.msdos   mkfs.vfat

 

这里mkfs -t ext4 == mkfs.ext4

 mkfs -t ext3 == mkfs.ext3

故可以直接使用mkfs.ext4命令来进行格式化操作。

事实上,mkfs命令在进行格式化操作时,功能不及mke2fs强大,此命令是专门用来创建ext2系列的文件系统的。故:

mkfs -t ext2 == mkfs.ext2==mke2fs

使用man命令来查看mke2fs的帮助文档,会发现mke2fs命令也可以用来创建ext3ext4等文件系统。

[root@localhost ~]# man mke2fs

MKE2FS(8)                                                            MKE2FS(8)

NAME

       mke2fs - create an ext2/ext3/ext4 filesystem

DESCRIPTION

  mke2fs is used to create an ext2, ext3, or ext4 filesystem, usually in a disk partition. device is the special file corresponding to the device (e.g /dev/hdXX)...

-t fs-type  Specify the filesystem type (i.e., ext2, ext3, ext4, etc.) that is to be created.

# mke2fs -t {ext2|ext3|ext4}  也可以用来指明具体的文件系统类型

-j   Create the filesystem with an ext3 journal.  

# mke2fs -j 可以用来创建ext3类型的文件系统。故 mkfs -t ext3 == mkfs.ext3 == mke2fs -j

-b block-size  Specify  the  size  of  blocks  in bytes.

指定块大小 mk2efs -b {1024|2048|4096},默认单位是k,大小为4k。块大小通常只有3中情况,

#1k2k4k,这个大小取决于cpu对内存页框大小的支持,x86系统的默认页框大小为4k

#(页框概念会在后文中介绍)

-E extended-options  Set  extended  options  for  the  filesystem.

设定文件系统的扩展属性

-L  new-volume-label  Set the volume label for the filesystem to new-volume-label.

设定卷标

-m reserved-blocks-percentage Specify the percentage of the filesystem blocks reserved for the super-user.

设定预留空间比例

-r   revision  Set the filesystem revision for the new filesystem.

设定预留给管理使用的块个数

 

 

 

默认情况下,mke2fs命令会将磁盘分区格式化ext2类型的文件系统,但该命令有自己的配置文件,可以让用户自行定制想要格式化的默认特性、以及各文件系统的默认特性:

 

[root@localhost ~]# vim /etc/mke2fs.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[defaults]
        base_features = sparse_super,filetype,resize_inode,dir_index,ext_attr
        blocksize = 4096
        inode_size = 256
        inode_ratio = 16384
  
[fs_types]
        ext3 = {
                features = has_journal  
# 如果将此属性补充在defaults属性后面,则默认创建为ext3类型的文件系统
        }
        ext4 = {
                features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize
                inode_size = 256
        } ...

下面我们使用mke2fs命令再格式化一次/dev/sdb3

[root@localhost ~]# mke2fs -t ext4 /dev/sdb3

——————————————运行结果—————————————————

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
  
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

使用tune2fs -l DEVICE命令,可以显示某磁盘分区文件系统的各种属性:

 

[root@localhost ~]# tune2fs -l /dev/sdb3

 

——————————————运行结果—————————————————

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
43
44
45
46
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name:   
Last mounted on:          
Filesystem UUID:          71bb1697-8f75-4d5d-b396-fa035fda2abb
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:  has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              655776
Block count:              2622603
Reserved block count:     131130
Free blocks:              2542903
Free inodes:              655765
First block:              0
Block size:               4096    
# 使用mke2fs命令格式化,默认块大小为4096
Fragment size:            4096
Reserved GDT blocks:      640
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8096
Inode blocks per group:   506
Flex block group size:    16
Filesystem created:       Thu Jul 10 21:14:34 2014
Last mount time:          n/a
Last write time:          Thu Jul 10 21:14:54 2014
Mount count:              0
Maximum mount count:      27
Last checked:             Thu Jul 10 21:14:34 2014
Check interval:           15552000 (6 months)
Next check after:         Tue Jan  6 20:14:34 2015
Lifetime writes:          291 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      486b6dff-fb55-430d-b24c-84b36d5253ac
Journal backup:           inode blocks

 

该命令可以和grep命令结合使用,以查询具体某一项属性值:

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Block size"

Block size:               4096

 

如果想换一种块大小,那么只能重新格式化,因此在格式化时,应该指定想要的块大小。这次再对/dev/sdb3格式化,并为其指定块大小:

[root@localhost ~]# mke2fs -t ext4 -b 2048 /dev/sdb3

——————————————运行结果—————————————————

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
657408 inodes, 5245206 blocks
262260 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=543162368
321 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
        16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 
        2048000, 3981312
  
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

再来查看一下块大小:

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Block size"

Block size:               2048

 

选择块大小应取决于存放文件的特性,如果磁盘上存放的多为体积较小的文件,则应使用较小的块大小;反之,最好使用块大小较大的方式。这是由于一个块只能属于一个文件,哪怕一个文件只占用了3个字节,也必须也占用一整个块。块大小越小,格式化需要的时间久越长。

 

除了-t-f-b 选项,mke2fs还可以使用-L选项来设定卷标。使用卷标和UUID都是用来避免挂载在服务器上的设备发生混淆的常用机制,但是卷标也容易发生混淆情况,故UUID更常用。

再来格式化一次分区,这次为该分区加上卷标:

 

[root@localhost ~]# mke2fs -t ext4 -b 1024 -L MYDATA /dev/sdb3

 

——————————————运行结果—————————————————

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYDATA
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
655872 inodes, 10490412 blocks
524520 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=77856768
1281 block groups
8192 blocks per group, 8192 fragments per group
512 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553, 
        1024001, 1990657, 2809857, 5120001, 5971969
  
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

使用 blkid 命令,来查看设备的UUID和卷标等信息:

 

[root@localhost ~]# blkid /dev/sdb3

/dev/sdb3: UUID="11d06150-6a5b-47b1-839c-557e29fdf9f5" TYPE="ext4" LABEL="MYDATA" 

 

假定一个磁盘只有10G,现在该磁盘已经彻底用完了,此时想将该磁盘上的数据挪出来一部分是无法操作的,因为任何对磁盘的增加、删除和修改操作都需要占用该磁盘的空间。故磁盘分区在格式化之前,都要预留一部分,使用tune命令可以查看到某个分区的预留空间大小:

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Reserved

——————————————运行结果—————————————————

1
2
3
4
Reserved block count:     524520
Reserved GDT blocks:      256
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

 

使用bc命令调出计算器,来计算一下预留空间所占整个磁盘大小的比例:

[root@localhost ~]# bc

1
2
3
4
5
6
7
8
9
10
11
12
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
524520/10490412
0
scale=3
#设定浮点小数的位数
524520/10490412
.049
  
# 可以看到预留空间默认为5%

 

如果一个磁盘分区只有5G或者10G5%的预留空间微不足道,但如果一块磁盘分区有100G,那么预留空间将会达到5G,这其实是一种资源的浪费,故使用mke2fs在进行磁盘分区格式化时,可以使用-m选项,来设定预留给管理使用的块所占据的总体空间的比例:

[root@localhost ~]# mke2fs -t ext4 -L MYDATA -b 2048 -m 3 /dev/sdb3

——————————————运行结果—————————————————

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYDATA
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
657408 inodes, 5245206 blocks
157356 blocks (3.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=543162368
321 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
        16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 
        2048000, 3981312
  
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Reserved"

1
2
3
4
5
Reserved block count:     157356
# 对比之前的预留空间大小:524520
Reserved GDT blocks:      512
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

 

可以看到预留空间大小比之前大为缩小,这是由于块大小改变了。如果将块大小改为1048,可以看到预留空间会有所变化:

 

[root@localhost ~]# mke2fs -t ext4 -L MYDATA -b 1024 -m 3 /dev/sdb3

——————————————运行结果—————————————————

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYDATA
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
655872 inodes, 10490412 blocks
314712 blocks (3.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=77856768
1281 block groups
8192 blocks per group, 8192 fragments per group
512 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553, 
        1024001, 1990657, 2809857, 5120001, 5971969
  
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Reserved"

1
2
3
4
5
Reserved block count:     314712
# 预留空间为总块数的3%,预留空间块数和总块数的比值和块大小相关联。
Reserved GDT blocks:      256
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

 

三、 tune2fs 命令

事实上,mke2fs 和 tune2fs的关系类似于 useradd/usermod的关系,两者的大多数选项都一样,后者除了不能调整块大小和文件系统类型外,可以用来调整前者设定的值。

-l 显示文件系统超级块信息(超级块的概念将在后文中详解)

-L 调整卷标

-m 调整预留空间比例

-r 调整预留给管理使用的块个数

————————下述选项后文中会详解——————————

-o 调整默认挂载选项

-O 调整文件系统默认特性

-E 调整文件系统的扩展属性

 

[root@localhost ~]# tune2fs -m 2 /dev/sdb3

1
2
3
# 预留块比例调整为2%
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 2% (209808 blocks)

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Reserved"

1
2
3
4
5
# 查看预留比例
Reserved block count:     209808
Reserved GDT blocks:      256
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

 

[root@localhost ~]# tune2fs -r 200000 /dev/sdb3

1
2
3
# 预留块个数调整200000
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks count to 200000

[root@localhost ~]# tune2fs -l /dev/sdb3 | grep "Reserved"

1
2
3
4
5
# 查看预留个数
Reserved block count:     200000
Reserved GDT blocks:      256
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

 

[root@localhost ~]# tune2fs -L TESTDATA /dev/sdb3

1
2
#调整卷标
tune2fs 1.41.12 (17-May-2010)

[root@localhost ~]# blkid /dev/sdb3

1
2
#查看卷标
/dev/sdb3: UUID="ead64b7a-80bd-4ad7-af3f-bece9a76e04c" TYPE="ext4" LABEL="TESTDATA"

 

事实上有个专门的命令e2label可以用来设定和调整卷标,其格式为:

e2label DEVICE [volum_label]

 

[root@localhost ~]# e2label /dev/sdb3

1
2
# 显示卷标
TESTDATA

[root@localhost ~]# e2label /dev/sdb3 MYDAT

修改卷标

[root@localhost ~]# e2label /dev/sdb3

查看修改后的结果

MYDAT

 

四、挂载文件系统

所谓挂载,就是将某个磁盘分区和一个目录建立关联关系的过程。既然有挂载,那么就会有卸载。所谓卸载,就是解除某个磁盘分区和目录的关联关系。

 

挂载使用的命令为mount,其格式为:

mount [-t fstype] DEVICE MOUNT_POINT

mount [-t fstype] LABEL=Volume_label MOUNT_POINT

mount [-t fstype] UUID=UUID MOUNT_POINT

这里[DEVICE]是要挂载的文件系统,MOUNT_POINT为挂载点,即要挂载的位置。在使用mount命令时,通常需要指定所挂载的文件系统的类型,如果不指定,那么mount命令会自动调用blkid命令来判断该文件系统的类型。

卸载(拆除关联关系)使用的命令为umont,其格式为:

umount DEVICE

或者

umount MOUNT_POINT

拆除关联关系只需要指定一个,或者是设备,或者是挂载点。

下面来举例演示一下挂载和卸载的过程:

 

[root@localhost ~]# mkdir /mydata

创建一个目录/mydat

[root@localhost ~]# cp /etc/fstab /mydata/

[root@localhost ~]# cp /etc/rc.d/rc.sysinit /mydata/

[root@localhost ~]# cp /etc/rc.d/init.d/functions /mydata

复制三个文件到/mydata

[root@localhost ~]# ls /mydata

fstab  functions  rc.sysinit

查看 /mydata下的文件

[root@localhost ~]# mount -t ext4 /dev/sdb3 /mydata

将 /dev/sdb3 挂载到 /mydata

[root@localhost ~]# ls /mydata

lost+found

这时可以看到 /mydata下原有的三个文件被隐藏了

[root@localhost ~]# cd /mydata

[root@localhost mydata]# ls

lost+found

进入到 /mydata下再次查看,可以发现原有的三个文件还是被隐藏了

[root@localhost mydata]# cp /etc/inittab ./

复制一个新文件到挂载后的/mydata目录下

[root@localhost mydata]# ls

inittab  lost+found

可以看到新文件在/mydata

[root@localhost mydata]# umount /dev/sdb3

卸载/dev/sdb3

umount: /mydata: device is busy.

        (In some cases useful info about processes that use

         the device is found by lsof(8) or fuser(1))

这时报系统繁忙的错误,是因为目前处在/mydata目录下

[root@localhost mydata]# pwd

/mydata

[root@localhost mydata]# cd

退出/mydata目录

[root@localhost ~]# umount /dev/sdb3

再次卸载,成功

[root@localhost ~]# ls /mydata

fstab  functions  rc.sysinit

再次查看/mydata目录,可以看到之前被隐藏的三个文件又出现了,但是后来复制的文件不存在了

[root@localhost ~]# cd /mydata

进入/mydata目录

[root@localhost mydata]# mount /dev/sdb3 /mydata

注意:和卸载不同的是,处于目录中可以挂载成功

[root@localhost mydata]# ls

fstab  functions  rc.sysinit

此时能看到这三个文件,是因为当前视图还没有被更改

[root@localhost mydata]# cd

离开/mydata目录

[root@localhost ~]# cd -

/mydata

再次进入/mydata目录

[root@localhost mydata]# ls

inittab  lost+found

查看当前目录会发现原有的三个文件又被隐藏了,取而代之的是挂载后的文件

 

通过上述例子,可以总结出以下规律:

A:挂载之后,原有数据会被隐藏,因此不能挂载到系统的常用目录上;

B:卸载之时,要确保没有进程正在访问挂载的设备,否则无法挂载

 

直接使用mount命令可以查看所有挂载的文件系统:

[root@localhost ~]# mount

—————————————运行结果———————————————

1
2
3
4
5
6
7
8
9
10
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdb3 on /mydata type ext4 (rw)
# 最新挂载的设备 /dev/sdb3

 

除了通过指定具体的设备挂载,指定卷标也可以用来挂载文件系统:

[root@localhost ~]# umount /dev/sdb3

卸载设备 /dev/sdb3

[root@localhost ~]# mount

—————————————运行结果———————————————

1
2
3
4
5
6
7
8
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)

 

[root@localhost ~]# e2label /dev/sdb3

MYDAT

查看设备/dev/sdb3的卷标

 

[root@localhost ~]# mount LABEL="MYDAT" /mydata

通过卷标来指定要挂载的设备

 

[root@localhost ~]# mount

—————————————运行结果———————————————

1
2
3
4
5
6
7
8
9
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdb3 on /mydata type ext4 (rw)

可以看到通过卷标挂载的新设备

 

再来通过UUID挂载设备:

[root@localhost ~]# umount /dev/sdb3

卸载设备/dev/sdb3

[root@localhost ~]# mount

—————————————运行结果———————————————

1
2
3
4
5
6
7
8
9
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
# 可以看到/dev/sdb3已被卸载

[root@localhost ~]# blkid /dev/sdb3

/dev/sdb3: UUID="ead64b7a-80bd-4ad7-af3f-bece9a76e04c" TYPE="ext4" LABEL="MYDAT" 

查看/dev/sdb3UUID

[root@localhost ~]# mount UUID="ead64b7a-80bd-4ad7-af3f-bece9a76e04c" /mydata

通过UUID来挂载/dev/sdb3

[root@localhost ~]# mount

—————————————运行结果———————————————

1
2
3
4
5
6
7
8
9
10
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sdb3 on /mydata type ext4 (rw)
# 可以看到通过UUID也能挂载成功

 

需要注意的是,上述手动挂载的设备,当重新启动系统后,是不会自动挂载的。所有系统启动后会自动挂载的文件系统都定义在/etc/fstab这个文件中。

本文出自 “重剑无锋 大巧不工” 博客,请务必保留此出处http://wuyelan.blog.51cto.com/6118147/1438647

阅读(2570) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~