Pages

Saturday, May 18, 2024

Recovering Mistakenly Deleted LVM Partitions: A Lifesaver for Linux Admins

We've all been there – a moment of inattention or a typo, and suddenly a crucial LVM partition is gone. Thankfully, Linux offers a built-in safety net for these scenarios. The vgcfgrestore command can be your lifeline for recovering accidentally deleted LVM partitions, saving you from potential data loss and downtime.

Understanding the Safety Net: LVM Configuration Backups

Linux diligently maintains backup copies of your LVM configurations in the /etc/lvm/archive directory. This archive acts as a time machine, allowing you to rewind and restore your LVM setup to a previous state.

Recovering a Deleted LVM Partition: Step-by-Step

Let's walk through a real-world scenario. Suppose you've accidentally deleted a 10GB LVM partition belonging to a volume group named "my-vg." Here's how to recover it:

Step 1: Locate the Backup Configuration

First, you need to find the relevant backup file in the /etc/lvm/archive directory. The vgcfgrestore command makes this easy:

sudo vgcfgrestore --list my-vg

This will list all available backup configurations for your "my-vg" volume group. The output might look something like this:

my-vg_00001-123456789.vg
my-vg_00002-692643462.vg  
... 

Identify the backup file you want to use (e.g., my-vg_00002-692643462.vg).

Step 2: Restore the LVM Partition

Now, you can restore the LVM configuration using the backup file and the vgcfgrestore command:

sudo vgcfgrestore -f /etc/lvm/archive/my-vg_00002-692643462.vg my-vg

If successful, you'll see the message:

Restored volume group my-vg

Important Note: Before restoring, double-check that you've selected the correct backup file! Restoring the wrong configuration could lead to unintended consequences.

After the Restoration

Once the volume group is restored, you'll need to reactivate it:

sudo vgchange -ay my-vg

You should now be able to see and use your recovered LVM partition again.

Prevention is Key

While vgcfgrestore is a lifesaver, it's always better to prevent data loss in the first place. Consider these best practices:

  • Regular Backups: Always maintain up-to-date backups of your entire system, including LVM metadata.
  • Double-Check Commands: Be extremely careful when executing commands that modify LVM partitions.
  • Use Snapshots: If you're unsure about a change, create an LVM snapshot first to have a rollback point.

Conclusion

The vgcfgrestore command is a powerful tool that can rescue you from the panic of accidentally deleting an LVM partition. By understanding how to use it and following preventive measures, you can confidently manage your LVM environment and ensure the safety of your data.

Using mdadm to Manage RAID and Multipath Storage on Linux: A Practical Guide with Examples

The mdadm command is a powerful tool for managing multiple device sets on Linux systems. It plays a crucial role in creating and maintaining RAID arrays, which provide redundancy and performance benefits, and multipath setups, which ensure data availability in case of hardware failure. Let's delve into how you can use mdadm to harness these powerful storage features, complete with practical examples.

Creating RAID Devices with mdadm

1. Define Your Configuration:

The /etc/mdadm.conf file is where you specify the devices and RAID level for your array.

Example: RAID 1 (Mirroring)

DEVICE /dev/sd[b,c]1  
ARRAY /dev/md0 level=raid1 raid-devices=2 /dev/sdb1 /dev/sdc1

This configuration creates a RAID 1 array (/dev/md0) that mirrors data across two devices (/dev/sdb1 and /dev/sdc1).

Example: RAID 5 (Striping with Parity)

DEVICE /dev/sd[b-d]1
ARRAY /dev/md0 level=raid5 raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

This configuration creates a RAID 5 array (/dev/md0) that stripes data across three devices with parity information for fault tolerance.

2. Create the RAID Array:

Use mdadm with the -C (create) option and the details from your configuration:

# RAID 1 example sudo mdadm -C /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1 # RAID 5 example sudo mdadm -C /dev/md0 --level=raid5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

3. Verify RAID Status:

Check the status of your newly created RAID array:

sudo mdadm --detail /dev/md0

You should see information about the RAID level, state (active, syncing, etc.), device status, and more.

Creating Multipath Devices with mdadm

Multipathing provides an additional layer of reliability by creating multiple paths to access a storage device.

sudo mdadm -C /dev/md1 --level=multipath --raid-devices=2 /dev/mapper/mpatha /dev/mapper/mpathb

This command creates a multipath device (/dev/md1) using two paths (/dev/mapper/mpatha and /dev/mapper/mpathb) that likely correspond to different physical disks.

Key Considerations

  • Choose the Right RAID Level:
    • RAID 0: Best for performance but no redundancy.
    • RAID 1: Offers redundancy with mirroring.
    • RAID 5: Good balance of performance and redundancy.
    • RAID 6: More redundancy than RAID 5 but slightly slower.
    • RAID 10: Combines mirroring and striping for both performance and redundancy.
  • Data Backup: RAID is not a backup solution; always maintain regular backups.
  • Hardware Compatibility: Ensure your hardware (controllers, disks) supports your chosen RAID level.

Conclusion

mdadm empowers you to create robust and fault-tolerant storage solutions on Linux. By mastering its capabilities, you can optimize your server's performance and protect your valuable data.

Let me know if you'd like more in-depth examples or have any specific scenarios you'd like to explore!

Google Apps Wizard cPanel plugin

This tool was developed for web hosting companies, webmasters and website developers that have to setup domains with Google Apps in the everyday work. The purpose of Google Apps Wizard cPanel plugin is to facilitate the steps needed to work with Google Apps services. cPanel end user doesn’t need to have any prior knowledge of DNS records management while working with this tool.

http://code.google.com/p/google-apps-wizard-cpanel-plugin/

Installation

Run the following shell commands as root via SSH:

# wget http://google-apps-wizard-cpanel-plugin.googlecode.com/files/gaw-2.0.tar
# tar -xf gaw-2.0.tar
# cd gaw-2.0
# ./gawinstall.sh
# cd ..
# rm -Rfv gaw-2.0/ gaw-2.0.tar

Go to WHM >> Main >> Plugins >> Google Apps Wizard and click Update Now.
Upgrade

If you running version 2+ please skip this part.

# wget http://google-apps-wizard-cpanel-plugin.googlecode.com/files/gaw-2.0.tar
# tar -xf gaw-2.0.tar
# cd gaw-2.0
# ./gawupdate.sh
# cd ..
# rm -Rfv gaw-2.0/ gaw-2.0.tar

Uninstall

# wget http://google-apps-wizard-cpanel-plugin.googlecode.com/files/gaw-2.0.tar
# tar -xf gaw-2.0.tar
# cd gaw-2.0
# ./gawuninstall.sh
# cd ..
# rm -Rfv gaw-2.0/ gaw-2.0.tar

Multi-languages support

The language files folder is located at: /usr/local/cpanel/base/3rdparty/GoogleAppsWizard/lang/
The en.php is the default fallback language file so do not delete it!
To create new language files you must use an existing cPanel prefix.
You can see your available languages by navigating to: Main >> Locales >> View Available Locales.

Templates support

The Google Apps Wizard plugin support third party cPanel templates.
All you need to do is to copy the default template to your third party template folder.
Template path: /usr/local/cpanel/base/frontend/x3/gaw
Example command: # cp /usr/local/cpanel/base/frontend/x3/gaw /usr/local/cpanel/base/frontend/{Your custom template folder name}/