linux(centos 6)調整掛載分區大小
安裝centos6使用自動推薦分區,發現一個問題/home 分區過大。
目標:/home分20G,剩下添加給/目錄下
1.查看分區模式
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用%% 掛載點
/dev/mapper/VolGroup-lv_root
50G 2.9G 44G 7% /
tmpfs 5.9G 100K 5.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/VolGroup-lv_home
1.1T 200M 988G 1% /home
2.卸載掛載分區
[root@localhost ~]# umount /home
3.檢查VolGroup-lv_home文件的錯誤性,-f 即使文件系統沒有錯誤跡象,仍強制地檢查正確性。
[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: 27/69304320 files (0.0% non-contiguous), 4400705/277215232 blocks
4.調整/home為20G,
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 5242880 (4k) blocks.
Begin pass 2 (max = 32784)
正在重定位塊 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 8460)
正在掃描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 15)
正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 5242880 blocks long.
5.重新掛載並查看
[root@localhost ~]# mount /home
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用%% 掛載點
/dev/mapper/VolGroup-lv_root
50G 2.9G 44G 7% /
tmpfs 5.9G 100K 5.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/VolGroup-lv_home
20G 172M 19G 1% /home
6.劃分20G外面的剩余空間。使用lvreduce指令用於減少LVM邏輯卷占用的空間大小。可能會刪除邏輯卷上已有的數據,所以在操作前必須進行確認。記得輸入 “y”
[root@localhost ~]# lvreduce -L 20G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 20.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 20.00 GiB
Logical volume lv_home successfully resized
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用%% 掛載點
/dev/mapper/VolGroup-lv_root
50G 2.9G 44G 7% /
tmpfs 5.9G 100K 5.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/VolGroup-lv_home
20G 172M 19G 1% /home
7.查看“Free PE / Size”剩余空間
[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 1.09 TiB
PE Size 4.00 MiB
Total PE 285022
Alloc PE / Size 19424 / 75.88 GiB
Free PE / Size 265598 / 1.01 TiB
VG UUID nSbflh-J7fN-xDvf-zLjL-tFcu-Y5Tm-ybnDk0
8.使用lvextend指令:擴展邏輯卷空間到/dev/mapper/VolGroup-lv_root目錄下,也就是“/”目錄下。
[root@localhost ~]# lvextend -L +1.01T /dev/mapper/VolGroup-lv_root
Rounding size to boundary between physical extents: 1.01 TiB
Extending logical volume lv_root to 1.06 TiB
Logical volume lv_root successfully resized
9.執行操作,使之生效,中間一定要耐心等待。
[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 = 68
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 284227584 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 284227584 blocks long.
10.查看分區成功
[root@localhost ~]# df -h
文件系統 容量 已用 可用 已用%% 掛載點
/dev/mapper/VolGroup-lv_root
1.1T 2.9G 1011G 1% /
tmpfs 5.9G 100K 5.9G 1% /dev/shm
/dev/sda1 485M 37M 423M 8% /boot
/dev/mapper/VolGroup-lv_home
20G 172M 19G 1% /home
11.重啟
[root@localhost ~]# shutdown -r now