In Linux, the ability to manage storage effectively is a crucial skill. One common task that arises is the need to remove an existing logical volume, a process that requires precision and understanding to avoid potential data loss.
This quick guide will walk you through the process of removing a logical volume on CentOS 6.3/RHEL6. In this example specifically focusing on a volume named ‘centos63_vol’.
Before we dive in, it’s important to note that this guide assumes you have a basic understanding of Linux administration and the Logical Volume Manager (LVM).
Let’s get started!
Step-by-Step Guide to Removing a Logical Volume on CentOS 6.3/RHEL6
Step 1: List All Logical Volumes
Start by listing all the logical volumes on your system. This can be done using the ‘lvs’ command:
lvs
This command will display all the logical volumes on your system, including ‘centos63_vol’.
[root@centos63 ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert lv_root vg_centos63 -wi-ao-- 5.54g lv_swap vg_centos63 -wi-ao-- 1.97g centos63_vol vg_data -wi-ao-- 4.99g
Step 2: Check Current Disk Layout
Next, check your current disk layout and find where ‘centos63_vol’ is mounted. You can do this using the ‘df -lh’ command:
df -lh
This command will display the file system’s disk space usage. Look for the ‘/mydata’ mount point, which is where ‘centos63_vol’ is mounted.
[root@centos63 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos63-lv_root 5.5G 2.2G 3.1G 41% / tmpfs 504M 0 504M 0% /dev/shm /dev/sda1 485M 65M 395M 15% /boot /dev/mapper/vg_data-centos63_vol 5.0G 139M 4.6G 3% /mydata
Step 3: View Current /etc/fstab Value
Before making any changes, it’s a good idea to view the current value of ‘/etc/fstab’. This file contains information about the file systems on your system. Use the ‘cat /etc/fstab’ command to display its contents:
cat /etc/fstab
For example:
[root@centos63 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Jul 15 20:17:38 2012 # # 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/vg_centos63-lv_root / ext4 defaults 1 1 UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot ext4 defaults 1 2 /dev/mapper/vg_centos63-lv_swap swap swap defaults 0 0 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 proc defaults 0 0 /dev/vg_data/centos63_vol /mydata ext4 defaults 1 1
Step 4: Unmount centos63_vol
Now that you’ve gathered all the necessary information, you can proceed to unmount ‘centos63_vol’. This can be done using the ‘umount’ command followed by the mount point:
umount /mydata
Step 5: Verify That centos63_vol Has Unmounted
After unmounting, verify that ‘centos63_vol’ has indeed been unmounted. You can do this by running the ‘df -lh’ command again:
df -lh
If ‘centos63_vol’ has been successfully unmounted, it will no longer appear in the output.
[root@centos63 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos63-lv_root 5.5G 2.2G 3.1G 41% / tmpfs 504M 0 504M 0% /dev/shm /dev/sda1 485M 65M 395M 15% /boot
Step 6: Remove the Logical Volume
With ‘centos63_vol’ unmounted, you can now remove the logical volume. This can be done using the ‘lvremove’ command followed by the path to the logical volume:
lvremove /dev/mapper/vg_data-centos63_vol
You will be asked to confirm the removal. Type ‘y’ to proceed.
[root@centos63 ~]# lvremove /dev/mapper/vg_data-centos63_vol Do you really want to remove active logical volume centos63_vol? [y/n]: y Logical volume "centos63_vol" successfully removed
Step 7: Verify the Logical Volume Has Been Removed
After removing the logical volume, it’s important to verify that ‘centos63_vol’ has indeed been removed. You can do this by running the ‘lvs’ command again:
lvs
If ‘centos63_vol’ has been successfully removed, it will no longer appear in the output.
[root@centos63 ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert lv_root vg_centos63 -wi-ao-- 5.54g lv_swap vg_centos63 -wi-ao-- 1.97g [root@centos63 ~]#
Step 8: Update /etc/fstab
Finally, you need to update ‘/etc/fstab’ to reflect the removal of the file system. This can be done using the ‘vi’ command to open the file in a text editor:
vi /etc/fstab
Remove the line that references ‘centos63_vol’.
# # /etc/fstab # Created by anaconda on Sun Jul 15 20:17:38 2012 # # 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/vg_centos63-lv_root / ext4 defaults 1 1 UUID=2217c7b1-4467-4c81-8596-c3ee7758e2cc /boot ext4 defaults 1 2 /dev/mapper/vg_centos63-lv_swap swap swap defaults 0 0 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 proc defaults 0 0
Save and exit the file when you’re done.
Commands Mentioned
- lvs – Lists all logical volumes on the system
- df -lh – Displays the file system’s disk space usage
- cat /etc/fstab – Displays the contents of ‘/etc/fstab’
- umount /mydata – Unmounts ‘centos63_vol’
- lvremove /dev/mapper/vg_data-centos63_vol – Removes the logical volume ‘centos63_vol’
- vi /etc/fstab – Opens ‘/etc/fstab’ in a text editor
Conclusion
Removing a logical volume in CentOS 6.3/RHEL6 is a task that requires careful execution. By following the steps outlined in this guide, you can successfully remove a logical volume without risking data loss or system instability.
Remember, always double-check your commands and their potential impact before executing them, especially when dealing with system data.
Hope you found this tutorial helpful.
If you have any questions or run into any issues, feel free to leave a comment below.
FAQ
-
What is a logical volume?
A logical volume is a component of the Logical Volume Manager (LVM) in Linux. It’s a virtual partition that can span across one or more physical hard drives, providing flexibility in disk management.
-
Why would I need to remove a logical volume?
There could be several reasons to remove a logical volume, such as reclaiming disk space, reorganizing storage, or decommissioning a service or application that was using the volume.
-
What is /etc/fstab and why is it important?
/etc/fstab is a configuration file in Linux that contains information about all the disk partitions and storage devices in your computer. It’s used by the system to determine where and how to mount these devices and partitions.
-
What does the ‘umount’ command do?
The ‘umount’ command is used to unmount a mounted file system in Linux. It’s important to unmount a file system before removing it to prevent data loss or corruption.
-
What does the ‘lvremove’ command do?
The ‘lvremove’ command is used to remove a logical volume in Linux. It’s part of the Logical Volume Manager (LVM) toolset.