LVM management reduces swap partition space and increases to the root Partition

Source: Internet
Author: User

LVM management reduces swap partition space and increases to the root Partition

Introduction

LVM is short for Logical Volume Manager (Logical Volume management). It is a mechanism for managing disk partitions in Linux. It is implemented by Heinz Mauelshagen on the Linux 2.4 kernel.

PhysicalStorageMedia)

It refers to the physical storage device of the system, such as/dev/hda and/dev/sda. It is the bottom-layer storage unit of the storage system.

Physical Volume (Physical Volume, PV)

It refers to a disk partition or a device (such as RAID) with the same functions as a disk partition logically. It is the basic storage Logical Block of LVM, however, compared with basic physical storage media (such as partitions and disks), it contains management parameters related to LVM.

Volume Group (Volume Group, VG)

Similar to a physical disk in a non-LVM system, it consists of one or more physical volume PVS. You can create one or more LV (logical volume) on the volume group ).

Logical Volume (LV)

Similar to the disk partition in a non-LVM system, the logical volume is built on the volume group VG. You can create a file system (such as/home or/usr) on top of the logical Volume LV ).

View information commands

Pvdisplay # view PV Information

[Root @ localhost ~] # Pvdisplay
--- Physical volume ---
PV Name/dev/sda3
VG Name VolGroup
PV Size 18.51 GiB/not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4738
Free PE 0
Allocated PE 4738.
Pvuuid ARNJxr-gfcH-rW5H-X6I1-c2da-QhM1-BJ7ljo

Vgdisplay # view VG Information

[Root @ localhost ~] # Vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
Max lv 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 18.51 GiB
PE Size 4.00 MiB
Total PE 4738
Alloc PE/Size 4738/18 .51 GiB
Free PE/Size 0/0
Vg uuid gFkWoE-8AVZ-kbd5-Clge-6Tq3-gcFh-4iVr1x

Lvdisplay # view LV Information

[Root @ localhost ~] # Lvdisplay
--- Logical volume ---
LV Path/dev/VolGroup/LogVol01
LV Name LogVol01
VG Name VolGroup
Lvuuid UeAMMJ-G6Ou-yMlJ-9Igz-pVBU-1HSy-jt6Trt
LV Write Access read/write
LV Creation host, time localhost. localdomain, 03:42:14-0400
LV Status available
# Open 1
LV Size 4.05 GiB
Current LE 1036
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 0

--- Logical volume ---
LV Path/dev/VolGroup/LogVol00
LV Name LogVol00
VG Name VolGroup
Lvuuid OF62jU-eVGO-4Rtd-TycU-aoGC-0Rs0-nDRRhE
LV Write Access read/write
LV Creation host, time localhost. localdomain, 03:42:15-0400
LV Status available
# Open 1
LV Size 14.46 GiB
Current LE 3702
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Blocks device 253: 1


Reduction and increase

To unmount a swap partition, use swapoff-.

[Root @ localhost ~] # Free-m
Total used free shared buffers cached
Mem: 1877 140 1737 0 6 39
-/+ Buffers/cache: 93 1783
Swap: 4143 0 4143
[Root @ localhost ~] # Swapoff-
[Root @ localhost ~] # Free-m
Total used free shared buffers cached
Mem: 1877 136 1740 0 6 39
-/+ Buffers/cache: 91 1786
Swap: 0 0 0

Use lvreduce-L-xxx filename or lvreduce-L xxx filename to reduce the swap partition space. "-" indicates the number of dropped partitions, and "-" indicates the number of dropped partitions. Leave 512 M for the swap partition.

Format partitions using mke2fs filename

Use resize2fs filename to override the partition Space

[Root @ localhost ~] # Lvreduce-L 512 M/dev/VolGroup/LogVol01
WARNING: switching active and open logical volume to 512.00 MiB
This may destroy your data (filesystem etc .)
Do you really want to reduce LogVol01? [Y/n]: y
Cing logical volume LogVol01 to 512.00 MiB
Logical volume LogVol01 successfully resized
[Root @ localhost ~] # Mke2fs/dev/VolGroup/LogVol01
Mke2fs 1.41.12 (17-May-2010)
Filesystem label =
OS type: Linux
Block size = 4096 (log = 2)
Fragment size = 4096 (log = 2)
Stride = 0 blocks, Stripe width = 0 blocks
32768 inodes, 131072 blocks
6553 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks = 134217728
4 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768,983 04

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
[Root @ localhost ~] # Resize2fs/dev/VolGroup/LogVol01
Resize2fs 1.41.12 (17-May-2010)
The filesystem is already 131072 blocks long. Nothing to do!

