Linux下如何調(diào)整根目錄的空間大小
一、目的
在使用CentOS6.3版本Linux系統(tǒng)的時(shí)候,發(fā)現(xiàn)根目錄(/)的空間不是很充足,而其他目錄空間有很大的空閑,所以本文主要是針對(duì)現(xiàn)在已有的空間進(jìn)行調(diào)整。首先,先來查看一下系統(tǒng)的空間分配情況:
[root@CentOS-78 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 50G 14G 34G 30% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 485M 37M 423M 8% /boot /dev/mapper/vg_centos-lv_home 404G 670M 382G 1% /home
下面的詳細(xì)步驟部分將從vg_centos-lv_home分區(qū)下取出100G的空間添加到/vg_centos-lv_root分區(qū)上去。
二、詳細(xì)步驟
1、卸載vg_centos-lv_home分區(qū)
[root@CentOS-78 /]# umount /home
此時(shí)在用df命令查看將會(huì)發(fā)現(xiàn)/home目錄已經(jīng)看不見了,如下所示:
[root@CentOS-78 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 50G 14G 34G 30% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 485M 37M 423M 8% /boot
2、從新設(shè)定vg_home-lv_home的大小
[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282G resize2fs 1.41.12 (17-May-2010) Please run 'e2fsck -f /dev/mapper/vg_centos-lv_home' first.
這一步設(shè)定vg_home-lv_home大小沒有成功,系統(tǒng)提示我們先運(yùn)行下面的命令,操作如下:
[root@CentOS-78 /]# e2fsck -f /dev/mapper/vg_centos-lv_home e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/vg_centos-lv_home: 1386/26836992 files (0.9% non-contiguous), 1855856/107344896 blocks
從新設(shè)定vg_home-lv_home的大?。?/p>
[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/vg_centos-lv_home to 73924608 (4k) blocks. Begin pass 2 (max = 43) Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 3276) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 4 (max = 266) Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/mapper/vg_centos-lv_home is now 73924608 blocks long.
檢查是否成功:
[root@CentOS-78 /]# mount /home [root@CentOS-78 /]# [root@CentOS-78 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 50G 14G 34G 30% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 485M 37M 423M 8% /boot /dev/mapper/vg_centos-lv_home 278G 663M 263G 1% /home [root@CentOS-78 /]#
3、將lv_home邏輯分區(qū)減小到指定大小
[root@CentOS-78 /]# lvreduce -L 282G /dev/mapper/vg_centos-lv_home WARNING: Reducing active and open logical volume to 282.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_home? [y/n]: y Reducing logical volume lv_home to 282.00 GiB Logical volume lv_home successfully resized [root@CentOS-78 /]#
我認(rèn)為這個(gè)命令是將已經(jīng)減少的100G空間拿到系統(tǒng)公共的區(qū)域,可以被其他分區(qū)加載和利用。
查詢卷組的信息:
[root@CentOS-78 /]# vgdisplay --- Volume group --- VG Name vg_centos 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 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 465.27 GiB PE Size 4.00 MiB Total PE 119109 Alloc PE / Size 86472 / 337.78 GiB Free PE / Size 32637 / 127.49 GiB VG UUID 1k4ooN-RFV9-uyf1-uMYf-aERG-YaGs-ZNoSD6
Free PE / Size指定的應(yīng)該是現(xiàn)在可在分配的空間。
4、增加vg_centos-lv_root分區(qū)的大小
將可用的空間添加到vg_centos-lv_root分區(qū)上面:
[root@CentOS-78 /]# lvextend -L +127.40G /dev/mapper/vg_centos-lv_root Rounding up size to full physical extent 127.40 GiB Extending logical volume lv_root to 177.40 GiB Logical volume lv_root successfully resized [root@CentOS-78 /]#
從新設(shè)定該分區(qū)的大?。?/p>
[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required old desc_blocks = 4, new_desc_blocks = 12 Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 46504960 (4k) blocks. The filesystem on /dev/mapper/vg_centos-lv_root is now 46504960 blocks long.
5、再次查看分區(qū)大小
[root@CentOS-78 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 175G 14G 153G 9% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 485M 37M 423M 8% /boot /dev/mapper/vg_centos-lv_home 278G 663M 263G 1% /home
我們發(fā)現(xiàn)vg_centos-lv_root分區(qū)的空間已經(jīng)增加了125G,之所以比lv_home減少的空間要多25G主要是由于我們把系統(tǒng)所有的可用的空間都加在了lv_root分區(qū)。
三、所遇到的問題
1、在卸載/home目錄的時(shí)候失敗
可先執(zhí)行如下fuser命令,然后再umount即可:
[root@CentOS-78 /]# fuser -m /home [root@CentOS-78 /]#
2、設(shè)定完lv_home的大小,再次mount該分區(qū)時(shí),發(fā)現(xiàn)用df命令無法看到給分區(qū),此時(shí)只要在mount一次即可
3、在設(shè)定lv_root的大小時(shí),不要把Free PE / Size的空間全部都用上,這很可能會(huì)出現(xiàn)Free PE空間不足的現(xiàn)象,建議保留一點(diǎn)Free PE的空間。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
environments was not found on the java.library.path 問題的解決方法
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path 問題的解決方法,需要的朋友可以參考下2016-08-08Linux使用scp命令進(jìn)行文件遠(yuǎn)程拷貝詳解
scp就是secure copy,一個(gè)在linux下用來進(jìn)行遠(yuǎn)程拷貝文件的命令。下面這篇文章主要給大家介紹了關(guān)于Linux使用scp命令進(jìn)行文件遠(yuǎn)程拷貝的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-12-12分別在Linux和Windows下設(shè)置JVM內(nèi)存的簡(jiǎn)單方法
下面小編就為大家?guī)硪黄謩e在Linux和Windows下設(shè)置JVM內(nèi)存的簡(jiǎn)單方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-01-01linux中啟動(dòng)tomcat后瀏覽器無法訪問的解決方法
最近在啟動(dòng)了tomcat后發(fā)現(xiàn)了一些問題,通過查找相關(guān)資料終于解決了,下面將解決方法分享給大家,這篇文章主要給大家介紹了關(guān)于linux中啟動(dòng)tomcat后瀏覽器無法訪問的解決方法,需要的朋友可以參考下。2017-12-12CentOS下RabbitMq高可用集群環(huán)境搭建教程
這篇文章主要為大家詳細(xì)介紹了CentOS下RabbitMq高可用集群環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08Centos7.3服務(wù)器搭建LNMP環(huán)境的方法
這篇文章主要介紹了Centos7.3服務(wù)器搭建LNMP環(huán)境的方法,結(jié)合實(shí)例形式分析了Centos7.3搭建LNMP環(huán)境的相關(guān)步驟、命令、使用方法及注意事項(xiàng),需要的朋友可以參考下2018-04-04CentOS 7更新時(shí)出現(xiàn):Multilib version problems問題的解決方法
這篇文章主要給大家介紹了關(guān)于CentOS 7系統(tǒng)更新時(shí)出現(xiàn):Multilib version problems問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-11-11