适用系统:Linux(Redhat , CentOS,Debian,Ubuntu)
* Linux的云服务器数据盘未做分区和格式化,可以根据以下步骤进行分区以及格式化操作。
下面的操作将会把数据盘划分为一个分区来使用。
1、查看数据盘
在没有分区和格式化数据盘之前,使用 “df –h”命令,是无法看到数据盘的
root@host:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 4.9G 14G 27% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 486M 4.0K 486M 1% /dev
tmpfs 100M 376K 99M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
可以使用“fdisk -l”命令查看。如下:
root@host:~# fdisk -l
Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 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 identifier: 0x000da36d
Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 41940991 20969472 83 Linux
Disk /dev/xvdb: 32.2 GB, 32212254720 bytes # Disk /dev/xvdb: 32.2 GB 是我们要挂载的硬盘
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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 identifier: 0x00000000
Disk /dev/xvdb doesn't contain a valid partition table
友情提示:若您执行 fdisk -l 命令,发现没有 /dev/xvdb 标明您的云服务器没有要挂载的数据盘,那么您无需进行挂载,此时该教程对您不适用
2、对数据盘进行分区
执行“fdisk /dev/xvdb”命令,对数据盘进行分区;
根据提示,依次输入“n”,“p”“1”,两次回车,“wq”,分区就开始了,很快就会完成。
root@host:~# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x24755197.
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)
Command (m for help): n #第一输入n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #第二输入 p
Partition number (1-4, default 1): 1 #第三输入 1
First sector (2048-62914559, default 2048): #第一次 回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559): #第二次 回车
Using default value 62914559
Command (m for help): wq #最后输入wq 完成
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、 查看新的分区
使用“fdisk -l”命令可以看到,新的分区xvdb1已经建立完成了。
root@host:~# fdisk -l
Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 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 identifier: 0x000da36d
Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 41940991 20969472 83 Linux
Disk /dev/xvdb: 32.2 GB, 32212254720 bytes
64 heads, 51 sectors/track, 19275 cylinders, total 62914560 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 identifier: 0x24755197
Device Boot Start End Blocks Id System
/dev/xvdb1 2048 62914559 31456256 83 Linux #新的分区xvdb1已经建立完成了
4、格式化新分区
使用“mkfs.ext3 /dev/xvdb1”命令对新分区进行格式化,格式化的时间根据硬盘大小有所不同。
(也可自主决定选用 ext4 格式)
root@host:~# mkfs.ext3 /dev/xvdb1
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1966080 inodes, 7864064 blocks
393203 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
240 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
5、添加分区信息
使用“echo '/dev/xvdb1 /wwwroot ext3 defaults 0 0' >> /etc/fstab”(不含引号)命令将信息写入fstab,让系统开启自动挂载。
然后使用“cat /etc/fstab”命令查看,出现以下信息就表示写入成功。
* 如果需要把数据盘单独挂载到某个文件夹,比如单独用来存放网页,可以修改以上命令中的 /wwwroot 部分
root@host:~# echo '/dev/xvdb1 /wwwroot ext3 defaults 0 0' >> /etc/fstab
root@host:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=af414ad8-9936-46cd-b074-528854656fcd / ext4 errors=remount-ro 0 1
/dev/xvdb1 /wwwroot ext3 defaults 0 0
6、挂载新分区
使用“mount -a”命令挂载新分区,然后用“df -h”命令查看,出现以下信息就说明挂载成功,可以开始使用新的分区了。
root@host:~# mount -a
root@host:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 1.3G 18G 7% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 486M 4.0K 486M 1% /dev
tmpfs 100M 376K 99M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/xvdb1 30G 45M 28G 1% /wwwroot
这是评论测试
飞歌导航东方红烦得很
这是新的一条评论
未来一年,中国的移动支付市场会是什么样?