LVM增大缩小分区,复现减小分区报错并修复

LVM的安装和LVM的在线增大比较简单,不记录,LVM的分区离线缩小坑较多

要缩小LVM设备为/dev/mapper/test-lv_test 的大小为200M

第一步:卸载设备(减小文件系统时需要卸载,文件系统和resize工具都不支持在线减小。)
umount /dev/mapper/test-lv_test
第二步:执行文件系统检查(先检查一下分区的完整性。)
fsck -f /dev/mapper/test-lv_test
第三步:调整文件系统大小(将文件系统减小到200M)
resize2fs /dev/mapper/test-lv_test 200M
第四步:缩小分区
lvreduce -L 200M /dev/mapper/test-lv_test 将分区缩小到200M
PS:参数:-200M 缩小了200M,参数:200M 缩小到200M

[[email protected] ~]# mkfs.ext3 /dev/mapper/test-lv_test
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# mount /dev/mapper/test-lv_test /aas/

一.lvm在线增大
[[email protected] aas]# lvextend -L +200M /dev/mapper/test-lv_test
Extending logical volume lv_test to 700.00 MiB
Logical volume lv_test successfully resized
[[email protected] aas]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 485M 11M 449M 3% /aas
调整文件系统大小
[[email protected] aas]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/test-lv_test is mounted on /aas; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/test-lv_test to 716800 (1k) blocks.
The filesystem on /dev/mapper/test-lv_test is now 716800 blocks long.

[[email protected] aas]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 678M 11M 633M 2% /aas

