{"id":319710,"date":"2021-03-16T21:00:38","date_gmt":"2021-03-16T21:00:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=319710"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=319710","title":{"rendered":"Data Recovery from LVM Volumes in Linux"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">Would you like to know how to use the LVM technology in Linux? How to create an LVM volume, how to configure and mount it in your operating system, how to add and remove disks, and how to recover the information you have accidentally deleted? In today\u2019s article, you will find all of that \u2013 and even more.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f4c\/fb7\/5b6\/f4cfb75b629618369a58ddf4a3071e00.png\" alt=\"image\"><\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h2>What is LVM?<\/h2>\n<p>  LVM (Logical Volume Manager) is a standard disk management feature available in every version of Linux. The volume manager provides a new level of interaction between your operating system and disks or volumes which this system is using. In a conventional disk management pattern, Linux looks for available drives first, and then checks what volumes are available on these devices.<\/p>\n<p>  With the help of LVM, disks or volumes can be united into a single space. If the disk space is treated like that, the operating system will see no difference between them and the volume manager will show the operating system only the necessary volume groups or physical disks.<\/p>\n<div class=\"oembed\"><iframe allowfullscreen id=\"60510c6630f707d266c0ecb0\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/60510c6630f707d266c0ecb0\"><\/iframe><\/div>\n<p>  In fact, LVM has several considerable advantages to offer:<\/p>\n<p>  It can create a logical volume based on any number of physical disks which will be represented in the operating system as a single disk space.<br \/>  The number of disks included and the size of such volume can be modified without interrupting your work.<br \/>  Also, the LVM technology lets you do many things on the fly, like copying certain volumes, or configuring the mirroring feature the way it works in RAID 1 systems.<\/p>\n<h2>How to add LVM to the operating system?<\/h2>\n<p>  If you are going to use LVM options for the first time, you have to install it. Here is the command you need for installation: <b>sudo apt install lvm2<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a23\/f09\/1f0\/a23f091f06d4906e16462ca13c0b45ba.png\" alt=\"image\"><\/p>\n<p>  After that, type the administrator\u2019s password, and click Yes to confirm your intention.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/751\/a39\/848\/751a398488789d44eff93465588b1713.png\" alt=\"image\"><\/p>\n<p>  Some Linux versions have this feature installed by default.<\/p>\n<p>  This can be checked easily, by typing the command <b>lvm <\/b>in the terminal window.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f5f\/bc1\/3fc\/f5fbc13fcd130d25c50d826908e88964.png\" alt=\"image\"><\/p>\n<p>  Now you can move on to dealing with disks.<\/p>\n<h2>How to format a physical disk<\/h2>\n<p>  Here we are, with three empty hard disks 320 GB each, which are unformatted and without any partitions.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/148\/0f1\/3ec\/1480f13ec1533691c17e86f55296106d.png\" alt=\"image\"><\/p>\n<p>  The easiest way to format a disk is by using a disk management utility. Click on a disk \u2013 open advanced settings \u2013 then format it.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/94e\/10d\/76f\/94e10d76f57741e40b7d89ab847e8fbd.png\" alt=\"image\"><\/p>\n<p>  Specify the name and file system \u2013 Next\u2013 and click Format again to confirm your action<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/4f9\/35d\/12e\/4f935d12edaf572b31f3344f4f0df9fb.png\" alt=\"image\"><\/p>\n<p>  Now you\u2019ll need the password to your administrator account.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/52a\/2ad\/66c\/52a2ad66c6805e6ea5df103df59e164b.png\" alt=\"image\"><\/p>\n<p>  Now that this disk is formatted, repeat the operation for every other disk which is not.<\/p>\n<p>  Also, a disk can be formatted with the terminal, using the command fdisk.<\/p>\n<p>  Sign in with a superuser account \u2013 <b>sudo \u2013i \u2013 type the password<\/b>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8e5\/f03\/570\/8e5f03570dd1a2656a36438840dcde43.png\" alt=\"image\"><\/p>\n<p>  Now run the following command: <b>fdisk \/dev\/sdb <\/b>\u2013 where sdb is the unformatted disk.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/844\/d49\/e0f\/844d49e0ffe4850993a9051207f0fe19.png\" alt=\"image\"><\/p>\n<p>  Before you continue, make sure you have selected the right disk, because this operation erases all data from there.<\/p>\n<p>  Type <b>n \u2013 new volume, p \u2013 primary, 1 \u2013 first partition<\/b>, then press Enter twice.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a84\/527\/9e0\/a845279e0c31ae6a424c4d6e76b4607b.png\" alt=\"image\"><\/p>\n<p>  Now let\u2019s get the volume ready to be used with LVM. Type<b> t <\/b>to change the volume type, and then <b>8e<\/b> to assign LVM type.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/731\/d5e\/f89\/731d5ef89e0368b7f5636c554f7fa2a3.png\" alt=\"image\"><\/p>\n<p>  Check the volume properties by pressing<b> p<\/b> \u2013 you can see everything is OK, a new formatted volume with the name <b>sdb1<\/b> appeared; press <b>w<\/b> to record the changes. Similarly, format all the disks which are not formatted yet.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/61d\/8c6\/131\/61d8c61312163bda06d4fb2c6c0a5169.png\" alt=\"image\"><\/p>\n<p>  Now create an LVM volume on the partition you have just created, by entering the command: <b>pvcreate \/dev\/sdb1<\/b>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e41\/d5f\/1f4\/e41d5f1f411641b925203d60a0a55b44.png\" alt=\"image\"><\/p>\n<p>  Repeat the command for every disk: <b>pvcreate \/dev\/sd\u04411, pvcreate \/dev\/sdd1<\/b>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9ab\/fb6\/721\/9abfb672189eab6d1063d07424ec36a4.png\" alt=\"image\"><\/p>\n<h2>Create a volume group<\/h2>\n<p>  Combine the three disks you have just prepared into an LVM volume. Here\u2019s the command to use:<\/p>\n<p>  <b>vgcreate vg1 \/dev\/sdb1 dev\/sdc1 dev\/sdd1<\/b><\/p>\n<p>  where <b>vg1<\/b> is the name of the new group. Actually, you can use any name you prefer, but it\u2019s recommended to put the vg letter combination before the name so that you know it is a volume group.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/49b\/3dd\/1b3\/49b3dd1b3cd299a493f22c72cb7f8bc2.png\" alt=\"image\"><\/p>\n<h2>Create a logical volume to use LVM<\/h2>\n<p>  When the disks are combined into the group, you need to create a new logical volume, so that you can use this group. For this purpose, type the command:<\/p>\n<p>  <b>lvcreate -L 10G -n lv1 vg1<\/b><\/p>\n<p>  Where the <b>-L<\/b> stands for the size of the logical volume \u2013 it is 10 GB in this case, and the <b>-n<\/b> assigns a name to the volume, and the <b>vg1 <\/b>indicates from which volume the space should be taken.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/82e\/81b\/218\/82e81b21817fad244d8ee06146e57df9.png\" alt=\"image\"><\/p>\n<p>  If there is any data on the disk, the operating system will warn you about it: type yes to confirm your decision to erase the information.<\/p>\n<h2>How to format and mount a logical volume?<\/h2>\n<p>  The last step you still have to take is to format the volume in the disk management utility and mount it. Click on it to open advanced settings and then format it; specify the name and file system \u2013 Next\u2013 and click Format again.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fd4\/dc5\/48e\/fd4dc548e6c65d05ef8310cb5d16687f.png\" alt=\"image\"><\/p>\n<p>  Type the <b>root<\/b> (superuser) <b>account password<\/b>, and click here to start mounting. Now you can use the new volume.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/761\/fd2\/6fb\/761fd26fb1fa21e1215e3283c0e09197.png\" alt=\"image\"><\/p>\n<p>  If you need to format it with the terminal, type the following command:<\/p>\n<p>  <b>mkfs -t ext4 \/dev\/vg1\/lv1<\/b><\/p>\n<p>  Specify the file system as <b>Ext4<\/b>, the group name, and the volume name.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/448\/900\/b2f\/448900b2f2722e8c4a4e8a2834fb68c5.png\" alt=\"image\"><\/p>\n<p>  For mounting, type the following: <b>mkdir \/mnt\/lv1<\/b>, and then \u2013 <b>mount -t ext4 \/dev\/vg1\/lv1 \/mnt\/lv1<\/b>.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/552\/027\/562\/552027562edd50582172cbe792f50b3b.png\" alt=\"image\"><\/p>\n<p>  The volume is mounted.<\/p>\n<h2>How to change the volume size?<\/h2>\n<p>  One of the advantages offered by logical volumes is the opportunity to add a new hard disk on the fly and expand the volume group. And on the contrary, if there is a hard disk in the volume group which is not in use, you can remove it.<\/p>\n<p>  There are three main tools to make physical volumes, volume groups and logical volumes larger or smaller.<\/p>\n<ul>\n<li>Resize \u2013 this command shrinks or extends physical and logical volumes, but can\u2019t handle volume groups;<\/li>\n<li>Extend \u2013 use it to increase logical volumes or volume groups;<\/li>\n<li>Reduce \u2013 it can make logical volumes or volume groups smaller.<\/li>\n<\/ul>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/24c\/fb8\/b2b\/24cfb8b2b08c83fdb698ff70fe671d05.png\" alt=\"image\"><\/p>\n<h2>How to add a new hard disk to a volume group<\/h2>\n<p>  The first step when you want to add a hard disk to a group is to format it. Scroll up to find a detailed explanation of this step.<\/p>\n<p>  After that, run the following command: <b>vgextend vg1 \/dev\/sde1<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/183\/e4a\/75b\/183e4a75b7be181bab85692ce606d400.png\" alt=\"image\"><\/p>\n<p>  where <b>vg1<\/b> is the group name, and <b>sde1<\/b> is the new (formatted) disk.<\/p>\n<h2>How to display detailed information about LVM<\/h2>\n<p>  To display detailed information on the composition of an LVM group, run the command pvdisplay.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/bf3\/1b8\/f51\/bf31b8f51bc9b06135994e1562b6a279.png\" alt=\"image\"><\/p>\n<p>  It displays the path to a physical disk, the name of the virtual group where it belongs, the information on the free and used disk space, disk ID and many other things.<\/p>\n<h2>How to remove a logical volume<\/h2>\n<p>  To remove a logical volume, make sure that i\u2019s disconnected (unmounted), then run the <b>lvremove<\/b> command, and the volume will be removed.<\/p>\n<p>  This command will help you to remove a volume group, but before that, you need to unmount the logical volume, so use another command first: <b>umount \/mnt\/lv1<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/183\/e4a\/75b\/183e4a75b7be181bab85692ce606d400.png\" alt=\"image\"><\/p>\n<p>  To proceed with removal, type this command:<b> lvremove \/dev\/vg1\/lv1<\/b>, and type Yes to confirm this operation.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ee7\/812\/181\/ee78121812e533909e206d5a9010594d.png\" alt=\"image\"><\/p>\n<p>  When the removal operation is successful, you\u2019ll see this message.<\/p>\n<p>  Now the group can be removed, with this command: <b>sudo vgremove vg1<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9d8\/64c\/409\/9d864c40981989d22de4539a7789906e.png\" alt=\"image\"><\/p>\n<p>  Now it is time to remove all the disks that used to constitute the group; this command will do it: <b>sudo pvremove \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d0f\/8dd\/b40\/d0f8ddb40532e6e07c7de123b5ed76fc.png\" alt=\"image\"><\/p>\n<p>  All the formatting of the physical disk is removed, and now the disk is back to its original condition.<\/p>\n<h2>How to recover deleted data from an LVM volume<\/h2>\n<p>  If you accidentally removed important information from an LVM logical volume, you can still restore it with the help of <a href=\"https:\/\/hetmanrecovery.com\/hard-drive-data-recovery-software\" rel=\"nofollow noopener noreferrer\">Hetman Partition Recovery<\/a>.<\/p>\n<p>  This utility supports LVM partitions and guarantees data recovery from there. It can handle most popular file systems used in Windows, Linux, Unix, and MacOS. It can ignore errors of the logical structure, scan the hard disk and restore the files you are looking for.<\/p>\n<p>  At the moment, there is no version of Hetman Partition Recovery for Linux. However, you can still run it with the help of a virtual machine based on Windows, install it as the secondary operating system on your PC, or connect the hard disk to another computer.<\/p>\n<p>  Start the program: after initialization, it recognized the logical volume without effort and now it displays all the data available on this volume.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/79f\/c7b\/95e\/79fc7b95e89661b7f1331817fb8914af.png\" alt=\"image\"><\/p>\n<p>  Start with running Fast scan \u2013 right-click on the disk, Open, Fast scan \u2013 and when the scan is over, the program will display the results in the right side of the window. Removed elements are marked with a red cross.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e77\/617\/efd\/e77617efd63c3607fc5d86a5e8b70b06.png\" alt=\"image\"><\/p>\n<p>  If the Fast scan doesn\u2019t find the data you need, then use Full analysis.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2fb\/e25\/dc9\/2fbe25dc921a02b49a6522813f59f5d6.png\" alt=\"image\"><\/p>\n<p>  Select the files to be restored, click Recovery, choose where to save them, then click Recovery again.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/07c\/5c9\/899\/07c5c98991def1b6a8d79124fc8a90e5.png\" alt=\"image\"><\/p>\n<p>  When the process is over, you will find all the files in the folder you have selected.<\/p>\n<h2>Conclusion<\/h2>\n<p>  In this article, we did our best to explain how to use <b>Logical Volume Management<\/b> \u2013 an integrated feature of Linux. We have reviewed all important stages: creating and configuring an LVM partition, adding and mounting new hard disks, shrinking and removing volumes. The LVM feature has been developed with servers in mind, but now you can enjoy all of its benefits on a desktop PC at home.<\/p>\n<p>  See the <a href=\"https:\/\/hetmanrecovery.com\/recovery_news\/lvm-partition-in-linux-os-creation-customization-management-and-recovery-of-lost-data.htm\" rel=\"nofollow noopener noreferrer\">full article<\/a> with all additional video tutorials.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/547430\/\"> https:\/\/habr.com\/ru\/post\/547430\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">Would you like to know how to use the LVM technology in Linux? How to create an LVM volume, how to configure and mount it in your operating system, how to add and remove disks, and how to recover the information you have accidentally deleted? In today\u2019s article, you will find all of that \u2013 and even more.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f4c\/fb7\/5b6\/f4cfb75b629618369a58ddf4a3071e00.png\" alt=\"image\"><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-319710","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319710"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319710\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}