背景
当前市面上大部分的云服务器产品,在购买Linux服务器并启动后,通常只帮我们挂载了系统盘到/目录。我们所购买的数据盘并没有帮我们挂载到系统。查看内存配置,一般swap也为0。
这里我们可以利用购买的数据盘来创建swap分区与数据分区,并将他们挂载到系统中去。
操作
1,查看当前的磁盘,如下,/dev/vda为系统盘,/dev/vdb为数据盘:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# fdisk -l
Disk
/dev/vda
: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0008e9bc
Device Boot Start End Blocks Id System
/dev/vda1
* 2048 2099199 1048576 83 Linux
/dev/vda2
2099200 104857566 51379183+ 83 Linux
Disk
/dev/vdb
: 429.5 GB, 429496729600 bytes, 838860800 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
|
2,对/dev/vdb进行分区操作,分割16G空间做swap,剩余空间做数据盘。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# 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 0xb07be21f.
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):
First sector (2048-838860799, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-838860799, default 838860799): +16G
Partition 1 of
type
Linux and of size 16 GiB is
set
Command (m
for
help): n
Partition
type
:
p primary (1 primary, 0 extended, 3
free
)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (33556480-838860799, default 33556480):
Using default value 33556480
Last sector, +sectors or +size{K,M,G} (33556480-838860799, default 838860799):
Using default value 838860799
Partition 2 of
type
Linux and of size 384 GiB is
set
Command (m
for
help): w
The partition table has been altered!
Calling ioctl() to re-
read
partition table.
Syncing disks.
# fdisk -l
Disk
/dev/vda
: 53.7 GB, 53687091200 bytes, 104857600 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: 0x0008e9bc
Device Boot Start End Blocks Id System
/dev/vda1
* 2048 2099199 1048576 83 Linux
/dev/vda2
2099200 104857566 51379183+ 83 Linux
Disk
/dev/vdb
: 429.5 GB, 429496729600 bytes, 838860800 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: 0x53b4d701
Device Boot Start End Blocks Id System
/dev/vdb1
2048 33556479 16777216 83 Linux
/dev/vdb2
33556480 838860799 402652160 83 Linux
|
可以看到创建了2个分区/dev/vdb1,/dev/vdb2。
3,创建swap分区,并启用:
1
2
|
# mkswap /dev/vdb1
# swapon /dev/vdb1
|
4,把/dev/vdb2格式化,并挂载到/data目录下:(这里格式成xfs文件系统)
1
2
3
|
# mkdir -p /data
# mkfs.xfs /dev/vdb2
# mount /dev/vdb2 /data
|
5,检查是否生效:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/vda2
49G 1.7G 45G 4% /
devtmpfs 7.8G 0 7.8G 0%
/dev
tmpfs 7.8G 0 7.8G 0%
/dev/shm
tmpfs 7.8G 25M 7.8G 1%
/run
tmpfs 7.8G 0 7.8G 0%
/sys/fs/cgroup
/dev/vda1
976M 146M 764M 16%
/boot
tmpfs 1.6G 0 1.6G 0%
/run/user/0
/dev/vdb2
384G 33M 384G 1%
/data
# free -m
total used
free
shared buff
/cache
available
Mem: 15885 393 14628 24 863 15158
|
6,把磁盘挂载信息写进fstab,使之开启自动挂载:
1
2
3
|
# vi /etc/fstab
/dev/vdb1
swap swap defaults 0 0
/dev/vdb2
/data
xfs defaults 0 0
|
本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/2065057,如需转载请自行联系原作者