linux调整分区大小

 

查看一下当前分区情况

1
2
3
4
5
6
7
8
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  747M   46G   2% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot
/dev/mapper/VolGroup-lv_home
                      163G  188M  155G   1% /home

 

我需要把VolGroup-lv_home下面的容量挪120G到VolGroup-lv_root中,

步骤如下:

1.先缩小VolGroup-lv_home,缩小是需要先umount的,扩大则不需要。

1
2
3
4
5
6
7
[root@localhost ~]# umount /home
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  747M   46G   2% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot

 

2.使用resize2fs命令调整文件系统大小:

1
2
3
[root@localhost ~]# resize2fs /dev/mapper/VolGroup-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mapper/VolGroup-lv_home' first.

 

执行resize2fs调整VolGroup-lv_home为20G,提示需要先执行e2fsck -f /dev/mapper/VolGroup-lv_home检查分区,那就执行吧。

 

1
2
3
4
5
6
7
8
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-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/VolGroup-lv_home: 11/10829824 files (0.0% non-contiguous), 727657/43313152 blocks

 

检查完成后重新执行resize2fs命令

 

1
2
3
4
[root@localhost ~]# resize2fs /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.
The filesystem on /dev/mapper/VolGroup-lv_home is now 5242880 blocks long.

 

3.调整LVM分区大小

 

1
2
3
4
5
6
[root@localhost ~]# lvresize -L 20G /dev/mapper/VolGroup-lv_home
  WARNING: Reducing active 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

 

执行成功, 重新mount /home

 

1
2
3
4
5
6
7
8
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  747M   46G   2% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot
/dev/mapper/VolGroup-lv_home
                       20G  172M   19G   1% /home

  

可以看到VolGroup-lv_home已经变成20G了

 

4.把VolGroup-lv_root调大,由于VolGroup-lv_home从163G变成了20G,所以可以使用的大小为143G

先调整Lvm大小

 

1
2
3
[root@localhost ~]# lvresize -L +143G /dev/mapper/VolGroup-lv_root
  Extending logical volume lv_root to 193.00 GiB
  Logical volume lv_root successfully resized

 

再调整文件系统大小

 

1
2
3
4
5
6
[root@localhost ~]# resize2fs /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 = 13
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 50593792 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 50593792 blocks long.

 

5.最后查看分区情况,可以看到已经调整成功了

1
2
3
4
5
6
7
8
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      190G  754M  180G   1% /
tmpfs                 7.8G     0  7.8G   0% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot
/dev/mapper/VolGroup-lv_home
                       20G  172M   19G   1% /home  

 

posted on 2014-02-18 15:45  solohac  阅读(750)  评论(0编辑  收藏  举报

导航