2022
我们一起努力

磁盘挂载(centos磁盘挂载)

目录:

  • 1、linux下如何挂载硬盘?
  • 2、八、磁盘分区和挂载
  • 3、服务器磁盘管理(分区和挂载)

linux下如何挂载硬盘?

1.插入新硬盘,启动Linux服务器,使用fdisk -l 查看硬盘

#fdisk -l

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes

2.格式化硬盘

#mkfs -t ext4 /dev/sdb

3.挂载硬盘

#mount 硬盘地址 要挂载的地址

#mount /dev/sdb /media/imgs

4.实现系统重启后自动挂载该分区

#vi /etc/fstab

在最后一行添加

/dev/sdb /media/imgs ext4 defaults 1 2

一、添加磁盘

添加加新硬盘重启服务器

添加完之后就可以重启机器了,如果你机器是开启的,进入系统并不能看见你刚添加的那块磁盘,只有等系统重启,重新加载之后才会显示安装的那块磁盘

二、进入系统

使用root用户进入系统

三、 查看硬盘信息

[root@localhost ~]# fdisk -l   //磁盘命令

1

Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000c4cb5

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xd0f5c869

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        2610    20964793+  83  Linux

Disk /dev/sdc: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

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

可以看到这台机器加载了三个磁盘sda、sdb、sdc

其中sda是初始磁盘,sdb已经初始化且经过使用,sdc是刚刚加载的,未格式化的新磁盘

四、创建新硬盘分区

[root@localhost ~]# fdisk /dev/sdc #进入磁盘

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x45a3cadb.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): m

Command action

a   toggle a bootable flag      #设定可启动标记

b   edit bsd disklabel

c   toggle the dos compatibility flag

d   delete a partition          #删除一个分区

l   list known partition types  #各分区类型所对应的ID

m   print this menu             #菜单

n   add a new partition         #添加一个分区

o   create a new empty DOS partition table

p   print the partition table   #显示该磁盘下的当前分区信息

q   quit without saving changes #不保存退出

s   create a new empty Sun disklabel

t   change a partition's system id

u   change display/entry units

v   verify the partition table

w   write table to disk and exit #保存退出

x   extra functionality (experts only)

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

知道命令之后就可以进行分区了

Command (m for help): p //打印分区信息,可以看到当前并没有分区

Disk /dev/sdc: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x45a3cadb

Device Boot      Start         End      Blocks   Id  System

Command (m for help): n //创建一个新的分区

Command action

e   extended//输入e为创建扩展分区

p   primary partition (1-4) //输入p为创建逻辑分区

p

Partition number (1-4): 1//划分逻辑分区

First cylinder (1-2610, default 1): //我这里直接回车,是不想把该磁盘分成多个分区,把整个磁盘作为1个分区

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):

Using default value 2610

Command (m for help): p //再次查看可以看到该磁盘已经有1个分区了

Disk /dev/sdc: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x45a3cadb

Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        2610    20964793+  83  Linux

Command (m for help): w //保存分区

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

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

再次使用”fdisk -l”命令查看磁盘信息

Disk /dev/sdc: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x406a4c58

Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        2610    20964793+  83  Linux

1

2

3

4

5

6

7

8

9

第三块磁盘/dev/sdc已经分区好了

五、格式化分区

[root@localhost ~]# mkfs.ext3 /dev/sdc1

//将/dev/sdc1格式化为ext3类型,好像大部分的磁盘都是格式化为ext3类型,具体为什么没有深入研究,暂时不清楚,想了解的朋友可以自己查一下

1

2

[root@localhost ~]# mkfs.ext3 /dev/sdc1

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5241198 blocks

262059 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=4294967296

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000

正在写入inode表: 完成                          

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 31 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

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

格式化完毕,此时就可以使用“mount”命令挂载分区了,然后使用这个磁盘空间了

六、挂载分区以及开机自动挂载

[root@localhost ~]# df -h //此时只有sda1和sdb1两个磁盘挂载

Filesystem                    Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root   18G   15G  1.5G  92% /

tmpfs                         932M   76K  932M   1% /dev/shm

/dev/sda1                     485M   40M  421M   9% /boot

/dev/sdb1                      20G  1.2G   18G   7% /disk/diskone

/dev/sr0                      4.2G  4.2G     0 100% /media/CentOS_6.5_Final

[root@localhost /]# cd /disk/

[root@localhost disk]# ll

总用量 4

drwxr-xr-x. 4 root root 4096 7月  28 17:04 diskone

[root@localhost disk]# cd diskone/

[root@localhost diskone]# ll

总用量 20

drwx------. 2 root root 16384 7月  28 16:12 lost+found

drwxr-xr-x. 2 root root  4096 7月  28 17:09 software

[root@localhost diskone]# cd ../