二.LVM离线减少分区大小的步骤
步骤严谨中间漏掉会报错:坏块,比较难修复,需要将大小恢复后再格式化
[[email protected] /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 678M 11M 633M 2% /aas
[[email protected] /]# umount /dev/mapper/test-lv_test
[[email protected] /]#
[[email protected] /]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-lv_test: 12/178816 files (0.0% non-contiguous), 33358/716800 blocks
[[email protected] /]#
[[email protected] /]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-lv_test: 12/178816 files (0.0% non-contiguous), 33358/716800 blocks
[[email protected] /]# resize2fs /dev/mapper/test-lv_test 200M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/test-lv_test to 204800 (1k) blocks.
The filesystem on /dev/mapper/test-lv_test is now 204800 blocks long.

[[email protected] /]# lvreduce -L 200M /dev/mapper/test-lv_test
WARNING: Reducing active logical volume to 200.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 200.00 MiB
Logical volume lv_test successfully resized
[[email protected] /]# mount /dev/mapper/test-lv_test /aas/
[[email protected] /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 194M 9.6M 175M 6% /aas

错误案例:
不按照步骤进行,看似成功减小实际并没有,因为没有写入文件系统4
resize2fs该命令执行报错,则未写入到文件系统中

[[email protected] /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 1.2G 11M 1.1G 1% /aas
[[email protected] /]# umount /aas/
[[email protected] /]# lvreduce -L -500M /dev/mapper/test-lv_test
WARNING: Reducing active logical volume to 724.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 724.00 MiB
Logical volume lv_test successfully resized

至此缩小分区出错,导致文件系统出现坏块,需要执行文件系统检查
[[email protected] /]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
请先运行 ‘e2fsck -f /dev/mapper/test-lv_test‘.

这里检查出来节点不对,但是修复不了,需要后面自己增大空间
[[email protected] /]# e2fsck -f /dev/mapper/test-lv_test
e2fsck 1.41.12 (17-May-2010)
The 文件系统 size (according to the 超级块) is 1253376 块s
The physical size of the 设备 is 741376 块s
Either the 超级块 or the partition table is likely to be corrupt!
中断<y>? 否

第一步: 检查inode,块,和大小
Error reading block 745475 (无效的参数) while getting next inode from scan. 忽略错误<y>? 是
强制覆盖<y>? 是
Error writing block 745475 (无效的参数) while getting next inode from scan. 忽略错误<y>? 是
Error reading block 745476 (无效的参数) while getting next inode from scan. 忽略错误<y>? 是
强制覆盖<y>? 否
Error reading block 745478 (无效的参数) while getting next inode from scan. 忽略错误<y>? 否
Error while scanning inodes (184912): Can‘t read next inode
e2fsck: 已中止
[[email protected] ~]#

修复的方法:

1.挂载,查看大小并没有减小
[[email protected] ~]# mount /dev/mapper/test-lv_test /aas/
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 1.2G 11M 1.1G 1% /aas
2.按照错误步骤减小了多少,就增加回来
[[email protected] ~]# lvextend -L +500M /dev/mapper/test-lv_test
Extending logical volume lv_test to 1.20 GiB
Logical volume lv_test successfully resized
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 1.2G 11M 1.1G 1% /aas
提示并没有修改文件系统,原大小没有更改
[[email protected] ~]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 1253376 blocks long. Nothing to do!

按照正常缩小分区的步骤再来一遍即可
[[email protected] ~]# umount /dev/mapper/test-lv_test
[[email protected] ~]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-lv_test: 12/310896 files (0.0% non-contiguous), 50246/1253376 blocks
[[email protected] ~]# resize2fs /dev/mapper/test-lv_test -500M
resize2fs 1.41.12 (17-May-2010)
resize2fs:无效选项 -- 5
Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size]

[[email protected] ~]# resize2fs /dev/mapper/test-lv_test 500M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/test-lv_test to 512000 (1k) blocks.
The filesystem on /dev/mapper/test-lv_test is now 512000 blocks long.

[[email protected] ~]# lvreduce -L -500M /dev/mapper/test-lv_test
WARNING: Reducing active logical volume to 724.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 724.00 MiB
Logical volume lv_test successfully resized
[[email protected] ~]# mount /dev/mapper/test-lv_test /aas/
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 6.2G 11G 38% /
tmpfs 940M 0 940M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/mapper/oracle-lv_oracle 21G 8.5G 12G 44% /oracle
/dev/mapper/test-lv_test 485M 11M 450M 3% /aas

原文地址:https://blog.51cto.com/7794482/2434998

时间: 2024-10-09 18:27:52

LVM增大缩小分区,复现减小分区报错并修复的相关文章

pip报错及修复

pip报错: 修复: wget https://pypi.python.org/packages/3c/ec/a94f8cf7274ea60b5413df054f82a8980523efd712ec55a59e7c3357cf7c/pyparsing-2.2.0.tar.gz (下载pyparsing-2.2.0.tar.gz) gunzip pyparsing-2.2.0.tar.gz tar -xvf pyparsing-2.2.0.tar cd pyparsing-2.2.0 sudo p

iOS9 关于明文HTTP报错的修复方法

报错:App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file. 解决办法: 在info.plist 加入key <key>NSAppTransportSecurity</key> <dict>

合同续签回写报错BUG修复(学习jar包)

1 private BaseDAO baseDAO; 2 public BaseDAO getBaseDAO(){ 3 if(baseDAO == null ){ 4 baseDAO = new BaseDAO(); 5 } 6 return baseDAO; 7 } 8 9 @Override 10 public String queryHiPsndocCtrtByPK(String pk_psndoc_sub, String pk_psndoc) 11 throws BusinessExce

linux启动报错23修复

前天修改cengos 6.5分辨率,一不小心把系统玩坏了 这是我改的错误的grub.conf文件,刚学linux,别笑我! 重启后报错23:Error while parsing number,没有截到图. 解决办法如下: vmware虚拟机光驱加载cengos6.5系统镜像 启动系统按ESC键选择CD-ROM Drive启动 选择rescue installed system(修复已安装系统) 输入chroot /mnt/sysimage 输入vi /boot/grub/grub.conf 按

Linux格式化分区报错Could not start /dev/sda No such file or directory 解决办法

查看已经分好的区 [[email protected] ~]# fdisk -l /dev/sda   Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Sector size (logical/physical): 512 bytes /512 bytes I/O size (m

Mongoose 报错代码 (node:10256)(node:13604)(node:13604) DeprecationWarning: Mongoose: findOneAndUpdate() { useUnifiedTopology: true } { useNewUrlParser: true } to MongoClient.connect.

起因 在MongoDB Node.js驱动程序中有几个弃用,Mongoose提供了解决这些弃用警告的选项 原因是因为:findOneAndUpdate()内部会使用findAndModify驱动,驱动即将被废弃,所以弹出警告!附上官方解释:Mongoose v5.5.8: Deprecation Warnings 被替换的还有下面几个: 将update()替换为updateOne(),updateMany(),replaceOne() 将remove()替换为deleteOne()或delete

redhat6 lvm 下缩小根分区

说明: 不是根分区都可是在线扩容和缩小 根分区是可以在线扩容,但不可以在线缩小 1.Linux系统进入救援模式 依次选择: 欢迎界面 ---------- Rescue installed system Chose a Language  -------------  English Keyboard Type  ---------   us Rescue Method ------------------  Local CD/DVD Setup Networking -------------

解决linux系统下因分区目录划分过小,导致tomcat使用系统临时文件夹(/tmp)没有足够空间而报错的问题

1. 故障现象. B/S应用进行文件上传后,系统反馈:没有足够的磁盘空间(No enough space available). 2. 故障分析 检查文件占用情况如下: [root@Qa2 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 6.7G 6.7G 20k 100% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/sh

partprobe分区报错

环境 centos 6.9 vmware 虚拟机 场景: 对磁盘进行在线扩容,扩容后,在线扫描,扫描过后进行LVM扩展,分区后,通过partprobe /dev/sda 扫描,出现以下错误: 分区报错shell > partprobe /dev/sdaWarning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it ma