LVM的安裝和LVM的在線增大比較簡單,LVM的分區(qū)離線縮小坑較多
要縮小LVM設(shè)備為/dev/mapper/test-lv_test 的大小為200M
第一步:卸載設(shè)備(減小文件系統(tǒng)時(shí)需要卸載,文件系統(tǒng)和resize工具都不支持在線減小。)
umount /dev/mapper/test-lv_test
第二步:執(zhí)行文件系統(tǒng)檢查(先檢查一下分區(qū)的完整性。)
fsck -f /dev/mapper/test-lv_test
第三步:調(diào)整文件系統(tǒng)大?。▽⑽募到y(tǒng)減小到200M)
resize2fs /dev/mapper/test-lv_test 200M
第四步:縮小分區(qū)
lvreduce -L 200M /dev/mapper/test-lv_test 將分區(qū)縮小到200M
PS:參數(shù):-200M 縮小了200M,參數(shù):200M 縮小到200M
公司主營業(yè)務(wù):成都做網(wǎng)站、成都網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)建站推出鐵山港免費(fèi)做網(wǎng)站回饋大家。
[root@master ~]# mkfs.ext3 /dev/mapper/test-lv_test
mke2fs 1.41.12 (17-May-2010)
文件系統(tǒng)標(biāo)簽=
操作系統(tǒng):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
第一個(gè)數(shù)據(jù)塊=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.
[root@master ~]# mount /dev/mapper/test-lv_test /aas/
1.lvm在線擴(kuò)展200M的磁盤使用空間
[root@master aas]# lvextend -L +200M /dev/mapper/test-lv_test
Extending logical volume lv_test to 700.00 MiB
Logical volume lv_test successfully resized
出現(xiàn)這個(gè)successfully關(guān)鍵詞代表成功擴(kuò)大了空間
然后用df命令查看空間增大后的情況
[root@master aas]# df -h /dev/mapper/test-lv_test
2.用resize2fs命令刷新新建lv的大小
[root@master 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.
[root@master aas]# df -h /dev/mapper/test-lv_test
二.LVM離線減少分區(qū)大小的步驟
步驟嚴(yán)謹(jǐn)中間漏掉會報(bào)錯(cuò):壞塊,比較難修復(fù),需要將大小恢復(fù)后再格式化
用df命令查看下磁盤使用情況
[root@master /]# umount /dev/mapper/test-lv_test
[root@master /]#
[root@master /]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結(jié)構(gòu)
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
/dev/mapper/test-lv_test: 12/178816 files (0.0% non-contiguous), 33358/716800 blocks
[root@master /]#
[root@master /]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結(jié)構(gòu)
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
/dev/mapper/test-lv_test: 12/178816 files (0.0% non-contiguous), 33358/716800 blocks
[root@master /]# 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.
[root@master /]# 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
[root@master /]# mount /dev/mapper/test-lv_test /aas/
用df命令查看下磁盤使用情況
錯(cuò)誤案例:
不按照步驟進(jìn)行,看似成功減小實(shí)際并沒有,因?yàn)闆]有寫入文件系統(tǒng)4
resize2fs該命令執(zhí)行報(bào)錯(cuò),則未寫入到文件系統(tǒng)中
用df命令查看下磁盤使用情況
[root@master /]# umount /aas/
[root@master /]# 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
至此縮小分區(qū)出錯(cuò),導(dǎo)致文件系統(tǒng)出現(xiàn)壞塊,需要執(zhí)行文件系統(tǒng)檢查
[root@master /]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
請先運(yùn)行 'e2fsck -f /dev/mapper/test-lv_test'.
這里檢查出來節(jié)點(diǎn)不對,但是修復(fù)不了,需要后面自己增大空間
[root@master /]# e2fsck -f /dev/mapper/test-lv_test
e2fsck 1.41.12 (17-May-2010)
The 文件系統(tǒng) size (according to the 超級塊) is 1253376 塊s
The physical size of the 設(shè)備 is 741376 塊s
Either the 超級塊 or the partition table is likely to be corrupt!
中斷
第一步: 檢查inode,塊,和大小
Error reading block 745475 (無效的參數(shù)) while getting next inode from scan. 忽略錯(cuò)誤
強(qiáng)制覆蓋
Error writing block 745475 (無效的參數(shù)) while getting next inode from scan. 忽略錯(cuò)誤
Error reading block 745476 (無效的參數(shù)) while getting next inode from scan. 忽略錯(cuò)誤
強(qiáng)制覆蓋
Error reading block 745478 (無效的參數(shù)) while getting next inode from scan. 忽略錯(cuò)誤
Error while scanning inodes (184912): Can't read next inode
e2fsck: 已中止
[root@master ~]#
修復(fù)的方法:
1.掛載,查看大小并沒有減小
[root@master ~]# mount /dev/mapper/test-lv_test /aas/
用df命令查看下磁盤使用情況
2.按照錯(cuò)誤步驟減小了多少,就增加回來
[root@master ~]# lvextend -L +500M /dev/mapper/test-lv_test
Extending logical volume lv_test to 1.20 GiB
Logical volume lv_test successfully resized
用df命令查看下磁盤使用情況
提示并沒有修改文件系統(tǒng),原大小沒有更改
[root@master ~]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 1253376 blocks long. Nothing to do!
按照正常縮小分區(qū)的步驟再來一遍即可
[root@master ~]# umount /dev/mapper/test-lv_test
[root@master ~]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結(jié)構(gòu)
第3步: 檢查目錄連接性
Pass 4: Checking reference counts
第5步: 檢查簇概要信息
/dev/mapper/test-lv_test: 12/310896 files (0.0% non-contiguous), 50246/1253376 blocks
[root@master ~]# resize2fs /dev/mapper/test-lv_test -500M
resize2fs 1.41.12 (17-May-2010)
resize2fs:無效選項(xiàng) -- 5
Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size]
[root@master ~]# 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.
[root@master ~]# 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
[root@master ~]# mount /dev/mapper/test-lv_test /aas/
用df命令查看下磁盤使用情況