Use lvextend-L + 1G filename to add free space for the root partition. The usage is the same as above. You can use vgdisplay to view idle space. You do not need to format the added space.

[Root @ localhost ~] # Lvextend-L + 3.54G/dev/VolGroup/LogVol00
Rounding size to boundary between physical extents: 3.54 GiB
Extending logical volume LogVol00 to 18.00 GiB
Logical volume LogVol00 successfully resized
[Root @ localhost ~] # Resize2fs/dev/VolGroup/LogVol00
Resize2fs 1.41.12 (17-May-2010)
Filesystem at/dev/VolGroup/LogVol00 is mounted on/; on-line resizing required
Old desc_blocks = 1, new_desc_blocks = 2
Ming an on-line resize of/dev/VolGroup/LogVol00 to 4719616 (4 k) blocks.
The filesystem on/dev/VolGroup/LogVol00 is now 4719616 blocks long.

Swap File

Create a 2G swap file, attach it to swap, and add it to the startup Item.

[Root @ localhost ~] # Dd if =/dev/zero of =/www/swap bs = 1024 count = 2048000
2048000 + 0 records in
2048000 + 0 records out
2097152000 bytes (2.1 GB) copied, 12.0018 s, 175 MB/s
[Root @ localhost ~] # Mkswap/www/swap
Mkswap:/www/swap: warning: don't erase bootbits sectors
On whole disk. Use-f to force.
Setting up swapspace version 1, size = 2047996 KiB
No label, UUID = 92ab4ed5-f301-4ba4-970f-9e5600610522
[Root @ localhost ~] # Swapon/www/swap
[Root @ localhost ~] # Free-m
Total used free shared buffers cached
Mem: 1877 1796 80 0 7 1647
-/+ Buffers/cache: 142 1735
Swap: 1999 0 1999
[Root @ localhost ~] # Swapon-s
Filename Type Size Used Priority
/Www/swap file 2047992 0-1

Modify startup Item

Edit the/etc/fstab file, remove the previous swap partition mount, and add the swap file mount in the last line.

[Root @ localhost ~] # Cat/etc/fstab

#
#/Etc/fstab
# Created by anaconda on Thu Jul 23 03:45:08 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info
#
/Dev/mapper/VolGroup-LogVol00/ext4 ults 1 1
UUID = 4221a802-6ce2-4638-a3a5-7c17b961f291/boot ext4 defaults 1 2
UUID = b720b68f-37b7-45ce-b4a2-40deeb9fa90f/www ext3 ults 1 2
Tmpfs/dev/shm tmpfs defaults 0 0
Devpts/dev/pts devpts gid = 5, mode = 620 0 0
Sysfs/sys sysfs defaults 0 0
Proc/proc defaults 0 0
/Www/swap defaults 0 0

After restarting, we can see that the root partition space is increased, and swap uses the swap file.

[Root @ localhost ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/VolGroup-LogVol00
18G 716 M 17G 5%/
Tmpfs 939 M 0 939 M 0%/dev/shm
/Dev/sda1 485 M 32 M 429 M 7%/boot
/Dev/sda2 61G 2.2G 55G 4%/www
[Root @ localhost ~] # Free-m
Total used free shared buffers cached
Mem: 1877 135 1741 0 7 36
-/+ Buffers/cache: 91 1786
Swap: 1999 0 1999
[Root @ localhost ~] # Swapon-s
Filename Type Size Used Priority
/Www/swap file 2047992 0-1

Note: In previous experiments, swap's LV was directly deleted and replaced by a file. However, an error is reported after swap's LV is deleted.

Press "e" and "enforcing = 0" to solve the problem on the Internet. This problem has been solved for the time being. If you have solved the problem, please tell the students.

  • Use LVM to create elastic disk storage-Part 1
  • Expanding/downgrading LVM in Linux (Part 2)
  • Recording and restoring logical volume snapshots in LVM (part 3)
  • Set a streamlined resource allocation volume in LVM (part 4)
  • Use fragmented I/O to manage multiple LVM disks (Part 5)

This article permanently updates the link address:

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.