当你在阿里云买了服务器,随着业务量越来越大。数据盘的容量也就会不够用。所以我们就会新增一块云盘。下面讲新增云盘之后,然后挂载上去。 这是新手的教程,也是我的笔记。
第一步: 使用远程连接工具,输入用户名 root 和密码登录到实例。
第二步:运行 fdisk -l 命令查看数据盘。注意:在没有分区和格式化数据盘之前,使用 df -h 命令是无法看到数据盘的。在下面的示例中,有一个 5 gb 的数据盘需要挂载。 [root@xxxx ~]# fdisk -l
disk /dev/xvda: 42.9 gb, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00078f9c
device boot start end blocks id system
/dev/xvda1 * 1 5222 41940992 83 linux
disk /dev/xvdb: 5368 mb, 5368709120 bytes
255 heads, 63 sectors/track, 652 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第三步:执行下列命令,对数据盘进行分区。 fdisk /dev/xvdb第四步:根据提示,依次输入 n,p,1,两次回车,wq,分区就开始了。 [root@xxx ~]# fdisk /dev/xvdb
device contains neither a valid dos partition table, nor sun, sgi or osf disklab el
building a new dos disklabel with disk identifier 0x33eb5059.
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): n
command action
e extended
p primary partition (1-4)
p
partition number (1-4): 1
first cylinder (1-652, default 1):
using default value 1
last cylinder, +cylinders or +size{k,m,g} (1-652, default 652):
using default value 652
command (m for help): wq
the partition table has been altered!
calling ioctl() to re-read partition table.
syncing disks.第五步:执行 fdisk -l 命令,查看新的分区。新分区 xvdb1 已经创建好。如下面示例中的/dev/xvdb1。 [root@xxx ~]# fdisk -l
disk /dev/xvda: 42.9 gb, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00078f9c
device boot start end blocks id system
/dev/xvda1 * 1 5222 41940992 83 linux
disk /dev/xvdb: 5368 mb, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x33eb5059
device boot start end blocks id system
/dev/xvdb1 1 652 5237158+ 83 linux第六步:执行下列命令,对新分区进行格式化。格式化所需时间取决于数据盘大小。您也可自主决定选用其他文件格式,如 ext14 等。mkfs.ext3 /dev/xvdb1第七步:执行下列命令写入新分区信息。 echo '/dev/xvdb1 /mnt ext3 defaults 0 0'>> /etc/fstab完成后,可以使用 cat /etc/fstab 命令查看。
注意: ubuntu 12.04 不支持 barrier,所以对该系统正确的命令是:echo '/dev/xvdb1 /mnt ext3 barrier=0 0 0'>>/etc/fstab如果需要把数据盘单独挂载到某个文件夹,比如单独用来存放网页,可以修改以上命令中的 /mnt 部分。
第八步:执行 mount /dev/xvdb1 /mnt 挂载新分区,然后执行 df -h 查看分区。如果出现数据盘信息,说明挂载成功,可以使用新分区了。 [root@xxx ~]# mount /dev/xvdb1 /mnt
[root@xxx ~]# df -h
filesystem size used avail use% mounted on
/dev/xvda1 40g 1.5g 36g 4% /
tmpfs 498m 0 498m 0% /dev/shm
/dev/xvdb1 5.0g 139m 4.6g 3% /mnt总结: 全部按照命令来的话,基本上是没有什么问题的。 可能比较疑惑的是挂载的路径问题。当前我以为挂载到某一个路径,然后就会把那个文件夹的容量增大。谁知道不是。而这只是一个链接指向而已。
也就是说。你的挂载路径,只是将路径重新指向到新的云盘。而且这个路径之前的数据就会看不见了。除非你umount ,才会看到原来的数据。
如果你们还有哪里不明白的地方,欢迎提问 或者加我qq 164418960
ad:真正免费,域名+虚机+企业邮箱=0元