首先说下步骤,添加硬盘->硬盘分区->LVM->重新挂载
- 硬盘分区
gpt分区表使用parted,mbr分区表使用fdisk和parted均可。 LVM核心命令
1
2
3
4pvcreate /dev/sdb1 # 将/dev/sdb1创建成物理卷
vgextend centos /dev/sdb1 # 将/dev/sdb1添加到centos卷组中
lvextend -L +19.92G /dev/centos/root # 扩容/dev/centos/root逻辑卷19.92G
lvextend -l +1 /dev/centos/root # 最后1PE(4MB)别浪费重新挂载
1
2resize2fs /dev/centos/root # ext2/ext3/ext4文件系统使用这条命令
xfs_growfs /dev/centos/root # xfs文件系统使用这条命令
扩容之前
在扩容之前,先查看下当前磁盘状况,只有sda这一块物理磁盘,根目录容量55G,准备添加一块20GB的sdb物理磁盘。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[root@localhost ~]# ls /dev
agpgart crash hugepages mcelog ptmx snapshot tty14 tty25 tty36 tty47 tty58 ttyS2 vcs4 vhost-net
autofs disk initctl mem pts snd tty15 tty26 tty37 tty48 tty59 ttyS3 vcs5 vmci
block dm-0 input midi random stderr tty16 tty27 tty38 tty49 tty6 uhid vcs6 vsock
bsg dm-1 kmsg mqueue raw stdin tty17 tty28 tty39 tty5 tty60 uinput vcsa zero
btrfs-control dmmidi kvm net rfkill stdout tty18 tty29 tty4 tty50 tty61 urandom vcsa1
bus dri log network_latency rtc tty tty19 tty3 tty40 tty51 tty62 usbmon0 vcsa2
centos fb0 loop-control network_throughput rtc0 tty0 tty2 tty30 tty41 tty52 tty63 usbmon1 vcsa3
char fd lp0 null sda tty1 tty20 tty31 tty42 tty53 tty7 usbmon2 vcsa4
console full lp1 nvram sda1 tty10 tty21 tty32 tty43 tty54 tty8 vcs vcsa5
core fuse lp2 oldmem sda2 tty11 tty22 tty33 tty44 tty55 tty9 vcs1 vcsa6
cpu hidraw0 lp3 port sg0 tty12 tty23 tty34 tty45 tty56 ttyS0 vcs2 vfio
cpu_dma_latency hpet mapper ppp shm tty13 tty24 tty35 tty46 tty57 ttyS1 vcs3 vga_arbiter
[root@localhost ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009869b
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 125829119 61864960 8e Linux LVM
磁盘 /dev/mapper/centos-root:59.1 GB, 59051606016 字节,115335168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:4294 MB, 4294967296 字节,8388608 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 55G 41G 15G 75% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 152K 3.9G 1% /dev/shm
tmpfs 3.9G 9.0M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 220M 795M 22% /boot
tmpfs 781M 12K 781M 1% /run/user/1000
添加物理磁盘
在VMWare 虚拟机->设置中添加一块20GB的SCSI物理磁盘
重启系统
重启系统后出现了/dev/sdb设备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[root@localhost ~]# ls /dev
agpgart crash hugepages mcelog ptmx sg1 tty12 tty23 tty34 tty45 tty56 ttyS0 vcs2 vfio
autofs disk initctl mem pts shm tty13 tty24 tty35 tty46 tty57 ttyS1 vcs3 vga_arbiter
block dm-0 input midi random snapshot tty14 tty25 tty36 tty47 tty58 ttyS2 vcs4 vhost-net
bsg dm-1 kmsg mqueue raw snd tty15 tty26 tty37 tty48 tty59 ttyS3 vcs5 vmci
btrfs-control dmmidi kvm net rfkill stderr tty16 tty27 tty38 tty49 tty6 uhid vcs6 vsock
bus dri log network_latency rtc stdin tty17 tty28 tty39 tty5 tty60 uinput vcsa zero
centos fb0 loop-control network_throughput rtc0 stdout tty18 tty29 tty4 tty50 tty61 urandom vcsa1
char fd lp0 null sda tty tty19 tty3 tty40 tty51 tty62 usbmon0 vcsa2
console full lp1 nvram sda1 tty0 tty2 tty30 tty41 tty52 tty63 usbmon1 vcsa3
core fuse lp2 oldmem sda2 tty1 tty20 tty31 tty42 tty53 tty7 usbmon2 vcsa4
cpu hidraw0 lp3 port sdb tty10 tty21 tty32 tty43 tty54 tty8 vcs vcsa5
cpu_dma_latency hpet mapper ppp sg0 tty11 tty22 tty33 tty44 tty55 tty9 vcs1 vcsa6
[root@localhost ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009869b
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 125829119 61864960 8e Linux LVM
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-root:59.1 GB, 59051606016 字节,115335168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:4294 MB, 4294967296 字节,8388608 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 55G 41G 15G 75% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 152K 3.9G 1% /dev/shm
tmpfs 3.9G 9.0M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 220M 795M 22% /boot
tmpfs 781M 8.0K 781M 1% /run/user/1000
磁盘分区
使用parted对/dev/sdb分区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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94[root@localhost ~]# parted
GNU Parted 3.1
使用 /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular
partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) select /dev/sdb
使用 /dev/sdb
(parted) print
错误: /dev/sdb: unrecognised disk label
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) prin all
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1049kB 1075MB 1074MB primary xfs 启动
2 1075MB 64.4GB 63.3GB primary lvm
错误: /dev/sdb: unrecognised disk label
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4295MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 4295MB 4295MB linux-swap(v1)
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 59.1GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system 标志
1 0.00B 59.1GB 59.1GB xfs
(parted) mklabel
新的磁盘标签类型? gpt
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
(parted) mkpart iphpjs 1 21400
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 21.4GB 21.4GB iphpjs
(parted) quit
信息: You may need to update /etc/fstab.
分完区后查看信息,出现了/dev/sdb11
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
55
56
57
58
59
60
61
62
63
64
65
66
67[root@localhost ~]# ls /dev
agpgart crash hugepages mcelog ptmx sg0 tty11 tty22 tty33 tty44 tty55 tty9 vcs1 vcsa6
autofs disk initctl mem pts sg1 tty12 tty23 tty34 tty45 tty56 ttyS0 vcs2 vfio
block dm-0 input midi random shm tty13 tty24 tty35 tty46 tty57 ttyS1 vcs3 vga_arbiter
bsg dm-1 kmsg mqueue raw snapshot tty14 tty25 tty36 tty47 tty58 ttyS2 vcs4 vhost-net
btrfs-control dmmidi kvm net rfkill snd tty15 tty26 tty37 tty48 tty59 ttyS3 vcs5 vmci
bus dri log network_latency rtc stderr tty16 tty27 tty38 tty49 tty6 uhid vcs6 vsock
centos fb0 loop-control network_throughput rtc0 stdin tty17 tty28 tty39 tty5 tty60 uinput vcsa zero
char fd lp0 null sda stdout tty18 tty29 tty4 tty50 tty61 urandom vcsa1
console full lp1 nvram sda1 tty tty19 tty3 tty40 tty51 tty62 usbmon0 vcsa2
core fuse lp2 oldmem sda2 tty0 tty2 tty30 tty41 tty52 tty63 usbmon1 vcsa3
cpu hidraw0 lp3 port sdb tty1 tty20 tty31 tty42 tty53 tty7 usbmon2 vcsa4
cpu_dma_latency hpet mapper ppp sdb1 tty10 tty21 tty32 tty43 tty54 tty8 vcs vcsa5
[root@localhost ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009869b
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 125829119 61864960 8e Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:gpt
# Start End Size Type Name
1 2048 41797631 20G Microsoft basic iphpjs
磁盘 /dev/mapper/centos-root:59.1 GB, 59051606016 字节,115335168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:4294 MB, 4294967296 字节,8388608 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:4294 MB, 4294967296 字节,8388608 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 55G 41G 15G 75% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 152K 3.9G 1% /dev/shm
tmpfs 3.9G 9.0M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 220M 795M 22% /boot
tmpfs 781M 8.0K 781M 1% /run/user/1000
进行LVM扩容
1 | [root@localhost ~]# pvcreate /dev/sdb1 |
LVM扩容完成后,发现逻辑卷已经变大了,但挂载点并没有变大
1 | [root@localhost ~]# fdisk -l |
重新挂载磁盘
重新挂载磁盘后根分区已经成功扩容1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3604224 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=14416896, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=7039, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 14416896 to 19640320
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 75G 41G 34G 55% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 152K 3.9G 1% /dev/shm
tmpfs 3.9G 9.0M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 220M 795M 22% /boot
tmpfs 781M 8.0K 781M 1% /run/user/1000