{"id":357,"date":"2023-07-28T13:50:11","date_gmt":"2023-07-28T11:50:11","guid":{"rendered":"https:\/\/independence.blinkenshell.org\/blog\/?p=357"},"modified":"2023-07-28T13:50:12","modified_gmt":"2023-07-28T11:50:12","slug":"replacing-software-raid1-boot-drives-with-uefi","status":"publish","type":"post","link":"https:\/\/independence.blinkenshell.org\/blog\/2023\/07\/28\/replacing-software-raid1-boot-drives-with-uefi\/","title":{"rendered":"Replacing software RAID1 boot drives with UEFI"},"content":{"rendered":"\n<p>I replaced both of the drives in my RAID1 boot array on a Ubuntu server yesterday and had some struggles so I thought I would write down my experience both for my future self and any others who needs to do something similar. I think my main problem was following a guide that was not for UEFI setups \ud83d\ude42<\/p>\n\n\n\n<p>So, my setup is two NVMe drives on nvme0n1 and nvme1n1. Both drives have the same partition table:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>UEFI 512M<\/li><li>md0 \/ boot 1G<\/li><li>md1 \/ LVM &lt;rest of disk&gt;<\/li><\/ol>\n\n\n\n<p>Before starting, check that all disks are online:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># cat \/proc\/mdstat\n Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] \n md1 : active raid1 nvme1n1p3[2] nvme0n1p3[3]\n       x blocks super 1.2 [2\/2] [<strong>UU<\/strong>]\n       bitmap: 3\/7 pages [12KB], xKB chunk\n md0 : active raid1 nvme0n1p2[3] nvme1n1p2[2]\n       x blocks super 1.2 [2\/2] [<strong>UU<\/strong>]<\/pre>\n\n\n\n<p>So it should say [UU] and not [U_] or something else.<\/p>\n\n\n\n<p>In my case I also did <code>smartctl -ia \/dev\/nvme0<\/code> to write down serial numbers etc to know which physical disk to replace in the box.<\/p>\n\n\n\n<p>Next up is to save a copy of your EFI partition for later use:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dd if=\/dev\/nvme0n1p1 bs=4M of=\/root\/EFI_PARTITITON.img<\/pre>\n\n\n\n<p>Pick one drive to start with and make it offline:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mdadm \/dev\/md0 --fail \/dev\/nvme0n1p2 --remove nvme0n1p2\nmdadm \/dev\/md1 --fail \/dev\/nvme0n1p3 --remove nvme0n1p3<\/pre>\n\n\n\n<p>Physically replace the drive in the server. It might also be a good idea to do a firmware upgrade of the new drive if it&#8217;s available.<\/p>\n\n\n\n<p>After disk is replaced, copy over the partition table from the remaining good disk to the newly replaced disk, and then generate new UUIDs for the partitions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sfdisk -d \/dev\/nvme1n1 | sfdisk \/dev\/nvme0n1\nsgdisk -G \/dev\/nvme0n1<\/code><\/pre>\n\n\n\n<p>Add the device back to the RAID1 array:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mdadm --manage \/dev\/md0 --add \/dev\/nvme0n1p2\nmdadm --manage \/dev\/md1 --add \/dev\/nvme0n1p3<\/pre>\n\n\n\n<p>Monitor the rebuild status with a command like <code>watch cat \/proc\/mdstat<\/code><\/p>\n\n\n\n<p>If the rebuild is slow\/limited to like 200MB\/s you can change the max speed to eg 1.6GB\/s with:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">echo 1600000 &gt; \/proc\/sys\/dev\/raid\/speed_limit_max<\/pre>\n\n\n\n<p>After the resync is done we need to fix EFI, start by copying back the partiton we backed up before:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dd if=\/root\/EFI_PARTITITON.img bs=4M of=\/dev\/nvme0n1p1<\/pre>\n\n\n\n<p>Fix grub:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">update-grub<br>grub-install \/dev\/nvme0n1<\/pre>\n\n\n\n<p>And lastly reinstall the UEFI boot option (for ubuntu):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">efibootmgr -v | grep ubuntu  # only shows one entry\nefibootmgr --create --disk \/dev\/nvme0n1 --part 1 --label \"ubuntu\" --loader \"\\EFI\\ubuntu\\shimx64.efi\"<\/pre>\n\n\n\n<p>You should after this have two ubuntu entries from efibootmgr, and that should be it! Try rebooting and make sure boot works from both drives. If you need to replace the other drive follow the same procedure as above but use eg nvme1n1.<\/p>\n\n\n\n<p>If the new drive is bigger you can also grow the RAID1:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mdadm \/dev\/md1 --fail \/dev\/nvme0n1p3 --remove nvme0n1p3<br>parted \/dev\/nvme0n1<\/pre>\n\n\n\n<p>Use <code>resizepart<\/code> command in <code>parted<\/code> to change the size.<\/p>\n\n\n\n<p>Add back to the array:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mdadm --manage \/dev\/md1 --add \/dev\/nvme0n1p3<\/pre>\n\n\n\n<p>Wait for resync (cat \/proc\/mdstat) and then grow the array:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mdadm --grow \/dev\/md1 --size=max<\/pre>\n\n\n\n<p>Then you need to resize the filesystem, in my case it&#8217;s LVM with ext filesystem on top so:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pvresize \/dev\/md1<br>lvextend -L +1G \/dev\/vg-md1\/lv-root<br>resize2fs \/dev\/vg-md1\/lv-root<\/pre>\n\n\n\n<p>Or just resize2fs \/dev\/md1 if it&#8217;s no LVM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I replaced both of the drives in my RAID1 boot array on a Ubuntu server yesterday and had some struggles so I thought I would write down my experience both for my future self and any others who needs to &hellip; <a href=\"https:\/\/independence.blinkenshell.org\/blog\/2023\/07\/28\/replacing-software-raid1-boot-drives-with-uefi\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,9,1],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-hardware","category-linux","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":3,"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":360,"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/posts\/357\/revisions\/360"}],"wp:attachment":[{"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/independence.blinkenshell.org\/blog\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}