centos 擴充root根分區的大小

來源:互聯網
上載者:User

標籤:

目標:將VolGroup-lv_home縮小到125G,並將剩餘的空間添加給VolGroup-lv_root
 
1.首先查看磁碟使用方式
[[email protected] ~]# df -h
檔案系統    容量  已用 可用  已用% 掛載點    
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hostname-lv_root
                       20G  8.7G  9.6G  48% /
tmpfs                 6.9G   72K  6.9G   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/vg_hostname-lv_home
                      171G  110G   53G  68% /home
/dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
/dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5

 
2、卸載/home
[[email protected] ~]# umount /home
umount: /home: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

umount /home 如果提示無法卸載,則是有進程佔用/home,使用如下命令來終止佔用進程:
[[email protected] ~]# fuser -m /home  
/home:               31112m
top
kill -9 31112
 
3、調整分區大小
[[email protected] ~]# resize2fs -p /dev/mapper/vg_hostname-lv_home 125G
resize2fs 1.41.12 (17-May-2010)
Please run ‘e2fsck -f /dev/mapper/vg_hostname-lv_home‘ first.

如果提示運行“e2fsck -f /dev/mapper/VolGroup-lv_home”,則執行相關命令:
[[email protected] ~]# e2fsck -f /dev/mapper/vg_hostname-lv_home 然後重新執行命令:
[[email protected] ~]# resize2fs -p /dev/mapper/vg_hostname-lv_home 125G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_hostname-lv_home to 32768000 (4k) blocks.
Begin pass 2 (max = 7110485)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1385)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 3237)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_hostname-lv_home is now 32768000 blocks long.

註:resize2fs 為重新設定磁碟大小,只是重新指定一下大小,並不對結果有影響,需要下面lvreduce的配合
 
4、掛載上/home,查看磁碟使用方式
[[email protected] ~]# mount /home
[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hostname-lv_root
                       20G  8.7G  9.6G  48% /
tmpfs                 6.9G   72K  6.9G   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
/dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5
/dev/mapper/vg_hostname-lv_home
                      124G  110G  7.4G  94% /home

 
5、設定空閑空間
使用lvreduce指令用於減少LVM邏輯卷佔用的空間大小。可能會刪除邏輯卷上已有的資料,所以在操作前必須進行確認。記得輸入 “y”
[[email protected] ~]# lvreduce -L 125G /dev/mapper/vg_hostname-lv_home
  WARNING: Reducing active and open logical volume to 125.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 125.00 GiB
  Logical volume lv_home successfully resized

註:lvreduce -L 125G的意思為設定當前檔案系統為125G,如果lvreduce -l 125G是指從當前檔案系統上減少125G
使用lvreduce減小邏輯卷的大小。注意:減小後的大小不能小於檔案的大小,否則會遺失資料。
 
可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看詳細資料。
[[email protected] ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_hostname
  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               199.51 GiB
  PE Size               4.00 MiB
  Total PE              51074
  Alloc PE / Size       38758 / 151.40 GiB
  Free  PE / Size       12316 / 48.11 GiB
  VG UUID               zk1eHH-QXe8-sdm8-cKfF-StSl-yffz-Dfe9sF
註:vgdisplay為顯示LVM卷組的中繼資料資訊
 
6.把閑置空間掛在到根目錄下
[[email protected] ~]# lvextend -L +48G /dev/mapper/vg_hostname-lv_root
  Extending logical volume lv_root to 67.53 GiB
  Logical volume lv_root successfully resized
註:lvextend -L +48G為在檔案系統上增加48G
[[email protected] ~]# resize2fs -p /dev/mapper/vg_hostname-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_hostname-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 5
Performing an on-line resize of /dev/mapper/vg_hostname-lv_root to 17702912 (4k) blocks.
The filesystem on /dev/mapper/vg_hostname-lv_root is now 17702912 blocks long.

7、檢查調整結果
[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_hostname-lv_root
                       67G  8.7G   55G  14% /
tmpfs                 6.9G   72K  6.9G   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/sdb5             2.0T  805G  1.1T  43% /xxxx_sdb5
/dev/sdc5             1.7T  197M  1.6T   1% /xxxx_sdc5
/dev/mapper/vg_hostname-lv_home
                      124G  110G  7.4G  94% /home

centos 擴充root根分區的大小

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.