{"id":92,"date":"2015-02-21T20:01:25","date_gmt":"2015-02-21T19:01:25","guid":{"rendered":"http:\/\/www.underealm.com\/tech\/?p=92"},"modified":"2015-02-21T20:01:25","modified_gmt":"2015-02-21T19:01:25","slug":"minty-rescue-lvm-basics-and-recovery","status":"publish","type":"post","link":"http:\/\/www.underealm.com\/tech\/2015\/02\/minty-rescue-lvm-basics-and-recovery\/","title":{"rendered":"Minty to the rescue, tales of LVM basics and recoveries"},"content":{"rendered":"<p>In this post I&#8217;ll document a few replicable techniques that might help the less experts in managing and recovering a faulty hard drive with <abbr title=\"Logical Volume Management\">LVM<\/abbr> in use. <em><strong>Note:<\/strong> it may contain Windows and Virtual Machines<\/em>.<\/p>\n<h1>Why Windows?<\/h1>\n<p>Due to my gaming and drawing habits, even though I love the freedom of OpenSource platforms, I find myself using Win7 most of the time. We could argue that in this day and age it&#8217;s not even necessary, and I would be better off with a XenServer and a couple passthroughs to run everything in parallel, and I would agree with you. But I&#8217;m also lazy, and why fix something that is not broken? In any case all headless servers expertise came to no use when I found myself having to deal with a faulty <abbr title=\"Logical Volume Management\">LVM<\/abbr> of a root partition in a notebook hard drive. Sort of a jackpot, of a kind. While <abbr title=\"Logical Volume Management\">LVM<\/abbr> have undoubtedly their advantages, I find myself more comfortable in the physical realm rather than the logical. So I wasn&#8217;t much of an expert in that regard, and the notebook wouldn&#8217;t properly load making all the usual on-machine troubleshooting useless. Being a linux installation I couldn&#8217;t even just plug it into my main PC and scan the extN, since I am sporting Win7 for my daily routines. But then it dawned on me\u2026<\/p>\n<h1>Why not virtual Zoidberg?<\/h1>\n<p>Given the monstrous specs of my PC, and the marvels of virtualization and passthrough technology, I thought to put them all to use and resurrect my dusty VMware Workstation I had lying around for such a long time. While attaching the external hard drive to a USB3 port, I could simply pass-through it to the *nix virtual machine, and while at it I&#8217;d try that neat Linux Mint distro I wanted to try for so long (and hence the name of the article). At this point it becomes a simple *nix recovery, which is for the best.<\/p>\n<h1>Dealing with <abbr title=\"Logical Volumes Management\">LVMs<\/abbr><\/h1>\n<p><a href=\"http:\/\/jazstudios.blogspot.it\/2006\/12\/lvm-basics.html\">I armed<\/a> <a href=\"http:\/\/forums.fedoraforum.org\/showthread.php?t=272684\">myself<\/a> <a href=\"https:\/\/www.centos.org\/docs\/5\/html\/5.1\/Deployment_Guide\/s2-swap-extending-lvm2.html\">with what<\/a> <a href=\"http:\/\/dustymabe.com\/2012\/05\/13\/easily-resize-lvs-and-underlying-filesystems\/\">documentation<\/a> I could find, and started going at it:<\/p>\n<pre class=\"nums:false\" lang=\"cmd\"><code># pvscan\r\n  PV \/dev\/sda5   VG mint-vg   lvm2 [9,76 GiB \/ 0    free]\r\n  Total: 1 [9,76 GiB] \/ in use: 1 [9,76 GiB] \/ in no VG: 0 [0   ]\r\n# lvm pvs\r\n  PV         VG      Fmt  Attr PSize PFree\r\n  \/dev\/sda5  mint-vg lvm2 a--  9,76g    0\r\n\r\n# lvm vgs\r\n  VG      #PV #LV #SN Attr   VSize VFree\r\n  mint-vg   1   2   0 wz--n- 9,76g    0 \r\n# vgdisplay\r\n  --- Volume group ---\r\n  VG Name               mint-vg\r\n  System ID             \r\n  Format                lvm2\r\n  Metadata Areas        1\r\n  Metadata Sequence No  6\r\n  VG Access             read\/write\r\n  VG Status             resizable\r\n  MAX LV                0\r\n  Cur LV                2\r\n  Open LV               2\r\n  Max PV                0\r\n  Cur PV                1\r\n  Act PV                1\r\n  VG Size               9,76 GiB\r\n  PE Size               4,00 MiB\r\n  Total PE              2498\r\n  Alloc PE \/ Size       2498 \/ 9,76 GiB\r\n  Free  PE \/ Size       0 \/ 0   \r\n  VG UUID               [UUID]\r\n\r\n# lvm lvs\r\n  LV     VG      Attr      LSize Pool Origin Data%  Move Log Copy%  Convert\r\n  root   mint-vg -wi-ao--- 8,76g                                           \r\n  swap_1 mint-vg -wi-ao--- 1,00g\r\n# lvdisplay\r\n  --- Logical volume ---\r\n  LV Path                \/dev\/mint-vg\/root\r\n  LV Name                root\r\n  VG Name                mint-vg\r\n  LV UUID                [UUID]\r\n  LV Write Access        read\/write\r\n  LV Creation host, time mint, 2015-02-08 22:44:19 +0100\r\n  LV Status              available\r\n  # open                 1\r\n  LV Size                8,76 GiB\r\n  Current LE             2242\r\n  Segments               2\r\n  Allocation             inherit\r\n  Read ahead sectors     auto\r\n  - currently set to     256\r\n  Block device           252:0\r\n   \r\n  --- Logical volume ---\r\n  LV Path                \/dev\/mint-vg\/swap_1\r\n  LV Name                swap_1\r\n  VG Name                mint-vg\r\n  LV UUID                [UUID]\r\n  LV Write Access        read\/write\r\n  LV Creation host, time mint, 2015-02-08 22:44:19 +0100\r\n  LV Status              available\r\n  # open                 2\r\n  LV Size                1,00 GiB\r\n  Current LE             256\r\n  Segments               1\r\n  Allocation             inherit\r\n  Read ahead sectors     auto\r\n  - currently set to     256\r\n  Block device           252:1<\/code><\/pre>\n<p>What does this all mean? Let&#8217;s divide it for simplicity. When not dealing with physical partitions but with <abbr title=\"Logical Volume Management\">LVM<\/abbr>, there are three different actors in play: physical volumes, volume groups, and logical volumes:<\/p>\n<ul>\n<li><strong>Physical Volumes:<\/strong> (<em>pvscan<\/em>, <em>lvm pvs<\/em>) are the classical partitions. They can be grouped into a single Volume Group to virtualize disk space and access and only handle space as a virtual entity.<\/li>\n<li><strong>Volume Group:<\/strong> (<em>lvm vgs<\/em>, <em>vgdisplay<\/em>) can be considered as a union of partitions. Just like logical volumes in RAID setups, VGs support the addition (and\/or removal) of drives from it, which makes it easier to silently expand the space available without touching a partition. Suppose for example that we want an additional hard drive in our PC, we can mount the new hard drive, format it and attach it to our current <abbr title=\"Volume Group\">VG<\/abbr>. From there we can simply &#8220;expand&#8221; the Logical Volume(s) we want the additional space to go to, and it&#8217;s done. No need to mount partitions in directories or similar, it just becomes a de-facto stripe.<\/li>\n<li><strong>Logical Volume:<\/strong> (<em>lvm lvs<\/em>, <em>lvdisplay<\/em>) the usable &#8220;virtual&#8221; partition. These <abbr title=\"Logical Volumes\">LVs<\/abbr> can be mounted just like the good ol&#8217; partitions, and can be used as such. If an hard drive is added to the <abbr title=\"Volume Group\">VG<\/abbr> we can simply expand it to make use of the new space. At the same time, we will have no need to take in accounting different mounting problems since it&#8217;s just a (possibly striped on various hard drives of different sizes) partition.<\/li>\n<\/ul>\n<p>With this knowledge at hand, after understanding the concepts of <abbr title=\"Logical Volumes Management\">LVMs<\/abbr>, it was a matter of simply using <code>mount \/dev\/&lt;VGNAME&gt;\/root \/mnt<\/code>, and recover what salvageable data I had left. A question I never found myself asking (for obvious reasons) was to be asked, though: &#8220;what if the damage to the hard drive was fatal for just coincidence, and could I just fix and reuse it for less than critical events?&#8221;.<\/p>\n<h1>Once upon a time, in a bad block far, far away\u2026<\/h1>\n<p>While everybody agrees that a bad block is a great signal for &#8220;duck and cover&#8221;, I&#8217;ve always been more of an inquisitorial type. Armed with a live Mint distro and <a href=\"http:\/\/www.howtogeek.com\/howto\/37659\/the-beginners-guide-to-linux-disk-utilities\/\">an idiot proof documentation<\/a>, I proceeded to simply do the following:<\/p>\n<pre class=\"nums:false\" lang=\"cmd\"><code># badblocks \/dev\/sda > .\/bad-blocks\r\n# fsck -l .\/bad-blocks \/dev\/sda<\/code><\/pre>\n<p>While reinstalling <em>ex novo<\/em> a new OS, I thought it would be helpful, in order to avoid the pesky &#8220;Unrecovered read error &#8211; auto reallocate failed&#8221; to leave a GB or two as unallocated space, for all intents and purposes. So far everything has worked fine, let&#8217;s hope and pray that it will continue to do so, but given the hard drive reassignment to non-aggressive duties, it probably will.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;ll document a few replicable techniques that might help the less experts in managing and recovering a faulty hard drive with LVM in use. Note: it may contain Windows and Virtual Machines. Why Windows? Due to my gaming and drawing habits, even though I love the freedom of OpenSource platforms, I find [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[25,22,21,23,24],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-sysad","tag-hdd","tag-linux-mint","tag-lvm","tag-recovery","tag-virtual-machine"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/92"}],"collection":[{"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":1,"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"predecessor-version":[{"id":129,"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/92\/revisions\/129"}],"wp:attachment":[{"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}