CentOS逻辑卷调整分区大小

CentOS逻辑卷调整分区大小目的

因为系统使用的是逻辑卷分区(LVM),且分区大小不合理

想增加root大小,减少home

查看磁盘使用情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@LinuxCentOS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_linuxcentos-lv_root
50G 3.4G 44G 8% /
tmpfs 3.9G 76K 3.9G 1% /dev/shm
/dev/xvda1 477M 36M 417M 8% /boot
/dev/mapper/vg_linuxcentos-lv_home
140G 60M 133G 1% /home
/dev/sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final


[root@LinuxCentOS ~]# vgdisplay
--- Volume group ---
VG Name vg_linuxcentos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
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 51074 / 199.51 GiB
Free PE / Size 0 / 0
VG UUID DqgWat-YkkU-V56r-xNFv-XmmX-mgwD-Fi0RWh

调整home分区大小

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@LinuxCentOS ~]# umount /home

[root@LinuxCentOS ~]# e2fsck -f /dev/mapper/vg_linuxcentos-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_linuxcentos-lv_home: 11/9289728 files (0.0% non-contiguous), 631025/37148672 blocks

[root@LinuxCentOS ~]# resize2fs -p /dev/mapper/vg_linuxcentos-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_linuxcentos-lv_home to 5242880 (4k) blocks.
Begin pass 2 (max = 32768)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1134)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_linuxcentos-lv_home is now 5242880 blocks long.

[root@LinuxCentOS ~]# mount /home

[root@LinuxCentOS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_linuxcentos-lv_root
50G 3.4G 44G 8% /
tmpfs 3.9G 76K 3.9G 1% /dev/shm
/dev/xvda1 477M 36M 417M 8% /boot
/dev/mapper/vg_linuxcentos-lv_home
20G 44M 19G 1% /home

释放空间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@LinuxCentOS ~]# lvreduce /dev/mapper/vg_linuxcentos-lv_home -L 20G
WARNING: Reducing active and open logical volume to 20.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg_linuxcentos/lv_home? [y/n]: y
Size of logical volume vg_linuxcentos/lv_home changed from 141.71 GiB (36278 extents) to 20.00 GiB (5120 extents).
Logical volume lv_home successfully resized.

[root@LinuxCentOS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_linuxcentos-lv_root
50G 3.4G 44G 8% /
tmpfs 3.9G 76K 3.9G 1% /dev/shm
/dev/xvda1 477M 36M 417M 8% /boot
/dev/mapper/vg_linuxcentos-lv_home
20G 44M 19G 1% /home

[root@LinuxCentOS ~]# vgdisplay
--- Volume group ---
VG Name vg_linuxcentos
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 19916 / 77.80 GiB
Free PE / Size 31158 / 121.71 GiB
VG UUID DqgWat-YkkU-V56r-xNFv-XmmX-mgwD-Fi0RWh

增加释放的空间到root

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@LinuxCentOS ~]# lvextend -L +120G /dev/mapper/vg_linuxcentos-lv_root   
Size of logical volume vg_linuxcentos/lv_root changed from 50.00 GiB (12800 extents) to 170.00 GiB (43520 extents).
Logical volume lv_root successfully resized.

[root@LinuxCentOS ~]# resize2fs -p /dev/mapper/vg_linuxcentos-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_linuxcentos-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 11
Performing an on-line resize of /dev/mapper/vg_linuxcentos-lv_root to 44564480 (4k) blocks.
The filesystem on /dev/mapper/vg_linuxcentos-lv_root is now 44564480 blocks long.

[root@LinuxCentOS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_linuxcentos-lv_root
168G 3.5G 156G 3% /
tmpfs 3.9G 76K 3.9G 1% /dev/shm
/dev/xvda1 477M 36M 417M 8% /boot
/dev/mapper/vg_linuxcentos-lv_home
20G 44M 19G 1% /home