linux挂载硬盘centos,Centos挂载硬盘_linux挂载硬盘mount

最近在配置服务器因为数据比较多,需要添加一块数据盘,接下来吾爱编程为大家介绍一下Centos挂载硬盘并实现开机自动挂载,有需要的小伙伴可以参考一下:

运行 fdisk -l 命令查看实例是否有数据盘。如果执行命令后,没有发现 /dev/vdb,表示实例没有数据盘

创建一个单分区数据盘,依次执行以下命令:

运行 fdisk /dev/vdb:对数据盘进行分区。

输入 n 并按回车键:创建一个新分区。

输入 p 并按回车键:选择主分区。因为创建的是一个单分区数据盘,所以只需要创建主分区。

如果要创建 4 个以上的分区,您应该创建至少一个扩展分区,即选择e。

输入分区编号并按回车键。因为这里仅创建一个分区,可以输入 1。

输入第一个可用的扇区编号:按回车键采用默认值 1。

输入最后一个扇区编号:因为这里仅创建一个分区,所以按回车键采用默认值。

输入 wq 并按回车键,开始分区。

[[email protected]~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

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

Be careful before using the write command.

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0xbf8b149e.

Command (m for help): n

Partition type:

p   primary (0 primary, 0 extended, 4 free)

e   extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):

Using default value 41943039

Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): wq

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

查看新的分区:运行命令 fdisk -l。如果出现以下信息,说明已经成功创建了新分区 /dev/vdb1

[[email protected]~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: dos

Disk identifier: 0x0008d73a

Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk label type: dos

Disk identifier: 0xbf8b149e

Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048    41943039    20970496   83  Linux

在新分区上创建一个文件系统:运行命令 mkfs.ext3 /dev/vdb1。

本示例要创建一个 ext3 文件系统。创建文件系统所需时间取决于数据盘大小。(您也可以根据自己的需要,选择创建其他文件系统,例如,如果需要在 Linux、Windows 和 Mac 系统之间共享文件,您可以使用 mkfs.vfat 创建 VFAT 文件系统。)

[[email protected]~]# mkfs.ext3 /dev/vdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5242624 blocks

262131 blocks (5.00%) reserved for the super user

First data block=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

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

(建议)备份 etc/fstab:运行命令:

cp /etc/fstab /etc/fstab.bak

向 /etc/fstab 写入新分区信息:运行命令:

echo /dev/vdb1 /data ext3 defaults 0 0 >> /etc/fstab。

Ubuntu 12.04 不支持 barrier,所以对该系统正确的命令是:`echo '/dev/vdb1 /data ext3 barrier=0 0 0' >> /etc/fstab`。如果需要把数据盘单独挂载到某个文件夹,比如单独用来存放文件,请将以上命令 `/data` 替换成所需的挂载点路径。

查看 /etc/fstab 中的新分区信息:运行命令:

cat /etc/fstab

[[email protected]~]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Sun Oct 15 15:19:00 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=eb448abb-3012-4d8d-bcde-xxxxxxxxx /      ext4    defaults        1 1

/dev/vdb1 /data ext3 defaults 0 0

挂载文件系统:运行命令:

mount /dev/vdb1 /data。

查看目前磁盘空间和使用情况:运行命令 df -h。如果出现新建文件系统的信息,说明挂载成功,可以使用新的文件系统了。

挂载操作完成后,不需要重启实例即可开始使用新的文件系统。

[[email protected]/]# mount /dev/vdb1 /data

[[email protected]/]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/vda1        40G   19G   19G  49% /

devtmpfs        486M     0  486M   0% /dev

tmpfs           496M     0  496M   0% /dev/shm

tmpfs           496M  488K  496M   1% /run

tmpfs           496M     0  496M   0% /sys/fs/cgroup

tmpfs           100M     0  100M   0% /run/user/0

/dev/vdb1        20G   45M   19G   1% /data

以上就是吾爱编程为大家介绍的Centos挂载硬盘的方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值