[go: up one dir, main page]

0% found this document useful (0 votes)
9 views12 pages

Extending & Reducing Partition

The document outlines procedures for extending and reducing partition space using LVM, detailing when to extend or reduce, and the necessary steps for each process. It emphasizes the importance of checking available space, resizing filesystems, and backing up data to prevent loss. Additionally, it notes that shrinking is not supported on XFS filesystems and provides a workaround for reducing their size by recreating the filesystem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Extending & Reducing Partition

The document outlines procedures for extending and reducing partition space using LVM, detailing when to extend or reduce, and the necessary steps for each process. It emphasizes the importance of checking available space, resizing filesystems, and backing up data to prevent loss. Additionally, it notes that shrinking is not supported on XFS filesystems and provides a workaround for reducing their size by recreating the filesystem.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

LVM:

Extending Partition Space:


When to Extend:

● Running out of space on critical volumes.


● Allocating additional storage to applications or databases.

Steps:

1. Identify Available Space: Use fdisk -l or lsblk or lvs to check for


unallocated space.
2. Resize Partition: Utilize tools like lvextend to extend the partition.
3. Resize Filesystem: Apply resize2fs for ext4 or xfs_growfs for XFS to adjust
the filesystem size.

Note: Always back up data before making changes.

Extending partition workflow:

Extending /data1(xfs) Partition to 1 GB and /data2(ext4) Partition to 500M

Step 1: Verify Available Free Space in Volume Group:

Before extending the logical volume, ensure that the volume group (appvg,vg2)
has sufficient free space.
Look for the VFree column to confirm that free space is available in appvg and
vg2.

Step 2: Extend the Logical Volume

If there is sufficient free space, extend the logical volume (lv01) to add 1 GB and
(lv02) to 500M.

Resize the Filesystem

After extending the logical volume, resize the filesystem to utilize the new space.

● For ext4 filesystems:


sudo resize2fs /dev/vg2/lv02
● For XFS filesystems:
sudo xfs_growfs /dev/appvg/lv01

Step 3: Verify the Changes

Check the new size of the logical volume and the filesystem.

Note: If the volume group does not have sufficient free space, you may need to add a
new physical volume to the volume group before extending the logical volume.
Reducing Partition Space:

When to Reduce:

● Reclaiming space for other partitions.


● Preparing for disk migrations or reallocations.

Steps:

1. Unmount Partition: Ensure the partition is unmounted using umount.


2. Check Filesystem: Run e2fsck -f to check for errors.
3. Resize Filesystem: Use resize2fs to shrink the filesystem.
4. Adjust Partition Size: Employ lvreduce to reduce the partition size.

Caution: Shrinking partitions can lead to data loss if not done correctly.

Reducing partition workflow:

Reducing /data2(ext4) Partition to 2G

Step 1: Unmount the Partition


Step 2: Check and Repair the Filesystem

● Run Filesystem Check:

The -f flag forces a check even if the filesystem seems clean. This step is crucial
before resizing

Step 3: Resize the Filesystem

● Shrink the Filesystem:


This command resizes the filesystem to 2 GB. Ensure that the filesystem is smaller
than the logical volume size before proceeding.

Step 4: Reduce the Logical Volume Size

This command reduces the logical volume size to 500 MB. Be cautious, as this
operation is irreversible and can lead to data loss if not done correctly

Step 5: Remount the Partition

Mount the Partition:


Step 6: Verify the Changes

Ensure that the partition is mounted correctly and the size reflects the desired 2 GB.

Reducing /data1(xfs) Partition to 2G

The primary reason XFS doesn't support shrinking is its internal structure, which
includes a central log and allocation groups. Shrinking would require moving data
blocks, potentially disrupting the file system's integrity. Additionally, there has been
minimal demand for shrinking capabilities, as storage needs typically grow rather than
shrink.

Workaround: Recreate the File System


To reduce the size of an XFS file system, you can follow these steps:

Step 1: Backup Data:

Use xfsdump to create a backup of the XFS filesystem. This utility is designed for
backing up and restoring XFS filesystems and supports incremental backups.

Step 2: Unmount the File System:

Unmount the filesystem to ensure data consistency during the resizing process.
● If the filesystem is busy, identify and stop the processes using it.
● Use lsof /data1 or fuser /data1 to find and terminate these processes if
necessary.

Step 3: Delete the Logical Volume (LV)

Remove the existing logical volume to free up space for the new, smaller volume.

Step 4: Create a New Logical Volume with Reduced Size

Create a new logical volume with the desired size.


● This command creates a 2GB logical volume named lv01 in the volume group
appvg.
● Adjust the size (-L 2G) as needed.

Step 5: Format the New Logical Volume with XFS and Mount the New Filesystem

Create a new XFS filesystem on the newly created logical volume and Mount the newly
created filesystem to make it accessible.

● This command formats /dev/appvg/lv01 with the XFS filesystem.


● Alternatively, you can use mount -a if the entry exists in /etc/fstab.
● Ensure that the mount point /data1 is empty before mounting.
Step 7: Restore the Backup

Restore the data from the backup to the new filesystem.

● This command restores the contents of /data1bkp.dump to /data1.


● Check the data in /data1

Important Notes:

● Backup Data: Always back up important data before performing operations that
modify disk partitions.

● Filesystem Compatibility: Shrinking is not supported on XFS filesystems.


Attempting to shrink an XFS filesystem will result in an error.

● Data Integrity: Improperly reducing the size of a filesystem or logical volume can
result in data loss. Ensure that the filesystem is smaller than the logical volume
before reducing its size.
● Online vs. Offline Operations:

○ Extending: Can be done online (while the filesystem is mounted).


○ Reducing: Requires the filesystem to be unmounted.

You might also like