lvm扩容

今天线上磁盘满了,一开始没有做lvm,最后还是坑的自己,下面是自己测试过程

1、挂载两个数据盘

/dev/sdb
/dev/sdc

 

 2、创建基于分区的LV

1、 通过fdisk创建分区  可参考如下:

#磁盘信息

fdisk  /dev/sdb


n
p
1


t
8e
w

 3、创建基于分区的物理卷     pvcreate

   pvcreate /dev/sdb1

pvcreate /dev/sdb2
root@master-node:~# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
root@master-node:~# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created 

4、 创建卷组:

soft 卷组名称

 vgcreate soft /dev/sdb1

[root@master-node ~]# vgcreate soft /dev/sdb1
  Volume group "soft" successfully created
    

4.1 将新的物理卷添加到现有卷组(如果只有一个分区可以不用这一步,扩容的时候是需要的) 

vgextend soft /dev/sdb2

root@master-node:~# vgextend soft /dev/sdb2
  Volume group "soft" successfully extended

  4.2  从卷组中删除物理卷(一般用不上,谁没事加上了还删除)

 [root@master-node ~]# vgreduce soft /dev/sdc1 
  Removed "/dev/sdc1" from volume group "soft"

5、 创建LV 

 
  Total PE              5119    ==   100%FREE

  
             全部大写   卷组名称    lvm命令
  
 lvcreate -l 100%FREE  soft -n      soft01
 
 
             -L200M  指定大写
 
  lvcreate -L200M     soft -n      soft01

6、创建文件系统

  [root@master-node ~]# mkfs.ext4 /dev/soft/soft01 
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 5241856 4k blocks and 1310720 inodes
Filesystem UUID: bce3312b-5a41-4d12-b4a7-62d440cce327
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

7、挂载文件系统 

  [root@master-node ~]# mkdir /soft
[root@master-node ~]# mount /dev/soft/soft01 /soft/
[root@master-node ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
udev                         468M     0  468M   0% /dev
tmpfs                         98M  4.6M   93M   5% /run
/dev/mapper/ubuntu--vg-root   19G  2.4G   15G  14% /
tmpfs                        488M     0  488M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                        488M     0  488M   0% /sys/fs/cgroup
/dev/sda1                    472M   58M  391M  13% /boot
tmpfs                         98M     0   98M   0% /run/user/1000
/dev/mapper/soft-soft01       20G   44M   19G   1% /soft
[root@master-node ~]# 

8、 扩lv(当线上磁盘空间不足的时候,添加一块新的磁盘,或者直接在分一个区,步骤差不多)

/dev/sdc 当做新挂载的磁盘(分区格式化)
root@master-node:~# fdisk -l /dev/sdc
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x6c62af31
root@master-node:~# fdisk  /dev/sdc

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type 'Linux' and of size 20 GiB.

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x6c62af31

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc1        2048 41943039 41940992  20G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

 8-1、初始化好了,就开始整吧

 pvcreate /dev/sdc1

root@master-node:~# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

8.1 将新的物理卷添加到现有卷组 

vgextend soft /dev/sdc1

vgdisplay soft 

root@master-node:~# vgextend soft /dev/sdc1
  Volume group "soft" successfully extended

 8.3、在现有的空间中添加2G    (重要的来了,现在加了磁盘空间还没有变化,还需要告诉一下磁盘变化了)

lvextend -L+2G /dev/soft/soft01

root@master-node:~#  lvextend -L+2G /dev/soft/soft01
  Size of logical volume soft/soft01 changed from 19.99 GiB (5118 extents) to 21.99 GiB (5630 extents).
  Logical volume soft01 successfully resized.

 8.4、扩容文件系统

resize2fs /dev/soft/soft01

root@master-node:~# resize2fs /dev/soft/soft01 
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/soft/soft01 is mounted on /soft; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/soft/soft01 is now 5765120 (4k) blocks long.

原文地址:https://www.cnblogs.com/zhaojingyu/p/11647706.html