Linux系统如何挂载硬盘

我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1q7qcbzk0x1vs

1.首先查看系统挂载状况

df -TH

返回信息:

[root@ecs-eD18 ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        19G  2.7G   16G  15% /
devtmpfs                devtmpfs  508M     0  508M   0% /dev
tmpfs                   tmpfs     520M   25k  520M   1% /dev/shm
tmpfs                   tmpfs     520M  7.1M  513M   2% /run
tmpfs                   tmpfs     520M     0  520M   0% /sys/fs/cgroup
/dev/vda1               xfs       1.1G  197M  867M  19% /boot
tmpfs                   tmpfs     104M     0  104M   0% /run/user/

此时并没有挂载硬盘

 

2.查看硬盘信息

fdisk -l

返回信息:

[root@ecs-eD18 ~]# fdisk -l

Disk /dev/vda: 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: 0x0000425c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200    41943039    19921920   8e  Linux LVM

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 /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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

我们可以看到一共有3个磁盘

/dev/mapper/centos-swap是虚拟内存

/dev/mapper/centos-root是系统盘

此时的数据盘就是/dev/vdb

 

3.现在使用fdisk对数据盘进行分区

fdisk /dev/vdb

(注意:/dev/vdb就是你的数据盘,这个命令需要根据上一步的磁盘信息修改)

返回信息

[root@ecs-eD18 ~]# 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 0x311bc542.

Command (m for help): 

输入

n

返回信息

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): 
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): 

输入

p

返回信息

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: 0x311bc542

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   83  Linux

 接下来输入

w

保存分区信息

返回信息

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

出现这个提示则表明分区成功

4.更新系统分区表

partprobe

5.更换新分区的文件格式

mkfs -t ext4 /dev/vdb1

注意:这里的/vdb1是/vdb这个磁盘的1号分区,要根据实际情况修改该命令

返回信息

[root@ecs-eD18 ~]# mkfs -t ext4 /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=2153775104
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   

6.挂载分区至目录

mount /dev/vdb1 /www/wwwroot

注意:

/dev/vdb1是上一步中格式化的分区(也就是本次需要挂载的分区)

/www/wwwroot是需要挂载的目录,如果需要挂载到其他目录请注意先新建目录再挂载

请根据实际情况修改此命令

 

7.检查挂载情况

df -Th

返回信息

[root@ecs-eD18 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        17G  2.5G   15G  15% /
devtmpfs                devtmpfs  485M     0  485M   0% /dev
tmpfs                   tmpfs     496M   24K  496M   1% /dev/shm
tmpfs                   tmpfs     496M  6.8M  489M   2% /run
tmpfs                   tmpfs     496M     0  496M   0% /sys/fs/cgroup
/dev/vda1               xfs      1014M  188M  827M  19% /boot
tmpfs                   tmpfs     100M     0  100M   0% /run/user/0
/dev/vdb1               ext4       20G   45M   19G   1% /www/wwwroot

 

我们可以看到/dev/vdb1这个分区已经挂载到了/www/wwwroot的目录上

注意:如果挂载目录内原本存有文件,那么该文件将会无法访问

 

Smiling

Smiling

我还没有学会写个人说明!

暂无评论

发表评论

您的电子邮件地址不会被公开,必填项已用*标注。

相关推荐

防止硬盘休眠

笔者近日在从iCloud的win版客户端下载接近7w张照片 但是发现如果挂机下载 即便网络通畅、电源选项设置为高性能 永不休 …

选择适合你的DNS服务器

域名系统(服务)协议(DNS)是一种分布式网络目录服务,主要用于域名与 IP 地址的相互转换,以及控制因特网的电子邮件 …

微信扫一扫,分享到朋友圈

Linux系统如何挂载硬盘