在linux中减小和增大LV的过程与思考
今天在安装oracle 11 rac的时候,查看操作系统df -lh,发现/home目录竟然分了500多G,/根目录才有50G,当时我就爆了句粗口,这TM系统是怎么做的。
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db5-lv_root 50G 6.2G 41G 14% /
tmpfs 127G 84K 127G 1% /dev/shm
/dev/sdq1 477M 37M 415M 9% /boot
/dev/mapper/vg_db5-lv_home 496G 70M 471G 1% /home
#vgdisplay
--- Volume group ---
VG Name vg_db5
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 557.26 GiB
PE Size 4.00 MiB
Total PE 142658
Alloc PE / Size 142658 / 557.26 GiB
Free PE / Size 0 / 0
VG UUID plc2K9-lRVy-bcck-B9Qp-3F8k-H6cW-W4vRdS
#lvdisplay
--- Logical volume ---
LV Path /dev/vg_db6/lv_root
LV Name lv_root
VG Name vg_db6
LV UUID 6HlVnp-6RGm-kORQ-eOx6-nQQV-8PWB-Gg4WNE
LV Write Access read/write
LV Creation host, time db6, 2015-02-02 19:25:11 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_db6/lv_home
LV Name lv_home
VG Name vg_db6
LV UUID yuBJai-96D6-JFwX-cmXR-EeXE-cUuU-uqRl3l
LV Write Access read/write
LV Creation host, time db6, 2015-02-02 19:25:17 +0800
LV Status available
# open 1
LV Size 503.26 GiB
Current LE 128834
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:10
--- Logical volume ---
LV Path /dev/vg_db6/lv_swap
LV Name lv_swap
VG Name vg_db6
LV UUID d5FqB1-tTHM-HSrb-b0tm-r1Ms-XnvP-dH5ovs
LV Write Access read/write
LV Creation host, time db6, 2015-02-02 19:27:23 +0800
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
有三个lv在一个VG里,决定把这三个LV的大小给调整一下。把lv_home调小,然后把lv_root调大。注意,缩小空间是有风险的,所以我先把里面的oracle,grid用户还有所有的组都删除了,然后重启系统。
#userdel oracle
#userdel grid
#groudel oinstall
....................
重启之后,查看/etc/group,/etc/passwd,确认没有用户和组了,我们就可以开始了。
1.#umount /home1.#umount /home
如果不成功,可能会报错,解决方法如下:umount: /mnt/cdrom: device is busy.
(In some cases useful info about processes that
use the device is found by lsof(8) or user(1))
#umount /mnt/cdrom/ -f //强制卸载也不行
umount2: 设备或资源忙
umount: /mnt: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))umount2: 设备或资源忙
#fuser -m /home
/home: 1338c
# ps aux |grep 1338
root 1338 0.0 0.2 108292 1912 pts/2 Ss+ 14:27 0:00 -bash
root 1423 0.0 0.1 103236 884 pts/1 S+ 14:49 0:00 grep 1338
#kill -9 1338
#fuser -m /home
#umount /home
解析:不过感觉这种方法也只是用于那些无关紧要的目录,因为进程使用的少,如果是/目录,可能进程会杀不过来,杀完了,系统估计也崩了。
逻辑卷的缩减,有风险,先缩减逻辑边界——在缩减物理边界
注意: 1、不能在线缩减,得先卸载;
2、确保缩减后的空间大小依然能存储原有的所有数据;
3、在缩减之前应该强行检查文件,确保文件系统处于一致性状态
2. 检查一下
#e2fsck -f /dev/vg_db5/lv_home
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg_db5/lv_home: 29/32989184 files (0.0% non-contiguous), 2121120/131926016 blocks
3.开始缩小文件系统:
#resize2fs /dev/vg_db5/lv_home 1024M
resize2fs 1.41.12 (17-May-2010)
resize2fs: New size smaller than minimum (307344)
显示1G太小了,最小是307344个块。得了,10个G吧
#resize2fs /dev/vg_db5/lv_home 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_db5/lv_home to 2621440 (4k) blocks.
The filesystem on /dev/vg_db5/lv_home is now 2621440 blocks long.
4.缩小lv大小:
# lvreduce -L 10G /dev/vg_db5/lv_home
WARNING: Reducing active logical volume to 10.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Size of logical volume vg_db5/lv_home changed from 503.26 GiB (128834 extents) to 10.00 GiB (2560 extents).
Logical volume lv_home successfully resized
#vgdisplay 发现空间已经释放出来了
--- Volume group ---
VG Name vg_db5
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 557.26 GiB
PE Size 4.00 MiB
Total PE 142658
Alloc PE / Size 16384 / 64.00 GiB
Free PE / Size 126274 / 493.26 GiB
VG UUID Ji4TQc-IbhS-O6Cb-XH5Q-q4Uk-DIer-DvSMMD
5.增大LV:lv_root 的大小,增大到500G
#lvextend -L 500G -f -r /dev/vg_db5/lv_root
Size of logical volume vg_db5/lv_root changed from 50.00 GiB (12800 extents) to 500.00 GiB (128000 extents).
Logical volume lv_root successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_db5-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 32
Performing an on-line resize of /dev/mapper/vg_db5-lv_root to 131072000 (4k) blocks.
The filesystem on /dev/mapper/vg_db5-lv_root is now 131072000 blocks long.
想再增加操作系统大小,看来不用做了。
# resize2fs /dev/vg_db5/lv_root 500G
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 131072000 blocks long. Nothing to do!
#resize2fs -p /dev/vg_db5/lv_root
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 131072000 blocks long. Nothing to do!
重启之后:
#df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db5-lv_root 493G 6.2G 461G 2% /
tmpfs 160G 144K 160G 1% /dev/shm
/dev/sdq1 477M 37M 415M 9% /boot
/dev/mapper/vg_db5-lv_home 9.8G 37M 9.2G 1% /home
终于搞定了。
更为详细的LVM的理论概念请参见博客:
http://80cto.blog.51cto.com/7503144/1610922
在linux中减小和增大LV的过程与思考的更多相关文章
- 第八周--Linux中进程调度与进程切换的过程
[潘恒 原创作品转载请注明出处 <Linux内核分析>MOOC课程 "http://mooc.study.163.com/course/USTC 1000029000 " ...
- 末学者笔记--Linux中RAID磁盘阵列及centos7启动过程
<一>RAID概念 磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意. 磁盘阵列是由很多价格较便 ...
- Linux中程序的编译和链接过程
1.从源码到可执行程序的步骤:预编译.编译.链接.strip 预编译:预编译器执行.譬如C中的宏定义就是由预编译器处理,注释等也是由预编译器处理的. 编译: 编译器来执行.把源码.c .S编程机器码. ...
- linux 中gcc的·安装、编译过程
一.安装gcc编译器 通过命令gcc -v查看当前的GCC版本 [root@localhost /]# gcc -v Reading specs from /usr/i386-glibc-2.1-li ...
- Linux中逻辑卷(LV)的创建、增大和减小
首先说一下在缩小逻辑卷的时候要注意的问题:第一步使用resize2fs命令更改文件系统的容量:第二步使用lvreduce命令减小逻辑卷的容量.这两个顺序千万不要搞反了,而且要保证缩减后的逻辑卷容量大于 ...
- Linux就这个范儿 第15章 七种武器 linux 同步IO: sync、fsync与fdatasync Linux中的内存大页面huge page/large page David Cutler Linux读写内存数据的三种方式
Linux就这个范儿 第15章 七种武器 linux 同步IO: sync.fsync与fdatasync Linux中的内存大页面huge page/large page David Cut ...
- 再说linux中的rm mv 遍历执行多个文件的操作: find + xagrs
参考文章: http://cfqtyaogang.blog.163.com/blog/static/218051022011812111342203/, 这篇文章讲得很全面很详细... 包括不好理解的 ...
- 转帖:对linux中半增加半连接数量和防止服务器被dos攻击
.增大队列SYN最大半连接数 在Linux中执行命令"sysctl -a|grep net.ipv4.tcp_max_syn_backlog",在返回的"net.ipv4 ...
- Linux中的SWAP交换分区
大多数 Linux 在系统安装时都会提醒并建议你划分一个 SWAP 交换分区,如果你是从 Windows 切换到 Linux 的新用户,兴许对这个 SWAP 会感到十分疑惑. SWAP 交换分区到底是 ...
随机推荐
- Androidstudio安装AVD出现no system images installed for this target解决方案
解决方案:
- Hibernate连接数据库超时设置autoReconnect=true
如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. 不用hibernate的话, connection url加参数: autoReconnect ...
- input-placeholder
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ color: #f00; } ::-moz-placeholder { /* Mozilla Fir ...
- nginx中将POST数据写到日志里面的正确方式
http://www.cnblogs.com/meteorx/p/3188647.html
- Map工具系列-05-添加业务参数工具
所有cs端工具集成了一个工具面板 -打开(IE) Map工具系列-01-Map代码生成工具说明 Map工具系列-02-数据迁移工具使用说明 Map工具系列-03-代码生成BySQl工具使用说明 Map ...
- 有关bat的一些代码
1.if语句 @echo off if exist E:\aa.dat dir C: >> E:\ff.txt pause type E:\ff.txt ...
- MyBatis学习总结(一)——MyBatis快速入门
一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...
- UITabBarController 、TabBar背景颜色设置,UITabBarItem的文字样式(颜色和大小)UITabBarItem的位置调整
改变UITabBarController的颜色 UIView*mView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,48)];//这是部分tabb ...
- UITableViewCell的重用机制
UITabelView一般会显示大量数据,如果有多少条数据就新建多少个cell,那么对于内存来说是种极大的负担,这样自然是不合理的,所以才会有重用机制 比如一个家庭办酒席,一共有13桌,每桌20个菜, ...
- Protecting against XML Entity Expansion attacks
https://blogs.msdn.microsoft.com/tomholl/2009/05/21/protecting-against-xml-entity-expansion-attacks/ ...