-
2022-04-06 15:34:32
- 查看初始空间
- 查看分区
扩容:
1、磁盘分区
[root@ecs-7837 ~]# fdisk /dev/sdaWARNING: 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 —P表示主分区
Partition number (1-4): 3 ----分区盘序号
First cylinder (1-166440, default 1): 83221 —分区开始序号
Last cylinder, +cylinders or +size{K,M,G} (83221-166440, default 166440): —直接回车
Using default value 166440Command (m for help): t -----改变分区格式
Partition number (1-4): 3
Hex code (type L to list codes): 8e -----分区为lvm格式
Changed system type of partition 3 to 8e (Linux LVM)Command (m for help): w ----保存
The partition table has been altered!Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
2.可以看到,新增的40G已划分成/dev/sda3了
这一步完成后最好重启一下服务器。
3、添加新LVM到已有的LVM组
1)pvcreate /dev/sda3
2)查看vg name
命令 vgdisplay
3)将pv加入到vg卷组
[root@ecs-7837 ~]# vgextend centos /dev/sda3
linux磁盘挂载和扩容。
4)查看 Free PE/Size 大小,这里为48635)查看根目录的lv名称
6)扩容lv
[root@ecs-7837 ~]# lvextend -l +10239 /dev/VolGroup/lv_root
lvextend指令用于在线扩展逻辑卷的空间大小,而不中断应用程序对逻辑卷的访问。其后有两个选项
选项 说明
-L 指定逻辑卷的大小,单位为“kKmMgGtT”字节,也就是Size
-l 指定逻辑卷的大小,单位为PE数
4、扩容文件系统
以上只是卷扩容了,还要对文件系统实现真正扩容CentOS 6 下执行:
[root@ecs-7837 ~]# resize2fs /dev/VolGroup/lv_rootCentOS 7 下执行:
[root@ecs-7837 ~]# xfs_growfs /dev/VolGroup/lv_root
5、查看磁盘空间是否扩容
更多相关内容 - 查看初始空间
-
linux 虚拟机扩容--直接扩容到根目录
2021-10-27 15:45:13参考:VMware虚拟机扩容根目录磁盘容量_子清的博客-CSDN博客 https://jingyan.baidu.com/article/fec4bce28c18caf2618d8b1b.html Linux系统将几块磁盘制作lvm_linux卷并分区挂载_qq_36445861的博客-CSDN博客 ...1.在虚拟机关机的状态下操作,我这又给了20G
2.开启虚拟机查看 fdisk -l 可以看到
8e linux lvm的 这个是新加的
3.将刚才分区的磁盘改能lvm类型,并保存分区
fdisk /dev/sda2
4.重启系统或partprobe使新分区表生效
5.查看可以用作物理卷的设备
6.创建物理卷并查看物理卷
pvcreate /dev/sdb
pvdisplay 查看
7.将新创建的物理卷加载到VG,vgextend 并查看VG可用空间
vgextend centos /dev/sdb
8.把添加的空间给根目录,并查看根可用空间
lvextend -l +100%FREE /dev/mapper/centos-root
可以看到从原来的的17扩到36
9.别着急还有最后一步 xfs_growfs /dev/mapper/centos-root
xfs_growfs /dev/mapper/centos-root
df -h 查看添加上了
完美,
如果你不想添加到根目录比如home目录
lvextend -l +100%FREE /dev/mapper/centos-home
看这里
参考:VMware虚拟机扩容根目录磁盘容量_子清的博客-CSDN博客
https://jingyan.baidu.com/article/fec4bce28c18caf2618d8b1b.html
-
Linux系统扩容根目录磁盘空间的操作方法
2021-01-10 08:51:16Linux根目录磁盘空间不够用了,当修改了虚拟机模版增加磁盘大小或者插入了一块新硬盘,但是发现系统里的大小还是没改变。 产生的原因是没有给磁盘格式化,没有增加分区。 二、操作方法 1. 查看磁盘空间大小,使用... -
Linux扩容(VmWare扩容linux根目录)
2022-05-01 22:58:063、扩容根目录 /dev/mapper/centos-root 一、VmWare操作 关闭虚拟机,点击扩展,把原来的10G 扩容成30G,此时多出来的20G处于未分配状态 二、创建新分区 sda3 2.1 查看已有的分区 [root@localhost ~]#...目录
2.5.4 用vgdisplay -v 查看最后一行 Total PE / Free PE 的大小
2.5.5 扩容根路径 /dev/mapper/centos-root 的容量
3.1 xfs_growfs /dev/mapper/centos-root
思路:
1、VmWare把原来的10G,扩容到30G,多出来的20G处于未分配状态。 2、创建新分区sda3,把20G分配给sda3,并设置sda3的磁盘格式,形成新的卷 3、设置sda3的lvm 4、扩容根目录 /dev/mapper/centos-root
一、VmWare操作
关闭虚拟机,点击扩展,把原来的10G 扩容成30G,此时多出来的20G处于未分配状态
二、创建新分区 sda3,并设置格式为xfs,设置lvm
2.1 查看已有的分区
[root@localhost ~]# fdisk -l
2.2创建新分区sda3
[root@localhost ~]# fdisk /dev/sda (1) 输入m : 打印此菜单 (2) 输入p : 打印分区表 (3) 输入n :添加新分区 【全部回车,使用默认值】 (4) 输入w : 将表写入磁盘并退出
输入 m 打印菜单
输入 p 打印分区表
输入 n 新建分区,全部回车,使用默认值
输入 w 保存退出
2.3重启系统并重新查看分区
[root@localhost ~]# fdisk -l
【一定需要重启!】发现多出来刚刚新建的分区 sda3
2.4设置 新分区sda3的格式
2.4.1 查看已有分区的格式
[root@localhost ~]# df -T -h 已有格式为 xfs 格式
2.4.2 设置新分区的格式为 xfs格式
[root@localhost ~]# mkfs.xfs /dev/sda3
2.5 设置sda3分区的lvm
2.5.1 输入lvm,并进入lvm
[root@localhost ~]# lvm
2.5.2 初始化分区sda3
lvm> pvcreate /dev/sda3
2.5.3将初始化过的分区加入到虚拟卷组centos
lvm> vgextend centos /dev/sda3
2.5.4 用vgdisplay -v 查看最后一行 Total PE / Free PE 的大小
lvm> vgdisplay -v
2.5.5 扩容根路径 /dev/mapper/centos-root 的容量
lvm> lvextend -l+3839 /dev/mapper/centos-root
2.5.6 quit 退出
lvm> quit
三 、根目录扩容生效
3.1 xfs_growfs /dev/mapper/centos-root
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
查看最终结果
df -h
-
虚拟机增加磁盘空间后lv扩容详细流程,linux扩容根目录详细流程【openstack和VMware虚拟机方法同理】,2021...
2021-12-29 10:10:01文章目录致辞说明环境准备扩容流程扩容根[/]目录做扇区增加pv空间增加vg空间增加lv空间扩容后信息一览和说明新增一块硬盘,把容量加到固定的vg和lv上做扇区增加pv空间创建vg和lv【测试用,必看】增加vg空间增加lv...文章目录
致辞
- 这篇文章呢,将是我2021年最后的一篇文章了,今年收获特别巨大,感谢各位一路上的支持,在这提前祝福各位:
- 新年有新愿,旧愿皆已偿。
- 新年所许,四季与你。
- 人间值得,未来可期。
- 以梦为马,不负韶华,阳光满路,温暖如初。
- 带着欢喜,奔向新的一年,愿2022 ,多喜乐, 常安宁。
我以为这是篇相对简单的博客,做完后发现已经超过4w字了,意义很大,肯定能让你对lv扩容有新的认知,值得各位一看。
说明
-
在做云运维的时候,有时候业务方有扩容磁盘的需求,但是业务方并不会在系统内用命令完成最终的扩容,所以这时候局方会让我们帮忙在系统内给完成一下扩容,然后有次扩容发现一个很奇怪的问题【系统是redhat6.4】,新增的sdb200G的盘在做lv的时候,并没有给sdb化扇区,而且之前的sda3格式是linux,并不是linux lvm格式,所以我很纳闷,这2个盘是如何能做成lv的,现在又要求新扩容,这个没法继续了,害怕导致之前的数据丢失。
-
我的疑问是:
- sda3不是linux LVM格式,咋能做成vg呢!!!
- sdb不划扇区直接用裸盘加vg里面,这不是把这个硬盘后路封死了吗!!!【后面这块盘理论上不能扩容了】
- 环境是redhat6.4的系统,但我没有这个老的iso,带着这些疑问,用7.6的系统来一一验证我的猜想
-
虽然我之前有完整的对lv扩容和fdisk分区做过详细说明,但云上的虚拟机我并没有做过中途的扩容,所以我今天在这特意模拟一下这个扩容流程吧,分两种情况扩容
- 1、扩容根目录【有时候业务方会有这种需求】
- 2、给某个硬盘加容量,扩到固定vg和lv上
- 3、新增一块硬盘空间,把容量加到固定vg和lv上
- 4、验证我上面的2个疑问
-
我下面所有内容都参照我下面这2个博客完成,所以我下面实操不会做太多解释,如果看不懂的,可以来看下面2个文章学习下相关知识。
环境准备
-
因为openstack和VMware上的镜像都是最小化安装的,所以我在这也装一台最小化的系统,模拟云上的虚拟机。
-
最小化安装的系统网卡默认是关闭的哈,需要ifup网卡才行,重启网络是没有用的哦
-
初始虚拟机信息如下:
[root@lv-test ~]# ip a | grep 59 inet 192.168.59.129/24 brd 192.168.59.255 scope global noprefixroute dynamic ens33 [root@lv-test ~]# [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 50.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]# [root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 99G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 41.1G 0 lvm /home sr0 11:0 1 1024M 0 rom [root@lv-test ~]# [root@lv-test ~]# fdisk -l /dev/sda Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00017d4d Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM [root@lv-test ~]#
扩容流程
- 我先给第一快盘给扩成200g,然后新增一个300g的盘把。
扩容根[/]目录
-
注:我在这呢,把说明中的1和2都给做了
-
我上面已经给硬盘扩成200g了,lsblk可以看到sda已经变成200了
并且可以看到/目录对应的是centos-root,所以我们只需要扩centos-root这个lv就是扩根目录了
[root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 99G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 41.1G 0 lvm /home sdb 8:16 0 300G 0 disk sr0 11:0 1 4.3G 0 rom [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 50.00g swap centos -wi-ao---- <7.88g
- lv名称锊清楚了,就开始搞吧
做扇区
- 现在可以看到,sda有214G,但实际只用了100g
[root@lv-test ~]# fdisk -l /dev/sda Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00017d4d Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM [root@lv-test ~]#
- 因为我是要把剩下空间全部给/的,所以我直接把全部剩下空间都划成一个扇区吧
# 注:需要吧格式给改成linux lvm哦【参数是8e】 [root@lv-test ~]# fdisk /dev/sda 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. Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00017d4d Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): First sector (209715200-419430399, default 209715200): Using default value 209715200 Last sector, +sectors or +size{K,M,G} (209715200-419430399, default 419430399): Using default value 419430399 Partition 3 of type Linux and of size 100 GiB is set Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00017d4d Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM /dev/sda3 209715200 419430399 104857600 83 Linux Command (m for help): t Partition number (1-3, default 3): 3 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00017d4d Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM /dev/sda3 209715200 419430399 104857600 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@lv-test ~]# # 刷新 [root@lv-test ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@lv-test ~]# # 可以看到sda3的100g空间了 [root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 50G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part sdb 8:16 0 300G 0 disk sr0 11:0 1 4.3G 0 rom [root@lv-test ~]#
增加pv空间
- 现在的pv信息
注:pv实际上都是新增,而不是把空间加到某个已有vp上
[root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 4.00m [root@lv-test ~]#
- 现在开始吧我们上面的创建的sda3的100g创成pv
很简单的,都不需要命名,直接pvcreate即可
[root@lv-test ~]# lsblk | grep sda3 └─sda3 8:3 0 100G 0 part [root@lv-test ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created. [root@lv-test ~]# [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 4.00m /dev/sda3 lvm2 --- 100.00g 100.00g [root@lv-test ~]# [root@lv-test ~]# pvscan PV /dev/sda2 VG centos lvm2 [<99.00 GiB / 4.00 MiB free] PV /dev/sda3 lvm2 [100.00 GiB] Total: 2 [<199.00 GiB] / in use: 1 [<99.00 GiB] / in no VG: 1 [100.00 GiB] [root@lv-test ~]#
增加vg空间
- 现有vg信息
注:增加vg的时候就需要注意了,如果有多个vg,得确定最终扩容lv所属vg是什么,如:现在扩容的 根目录是在这个 centos的vg下的【因为根目录lv的vg是centos所以我们增加容量必须得增加到这个centos的vg上才行】。
[root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 3 0 wz--n- <99.00g 4.00m [root@lv-test ~]# # lvs可以看到需要扩容的vg名称 [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 50.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]#
- 开始把上面100g的lv空间加到这个centos上
可以看到vg已经变成198g,并且可用是100g了
[root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 3 0 wz--n- <99.00g 4.00m [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 4.00m /dev/sda3 lvm2 --- 100.00g 100.00g [root@lv-test ~]# [root@lv-test ~]# vgextend centos /dev/sda3 Volume group "centos" successfully extended [root@lv-test ~]# [root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 100.00g [root@lv-test ~]#
增加lv空间
- 扩容前根目录的lv和df看到的信息都是50G,我们需要扩100g,那么最终根会为150G才对
[root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 50.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 1.1G 49G 3% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 12M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 1014M 146M 869M 15% /boot /dev/mapper/centos-home 42G 33M 42G 1% /home tmpfs 781M 0 781M 0% /run/user/0 [root@lv-test ~]#
- 开始扩
可以看到扩容后root信息已经变成150G了
[root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 50.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]# # 不知道lv名称格式的,可以用lvdisplay 查看详细路径 [root@lv-test ~]# lvextend -L +100G /dev/centos/root Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents). Logical volume centos/root successfully resized. [root@lv-test ~]# [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]#
- 现在df呢,是看不到150g空间的,需要刷新以后才能看到
刷新之前呢,需要先看这个是啥格式的,如我的根是xfs格式的,那么我就需要用xfs的方式来刷新
[root@lv-test ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 50G 1.1G 49G 3% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 12M 3.8G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 146M 869M 15% /boot /dev/mapper/centos-home xfs 42G 33M 42G 1% /home tmpfs tmpfs 781M 0 781M 0% /run/user/0 [root@lv-test ~]# # xfs的刷新,ext4不能用 # 一般是用挂载目录作为刷新地址,所以我直接用 / [root@lv-test ~]# xfs_growfs / meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 13107200 to 39321600 # 刷新后就可以看到/目录空间已经增加了 [root@lv-test ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 150G 1.1G 149G 1% / devtmpfs 3.8G 0 3.8G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 12M 3.8G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 1014M 146M 869M 15% /boot /dev/mapper/centos-home 42G 33M 42G 1% /home tmpfs 781M 0 781M 0% /run/user/0 [root@lv-test ~]#
扩容后信息一览和说明
- 其中就pv能看到多了一个空间罢了,其他基本看不出啥
[root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 [root@lv-test ~]# [root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 [root@lv-test ~]# [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]#
- lsblk的话就能看到很多东西了,可以看到sda2下面的centos-root和sda3下面同样有一个centos-root,这2个信息是一摸一样的,别慌这是正常的,表示 centos-root是由 sda2和sda3的空间组成的一个总容量为150G【这时候可以看到sda3有100g,所以可以得知sda2中用了50g】
[root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk sr0 11:0 1 4.3G 0 rom [root@lv-test ~]#
新增一块硬盘,把容量加到固定的vg和lv上
做扇区
-
做扇区的意义其实还是挺重要的,比如我现在有一个300g的新硬盘,我这次只想用100g,把100g的空间加到某个lv上,剩下的200g先不用。
然后后面200g想用的时候再随时做扇区,这样有规划的使用是不是正规的多?【其实最主要的是如果想把空间增加到不同的vg上,就必须这么做】
如果只有一个vg,那么我们直接把这300g做成一个扇区也无所谓,300g全部划到vg上。lv用多少取多少,只是只能在这一个vg上做罢了,不能跨vg使用这300g容量 -
我这呢准备用2个vg来做实验,方便更能理解vg,所以我扇区先做2个100g的,剩余100g我后面做其他实验用。
# 现在没有扇区的 [root@lv-test ~]# fdisk -l /dev/sdb Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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 [root@lv-test ~]# # 开始增加2个100g空间 [root@lv-test ~]# fdisk /dev/sdb 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 0x359bff9f. 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): 1 First sector (2048-629145599, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): +100G Partition 1 of type Linux and of size 100 GiB is set Command (m for help): p Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x359bff9f Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 83 Linux 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): 2 First sector (209717248-629145599, default 209717248): Using default value 209717248 Last sector, +sectors or +size{K,M,G} (209717248-629145599, default 629145599): +100G Partition 2 of type Linux and of size 100 GiB is set Command (m for help): p Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x359bff9f Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 83 Linux /dev/sdb2 209717248 419432447 104857600 83 Linux Command (m for help): t Partition number (1,2, default 2): 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x359bff9f Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 8e Linux LVM /dev/sdb2 209717248 419432447 104857600 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@lv-test ~]# # 可以看到已经有2个100g空间了,还剩100g [root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part └─sdb2 8:18 0 100G 0 part sr0 11:0 1 4.3G 0 rom [root@lv-test ~]#
增加pv空间
- 现在的pv信息
注:pv实际上都是新增,而不是把空间加到某个已有vp上
[root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 [root@lv-test ~]#
- 现在开始吧我们上面的创建的sdb1和sdb2的100g创成pv
很简单的,都不需要命名,直接pvcreate即可
[root@lv-test ~]# lsblk | grep sdb sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part └─sdb2 8:18 0 100G 0 part [root@lv-test ~]# [root@lv-test ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@lv-test ~]# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created. [root@lv-test ~]# [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 lvm2 --- 100.00g 100.00g /dev/sdb2 lvm2 --- 100.00g 100.00g [root@lv-test ~]# lsblk | grep sdb sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part └─sdb2 8:18 0 100G 0 part [root@lv-test ~]#
创建vg和lv【测试用,必看】
- 注意啊,因为我系统只有一个默认的centos的vg,我现在新建一个vg,是为了后面测试说明啊,如果你已有vg和lv,跳过创建,看下面需要扩的挂载目录信息
- 因为现在只有一个系统默认vg,我新建一个vg吧
可以看到,上面创建的2个pv此时是没有绑定vg的,我在这创建一个vg绑定到/sev/sdb1
上,此时再次查看pv,可以看到/dev/sdb1
的这个pv自动给绑定上我刚创建的vg了
[root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 lvm2 --- 100.00g 100.00g /dev/sdb2 lvm2 --- 100.00g 100.00g [root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 [root@lv-test ~]# [root@lv-test ~]# vgcreate vg-test /dev/sdb1 Volume group "vg-test" successfully created [root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 1 0 0 wz--n- <100.00g <100.00g [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g <100.00g /dev/sdb2 lvm2 --- 100.00g 100.00g [root@lv-test ~]#
- 然后我们再创建一个lv
#创建前 [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g [root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 1 0 0 wz--n- <100.00g <100.00g [root@lv-test ~]# [root@lv-test ~]# lvcreate -l 100%free -n lv-test vg-test Logical volume "lv-test" created. [root@lv-test ~]# #可以看到,最下面新增了一个lv,vg名称和上面的不一样哦 [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g lv-test vg-test -wi-a----- <100.00g [root@lv-test ~]#
- 格式化这个lv并挂载到任意目录
[root@lv-test ~]# mkfs.xfs /dev/vg-test/lv-test meta-data=/dev/vg-test/lv-test isize=512 agcount=4, agsize=6553344 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=26213376, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=12799, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@lv-test ~]# [root@lv-test ~]# mkdir /date-test [root@lv-test ~]# mount /dev/vg-test/lv-test /date-test/ [root@lv-test ~]# [root@lv-test ~]# df -h |tail -n 1 /dev/mapper/vg--test-lv--test 100G 33M 100G 1% /date-test [root@lv-test ~]# # 模拟这个lv是在使用的,所以我们随便写点内容进去吧 [root@lv-test ~]# cd /date-test/ [root@lv-test date-test]# ls [root@lv-test date-test]# [root@lv-test date-test]# touch ccx{1..66} [root@lv-test date-test]# ls ccx1 ccx15 ccx20 ccx26 ccx31 ccx37 ccx42 ccx48 ccx53 ccx59 ccx64 ccx10 ccx16 ccx21 ccx27 ccx32 ccx38 ccx43 ccx49 ccx54 ccx6 ccx65 ccx11 ccx17 ccx22 ccx28 ccx33 ccx39 ccx44 ccx5 ccx55 ccx60 ccx66 ccx12 ccx18 ccx23 ccx29 ccx34 ccx4 ccx45 ccx50 ccx56 ccx61 ccx7 ccx13 ccx19 ccx24 ccx3 ccx35 ccx40 ccx46 ccx51 ccx57 ccx62 ccx8 ccx14 ccx2 ccx25 ccx30 ccx36 ccx41 ccx47 ccx52 ccx58 ccx63 ccx9 [root@lv-test date-test]#
- 假设我们现在需要扩的目录是
/date-test
,可以看到该目录对应的是vg--test-lv--test
,所以,最终我们需要扩的是vg–test-lv–test这个lv
[root@lv-test date-test]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:3 0 100G 0 lvm /date-test └─sdb2 8:18 0 100G 0 part sr0 11:0 1 4.3G 0 rom [root@lv-test date-test]#
增加vg空间
- 现有vg信息
[root@lv-test date-test]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 1 1 0 wz--n- <100.00g 0 [root@lv-test date-test]#
- 增加vg空间
注:增加vg的时候就需要注意了,如果有多个vg,得确定最终扩容lv所属vg是什么,如,我现在要扩的是lv-test,这个lv是属于vg-test的,所以我们需要把空间扩到vg-test上
[root@lv-test date-test]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 lvm2 --- 100.00g 100.00g [root@lv-test date-test]# vgextend vg-test /dev/sdb2 Volume group "vg-test" successfully extended [root@lv-test date-test]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <100.00g [root@lv-test date-test]#
增加lv空间
- 因为我们需要扩容的目录是
/date-test
,现在是100G,我们扩60g吧,那么最终/date-test
为160g才对
扩容这个其实可以不用卸载的,如果版本过低,先umoun卸载挂载信息在扩也无所谓哈。
[root@lv-test date-test]# df -h | grep /date-test /dev/mapper/vg--test-lv--test 100G 33M 100G 1% /date-test [root@lv-test date-test]# [root@lv-test date-test]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g lv-test vg-test -wi-ao---- <100.00g [root@lv-test date-test]#
- 开始扩
[root@lv-test date-test]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <100.00g [root@lv-test date-test]# lvs | tail -n1 lv-test vg-test -wi-ao---- <100.00g [root@lv-test date-test]# # 不知道lv名称格式的,可以用lvdisplay 查看详细路径 [root@lv-test date-test]# lvextend -L +60G /dev/vg-test/lv-test Size of logical volume vg-test/lv-test changed from <100.00 GiB (25599 extents) to <160.00 GiB (40959 extents). Logical volume vg-test/lv-test successfully resized. [root@lv-test date-test]# [root@lv-test date-test]# lvs | tail -n1 lv-test vg-test -wi-ao---- <160.00g [root@lv-test date-test]#
- 现在df呢,是看不到160g空间的,需要刷新以后才能看到
刷新之前呢,需要先看这个是啥格式的,如我的/date-test
是xfs格式的,那么我就需要用xfs的方式来刷新
[root@lv-test date-test]# df -Th | tail -n1 /dev/mapper/vg--test-lv--test xfs 100G 33M 100G 1% /date-test [root@lv-test date-test]# # xfs的刷新,ext4不能用 # 一般是用挂载目录作为刷新地址,所以我直接用 /date-test [root@lv-test date-test]# xfs_growfs /date-test meta-data=/dev/mapper/vg--test-lv--test isize=512 agcount=4, agsize=6553344 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=26213376, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=12799, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 26213376 to 41942016 [root@lv-test date-test]# # 完成扩容 [root@lv-test date-test]# df -Th | tail -n1 /dev/mapper/vg--test-lv--test xfs 160G 33M 160G 1% /date-test [root@lv-test date-test]# # 进去看看里面的内容,依然存在,扩容完成 [root@lv-test date-test]# cd /date-test/ [root@lv-test date-test]# [root@lv-test date-test]# ls ccx1 ccx15 ccx20 ccx26 ccx31 ccx37 ccx42 ccx48 ccx53 ccx59 ccx64 ccx10 ccx16 ccx21 ccx27 ccx32 ccx38 ccx43 ccx49 ccx54 ccx6 ccx65 ccx11 ccx17 ccx22 ccx28 ccx33 ccx39 ccx44 ccx5 ccx55 ccx60 ccx66 ccx12 ccx18 ccx23 ccx29 ccx34 ccx4 ccx45 ccx50 ccx56 ccx61 ccx7 ccx13 ccx19 ccx24 ccx3 ccx35 ccx40 ccx46 ccx51 ccx57 ccx62 ccx8 ccx14 ccx2 ccx25 ccx30 ccx36 ccx41 ccx47 ccx52 ccx58 ccx63 ccx9 [root@lv-test date-test]#
疑问验证
说明
-
需要解决这个疑惑
-
这呢,我模拟了上面的环境问题,之前的sdb还剩100g,我待会给划分成sdb3,格式为linux,sdc呢,我不做扇区,直接加pv,看后面会咋样
-
sdb创建一个linux格式的扇区sdb3,然后sdc我不做扇区,最终信息如下
[root@lv-test ~]# fdisk /dev/sdb 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. Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): First sector (419432448-629145599, default 419432448): Using default value 419432448 Last sector, +sectors or +size{K,M,G} (419432448-629145599, default 629145599): Using default value 629145599 Partition 3 of type Linux and of size 100 GiB is set Command (m for help): p Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x359bff9f Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 8e Linux LVM /dev/sdb2 209717248 419432447 104857600 8e Linux LVM /dev/sdb3 419432448 629145599 104856576 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@lv-test ~]# [root@lv-test ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@lv-test ~]# [root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:3 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:3 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part sdc 8:32 0 66G 0 disk sr0 11:0 1 4.3G 0 rom [root@lv-test ~]#
环境准备
- 因为遇到的环境最开始是用sda3这个linux格式的扇区创建了一个lv的100g空间,sdb无扇区的200g是后面加上去的,所以lvm2的300g是由前面2个磁盘组成。
- 所以我现在先模拟这套环境出来【sdb3是linux格式,sdc是无扇区】
[root@lv-test ~]# vgextend vg-test /dev/sdc Volume group "vg-test" successfully extended [root@lv-test ~]# [root@lv-test ~]# pvcreate /dev/sdb3 Physical volume "/dev/sdb3" successfully created. [root@lv-test ~]# [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 vg-test lvm2 a-- <100.00g <40.00g /dev/sdb3 lvm2 --- <100.00g <100.00g /dev/sdc lvm2 --- 66.00g 66.00g [root@lv-test ~]# [root@lv-test ~]# vgreduce vg-test /dev/sdc Removed "/dev/sdc" from volume group "vg-test" [root@lv-test ~]# [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 vg-test lvm2 a-- <100.00g <40.00g /dev/sdb3 lvm2 --- <100.00g <100.00g /dev/sdc lvm2 --- 66.00g 66.00g [root@lv-test ~]# [root@lv-test ~]# vgcreate vg01 /dev/sdb3 Volume group "vg01" successfully created [root@lv-test ~]# [root@lv-test ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <40.00g vg01 1 0 0 wz--n- <100.00g <100.00g [root@lv-test ~]# lvcreate -L 88G -n lvm2 vg01 Logical volume "lvm2" created. [root@lv-test ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g lv-test vg-test -wi-ao---- <160.00g lvm2 vg01 -wi-a----- 88.00g [root@lv-test ~]# mkfs.xfs /dev/vg01/lvm2 meta-data=/dev/vg01/lvm2 isize=512 agcount=4, agsize=5767168 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=23068672, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=11264, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@lv-test ~]# [root@lv-test ~]# mkdir /aidmp [root@lv-test ~]# mount /dev/vg01/lvm2 /aidmp/ [root@lv-test ~]# df -h | tail -n1 /dev/mapper/vg01-lvm2 88G 33M 88G 1% /aidmp [root@lv-test ~]# # 随便写点数据进去 [root@lv-test ~]# cd /aidmp/ [root@lv-test aidmp]# ls [root@lv-test aidmp]# mkdir ccx_hero{1..66} [root@lv-test aidmp]# ls ccx_hero1 ccx_hero2 ccx_hero3 ccx_hero4 ccx_hero5 ccx_hero6 ccx_hero10 ccx_hero20 ccx_hero30 ccx_hero40 ccx_hero50 ccx_hero60 ccx_hero11 ccx_hero21 ccx_hero31 ccx_hero41 ccx_hero51 ccx_hero61 ccx_hero12 ccx_hero22 ccx_hero32 ccx_hero42 ccx_hero52 ccx_hero62 ccx_hero13 ccx_hero23 ccx_hero33 ccx_hero43 ccx_hero53 ccx_hero63 ccx_hero14 ccx_hero24 ccx_hero34 ccx_hero44 ccx_hero54 ccx_hero64 ccx_hero15 ccx_hero25 ccx_hero35 ccx_hero45 ccx_hero55 ccx_hero65 ccx_hero16 ccx_hero26 ccx_hero36 ccx_hero46 ccx_hero56 ccx_hero66 ccx_hero17 ccx_hero27 ccx_hero37 ccx_hero47 ccx_hero57 ccx_hero7 ccx_hero18 ccx_hero28 ccx_hero38 ccx_hero48 ccx_hero58 ccx_hero8 ccx_hero19 ccx_hero29 ccx_hero39 ccx_hero49 ccx_hero59 ccx_hero9 [root@lv-test aidmp]# # 然后把sdc这个无扇区盘加到vg01里下面的lvm2中 [root@lv-test aidmp]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 vg-test lvm2 a-- <100.00g <40.00g /dev/sdb3 vg01 lvm2 a-- <100.00g <12.00g /dev/sdc lvm2 --- 66.00g 66.00g [root@lv-test aidmp]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <40.00g vg01 1 1 0 wz--n- <100.00g <12.00g [root@lv-test aidmp]# [root@lv-test aidmp]# vgextend vg01 /dev/sdc Volume group "vg01" successfully extended [root@lv-test aidmp]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <40.00g vg01 2 1 0 wz--n- 165.99g 77.99g [root@lv-test aidmp]# lvextend -L +66G /dev/vg01/lvm2 Size of logical volume vg01/lvm2 changed from 88.00 GiB (22528 extents) to 154.00 GiB (39424 extents). Logical volume vg01/lvm2 successfully resized. [root@lv-test aidmp]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g lv-test vg-test -wi-ao---- <160.00g lvm2 vg01 -wi-ao---- 154.00g [root@lv-test aidmp]# [root@lv-test aidmp]# xfs_growfs /aidmp/ meta-data=/dev/mapper/vg01-lvm2 isize=512 agcount=4, agsize=5767168 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=23068672, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=11264, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 23068672 to 40370176 [root@lv-test aidmp]# [root@lv-test aidmp]# df -h | tail -n1 /dev/mapper/vg01-lvm2 154G 33M 154G 1% /aidmp [root@lv-test aidmp]# [root@lv-test aidmp]# ls ccx_hero1 ccx_hero2 ccx_hero3 ccx_hero4 ccx_hero5 ccx_hero6 ccx_hero10 ccx_hero20 ccx_hero30 ccx_hero40 ccx_hero50 ccx_hero60 ccx_hero11 ccx_hero21 ccx_hero31 ccx_hero41 ccx_hero51 ccx_hero61 ccx_hero12 ccx_hero22 ccx_hero32 ccx_hero42 ccx_hero52 ccx_hero62 ccx_hero13 ccx_hero23 ccx_hero33 ccx_hero43 ccx_hero53 ccx_hero63 ccx_hero14 ccx_hero24 ccx_hero34 ccx_hero44 ccx_hero54 ccx_hero64 ccx_hero15 ccx_hero25 ccx_hero35 ccx_hero45 ccx_hero55 ccx_hero65 ccx_hero16 ccx_hero26 ccx_hero36 ccx_hero46 ccx_hero56 ccx_hero66 ccx_hero17 ccx_hero27 ccx_hero37 ccx_hero47 ccx_hero57 ccx_hero7 ccx_hero18 ccx_hero28 ccx_hero38 ccx_hero48 ccx_hero58 ccx_hero8 ccx_hero19 ccx_hero29 ccx_hero39 ccx_hero49 ccx_hero59 ccx_hero9 [root@lv-test aidmp]#
- 现在我这有了和之前生产环境中一摸一样的环境,而且可以得出结论,linux格式的扇区是可以正常做lv的,不做扇区的磁盘也是可以正常加入到已有lv中的。【只是这种方式不推荐,不正规(最后的倔强)】
[root@lv-test aidmp]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:3 0 160G 0 lvm /date-test ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:3 0 160G 0 lvm /date-test └─sdb3 8:19 0 100G 0 part └─vg01-lvm2 253:4 0 154G 0 lvm /aidmp sdc 8:32 0 66G 0 disk └─vg01-lvm2 253:4 0 154G 0 lvm /aidmp sr0 11:0 1 4.3G 0 rom [root@lv-test aidmp]# [root@lv-test aidmp]# fdisk -l /dev/sdb Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x359bff9f Device Boot Start End Blocks Id System /dev/sdb1 2048 209717247 104857600 8e Linux LVM /dev/sdb2 209717248 419432447 104857600 8e Linux LVM /dev/sdb3 419432448 629145599 104856576 83 Linux [root@lv-test aidmp]# fdisk -l /dev/sdc Disk /dev/sdc: 70.9 GB, 70866960384 bytes, 138412032 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 [root@lv-test aidmp]#
疑问验证开始【注意看每个验证后面的总结】
- 先对硬盘做如下操作
验证1【对没有做扇区的硬盘做扩容后能不能加入到已有lv】
-
没有做扇区的硬盘,扩容以后,能不能重新加到vg里面
这种情况肯定不能做扇区的,做了扇区,之前的数据肯定没了,这个实验最后再做 -
现在环境可以看到,sdc总容量已经增加,但是pv中还是66g
[root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:3 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part └─vg01-lvm2 253:2 0 154G 0 lvm sdc 8:32 0 166G 0 disk └─vg01-lvm2 253:2 0 154G 0 lvm sdd 8:48 0 88G 0 disk sr0 11:0 1 4.3G 0 rom [root@lv-test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 vg-test lvm2 a-- <100.00g <40.00g /dev/sdb3 vg01 lvm2 a-- <100.00g 0 /dev/sdc vg01 lvm2 a-- <66.00g 11.99g [root@lv-test ~]#
- 我先把sdc重新加vg试试,看看数据会不会丢
# 加pv报错了 [root@lv-test ~]# pvcreate /dev/sdc Can't initialize physical volume "/dev/sdc" of volume group "vg01" without -ff /dev/sdc: physical volume not initialized. [root@lv-test ~]# # 试试加vg呢,也报错了 [root@lv-test ~]# vgextend vg01 /dev/sdc Physical volume '/dev/sdc' is already in volume group 'vg01' Unable to add physical volume '/dev/sdc' to volume group 'vg01' /dev/sdc: physical volume not initialized. [root@lv-test ~]#
- 结论 没有做扇区的扩容以后无法新增到现有的vg里面。
验证2【新增硬盘空间加入已有lv会不会影响之前的数据】
- 验证这个的意义,我只是想知道,这样做会不会导致之前没有扇区的硬盘中的数据丢失。
我这用sdd的空间来做【我还是用正规流程,划扇区】
# 先划扇区 [root@lv-test ~]# fdisk /dev/sdd 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 0xf0f22ffd. 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-184549375, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-184549375, default 184549375): Using default value 184549375 Partition 1 of type Linux and of size 88 GiB is set Command (m for help): e^H e: unknown command Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/sdd: 94.5 GB, 94489280512 bytes, 184549376 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: 0xf0f22ffd Device Boot Start End Blocks Id System /dev/sdd1 2048 184549375 92273664 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@lv-test ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:3 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part └─vg01-lvm2 253:2 0 154G 0 lvm sdc 8:32 0 166G 0 disk └─vg01-lvm2 253:2 0 154G 0 lvm sdd 8:48 0 88G 0 disk └─sdd1 8:49 0 88G 0 part sr0 11:0 1 4.3G 0 rom # 重启以后挂载没了,我重新挂载一下,并且确保现在有数据的 [root@lv-test ~]# mount /dev/vg01/lvm2 /aidmp/ [root@lv-test ~]# cd /aidmp/ [root@lv-test aidmp]# ls ccx_hero1 ccx_hero2 ccx_hero3 ccx_hero4 ccx_hero5 ccx_hero6 ccx_hero10 ccx_hero20 ccx_hero30 ccx_hero40 ccx_hero50 ccx_hero60 ccx_hero11 ccx_hero21 ccx_hero31 ccx_hero41 ccx_hero51 ccx_hero61 ccx_hero12 ccx_hero22 ccx_hero32 ccx_hero42 ccx_hero52 ccx_hero62 ccx_hero13 ccx_hero23 ccx_hero33 ccx_hero43 ccx_hero53 ccx_hero63 ccx_hero14 ccx_hero24 ccx_hero34 ccx_hero44 ccx_hero54 ccx_hero64 ccx_hero15 ccx_hero25 ccx_hero35 ccx_hero45 ccx_hero55 ccx_hero65 ccx_hero16 ccx_hero26 ccx_hero36 ccx_hero46 ccx_hero56 ccx_hero66 ccx_hero17 ccx_hero27 ccx_hero37 ccx_hero47 ccx_hero57 ccx_hero7 ccx_hero18 ccx_hero28 ccx_hero38 ccx_hero48 ccx_hero58 ccx_hero8 ccx_hero19 ccx_hero29 ccx_hero39 ccx_hero49 ccx_hero59 ccx_hero9 [root@lv-test aidmp]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:3 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part └─vg01-lvm2 253:2 0 154G 0 lvm /aidmp sdc 8:32 0 166G 0 disk └─vg01-lvm2 253:2 0 154G 0 lvm /aidmp sdd 8:48 0 88G 0 disk └─sdd1 8:49 0 88G 0 part sr0 11:0 1 4.3G 0 rom [root@lv-test aidmp]#
- 现在开始把这个100g增加到lvm2中
[root@lv-test aidmp]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 vg-test lvm2 a-- <100.00g <40.00g /dev/sdb3 vg01 lvm2 a-- <100.00g 0 /dev/sdc vg01 lvm2 a-- <66.00g 11.99g [root@lv-test aidmp]# pvcreate /dev/sdd1 Physical volume "/dev/sdd1" successfully created. [root@lv-test aidmp]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <40.00g vg01 2 1 0 wz--n- 165.99g 11.99g [root@lv-test aidmp]# vgextend vg01 /dev/sdd1 Volume group "vg01" successfully extended [root@lv-test aidmp]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <40.00g vg01 3 1 0 wz--n- <253.99g <99.99g [root@lv-test aidmp]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <99.00g 0 /dev/sda3 centos lvm2 a-- <100.00g 0 /dev/sdb1 vg-test lvm2 a-- <100.00g 0 /dev/sdb2 vg-test lvm2 a-- <100.00g <40.00g /dev/sdb3 vg01 lvm2 a-- <100.00g 0 /dev/sdc vg01 lvm2 a-- <66.00g 11.99g /dev/sdd1 vg01 lvm2 a-- <88.00g <88.00g [root@lv-test aidmp]# [root@lv-test aidmp]# lvextend -l 100%free /dev/vg01/lvm2 New size given (25597 extents) not larger than existing size (39424 extents) [root@lv-test aidmp]# [root@lv-test aidmp]# lvextend -L +80G /dev/vg01/lvm2 Size of logical volume vg01/lvm2 changed from 154.00 GiB (39424 extents) to 234.00 GiB (59904 extents). Logical volume vg01/lvm2 successfully resized. [root@lv-test aidmp]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g lv-test vg-test -wi-a----- <160.00g lvm2 vg01 -wi-ao---- 234.00g [root@lv-test aidmp]# xfs_growfs /dev/vg01/lvm2 meta-data=/dev/mapper/vg01-lvm2 isize=512 agcount=7, agsize=5767168 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=40370176, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=11264, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 40370176 to 61341696 [root@lv-test aidmp]# [root@lv-test aidmp]# df -h | tail -n1 /dev/mapper/vg01-lvm2 234G 33M 234G 1% /aidmp [root@lv-test aidmp]# ls ccx_hero1 ccx_hero2 ccx_hero3 ccx_hero4 ccx_hero5 ccx_hero6 ccx_hero10 ccx_hero20 ccx_hero30 ccx_hero40 ccx_hero50 ccx_hero60 ccx_hero11 ccx_hero21 ccx_hero31 ccx_hero41 ccx_hero51 ccx_hero61 ccx_hero12 ccx_hero22 ccx_hero32 ccx_hero42 ccx_hero52 ccx_hero62 ccx_hero13 ccx_hero23 ccx_hero33 ccx_hero43 ccx_hero53 ccx_hero63 ccx_hero14 ccx_hero24 ccx_hero34 ccx_hero44 ccx_hero54 ccx_hero64 ccx_hero15 ccx_hero25 ccx_hero35 ccx_hero45 ccx_hero55 ccx_hero65 ccx_hero16 ccx_hero26 ccx_hero36 ccx_hero46 ccx_hero56 ccx_hero66 ccx_hero17 ccx_hero27 ccx_hero37 ccx_hero47 ccx_hero57 ccx_hero7 ccx_hero18 ccx_hero28 ccx_hero38 ccx_hero48 ccx_hero58 ccx_hero8 ccx_hero19 ccx_hero29 ccx_hero39 ccx_hero49 ccx_hero59 ccx_hero9 [root@lv-test aidmp]#
- 结论,新增一个硬盘加入到已有lv中,不会对之前的数据有影响。
验证3【没有扇区的硬盘扩容后重做扇区会不会导致数据丢失】
- 上面验证2中的空间成功加入到已有lvm2中,且不会对数据有影响。
但sdc没有做扇区的盘扩容后是没有重新加入成功的【看验证1】
[root@lv-test aidmp]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:3 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part └─vg01-lvm2 253:2 0 234G 0 lvm /aidmp sdc 8:32 0 166G 0 disk └─vg01-lvm2 253:2 0 234G 0 lvm /aidmp sdd 8:48 0 88G 0 disk └─sdd1 8:49 0 88G 0 part └─vg01-lvm2 253:2 0 234G 0 lvm /aidmp sr0 11:0 1 4.3G 0 rom [root@lv-test aidmp]# df -h | tail -n1 /dev/mapper/vg01-lvm2 234G 33M 234G 1% /aidmp [root@lv-test aidmp]#
- 现在我对sdc这个盘重新做扇区
之前66g是已经加入到lvm2中的,后面扩容的100g未能成功使用
但是做扇区呢,是从头做,所以我打算把166做为一个扇区。
[root@lv-test aidmp]# fdisk /dev/sdc 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 0x80754ec0. Command (m for help): p Disk /dev/sdc: 178.2 GB, 178241142784 bytes, 348127232 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: 0x80754ec0 Device Boot Start End Blocks Id System 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-348127231, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-348127231, default 348127231): Using default value 348127231 Partition 1 of type Linux and of size 166 GiB is set Command (m for help): w^H The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@lv-test aidmp]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@lv-test aidmp]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:3 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:4 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part └─vg01-lvm2 253:2 0 234G 0 lvm /aidmp sdc 8:32 0 166G 0 disk ├─sdc1 8:33 0 166G 0 part └─vg01-lvm2 253:2 0 234G 0 lvm /aidmp sdd 8:48 0 88G 0 disk └─sdd1 8:49 0 88G 0 part └─vg01-lvm2 253:2 0 234G 0 lvm /aidmp sr0 11:0 1 4.3G 0 rom [root@lv-test aidmp]#
- 上面可以看到重做扇区好像没有导致数据丢失,那么我们加入到pv和vg试试呢
可以发现都失败,这样也好,最起码保证了之前sdc的数据安全。
[root@lv-test aidmp]# pvcreate /dev/sdc1 WARNING: Device for PV 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr not found or rejected by a filter. Couldn't find device with uuid 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr. WARNING: Couldn't find all devices for LV vg01/lvm2 while checking used and assumed devices. Can't open /dev/sdc1 exclusively. Mounted filesystem? Can't open /dev/sdc1 exclusively. Mounted filesystem? [root@lv-test aidmp]# [root@lv-test aidmp]# vgextend vg01 /dev/sdc1 WARNING: Device for PV 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr not found or rejected by a filter. Couldn't find device with uuid 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr. WARNING: Couldn't find all devices for LV vg01/lvm2 while checking used and assumed devices. Can't open /dev/sdc1 exclusively. Mounted filesystem? Can't open /dev/sdc1 exclusively. Mounted filesystem? [root@lv-test aidmp]#
- 数据都在,我重启一下看看呢
[root@lv-test aidmp]# ls ccx_hero1 ccx_hero2 ccx_hero3 ccx_hero4 ccx_hero5 ccx_hero6 ccx_hero10 ccx_hero20 ccx_hero30 ccx_hero40 ccx_hero50 ccx_hero60 ccx_hero11 ccx_hero21 ccx_hero31 ccx_hero41 ccx_hero51 ccx_hero61 ccx_hero12 ccx_hero22 ccx_hero32 ccx_hero42 ccx_hero52 ccx_hero62 ccx_hero13 ccx_hero23 ccx_hero33 ccx_hero43 ccx_hero53 ccx_hero63 ccx_hero14 ccx_hero24 ccx_hero34 ccx_hero44 ccx_hero54 ccx_hero64 ccx_hero15 ccx_hero25 ccx_hero35 ccx_hero45 ccx_hero55 ccx_hero65 ccx_hero16 ccx_hero26 ccx_hero36 ccx_hero46 ccx_hero56 ccx_hero66 ccx_hero17 ccx_hero27 ccx_hero37 ccx_hero47 ccx_hero57 ccx_hero7 ccx_hero18 ccx_hero28 ccx_hero38 ccx_hero48 ccx_hero58 ccx_hero8 ccx_hero19 ccx_hero29 ccx_hero39 ccx_hero49 ccx_hero59 ccx_hero9 [root@lv-test aidmp]# df -h | tail -n1 /dev/mapper/vg01-lvm2 234G 33M 234G 1% /aidmp [root@lv-test aidmp]# [root@lv-test aidmp]# reboot
- 重启以后,sdc所属vg和lv系统识别不到【虽然能看到,但已经无法挂载了】,现在所有数据丢失。
[root@lv-test ~]# vgs WARNING: Device for PV 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr not found or rejected by a filter. Couldn't find device with uuid 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr. VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- 198.99g 0 vg-test 2 1 0 wz--n- 199.99g <40.00g vg01 3 1 0 wz-pn- <253.99g <19.99g [root@lv-test ~]# mount /dev/vg01/^C [root@lv-test ~]# [root@lv-test ~]# lvs WARNING: Device for PV 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr not found or rejected by a filter. Couldn't find device with uuid 4zUEi7-NhW6-A3Ya-Vpud-pGYk-t2xG-Sroxdr. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- <41.12g root centos -wi-ao---- 150.00g swap centos -wi-ao---- <7.88g lv-test vg-test -wi-a----- <160.00g lvm2 vg01 -wi-----p- 234.00g [root@lv-test ~]# mount /dev/vg01/lvm2 /aitmp mount: mount point /aitmp does not exist [root@lv-test ~]# [root@lv-test ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 99G 0 part │ ├─centos-root 253:0 0 150G 0 lvm / │ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] │ └─centos-home 253:2 0 41.1G 0 lvm /home └─sda3 8:3 0 100G 0 part └─centos-root 253:0 0 150G 0 lvm / sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 100G 0 part │ └─vg--test-lv--test 253:3 0 160G 0 lvm ├─sdb2 8:18 0 100G 0 part │ └─vg--test-lv--test 253:3 0 160G 0 lvm └─sdb3 8:19 0 100G 0 part sdc 8:32 0 166G 0 disk └─sdc1 8:33 0 166G 0 part sdd 8:48 0 88G 0 disk └─sdd1 8:49 0 88G 0 part sr0 11:0 1 4.3G 0 rom [root@lv-test ~]#
- 总结:未做扇区的硬盘加入lv以后,对后面新增的容量进行重新扇区,会直接导致该硬盘所属的lv损坏,无法挂载。
- 这篇文章呢,将是我2021年最后的一篇文章了,今年收获特别巨大,感谢各位一路上的支持,在这提前祝福各位:
-
linux虚拟机根目录扩容
2020-08-27 15:58:27reboot 重启linux,否则/dev/sda4无法格式化。 sda3分区创建完成。 pvcreate /dev/sda3 通过 pvcreate 命令创建物理卷 pvdisplay 查看物理卷 vgdisplay vgdisplay 查看系统中的卷组 vgextend centos /dev/sda3... -
Linux虚拟机磁盘扩容CentOS
2021-12-20 19:01:31测试个东西,发现虚拟机磁盘不够用了,,,,找了半天扩容方法,都是东拼西凑的没个有用的,最后终于找到个完美扩容的,记录下,防止原文以后看不了 原文:https://www.linuxidc.com/Linux/2019-04/158346.htm 文章... -
Linux系统扩容根目录磁盘空间
2022-03-17 14:19:55在安装harbor镜像仓库的时候由于磁盘空间不足安装失败,所以这里记录如何扩容linux根目录磁盘空间。 1.关闭虚拟机,修改虚拟机模版增加磁盘大小 2. -
扩容linux虚拟机的根目录空间
2021-05-15 04:22:05我们在使用linux虚拟机时会经常出现空间不够用的情况,下面主要分享下如何增加VMWare(ESXI)虚拟机(Linux)的根目录磁盘空间:(亲测可用)*有时会下面会出现设置大小的时候为灰色无法编辑的情况(灰色的原因:虚拟机有... -
VMware虚拟机linux扩容
2021-12-11 15:36:46VMware虚拟机linux扩容,参考,谢谢 https://www.jb51.net/article/144291.htm centos7扩展磁盘空间 - 李老客儿 - 博客园 [root@localhost /]# fdisk -l 磁盘 /dev/sda:85.9 GB, 85899345920 字节,167772160... -
VMware虚拟机扩容根目录磁盘容量
2021-01-06 22:57:16这里提示我们需要到客户端虚拟机进行分区和扩展文件系统,因此进入系统 2、开启虚拟机 3、查看磁盘信息,可以看到系统下只有一块硬盘sda; [root@hadoop001 ~]# df -h Filesystem Size Used Avail Use% Mounted on /... -
【linux虚拟机磁盘扩容--VMware非LVM管理的根目录扩容】
2021-12-09 12:17:20linux虚拟机磁盘扩容–VMware非LVM管理的根目录扩容 我的centos系统是非LVM管理的,什么是LVM可以参考这篇博客. 执行一下命令 [root@hjc02 201909515127]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda3 18... -
如何对linux虚拟机扩容
2020-10-15 23:41:141.给虚拟机扩展容量 2.执行命令行 fdisk -l #找目前最大的分区/dev/sda3 fdisk /dev/sda #Command (m for help): m #查看help n #添加分区 p #创建主分区 回车 #默认空间 回车 #默认为start cylinder w #保持修改 ... -
Kali虚拟机的LVM根目录扩容
2022-03-11 22:52:52Kali的LVM扩容背景VMware添加新的磁盘查看磁盘和块设备信息创建新的磁盘 背景 有一个docker有6个多G,Kali最开始只分了20G,不太够用,用LVM扩容一下。 VMware添加新的磁盘 查看磁盘和块设备信息 查看磁盘信息 ... -
Redhat虚拟机根目录扩容
2019-03-07 10:51:35Redhat虚拟机系统用久了,突然发现根目录内存不够用,此时,需要对根目录进行扩容。 本贴针对于磁盘分区采用**LVM**格式的虚拟机进行扩容操作,全称Logical Volume Manager,逻辑卷管理,在linux系统下对磁盘分区... -
Linux扩展磁盘空间到根目录(Vmware虚拟机)
2022-03-15 15:51:301.在虚拟机中扩展磁盘大小。 此时该虚拟机是关闭状态。 2.对新增的挂载盘进行分区和格式化 先通过 ls /dev/ 命令查找到新添加的挂载盘。 经过多次实操,新增得挂载盘名称都为sda ls /dev/ 然后对新增加的盘进行... -
vmware虚拟机扩展Ubuntu系统根目录
2022-06-05 11:41:20vmware虚拟机扩展Ubuntu系统根目录 -
Centos7扩容根目录
2021-06-02 10:13:48一、扩容原磁盘:将新分区扩展/root 1、原磁盘大小 2、扩容 -
扩容linux的根目录(实操记录!!)
2021-05-08 22:36:05数据无价,以下所有操作请务必在虚拟机上先操作1次2.在服务器中加入硬盘;sdb就是本次加入的硬盘[root@compute11 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 1.8T 0 disk├─sda1 8:1 0 ... -
在 Linux 虚拟机上扩展根文件系统 扩容(azure cloud)
2022-03-18 11:00:23文章目录linux文件系统扩展1.登录azure cloud2.进入服务器,查看当前的文件系统3.服务器关机(关机扩容)4.服务器上文件系统扩展调整 linux文件系统扩展 1.登录azure cloud 【azure cloud】 #1)登录当前azure ... -
Vmware Linux虚拟机磁盘扩容方法
2021-05-12 18:17:32我的LINUX版本是ubuntu12.04 32bit。今天在下载android源代码的时候发现自己最初给这个...进入要扩容虚拟机的设置界面,在设备框中选择磁盘,然后选择实用工具,再选择扩容选项。在跳出来的方框中输入你要扩容后... -
win10给VirtualBox下Linux虚拟机磁盘空间扩容
2022-05-10 09:36:061、在win10系统里面找到开始图标,右键单击找到 Windows PowerShell(管理员)选项打开 2、跳转到VirtualBox的安装路径,我的安装路径为F盘 3、输入.\VBoxManage modifyhd “G:\UbuntuBox\lt\lt.vdi” --resize ... -
虚拟机 Centos7(非LVM)扩容根目录
2021-05-14 12:45:52最近使用本机安装的虚拟Centos7部署了一套环境,再次开机的时候,被提示根目录空间不足,oh、no,这是什么鬼,为什么,安装centos7分配了20G硬盘,就这样没有了。经过查找网络资料发现,默认安装了一些环境,导致... -
vmware虚拟机 ubuntu根目录磁盘扩容
2021-08-07 03:09:30本以为磁盘扩容是个简单的事儿,结果却折腾一个多小时... 先在虚拟机软件上进行常规的扩容操作虚拟机执行扩容服务器关机后,粗暴的先直接扩容完事2. 使用fdisk进行分区修改扩容废话开篇:在虚拟机操作完扩容后,重启... -
linux中Centos7的LVM磁盘扩容问题
2021-01-20 15:51:24注意:sda为硬盘,需要扩容的是系统的根目录,这里RHEL的系统根目录为/dev/mapper/rhel-root(系统不一样,根目录也不一样) 关闭系统,在vmware—>设置—>硬盘—>扩展—>输入数字大于当前系统内存—>点击扩展 开机... -
kali虚拟机根目录扩容
2017-03-31 15:19:39kali虚拟机根目录扩容注意:操作之前一定要将虚拟机所有文件进行备份!备份!备份!(不是快照!)不保证方法一定有效,扩容出错本人概不负责0x01 背景随着kali的使用与更新,我们原本分配的硬盘大小也就往往无法满足... -
Vmware虚拟机Ubantu20.04根目录磁盘空间扩容教程(利用GParted)
2021-04-18 19:44:58Vmware虚拟机Ubantu20.04根目录磁盘空间扩容教程 背景 在虚拟机ubantu20.04上做实验时,磁盘根目录空间不足,导致重启后黑屏,需要对磁盘空间进行扩容。 操作步骤 一、改变硬盘大小(两种方法) 1.直接在VMware上扩...