以前购ECS都是直接选一个盘(容量大的)即可,但有时我们需要系统盘和数据盘分开。
本机实例:系统盘500G, 数据盘500G.
操作步骤:
1.查看容量和挂载情况. df -h
[root@iZuf6995ou9mbuo2xefaksZ ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 512K 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 493G 2.9G 469G 1% /
tmpfs 3.2G 0 3.2G 0% /run/user/0
可以看到只有一块磁盘。
2.查看当前机器的磁盘情况. fdisk -l
[root@iZuf6995ou9mbuo2xefaksZ ~]# fdisk -l
Disk /dev/vda: 536.9 GB, 536870912000 bytes, 1048576000 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 label type: dos
Disk identifier: 0x000b2d99
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1048562549 524280251 83 Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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
3.对数据盘进行分区处理。fdisk /dev/vdb
[root@iZuf6995ou9mbuo2xefaksZ ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x42447a47.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1048575999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999):
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
在first sector 和 last sector分别直接按回车就好了。
4.查看分区是否完成.fdisk -l
[root@iZuf6995ou9mbuo2xefaksZ ~]# fdisk -l
Disk /dev/vda: 536.9 GB, 536870912000 bytes, 1048576000 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 label type: dos
Disk identifier: 0x000b2d99
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1048562549 524280251 83 Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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 label type: dos
Disk identifier: 0x42447a47
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048575999 524286976 83 Linux
可以看到 /dev/vdb1 这个已经出现。
5.对未格式化的磁盘进行格式化操作。mkfs.ext3 /dev/vdb1
[root@iZuf6995ou9mbuo2xefaksZ ~]# mkfs.ext3 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131071744 blocks
6553587 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
4000 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, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
6.到根目录下创建一个data1的目录用于挂载数据盘。
[root@iZuf6995ou9mbuo2xefaksZ ~]# cd /
[root@iZuf6995ou9mbuo2xefaksZ /]# mkdir -p data1
[root@iZuf6995ou9mbuo2xefaksZ /]# mount /dev/vdb1 /data1
7.设置开机重启自动挂载。
[root@iZuf6995ou9mbuo2xefaksZ /]# echo '/dev/vdb1 /data1 ext3 defaults 0 0'>> /etc/fstab
8.再次查看挂载和磁盘空间情况。df -h
[root@iZuf6995ou9mbuo2xefaksZ /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 516K 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 493G 2.9G 469G 1% /
tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/vdb1 493G 70M 467G 1% /data1
完成✅。