萬盛學電腦網

 萬盛學電腦網 >> 服務器教程 >> linux 邏輯卷管理 調整分區大小例子

linux 邏輯卷管理 調整分區大小例子

 文章就是一個關於linux 邏輯卷管理 調整分區大小例子,我們只要按下面代碼操作就完成100%完成邏輯卷管理 調整分區大小了.

 

測試機各種報錯,創建個目錄都報錯,df看了一下,發現VolGroup-lv_root 100%,虛擬磁盤滿了,怎麼辦呢

1,解決過程
  
# df -h //查看分區  
# umount /home //取消掛載  
# e2fsck -f /dev/mapper/VolGroup-lv_home //分區檢測  
# resize2fs -p /dev/mapper/VolGroup-lv_home 100G //將lv_home虛擬分區設為100G  
# mount /home //掛載home  
# df -h //查看分區  
# lvreduce -L 100G /dev/mapper/VolGroup-lv_home //釋放空間  
# vgdisplay //查看可用空間大小  
# lvextend -L +311.47G /dev/mapper/VolGroup-lv_root //擴展lv_root虛擬分區  
# resize2fs -p /dev/mapper/VolGroup-lv_root //lv_root重設分區大小 

LVM(邏輯磁盤管理),靈活性很高.

2,詳細解決過程
  
[root@localhost ~]# df -h  
Filesystem Size Used Avail Use% Mounted on  
/dev/mapper/VolGroup-lv_root 50G 47G 16M 100% /   //lv_root滿了  
tmpfs 1.9G 72K 1.9G 1% /dev/shm  
/dev/sda1 485M 40M 420M 9% /boot  
/dev/mapper/VolGroup-lv_home 406G 19G 366G 5% /home   //lv_home空間很多  
  
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 100G  
resize2fs 1.41.12 (17-May-2010)  
Filesystem at /dev/mapper/VolGroup-lv_home is mounted on /home; on-line resizing required  
On-line shrinking from 107865088 to 65536000 not supported.    //先umount才能resize2fs  
  
[root@localhost ~]# umount /home   //umount home目錄  
  
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 100G  
resize2fs 1.41.12 (17-May-2010)  
請先運行 'e2fsck -f /dev/mapper/VolGroup-lv_home'.   //提示要先進行磁盤檢測  
  
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home  
e2fsck 1.41.12 (17-May-2010) 

第一步: 檢查inode,塊,和大小  
第二步: 檢查目錄結構 

第3步: 檢查目錄連接性 

Pass 4: Checking reference counts 

第5步: 檢查簇概要信息 

/dev/mapper/VolGroup-lv_home: 1459/16384000 files (4.0% non-contiguous), 5914204/65536000 blocks  
  
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 100G    //重定大小  
resize2fs 1.41.12 (17-May-2010)  
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 26214400 (4k) blocks.  
Begin pass 2 (max = 32768)  
正在重定位塊 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  
Begin pass 3 (max = 2000)  
正在掃描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  
The filesystem on /dev/mapper/VolGroup-lv_home is now 26214400 blocks long.  
  
[root@localhost ~]# mount /home/  
  
[root@localhost ~]# df -h  
Filesystem Size Used Avail Use% Mounted on  
/dev/mapper/VolGroup-lv_root 50G 47G 16M 100% /  
tmpfs 1.9G 72K 1.9G 1% /dev/shm  
/dev/sda1 485M 40M 420M 9% /boot  
/dev/mapper/VolGroup-lv_home 99G 19G 75G 20% /home  
  
[root@localhost ~]# lvreduce -L 100G /dev/mapper/VolGroup-lv_home   //釋放空間  
 WARNING: Reducing active and open logical volume to 100.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 100.00 GiB  
 Logical volume lv_home successfully resized  
  
[root@localhost ~]# df -h  
Filesystem Size Used Avail Use% Mounted on  
/dev/mapper/VolGroup-lv_root 50G 47G 16M 100% /  
tmpfs 1.9G 72K 1.9G 1% /dev/shm  
/dev/sda1 485M 40M 420M 9% /boot  
/dev/mapper/VolGroup-lv_home 99G 19G 75G 20% /home  
  
[root@localhost ~]# vgdisplay  
 --- Volume group ---  
 VG Name VolGroup  
 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 39372 / 153.80 GiB  
 Free PE / Size 79737 / 311.47 GiB       //空閒空間  
 VG UUID Vt2V4t-Byxs-tQqk-cY0h-IDE3-pabX-LUfkRS  
  
[root@localhost ~]# lvextend -L +311.47G /dev/mapper/VolGroup-lv_root   //空閒空間加入到lv_root  
 Rounding size to boundary between physical extents: 311.47 GiB  
 Extending logical volume lv_root to 361.47 GiB  
 Logical volume lv_root successfully resized  
  
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_root  
resize2fs 1.41.12 (17-May-2010)  
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required  
old desc_blocks = 4, new_desc_blocks = 23    //這兒要耐心等待,擴大越多,時間越長  
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 94757888 (4k) blocks.  
The filesystem on /dev/mapper/VolGroup-lv_root is now 94757888 blocks long.  
  
[root@localhost openfire]# df -h  
Filesystem Size Used Avail Use% Mounted on  
/dev/mapper/VolGroup-lv_root 356G 48G 308G 14% /  
tmpfs 1.9G 72K 1.9G 1% /dev/shm  
/dev/sda1 485M 40M 420M 9% /boot  
/dev/mapper/VolGroup-lv_home 99G 19G 75G 20% /home

copyright © 萬盛學電腦網 all rights reserved