-
Linux6.4
硬盘扩容
< br>LVM
逻辑卷管理操作手册
1.
对新增加的硬盘进行分区、格式化
1.1.
用
root
用户登录系统
使用
SSH
客户端登录
Linux
< br>服务器。
1.2.
查看挂载情况(此步可省略)
(
p>
加上
-T
这个参数,就可以列出所有系统挂
载的分区的文件类型信息
)
[root@servername ~]# df -lh
文件系统
容量
已用
可用
已用
%%
挂载点
/dev/sda3
95G
4.0G
86G
5% /
tmpfs
3.9G
72K
3.9G
1% /dev/shm
/dev/sda1
388M
37M
331M
10% /boot
[root@servername ~]#
1.3.
查看磁盘情况(此步不建议省略)
下
方
红色
字为要创建分区的硬盘。
[root@servername ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 1
bytes
255 heads, 63 sectors/track,
13054 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: 0x000bf627
Device Boot
Start
End
Blocks
Id
System
/dev/sda1
*
1
52
409600
83
Linux
Partition 1 does not end on cylinder
boundary.
/dev/sda2
52
574
4194304
82
Linux swap
/ Solaris
Partition 2 does not end on cylinder
boundary.
-1-
/dev/sda3
574
13055
100252672
83
Linux
Disk
/dev/sdb
: 1073.7 GB, 1 bytes
255 heads, 63 sectors/track, 130541
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
[root@servername ~]#
1.4.
创建分区
下方
红色
字为要创建分区的硬盘注意跟上面查看到的要对应。
[root@servername ~]# fdisk
/dev/sdb
Device
contains neither a valid DOS partition table, nor
Sun, SGI or OSF disklabel
Building a
new DOS disklabel with disk identifier 0x883e515a.
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
p>
分区编号选
1
,如果被占依此类推
First cylinder (1-130541,
default 1):
按回车
默认(起始扇区)
Using
default value 1
Last cylinder,
+cylinders or +size{K,M,G} (1-130541, default
130541):
按回车
默认
(结束扇区)
也可以使用
+100M
即创建
100M
的
分区
也可以使用
(
< br>K,M,G
)
Using
default value 130541
Command (m for help): w
写分区表(可以输入
t
进行分区格式调整,见
1.6
调整分区格式
)
The
partition table has been altered!
-2-
Calling ioctl() to re-read partition
table.
Syncing disks.
[root@servername ~]#
1.5.
重新查看磁盘情况(此步可省略)
下
方
红色
字为新创建的磁盘分区信息。
[root@servername ~]# fdisk
-l
Disk /dev/sda: 107.4 GB,
1 bytes
255 heads, 63 sectors/track,
13054 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: 0x000bf627
Device Boot
Start
End
Blocks
Id
System
/dev/sda1
*
1
52
409600
83
Linux
Partition 1 does not end on cylinder
boundary.
/dev/sda2
52
574
4194304
82
Linux swap
/ Solaris
Partition 2 does not end on cylinder
boundary.
/dev/sda3
574
13055
100252672
83
Linux
Disk
/dev/sdb: 1073.7 GB, 1 bytes
255 heads,
63 sectors/track, 130541 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: 0x883e515a
Device Boot
Start
End
Blocks
Id
System
/dev/sdb1
1
130541
1048570551
83
Linux
[root@servername ~]#
1.6.
调整分区格式(可以跟创建分区合并执行)
< br>我们的新建分区,
却不是
LVM
的。
所以,
接下来使用
fdisk
p>
将其改成
LVM
的,
使用
LVM
逻辑卷管理可以方便以后扩容。
< br>
-3-
[root@servername ~]# fdisk
/dev/sdb
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): t
修改分区类型
Selected
partition 1
p>
选分区
1
(与上面新创建的分区要对应)<
/p>
Hex code (type L to list
codes): 8e
修改为
L
VM
类型(
8e
就是
< br>LVM
)
Changed
system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
写分区表
The partition table has been altered!
Calling ioctl() to re-read
partition table.
Syncing disks.
[root@servername ~]#
1.7.
重启服务器
[root@servername ~]# reboot
Broadcast message from root@servername
(/dev/pts/0) at 15:30 ...
The system is going down for reboot
NOW!
[root@servername ~]#
1.8.
分区格式化
下方
红色
字为要格式化的分区,要与上面新创建分区的对应。
(
如果不确定
可以执行
fdisk -l
查看磁盘情况,见
1.5
重新查看磁盘情况
)
[root@servername ~]# 4
/dev/sdb1
mke2fs
1.41.12 (17-May-2010)
文件系统标签
=
操作系统
:Linux
块大小
=4096 (log=2)
分块大小
=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536000 inodes, 262142637 blocks
-4-
13107131 blocks (5.00%) reserved for
the super user
第一个数据块
=0
Maximum filesystem blocks=4294967296
8000 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, 214990848
正在写入
inode
表
:
完成
Creating
journal (32768 blocks):
完成
Writing superblocks and filesystem
accounting information:
完成
This filesystem will be
automatically checked every 27 mounts or
180 days, whichever comes first.
Use tune2fs -c or -i to
override.
[root@servername ~]#
2.
<
/p>
创建
LVM
卷组分区添加到卷组创建卷实
现扩容
2.1.
硬盘分区初始化为物理卷
pvcre
ate
指令用于将物理硬盘分区初始化为物理卷,以便被
LVM
使用。
下方
红色
字为要初始化为物理卷的分区,要与上面新创建分区的对应。
[root@servername ~]# lvm
lvm> pvcreate
/dev/sdb1
Physical volume
lvm>
2.2.
创建逻辑卷组
vgcreate
命令执行几个操作。除了创建
卷组以外,它还设置
-5-
/dev/sdb1
,
使它使用
32 MB
的范围,
并将引导的最大
逻辑卷大小增加到
2 TB
(默
认
p>
4M
最大支持
256G
)
下方
红色
字为要创建逻辑卷组的物理分区,
要与上面新创建分区的对应,
蓝
色
字为要创建的卷组名。
lvm> vgcreate
-s 32M
company
/dev/sdb1
Volume group
lvm>
2.3.
激活分区(默认激活)
lvm> vgchange -a y
company
0 logical volume(s) in
volume group
2.4.
将分区加入到逻辑卷组
lvm>
vgextend
company
/dev/sdb1
Physical volume '/dev/sdb1'
is already in volume group 'company'
Unable to add physical
volume '/dev/sdb1' to volume group 'company'.
2.5.
创建逻辑卷
在最初时将它的大小设置为
4.96G
,并称它作
,最后要跟着逻辑卷
组名。
下方
蓝色
字为新创建的卷组名,
橘黄色
为要创建的逻辑卷,
红色
字为要创建
的逻辑卷大小(注意如分配了
5G
的硬盘空间可能只能创建
4.96G
逻辑卷大
小,
此处需要一点点试直到创建成功)
。
进行一点点减少容量尝试创建(比较
space
(
31999
extents):
34359
r
equired.
差距然后减少创建的容量,直到出现“
Log
ical
volume
creat
ed
”表示创建
成功)
。
lvm> lvcreate -L
1073.7G
-n
data
company
Rounding up size to full
physical extent 1.05 TiB
Volume group
required.
-6-
lvm> lvcreate -L
1.05T
-n
data
company
Rounding up size to full
physical extent 1.05 TiB
Volume group
required.
lvm> lvcreate -L
0.98T
-n
data
company
Rounding up size to full
physical extent 1003.53 GiB
Volume group
required.
lvm> lvcreate -L
0.97T
-n
data
company
Rounding up size to full
physical extent 993.28 GiB
Logical volume
lvm>
2.6.
退出
LVM
管理
lvm> quit
p>
退出
LVM
管理
Exiting.
2.7.
格式化文件系统
以上只是卷扩容了,下面是文件系统的真正扩容
格式化为
EXT4
文件系统
[root@servername ~]# 4
/dev/company/data
mke2fs 1.41.12 (17-May-2010)
文件系统标签
=
操作系统
:Linux
块大小
=4096 (log=2)
分块大小
=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65101824 inodes, 260382720 blocks
13019136 blocks (5.00%) reserved for
the super user
第一个数据块
=0
Maximum filesystem blocks=4294967296
7947 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,
-7-
4096000,
7962624, 11239424, 20480000, 23887872, 71663616,
78675968,
102400000, 214990848
正在写入
inode
表
:
完成
Creating
journal (32768 blocks):
完成
Writing superblocks and filesystem
accounting information:
完成
This filesystem will be
automatically checked every 32 mounts or
180 days, whichever comes first.
Use tune2fs -c or -i to
override.
[root@servername ~]#
3.
挂载分区及配置开机自动挂载
3.1.
创建临时文件夹挂载文件夹
[root@servername ~]# mkdir
/webdata
[root@servername ~]# mount
/dev/company/data
/webdata
[root@servername ~]#
3.2.
查看创建结果
[root@servername ~]# df -h
文件系统
容量
已用
可用
已用
%%
挂载点
/dev/sda3
95G
4.0G
86G
5% /
tmpfs
3.9G
72K
3.9G
1% /dev/shm
/dev/sda1
388M
37M
331M
10% /boot
/dev/mapper/company-data
978G
200M
928G
1% /webdata
[root@servername ~]#
3.3.
配置开机自动挂载
然后,应该设置服务器以使我的新
/
webdata
分区可以在每次启动机器时使
用。首先修改
p>
/etc/fstab
以使它包括新的
/webdata
项:
下方
红色
字为要添加的内容。
-8-
[root@servername ~]# vi
/etc/fstab
#
#
/etc/fstab
# Created by anaconda on Tue
Mar 25 13:20:45 2014
#
#
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
#
UUI
D=0fcfd8a1-056e-4948-9fb2-ec34ffd3f7bf /
ext4
defaults
1 1
UUID=eed74f6
a-dad2-450a-af47-7abb2889c085 /boot
ext4
defaults
1 2
UUID=efe0bafa-4893-415c-9ee2-d0dcd349d5
47 swap
swap
defaults
0 0
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/company/data
/webdata
ext4
defaults
1
2
~
~
~
~
~
[root@servername ~]#
保存退出。
(
注:
i
插入;
Esc
退出编辑模式;
:wq
保存退出
)
3.4.
重启计算机试效果
[root@servername ~]# reboot
Broadcast message from root@servername
(/dev/pts/0) at 18:08 ...
The system is going down for reboot
NOW!
-9-