一.磁盘扩容 

centos root分区 centos6.5分区_直接访问

centos root分区 centos6.5分区_centos root分区_02

随后,开启此虚拟机

二.创建新的磁盘分区

fdisk -l --查看磁盘情况

centos root分区 centos6.5分区_linux_03

如上所示,磁盘空间扩展为42.9GB 

fdisk /dev/sda --为/dev/sda设备分区

 我这里将原来的第四个分区删除,并重新创建以达到扩容目的:

[root@node1 ~]# fdisk /dev/sda

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): n
You must delete some partition and add an extended partition first

Command (m for help): ^C
[root@node1 ~]# fdisk /dev/sda

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): d
Partition number (1-4): 4

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (2611-5221, default 2611): 
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-5221, default 5221): 
Using default value 5221

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

mkdir /disk4 --创建挂载目录

由于我这里是扩容,先前 /disk4 目录已经创建好了

reboot --重启

mkfs.ext4 /dev/sda4 --格式化

 三.挂载并设置自动挂载

mount /dev/sda4 /disk4/ --挂载

vi /etc/fstab --设置开机自动挂载

centos root分区 centos6.5分区_centos root分区_04

centos root分区 centos6.5分区_文件系统_05

扩容成功! 

 

一些总结:

  1. 挂载点必须是目录
  2. 目录不可以为空,而且挂载后这个目录以前的内容将不可用
  3. 挂载前要了解linux是否支持
  4. mount了才能读取内容,而直接访问只能读设备信息
    好比看碟,你访问dev相当于直接拿碟片用眼看最多你能看出来是个CD或DVD;但插到光驱里读就能看到电影了.
  5. /dev的根是/,但是却不是挂载点。为什么一个设备已经被os识别在/dev下,为啥不能之间访问,而需要mount?要回答这个,首先我们要知道,linux下有哪些文件类型。普通文件,目录之外,还有什么?首先就是以l开始的符号链接文件。还有用ll命令时,输出的以c开始的和以b开始的文件,分别是字符设备文件和块设备文件。还有比较少见的以s开始的套接字文件。既然linux都能识别这些文件,那还mount个毛线,直接访问不就行了,但是事实就是需要mount,那mount到底干了什么?原因在于,很多设备的数据组织和linux的文件系统并不一样。没法直接读取,你要看到文件目录,你必须得按照一定的格式去解析设备里的文件。这就是mount干得事,它按照你指定的格式去读取设备里的数据。就是转化为linux自己的文件系统,这样才能解析并读取数据。