Linux Swap/home/root Partition Sizing

Source: Internet
Author: User

Zhou clan, finishing technical documents, for the next generation to stay a little tutorial ...


The system defaults to the most installed students know, basically the home partition is very big, but in reality, our home does not need so big, most of our data is placed in/directory, so need to adjust the size, otherwise in the production environment, it is easy to cause the hard disk partition overflow, no write permission.


First look at my hard disk partition and size situation, it is obvious that this is a 600G hard disk, but I root only 53.7g,swap only 16.9G, but home unexpectedly has 529G

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/34/wKiom1PRulmgsVb9AAPkPfA0Ra8165.jpg "title=" Qq20140724164345.png "alt=" Wkiom1prulmgsvb9aapkpfa0ra8165.jpg "/>


1. Reduce the home partition size

Umount/home

Resize2fs-p/dev/mapper/volgroup-lv_home 100G

Mount/home

Under normal circumstances, only three commands are needed to get the home down to 100G.

Attention:

Umount/home

If it is a new system, this command is OK, if it is not a new system, there may be other programs occupy home, then you have to release the "fuser-m"

Resize2fs-p/dev/mapper/volgroup-lv_home 100G

In general, this command, after input, will prompt to run "e2fsck-f/dev/mapper/volgroup-lv_home"

Then you run it and then run Resize2fs-p/dev/mapper/volgroup-lv_home 100G

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/41/35/wKiom1PRvKbjLS3xAAMMjgO2LoE177.jpg "title=" Qq20140724164506.png "alt=" Wkiom1prvkbjls3xaammjgo2loe177.jpg "/>


We can look at the current home partition size, using the command df-h

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/35/wKioL1PRvgzxAt7UAADxIhBHNns085.jpg "title=" Qq20140724164526.png "alt=" Wkiol1prvgzxat7uaadxihbhnns085.jpg "/>


2, first to clear one thing, we reduce home after the purpose is to do, is home occupy too much, we take it out of space, throw to swap or root, then, now home has been reduced, is it meant to be directly to swap or root plus space size it?

This is a clear mistake, if you do not understand, the estimated first from the grass-roots learning, we have just reduced the size of the home, not the size of the whole volume group, we have to reduce the size of the home volume group, so as to more free space

Lvreduce-l 100g/dev/mapper/volgroup-lv_home

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/35/wKiom1PRvgyT0XXuAAEL92FTdms273.jpg "title=" Qq20140724164737.png "alt=" Wkiom1prvgyt0xxuaael92ftdms273.jpg "/>

Attention:

Use the Lvreduce directive to reduce the amount of space that LVM logical volumes occupy. The data already on the logical volume may be deleted, so you must confirm it before the operation. I still suggest that when the new system, to adjust, if the project is put into use stage, you come again to engage in this thing, your little heart to prepare yourself first, not good on the data all finished.


3. Use the Vgdisplay command to view the free space of the LVM.

[Email protected] ~]# Vgdisplay

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/35/wKioL1PRv_bCDPZ3AAFjRRCg7aw244.jpg "title=" Qq20140724164758.png "alt=" Wkiol1prv_bcdpz3aafjrrcg7aw244.jpg "/>

Now you can see that I have 392.70G available free space, so now I'm going to allocate this 392.70G space rationally.


4, I first to deal with swap space bar, we all know that this swap is the memory exchange, is generally set to hardware memory twice times, then I first swap off

[Email protected] ~]# swapoff /dev/mapper/volgroup-lv_Swap

[Email protected] ~]# free-m

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/36/wKiom1PRv5TCO-EcAAC_5YuI8t0038.jpg "title=" Qq20140724164849.png "alt=" Wkiom1prv5tco-ecaac_5yui8t0038.jpg "/>

Obviously, I this memory is 32G, then I should give him to set a 64G about swap space bar, we also see, I swap space, less pitiful, only 16.9G, this is not pit me?


5. Adjust Swap space

Extended/dev/mapper/volgroup-lv_swap, increased by 48G

[email protected]localhost ~]# lvextend-l +48g/dev/mapper/volgroup-lv_swap


To set/dev/mapper/volgroup-lv_swap to a swap partition

[email protected]localhost ~]# mkswap/dev/mapper/volgroup-lv_swap


Start swap partition

[email protected]localhost ~]# swapon/dev/mapper/volgroup-lv_swap

[email protected]localhost ~]# free-m


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/36/wKioL1PRwlKB3bgGAAK8_vtUOpk577.jpg "title=" Qq20140724172321.png "alt=" Wkiol1prwlkb3bggaak8_vtuopk577.jpg "/>

Obviously, I'm now in the swap partition, which is already 66.8G, and basically meet the project ran


6, the rest of the space, lost to/directory, that is,/dev/mapper/volgroup-lv_root

Before you lose, look at the overall current space distribution, how much space can be lost, the same

[Email protected] ~]# Vgdisplay

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/41/36/wKioL1PRwwKxKaEhAAFXyzUk5Aw309.jpg "title=" Qq20140724172433.png "alt=" Wkiol1prwwkxkaehaafxyzuk5aw309.jpg "/>

There are 344.70G, you can completely throw him all to root, but I generally do not do so, I want to reserve a bit of spare, so I give him to lose 300G, leave 40G left or right, just in case.


7. What are you waiting for?

[Email protected] ~]# lvextend-l +300g/dev/mapper/volgroup-lv_root

[Email protected] ~]# resize2fs-p/dev/mapper/volgroup-lv_root

[Email protected] ~]# df-h

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/41/36/wKiom1PRwoLho2ZVAAH7tdpq5Qo991.jpg "title=" Qq20140724173532.png "alt=" Wkiom1prwolho2zvaah7tdpq5qo991.jpg "/>


8, to here, it is over, the entire server partition is completed, in the partition process, must concentrate, otherwise it is prone to error, an error, then play, I myself have experienced two times not concentrate, resulting in the server hangs, the final reload system, fortunately my system is brand new, no data.

This article from the "Zhou Clan" blog, declined to reprint!

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.