Friday 19 April 2019

Terms and Conditions of Use Recover logical volumes data from deleted LVM partition

Have you ever deleted a logical volume by accident? Can you recover it looking into the backups? Well, the answer is YES. For those who are not familiar with Logical Volume Management (LVM) is a device mapper target that provides logical volume management for the Linux kernel.- WikipediaIt is an abstraction layer or software that has been placed on top of your hard drive for flexible manipulation of the disk space. Some of the articles published in the past on LVM are:
All test carried out on this blog post have been tested on a CentOS machine. Please don't make a live test on a production server.
Image Credits: Redhat.com
Image Credits: Redhat.com
1. So, as you can see below I have an lv called lvopt which is from a vg called centos.
2. Same is mounted on the /opt
3. There are some data in that partition as well:
4. I created a directory inside the /opt directory
5. Now, let's pretend to remove the lvm lvopt. Or say, someone did it by accident because it was unmounted. The command lvremove will be used here to remove the lv. Note: that the lv need to be unmounted.
6. If you make an lvs, lvdisplay or vgs or even mount again the partition, you cannot do it. The data is lost. But you can still recover it. This is because the lvm contains the archive of your lv inside the folder /etc/lvm/archive. But, you cannot read the files directly.
7. But you can still, interpret part of the files. Since we deleted the volume group called "centos", we knew that it is referenced in the file centos_... The question that arises here is which file is relevant for you. Right? So to understand which archive you want to restore, you need to use the command vgcfgrestore --list <name of volume group>. Here is an example:
8.  If you observe carefully, each archive has been backup at a certain time. In my case, I deleted the LV on 18-Apr-2019 at 11:17:17 2019:
9. So, I want to restore from that last archive. You will need to copy the full patch of the vg file. In my case it is /etc/lvm/archive/centos_00004-1870674349.vg. The goal here is to restore the lv before this specific time, or simply restore back the lv before the command lvremove was fired. Here is the command:
10. If you launch the command lvs, you will notice the presence of the lv.
11. But, mounting back the lv won't result in anything. This is because the lv is inactive. You can see it with the command lvscan. Please take note below that the lvopt is inactive.
12. To activate it you simply need to use the command lvchange.
13. Mount it back and you are done.
I believe this can be very useful especially when you have encountered a situation where someone deleted an lv. I hope you enjoy this blog post. Please share and comment below if you like it.

Thursday 24 January 2019

Downloading a Specific Version of Package and Its Dependencies from Repository for Offline Installation Using YUM

Question : How to download a specific version of the package along with its dependencies using YUM offline.
Answer :
1. To see what particular versions are available to you via yum you can use the –showduplicates switch.
# yum --showduplicates list [package_name]
For Example :
# yum --showduplicates list httpd
Loaded plugins: product-id, security, subscription-manager.
Installed Packages
httpd.x86_64 2.2.15-39.0.1.el6 @ol6_x86_64_latest         --- installed
Available Packages
httpd.x86_64 2.2.15-5.0.1.el6 ol6_x86_64_latest           --- older versions
httpd.x86_64 2.2.15-9.0.1.el6 ol6_x86_64_latest
....
2. If there is a need to download the older version package along with its dependencies for an off-line installation, you can use one of the following options to download a particular version of RPM from the web, and then use yum to install it.

Method 1

To download the packages into a local directory, use – -downloaddir=[dir] option along with the –downloadonly switch of yum command.
# yum install --downloadonly --downloaddir=[directory] [package]
For example :
# yum install --downloadonly --downloaddir=/tmp/ httpd.x86_64 2.2.15-5.0.1.el6

Method 2

To download package with its dependencies using yumdownloader :
# yumdownloader [package]
To download the package to a local folder try the option “- -destdir=DESTDIR”
# yumdownloader --destdir=[DIR] [package]
For example :
# yumdownloader --destdir=/tmp httpd.x86_64 2.2.15-5.0.1.el6
To download the packe along with all dependencies, use option “- -resolve” along with “- -destdir”
# yumdownloader --destdir=[DIR] --resolve [package]

Installing packages locally

Now install the packages from the local directory with yum command option “localinstall”
# yum localinstall [path to rpm]