<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Autarchy of the Private Cave &#187; GPT</title> <atom:link href="https://bogdan.org.ua/tags/gpt/feed" rel="self" type="application/rss+xml" /><link>https://bogdan.org.ua</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Wed, 28 Dec 2022 16:09:04 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>https://wordpress.org/?v=3.8.27</generator> <item><title>How to remotely convert live 1xHDD/LVM Linux server to 2xHDD RAID1/LVM (GRUB2, GPT)</title><link>https://bogdan.org.ua/2011/05/17/how-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html</link> <comments>https://bogdan.org.ua/2011/05/17/how-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html#comments</comments> <pubDate>Tue, 17 May 2011 13:23:05 +0000</pubDate> <dc:creator><![CDATA[Bogdan]]></dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[GPT]]></category> <category><![CDATA[grub2]]></category> <category><![CDATA[LVM]]></category> <category><![CDATA[mdadm]]></category> <category><![CDATA[RAID]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=1593</guid> <description><![CDATA[Assumptions: current HDD is /dev/sda, it has a GPT (with bios_grub being /dev/sda1), separate /boot partition (/dev/sda2), and a physical LVM volume (/dev/sda3), where LVM holds all the remaining partitions (root, /home, /srv, &#8230;); LVM is properly configured, and system reboots with no problems your new drive is /dev/sdb, it is identical to /dev/sda, and [&#8230;]]]></description> <content:encoded><![CDATA[<p>Assumptions:</p><ul><li>current HDD is /dev/sda, it has a GPT (with bios_grub being /dev/sda1), separate /boot partition (/dev/sda2), and a physical LVM volume (/dev/sda3), where LVM holds all the remaining partitions (root, /home, /srv, &#8230;); LVM is properly configured, and system reboots with no problems</li><li>your new drive is /dev/sdb, it is identical to /dev/sda, and it comes empty from the manufacturer (this is important! wipe the drive if it is not empty, especially if it used to be a part of another RAID)</li><li>your system is Debian or Debian-based; in this exact example I&#8217;ve been using Ubuntu Server 10.04</li><li>your LVM volume group is named vg0</li><li>make sure you understand what each command does before executing it</li><li>you do have an external backup of all your important data, and you do understand that the following operations are potentially dangerous to your data integrity</li></ul><p>Inspired by: <a
href="http://www200.pair.com/mecham/raid/raid1-degraded-etch.html" class="broken_link" rel="nofollow">Debian Etch RAID guide</a>, <a
href="http://serverfault.com/questions/267819/convert-1x2tb-hdd-with-lvm-into-2x2tb-hdd-with-raid1lvm-or-with-lvm-mirroring">serverfault question</a>.<br
/> <span
id="more-1593"></span></p><ol><li>Create the GPT on the new drive:<br
/> <strong>parted /dev/sdb mklabel gpt</strong></li><li>Get the list of partitions on /dev/sda:<br
/> <strong>parted -m /dev/sda print</strong></li><li>Create /dev/sdb partitions similarly to what you have on /dev/sda (my example numbers follow, use your numbers here):<br
/> <strong>parted /dev/sdb mkpart bios_grub 1049kB 2097kB</strong><br
/> <strong>parted /dev/sdb mkpart boot 2097kB 258MB</strong><br
/> <strong>parted /dev/sdb mkpart lvm 258MB 2000GB</strong></li><li>Set proper flags on partitions:<br
/> <strong>parted /dev/sdb set 1 bios_grub on</strong> (GPT doesn&#8217;t have MBR, so you create a 1-MB partition instead to hold grub2&#8242;s boot code)<br
/> <em>(possibly optional)</em> <strong>parted /dev/sdb set 2 raid on</strong><br
/> <em>(possibly optional)</em> <strong>parted /dev/sdb set 3 raid on</strong></li><li><em>(possibly optional)</em> To make sure /dev/sdb1 (the bios_grub) indeed contains grub&#8217;s boot code, I did <strong>dd if=/dev/sda1 of=/dev/sdb1</strong></li><li><strong>apt-get install mdadm</strong></li><li>Note: at this point, older tutorials suggest adding a bunch of raid* kernel modules to /etc/modules and to grub&#8217;s list of modules to load. I&#8217;m not sure this is really necessary, but do see the tutorials mentioned at the top for more information. If you do modify the lists of modules &#8211; don&#8217;t forget to run <strong>update-initramfs -u</strong>.</li><li>Create two initially-degraded RAID1 devices (one for /boot, another for LVM):<br
/> <strong>mdadm &ndash;&ndash;create /dev/md0 &ndash;&ndash;level=1 &ndash;&ndash;raid-devices=2 /dev/sdb2 missing</strong><br
/> <strong>mdadm &ndash;&ndash;create /dev/md1 &ndash;&ndash;level=1 &ndash;&ndash;raid-devices=2 /dev/sdb3 missing</strong></li><li>Store the configuration of your RAID1 to the mdadm.conf file (important! this is not done automatically!)<br
/> <strong>mdadm -Es >> /etc/mdadm/mdadm.conf</strong></li><li>Verify the contents of your mdadm.conf:<br
/> <strong>cat /etc/mdadm/mdadm.conf</strong><br
/> <strong>dpkg-reconfigure mdadm</strong>, and enable booting in degraded mode</li><li>Copy your current /boot (/dev/sda2) to the new /dev/md0 /boot partition:<br
/> (one can use something like <strong>dd -if /dev/sda2 -of /dev/md0</strong> here as well, but for some reason my attempt at dd failed writing 1 last byte of data)<br
/> <strong>mkdir /mnt/md0</strong><br
/> <strong>mkfs.ext4 /dev/md0</strong> (one can also use other filesystems here, e.g. mkfs.ext3 or even mkfs.ext2)<br
/> <strong>mount /dev/md0 /mnt/md0</strong><br
/> <strong>cp -a /boot/* /mnt/md0/</strong><br
/> <strong>umount /dev/md0</strong><br
/> <strong>rmdir /mnt/md0</strong></li><li>Now extend your existing volume group to include the newly-created /dev/md1:<br
/> <strong>pvcreate /dev/md1</strong><br
/> <strong>vgextend vg0 /dev/md1</strong></li><li>Verify the list of logical volumes you curently have: enter <strong>lvm</strong> shell, and type <strong>lvs</strong>. Here&#8217;s what I had:<br
/> LV   VG    Attr   LSize   Origin Snap%  Move Log Copy%  Convert<br
/> home vg0   -wi-ao   1.70t<br
/> logs vg0   -wi-ao   4.66g<br
/> root vg0   -wi-ao  10.24g<br
/> srv  vg0   -wc-ao 100.00g<br
/> swap vg0   -wi-ao   1.86g<br
/> tmp  vg0   -wi-ao   4.66g</li><li>Now, you can move all the logical volumes to new physical volume in one command: <strong>pvmove /dev/sda3 /dev/md1</strong>. Personally, remembering the problem I had with dd from /dev/sda2 to /dev/md0, I decided to move all logical volumes one-by-one; as this takes time, you may consider joining these operations with <strong>;</strong> or <strong>&#038;&#038;</strong>, and putting the /tmp last (as the easiest one to re-create if it fails to move):<br
/> <strong>pvmove &ndash;&ndash;name home /dev/sda3 /dev/md1</strong><br
/> <strong>pvmove &ndash;&ndash;name srv /dev/sda3 /dev/md1</strong><br
/> <strong>pvmove &ndash;&ndash;name logs /dev/sda3 /dev/md1</strong><br
/> <strong>pvmove &ndash;&ndash;name swap /dev/sda3 /dev/md1</strong><br
/> <strong>pvmove &ndash;&ndash;name root /dev/sda3 /dev/md1</strong><br
/> <strong>pvmove &ndash;&ndash;name tmp /dev/sda3 /dev/md1</strong></li><li>To be safer, I ran FS check on a few volumes I could umount:<br
/> <strong>umount /dev/mapper/vg0-srv</strong><br
/> <strong>fsck -f /dev/mapper/vg0-srv</strong><br
/> <strong>mount /dev/mapper/vg0-srv</strong><br
/> <strong>umount /dev/mapper/vg0-tmp</strong><br
/> <strong>fsck -f /dev/mapper/vg0-tmp</strong><br
/> <strong>mount /dev/mapper/vg0-tmp</strong></li><li>Remove /dev/sda3 from the physical space available to your volume group:<br
/> <strong>vgreduce vg0 /dev/sda3</strong></li><li>Install grub2 to both drives, so as to make them both bootable in case of failure:<br
/> <strong>grub-install &#8216;(hd0)&#8217;</strong><br
/> <strong>grub-install &#8216;(hd1)&#8217;</strong></li><li>Edit <strong>/etc/fstab</strong>, pointing /boot to /dev/md0. You may use UUIDs here, but please do not use UUIDs from mdadm.conf &#8211; those are different from FS-UUIDs, instead do <strong>ls -l /dev/disk/by-uuid</strong> to find the UUID of /dev/md0. Personally, I had no problems just using /dev/md0.</li><li>Now is the time to add your original /dev/sda to the RAID1; be absolutely sure you have moved all the data off that drive, because these commands will destroy it:<br
/> <strong>mdadm &ndash;&ndash;manage &ndash;&ndash;add /dev/md0 /dev/sda2</strong><br
/> <strong>mdadm &ndash;&ndash;manage &ndash;&ndash;add /dev/md1 /dev/sda3</strong><br
/> Re-syncing array will take some time.</li><li>To be on the safe side, you may want to run again <strong>update-initramfs -u</strong> and <strong>update-grub</strong>; I have also edited /etc/grub.d/40_custom, adding there 2 more boot options: from /dev/sda2 and /dev/sdb2 (/boot on both drives) &#8211; have no idea if that will work, but having more boot options didn&#8217;t hurt</li><li>Reboot into your new system. Actually, at this point reboot is only necessary to verify that your system is bootable &#8211; you may delay this reboot as long as you want to.</li><li>Many tutorials also suggest testing your RAID1 by manually &#8220;degrading&#8221; it, trying to boot, and then rebuilding it back. I haven&#8217;t done that, but you may want to.</li></ol><p>Improvement suggestions, criticism and thank-you are welcome in the comments.</p><p><a
class="a2a_button_citeulike" href="https://www.addtoany.com/add_to/citeulike?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F05%2F17%2Fhow-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html&amp;linkname=How%20to%20remotely%20convert%20live%201xHDD%2FLVM%20Linux%20server%20to%202xHDD%20RAID1%2FLVM%20%28GRUB2%2C%20GPT%29" title="CiteULike" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F05%2F17%2Fhow-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html&amp;linkname=How%20to%20remotely%20convert%20live%201xHDD%2FLVM%20Linux%20server%20to%202xHDD%20RAID1%2FLVM%20%28GRUB2%2C%20GPT%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_kindle_it" href="https://www.addtoany.com/add_to/kindle_it?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F05%2F17%2Fhow-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html&amp;linkname=How%20to%20remotely%20convert%20live%201xHDD%2FLVM%20Linux%20server%20to%202xHDD%20RAID1%2FLVM%20%28GRUB2%2C%20GPT%29" title="Kindle It" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_evernote" href="https://www.addtoany.com/add_to/evernote?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F05%2F17%2Fhow-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html&amp;linkname=How%20to%20remotely%20convert%20live%201xHDD%2FLVM%20Linux%20server%20to%202xHDD%20RAID1%2FLVM%20%28GRUB2%2C%20GPT%29" title="Evernote" rel="nofollow noopener" target="_blank"></a><a
class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fbogdan.org.ua%2F2011%2F05%2F17%2Fhow-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html&amp;linkname=How%20to%20remotely%20convert%20live%201xHDD%2FLVM%20Linux%20server%20to%202xHDD%20RAID1%2FLVM%20%28GRUB2%2C%20GPT%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a
class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fbogdan.org.ua%2F2011%2F05%2F17%2Fhow-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html&#038;title=How%20to%20remotely%20convert%20live%201xHDD%2FLVM%20Linux%20server%20to%202xHDD%20RAID1%2FLVM%20%28GRUB2%2C%20GPT%29" data-a2a-url="https://bogdan.org.ua/2011/05/17/how-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html" data-a2a-title="How to remotely convert live 1xHDD/LVM Linux server to 2xHDD RAID1/LVM (GRUB2, GPT)"><img
src="https://static.addtoany.com/buttons/share_save_120_16.png" alt="Share"></a></p>]]></content:encoded> <wfw:commentRss>https://bogdan.org.ua/2011/05/17/how-to-remotely-convert-live-hdd-lvm-linux-server-to-raid1-grub2-gpt.html/feed</wfw:commentRss> <slash:comments>6</slash:comments> </item> </channel> </rss>