Linux LVM and swap control size adjustment

Source: Internet
Author: User

Partition magic can be said to be a partition tool in windows. If you want to share a hard disk, you can do everything you need. What about Linux? Fdisk cannot properly resize the partition size. It is very troublesome to change the partition size once fdisk is used. Is there no way in Linux? None!

We also have the hardware disk partition management super weapon-LVM.

LVM (logical volume manager) is a multi-disk management software in Linux. It can treat multiple hard disks (PVs) as one hard disk group (VG ), on this hard disk group, you can perform any operations on the partition (LV. For example, if you have three hard disks pv1, pv2, pv3, and LVM will treat them as a hard disk (VG), you can create any partition (LV) on this VG ), you can also make any modifications to these partitions (similar to partition magic). All modifications take effect immediately without restarting. In addition, LVM can expand the VG without limit. That is to say, when your original hard disk is full and you want to add a new hard disk, you can add a new hard disk to your original VG through LVM, and allocate the added hard disk space to the partition you want to expand. Simply put, you can expand the partition size without changing the current partition structure.

Let's look at a simple example. After a long BT download, your hard disk is full. One of the media partitions stores media files. Now you need to add a new hard disk, this hard disk is mainly used to store media files.

Practices in Windows
Mount the hard disk, format the file, and separate a media partition to store the media file. In this way, you have two media partitions. If the partition is full, separate one... over time, you will have n partitions to store files of the same type, which is inconvenient to find. This is acceptable to individual users but fatal to servers.

Linux does not use LVM
Not much is found in Windows. The difference is that there are many more mount points.

Use LVM in Linux
Mount the hard disk, add the hard disk to the existing hard disk group (VG), and expand the media partition in the hard disk group. You still have only one media partition.

After talking about so many things, let's take a look. Note that most Linux distributions now use LVM for default partition installation, and Fedora 7 is no exception.

Most new users install Fedora 7 all the way to next and seldom perform manual partitioning. The default partition after installation is as follows:

--/Boot
-- Volgroup00
| -- Logvol00 (/)
| -- Logvol01 (SWAP)

In my Partition Table

/Dev/sda7 is/boot
/Dev/sda8 is volgroup (VG)

If you install it by default, use

# Vgdisplay volgroup view the disk group (VG) Information
# Lvdisplay volgroup view partition (LV) Information

Because it is installed by default, my swap is 2 GB, which is too wasteful. Therefore, we plan to reduce it by a little. Because swap is in volgroup00, It is very convenient to adjust the size,

The procedure is as follows:

Disable swap first
# Swapoff-V/dev/volgroup/logvol01

Reduce 1g (if you want to add, you just need to change-to + on the premise that there is extra space)
# LVM lvreduce/dev/volgroup00/logvol01-L-1g

Format the swap (you only need to re-format the swap when changing the swap. Other partitions do not need to be formatted. You can simply remove them)
# Mkswap/dev/volgroup/logvol01

Re-open swap
# Swapon-va

It's so easy to change the swap.

Now that you have more than 1 GB of hard disk space, you can extend it to the root directory (/), which is also very simple, as shown below:

Increase 1 GB to logvol00
# Lvextend-L + 1g/dev/volgroup/logvol00

In the previous step, only logvol00 is added, and no file system is added.
# Resize2fs/dev/volgroup/logvol00

Added the root directory (/).

This is a small part of LVM applications.

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.