假如硬盘分区没有空间了,如何知道应该对哪个分区进行扩容呢? 例如应用安装在/opt目录下,因为应用数据占满了空间,就要对应用所在的分区进行扩容。
以下面的显示为例,并没有一个独立的分区挂载到/opt目录,因此查看上层目录(即根目录/)是对应哪个分区的。从显示结果看,是/dev/mapper/centos-root挂载到根目录。
/dev/mapper/centos-root并没有显示得像传统的分区名称一样,如/dev/sda1。它和哪个分区对应呢?
lsblk可以看到块设备挂载在哪个目录,df可以看到文件系统挂载到哪个目录,而文件系统可以看成是经过格式化的分区?
[root@centos ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 28G 1.2G 27G 5% / devtmpfs 233M 0 233M 0% /dev tmpfs 244M 0 244M 0% /dev/shm tmpfs 244M 4.5M 240M 2% /run tmpfs 244M 0 244M 0% /sys/fs/cgroup /dev/sda1 1014M 159M 856M 16% /boot tmpfs 49M 0 49M 0% /run/user/0
使用fdisk查看时,/dev/mapper/centos-root显示为一个磁盘(而不是一个分区),与/dev/sda一样。
[root@centos ~]# fdisk -l [ 235.885589] blk_update_request: I/O error, dev fd0, sector 0 [ 235.907603] blk_update_request: I/O error, dev fd0, sector 0 Disk /dev/sda: 32.2 GB, 32212254720 bytes, 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 label type: dos Disk identifier: 0x0005ef33 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 62914559 30407680 8e Linux LVM Disk /dev/mapper/centos-root: 30.1 GB, 30056382464 bytes, 58703872 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 /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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
使用lsblk查看时,centos-root是位于sda2之下,而centos-root就是fdisk命令中看到的/dev/mapper/centos-root,而且是lvm类型的,所以应该对lvm进行扩容
[root@centos ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 30G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 29G 0 part ├─centos-root 253:0 0 28G 0 lvm / └─centos-swap 253:1 0 1G 0 lvm [SWAP] sr0 11:0 1 1024M 0 rom
对LVM进行扩容的基本步骤
- 新增磁盘空间,例如添加一块硬盘
- 对磁盘空间进行分区
- 将物理分区转换为PV
- 对VG进行扩容,即PV加入原有的VG
- 对原有的LV进行扩容
- 对文件系统进行扩容
那应该对哪个VG、LV进行扩容呢?就是对sda2所在的VG进行扩容。 使用pvscan查看当前的PV
[root@centos ~]# pvscan PV /dev/sda2 VG centos lvm2 [<29.00 GiB / 4.00 MiB free] Total: 1 [<29.00 GiB] / in use: 1 [<29.00 GiB] / in no VG: 0 [0 ]
PV是由物理分区转换而来的,如这里的PV是/dev/sda2,PV所属的VG是centos。
这里应该对名称为centos的VG进行扩容
[root@centos ~]# vgscan Reading volume groups from cache. Found volume group "centos" using metadata type lvm2 [root@centos ~]# lvscan ACTIVE '/dev/centos/swap' [1.00 GiB] inherit ACTIVE '/dev/centos/root' [27.99 GiB] inherit
dm: Device Mapper
[root@centos ~]# ll /dev/centos/root lrwxrwxrwx. 1 root root 7 Aug 15 17:32 /dev/centos/root -> ../dm-0 [root@centos ~]# ll /dev/mapper/centos-root lrwxrwxrwx. 1 root root 7 Aug 15 17:32 /dev/mapper/centos-root -> ../dm-0 [root@centos ~]# ll /dev/dm* brw-rw----. 1 root disk 253, 0 Aug 15 17:32 /dev/dm-0 brw-rw----. 1 root disk 253, 1 Aug 15 17:32 /dev/dm-1
文章评论