我们相信:世界是美好的,你是我也是。平行空间的世界里面,不同版本的生活也在继续...

linux下面纯正命令行,干什么事情都特别有黑客范。这不,挂载个新硬盘,在window下面是不是个非常简单的事情?linux下面就变得神秘莫测了。下面是教程。大家请保存,linux的云主机必备教程。

苏南大叔:centos 系统如何挂载识别新硬盘? - centos-disk
centos 系统如何挂载识别新硬盘?(图7-1)

本范例中,实验机的操作系统是centos7

查看基本状况

通过下面的命令,我们可以看到/dev/xvdb(此名称因系统而异)容量有23.6G,而且没有分区。

fdisk -l
 [root@MyVPS ~]# fdisk -l
 Disk /dev/xvda: 8589 MB, 8589934592 bytes
 255 heads, 63 sectors/track, 1044 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Device Boot Start End Blocks Id System
 /dev/xvda1 * 1 13 104391 83 Linux
 /dev/xvda2 14 1044 8281507+ 8e Linux LVM
 Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
 255 heads, 63 sectors/track, 2871 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Device Boot Start End Blocks Id System

苏南大叔:centos 系统如何挂载识别新硬盘? - 002
centos 系统如何挂载识别新硬盘?(图7-2)

分区格式化

接下来我们对/dev/sdb(此名称因系统而异)进行分区。注意,这里,我们会主动键入几个命令。具体见截图中的箭头所示。

fdisk /dev/sdb
 [root@MyVPS ~]# fdisk /dev/sdb
 The number of cylinders for this disk is set to 2871.
 There is nothing wrong with that, but this is larger than 1024,
 and could in certain setups cause problems with:
 1) software that runs at boot time (e.g., old versions of LILO)
 2) booting and partitioning software from other OSs
 (e.g., DOS FDISK, OS/2 FDISK)
 输入n新建分区
 Command (m for help): n
 Command action
 e extended
 p primary partition (1-4)
 p
 /dev/xvdb中第1个分区
 Partition number (1-4): 1
 First cylinder (1-2871, default 1):
 Using default value 1
 Last cylinder or +size or +sizeM or +sizeK (1-2871, default 2871):
 Using default value 2871
 输入W保存退出
 Command (m for help): w
 The partition table has been altered!
 Calling ioctl() to re-read partition table.
 Syncing disks.

苏南大叔:centos 系统如何挂载识别新硬盘? - 003
centos 系统如何挂载识别新硬盘?(图7-3)

分区格式化

将新分区sdb1(此名称因系统而异)格式化为ext3格式。

mkfs -t ext3 /dev/sdb1
 [root@MyVPS ~]# mkfs -t ext3 /dev/sdb1
 mke2fs 1.39 (29-May-2006)
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 2883584 inodes, 5765319 blocks
 288265 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=4294967296
 176 block groups
 32768 blocks per group, 32768 fragments per group
 16384 inodes per group
 Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
 4096000
 Writing inode tables: done
 Creating journal (32768 blocks): done
 Writing superblocks and filesystem accounting information: done
 This filesystem will be automatically checked every 24 mounts or
 180 days, whichever comes first. Use tune2fs -c or -i to override.

苏南大叔:centos 系统如何挂载识别新硬盘? - 004
centos 系统如何挂载识别新硬盘?(图7-4)

这一步可能要在最后的时候等待较长时间,而界面无任何动作输出。一个字:等!

挂载新分区

我们示范将新分区xvdb1挂载到目录/home

mount /dev/sdb1 /home
 [root@MyVPS ~]# mount /dev/sdb1 /home

苏南大叔:centos 系统如何挂载识别新硬盘? - 005
centos 系统如何挂载识别新硬盘?(图7-5)

当然我们也可以新建目录/home1,然后挂载home1目录。

mkdir /home1
mount /dev/xvdb1 /home1

查看状态

完成后我们通过df -hal可以看到,新分区已经挂载到目录/home上了

df -hal
 [root@MyVPS ~]# df -hal
 Filesystem Size Used Avail Use% Mounted on
 /dev/mapper/VolGroup00-LogVol00
 5.7G 1.4G 4.1G 25% /
 proc 0 0 0 - /proc
 sysfs 0 0 0 - /sys
 devpts 0 0 0 - /dev/pts
 /dev/xvda1 99M 28M 67M 30% /boot
 tmpfs 256M 0 256M 0% /dev/shm
 none 0 0 0 - /proc/sys/fs/binfmt_misc
 sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs
 /dev/xvdb1 22G 173M 21G 1% /home

苏南大叔:centos 系统如何挂载识别新硬盘? - 006
centos 系统如何挂载识别新硬盘?(图7-6)

开机自动挂载

最后添加开机自动挂载:

echo "/dev/sdb1 /home ext3 defaults 1 2" >> /etc/fstab

苏南大叔:centos 系统如何挂载识别新硬盘? - 007
centos 系统如何挂载识别新硬盘?(图7-7)

注意:
检验是否挂盘成功,需要重启服务器,如果能够连接则成功,不能则失败。重启命令为reboot

题外话

当然了如果重装系统的话,应该简单的挂载硬盘,即可找回原来的数据。

 [root@MyVPS ~]# mkdir /home
 [root@MyVPS ~]# mount /dev/sdb1 /home
 [root@MyVPS ~]# echo "/dev/sdb1 /home ext3 defaults 1 2" >> /etc/fstab

结论

更多centos相关经验,请点击苏南大叔的相关文章:

如果本文对您有帮助,或者节约了您的时间,欢迎打赏瓶饮料,建立下友谊关系。
本博客不欢迎:各种镜像采集行为。请尊重原创文章内容,转载请保留作者链接。

 【福利】 腾讯云最新爆款活动!1核2G云服务器首年50元!

 【源码】本文代码片段及相关软件,请点此获取更多信息

 【绝密】秘籍文章入口,仅传授于有缘之人   centos