Adjust the size of the root directory under Linux

Source: Internet
Author: User

Original

First, the purpose

When using the CentOS6.3 version of the Linux system, found that the root directory (/) is not enough space, and other directory space is very free, so this article is mainly for the existing space to adjust. First, let's look at the spatial distribution of the system:

  1. [Email protected]/]# df-h
  2. Filesystem Size used Avail use% mounted on
  3. /dev/mapper/vg_centos-lv_root
  4. 50G 14G 34G 30%/
  5. Tmpfs 1.9G 0 1.9G 0%/dev/shm
  6. /DEV/SDA1 485M 37M 423M 8%/boot
  7. /dev/mapper/vg_centos-lv_home
  8. 404G 670M 382G 1%/Home

The detailed steps section below will take 100G of space from the Vg_centos-lv_home partition and add it to the/vg_centos-lv_root partition.

Second, detailed steps

1. Uninstalling the Vg_centos-lv_home partition

    1. [Email protected]/]# Umount/home

At this point in the DF command, you will see that the/home directory is missing, as shown below:

    1. [Email protected]/]# df-h
    2. Filesystem Size used Avail use% mounted on
    3. /dev/mapper/vg_centos-lv_root
    4. 50G 14G 34G 30%/
    5. Tmpfs 1.9G 0 1.9G 0%/dev/shm
    6. /DEV/SDA1 485M 37M 423M 8%/boot

2, the new setting vg_home-lv_home size

    1. [Email protected]/]# resize2fs-p/dev/mapper/vg_centos-lv_home 282G
    2. RESIZE2FS 1.41.12 (17-may-2010)
    3. Please run ' e2fsck-f/dev/mapper/vg_centos-lv_home ' first.

This step set Vg_home-lv_home size is not successful, the system prompts us to run the following command, the operation is as follows:

    1. [Email protected]/]# e2fsck-f/dev/mapper/vg_centos-lv_home
    2. E2fsck 1.41.12 (17-may-2010)
    3. Pass 1:checking inodes, blocks, and sizes
    4. Pass 2:checking directory structure
    5. Pass 3:checking Directory Connectivity
    6. Pass 4:checking Reference counts
    7. Pass 5:checking Group summary Information
    8. /dev/mapper/vg_centos-lv_home:1386/26836992 files (0.9% non-contiguous), 1855856/107344896 blocks

From the new setting Vg_home-lv_home size:

  1. [Email protected]/]# resize2fs-p/dev/mapper/vg_centos-lv_home 282G
  2. RESIZE2FS 1.41.12 (17-may-2010)
  3. Resizing the filesystem on/dev/mapper/vg_centos-lv_home to 73924608 (4k) blocks.
  4. Begin Pass 2 (max = 43)
  5. Relocating blocks Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  6. Begin Pass 3 (max = 3276)
  7. Scanning Inode Table Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  8. Begin Pass 4 (max = 266)
  9. Updating Inode References Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  10. The filesystem on/dev/mapper/vg_centos-lv_home is now 73924608 blocks long.

Check for success:

  1. [Email protected]/]# Mount/home
  2. [Email protected]/]#
  3. [Email protected]/]# df-h
  4. Filesystem Size used Avail use% mounted on
  5. /dev/mapper/vg_centos-lv_root
  6. 50G 14G 34G 30%/
  7. Tmpfs 1.9G 0 1.9G 0%/dev/shm
  8. /DEV/SDA1 485M 37M 423M 8%/boot
  9. /dev/mapper/vg_centos-lv_home
  10. 278G 663M 263G 1%/Home
  11. [Email protected]/]#

3. Reduce the Lv_home logical partition to the specified size

    1. [Email protected]/]# lvreduce-l 282g/dev/mapper/vg_centos-lv_home
    2. Warning:reducing Active and open logical volume to 282.00 GiB
    3. This May DESTROY YOUR DATA (filesystem etc)
    4. Does really want to reduce lv_home? [y/n]: Y
    5. Reducing logical volume Lv_home to 282.00 GiB
    6. Logical Volume Lv_home successfully resized
    7. [Email protected]/]#

I think this command is to take the reduced 100G space to the public areas of the system, can be loaded and used by other partitions.

To query volume group information:

  1. [Email protected]/]# Vgdisplay
  2. ---Volume Group---
  3. VG Name Vg_centos
  4. System ID
  5. Format lvm2
  6. Metadata Areas 1
  7. Metadata Sequence No 5
  8. VG Access Read/write
  9. VG Status resizable
  10. MAX LV 0
  11. Cur LV 3
  12. Open LV 3
  13. Max PV 0
  14. Cur PV 1
  15. ACT PV 1
  16. VG Size 465.27 GiB
  17. PE Size 4.00 MiB
  18. Total PE 119109
  19. Alloc pe/size 86472/337.78 GiB
  20. Free Pe/size 32637/127.49 GiB
  21. VG UUID 1k4oon-rfv9-uyf1-umyf-aerg-yags-znosd6

Free pe/size Specifies that the allocated space should now be available.

4, increase the size of the Vg_centos-lv_root partition

Add the available space to the Vg_centos-lv_root partition:

    1. [Email protected]/]# lvextend-l +127.40g/dev/mapper/vg_centos-lv_root
    2. Rounding up size to full physical extent 127.40 GiB
    3. Extending logical Volume Lv_root to 177.40 GiB
    4. Logical Volume Lv_root successfully resized
    5. [Email protected]/]#

Size the partition from the new setting:

    1. [Email protected]/]# resize2fs-p/dev/mapper/vg_centos-lv_root
    2. RESIZE2FS 1.41.12 (17-may-2010)
    3. Filesystem at/dev/mapper/vg_centos-lv_root is mounted on/; On-line resizing required
    4. Old desc_blocks = 4, new_desc_blocks = 12
    5. Performing an on-line resize of/dev/mapper/vg_centos-lv_root to 46504960 (4k) blocks.
    6. The filesystem on/dev/mapper/vg_centos-lv_root is now 46504960 blocks long.

5. Check the partition size again

  1. [Email protected]/]# df-h
  2. Filesystem Size used Avail use% mounted on
  3. /dev/mapper/vg_centos-lv_root
  4. 175G 14G 153G 9%/
  5. Tmpfs 1.9G 0 1.9G 0%/dev/shm
  6. /DEV/SDA1 485M 37M 423M 8%/boot
  7. /dev/mapper/vg_centos-lv_home
  8. 278G 663M 263G 1%/Home

We found that the space in the Vg_centos-lv_root partition has increased by 125G, and the reason for the reduction in space compared to Lv_home 25G is mainly due to the fact that we have added all the available space in the system to the Lv_root partition.

Third, the problems encountered

1. Failed while uninstalling the/home directory

You can do the following Fuser command first, and then Umount:

    1. [Email protected]/]# fuser-m/Home
    2. [Email protected]/]#

2, set the size of the lv_home, again mount the partition, found with the DF command can not see to the partition, at this time as long as the mount can be

3, in the setting lv_root size, do not put free pe/size space all use, this is likely to appear free PE space is not enough, it is recommended to keep a little free pe space.


==================================================================

Reference:

Http://hi.baidu.com/%B7%E7%B6%C0/blog/item/c4aa9a81b204dbc89023d956.html

http://qianxunniao.iteye.com/blog/1393726

Adjust the size of the root directory under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.