一、挂载数据盘
下面以新买的服务器为例介绍挂载数据盘的操作过程。参考资料 https://help.aliyun.com/document_detail/25426.html
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
没有看到数据盘,说明没有挂载
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# fdisk -l
Disk /dev/vda: 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: 0x00053156
Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41942016 83 Linux
Disk /dev/vdb: 128.8 GB, 128849018880 bytes <- 看到120G的数据盘/dev/vdb
16 heads, 63 sectors/track, 249660 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
如果执行了 fdisk -l 命令后,没有发现 /dev/vdb,则表示您的实例没有数据盘,因此无需挂载
运行 fdisk /dev/xvdb,对数据盘进行分区。根据提示,依次输入 n,p,1,两次回车,wq,分区操作就开始了。
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x011f7cc4.
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-249660, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-249660, default 249660):
Using default value 249660
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
运行 fdisk -l 命令,查看新的分区。新分区 vdb1 已经创建好。如下面示例中的/dev/vdb1。
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# fdisk -l
Disk /dev/vda: 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: 0x00053156
Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41942016 83 Linux
Disk /dev/vdb: 128.8 GB, 128849018880 bytes
16 heads, 63 sectors/track, 249660 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x011f7cc4
Device Boot Start End Blocks Id System
/dev/vdb1 1 249660 125828608+ 83 Linux <- 发现了/dev/vdb1
运行 mkfs.ext3 /dev/vdb1,对新分区进行格式化。格式化所需时间取决于数据盘大小。您也可自主决定选用其他文件格式,如 ext4 等。
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# mkfs.ext3 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
7864320 inodes, 31457152 blocks
1572857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
960 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, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
运行 echo /dev/vdb1 /home ext3 defaults 0 0 >> /etc/fstab 写入新分区信息(系统重启后能自动挂载)。完成后,可以使用 cat /etc/fstab 命令查看。
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# echo /dev/vdb1 /home ext3 defaults 0 0 >> /etc/fstab
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Feb 23 07:28:22 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=3d083579-f5d9-4df5-9347-8d27925805d4 / ext4 defaults 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/vdb1 /home ext3 defaults 0 0
运行 mount /dev/vdb1 /home 挂载新分区,然后执行 df -h 查看分区。如果出现数据盘信息,说明挂载成功,可以使用新分区了。
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# mount /dev/vdb1 /home
[root@iZ2ze41df2mogmrk6x6e5jZ ~]# df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/vdb1 119G 188M 112G 1% /home
可以看到/dev/vdb1已经挂载到了/home,再执行reboot,看重启系统后,是否会自动挂载数据盘