[root@localhost disk]# mkdir disktwo //创建被挂载的路径

[root@localhost disk]# ll

总用量 8

drwxr-xr-x. 4 root root 4096 7月  28 17:04 diskone

drwxr-xr-x. 2 r

八、磁盘分区和挂载

主要知识点: 基本分区、逻辑卷LVM、EXT3/4/XFS文件系统、RAID

1.1.初识硬盘

SSD的优势

与传统硬盘相比,SSD固态电子盘具有以下优点:

硬盘尺寸

从插拔方式

从硬盘接口

IDE和SATA的区别:

SAS与SCSI的区别

硬盘设备命名

HP服务器硬盘

从存储连接方式

1.2从分区方式区分

首先需要先给虚拟机添加磁盘

磁盘的命名规则上面有介绍

1.1.fdisk

创建分区:

1.2 gdisk

创建分区:

2.创建文件系统(格式化)centos7默认使用xfs

注意:这里一定要明确指定分区sdb1,或者sdb2,不能选择整块磁盘

3.挂载mount(临时挂载)

取消挂载

3.1./etc/fstab文件实现自动挂载

查看磁盘挂载与磁盘使用空间

3.2/etc/rc.drc.local开机自动挂载

1.1分类

1.2概念

1.3.EXT

1.4.XFS

服务器磁盘管理(分区和挂载)

以ext4文件系统为例,设计的时候分为4个部分

由于 ls -l 获取的是i节点记录的数据使用的数据块个数,而 du 则是通过i节点获取实际大小, 所以 ls -l 和 du 显示的数据大小不同。

RAID全称是Redundant Array of Independent Disks,也就是磁盘阵列,通过整合多块硬盘从而提升服务器数据的安全性,以及提高数据处理时的I/O性能。

RAID目前常用的是RAID5, 至少需要3块硬盘,其中一块硬盘用于奇偶校验,保证数据安全,其余硬盘同时读写,提高性能。此外,你还需要知道最原始的是RAID0,同时将数据读写到所有硬盘里,速度就变成了原来的N倍。RAID1至少需要两块盘,其中一块硬盘是另外硬盘的镜像。它不提高读写效率,只提高了数据安全性。RAID10是RAID0和RAID1的组合。

目前的服务器都配备了硬件RAID卡,因此在为服务器增加或更换硬盘时,需要 格外注意 ,

fdisk只能对不多于2TB的硬盘进行分区

假如你的硬盘大于2TB,那么会输出如下信息

提示信息中的警告中,就建议"Use parted(1) and GUID partition table format (GPT)."

因此,对于大于2TB的硬盘就需要用 parted 进行分区

输出信息如下

创建新的GPT标签,例如

设置单位

创建分区, 比如我将原来的10T分成2TB和8TB

查看分区表

输出如下

退出

此时会提示"Information: You may need to update /etc/fstab." /etc/fstab 用于设置开机硬盘自动挂载。如果硬盘被拔走了,而 /etc/fstab 没有修改,那么会就提示进行修复模式。

在挂载硬盘之前,需要先对磁盘进行格式化。使用的命令为 mkfs , 使用 -t 指定文件系统,或者用 mkfs.xxx ,其中xxx就是对应的文件系统。文件系统有如下几类

目前最流行的是ext4和xfs,足够稳定。其中xfs是CentOS7之后的默认文件系统。

之后用 mount 进行硬盘挂载,分别两种情况考虑

一种是新建一个文件路径,进行挂载。

另一种是挂载一个已有目录,比如说临时文件目录 /tmp 挂载到新的设备中。

第一步: 新建一个挂载点,将原有数据移动到该目录下

第二步: 删除原来的 /tmp 下内容

第三步: 重新挂载

和mount相关的文件如下

此外mount在挂载的时候还可以设置文件系统参数,例如是否支持磁盘配额,对应 -o 参数

第零步: 检查服务器是否具备RAID阵列卡,如果有,则需要先为硬盘做RAID。

第一步: 使用 fdisk -l 检查硬盘是否能被系统检测到

第二步(可选): 假如需要 硬盘分区 ,则用 fdisk/gdisk/parted 对硬盘划分磁盘

第三步: 使用mkfs进行磁盘 格式化 ,有如下几种可选,

第四步: 用mkdir新建一个目录,然后用mount将格式化的硬盘挂载到指定目录下。卸载硬盘,则是 umout

第五步: 修改 /etc/fstab 将硬盘在重启的时候自动挂载。 注意 : 如果硬盘不在了,则需要将对应行注释掉,否则会进入到emergency模式。

版权声明 :本博客所有文章除特别声明外,均采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 (CC BY-NC-ND 4.0) 进行许可。

赞(0)
文章名称:《磁盘挂载(centos磁盘挂载)》
文章链接:https://www.fzvps.com/242252.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!