{"id":1020,"date":"2019-10-31T18:04:09","date_gmt":"2019-10-31T18:04:09","guid":{"rendered":"https:\/\/hostry.com\/blog\/?p=1020"},"modified":"2019-10-31T18:06:57","modified_gmt":"2019-10-31T18:06:57","slug":"moving-hdd-without-raid-controller","status":"publish","type":"post","link":"https:\/\/hostry.com\/blog\/moving-hdd-without-raid-controller\/","title":{"rendered":"Ability to switch to a new hard drive without a RAID controller and reboot"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you have a <strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/Linux\" target=\"_blank\" rel=\"noopener\">Linux<\/a><\/strong> server without a hardware <strong> <a href=\"https:\/\/en.wikipedia.org\/wiki\/RAID\" target=\"_blank\" rel=\"noopener\">RAID controller<\/a><\/strong><a href=\"https:\/\/en.wikipedia.org\/wiki\/RAID\" target=\"_blank\" rel=\"noopener\"> <\/a> that you\u2019d never want to shut down, and one of the disks starts to fail. \u00a0If a minimum of these conditions is met: \u00a0<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>All data from a dying disk can be read, although slowly but read; <\/strong><\/li><li><strong>The equipment supports &#8220;hot&#8221; connection of &#8220;SATA&#8221; or &#8220;SAS&#8221; drives or what we have there &#8230;<\/strong><\/li><li><strong>There is a free slot for connecting a disk.;<\/strong><\/li><li><strong>Disk partitioning uses LVM<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this, you can replace the disk &#8220;on the fly&#8221; without rebooting the server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How you can do this?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is exactly the story that happened to one of the servers that I served. Now will be described the whole process of &#8220;heart surgery&#8221; of the trust server. At one point, one of the installed drives began to crumble as they say  <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>HDD1 - SATA 500GB - SMART status BAD - needs to be replaced <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>HDD2 - SATA 1000GB - SMART status GOOD<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Naturally, we needed a serviceable replacement disk with a volume not less than the one that needs to be replaced &#8211; we could take more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The current partition geometry was viewed<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# lsblk<br><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[root@vsnlinx02 ~]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"># lsblk\n   NAME                                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\n   sda                                      8:0    0  500G  0 disk \n   \u251c\u2500sda1                                   8:1    0    2M  0 part \n   \u251c\u2500sda2                                   8:2    0    1G  0 part \/boot\n   \u251c\u2500sda3                                   8:3    0  498G  0 part \n   \u2502 \u251c\u2500centos-root                        253:0    0  120G  0 lvm  \/\n   \u2502 \u2514\u2500centos-swap                        253:1    0   32G  0 lvm  [SWAP]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We see that the SIZE 500G has a device called \u2018sda\u2019, and it is he who needs to be replaced. Further it was looked that at us with physical volumes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost ~]# vgdisplay \n\n  --- Volume group ---\n\n  VG Name               centos\n\n  System ID             \n\n  Format                lvm2\n\n  Metadata Areas        1\n\n  Metadata Sequence No  3\n\n  VG Access             read\/write\n\n  VG Status             resizable\n\n  MAX LV                0\n\n  Cur LV                2\n\n  Open LV               2\n\n  Max PV                0\n\n  Cur PV                1\n\n  Act PV                1\n\n  VG Size               498,00 GiB\n\n  PE Size               4,00 MiB\n\n  Total PE              127488\n\n  Alloc PE \/ Size       127488 \/ 498,00 GiB\n\n  Free  PE \/ Size       0 \/ 0   \n\n---------------\/\/------------------------------<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It can be seen that the volume group is called \u2018centos\u2019 and other statistics. A replacement drive was connected. He got the name \u2018sdc\u2019 (it could be \u2018sdd\u2019 \u2013 depending on which last letter is free). There are 3 partitions on a \u201cdying\u201d disk. (sda1, sda2 and sda3).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To replace a fully marked drive in LVM, it is enough to do 2 things:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Command&nbsp;<strong>* vgextend * \/dev\/sdc<\/strong>&nbsp;\u2013 Add a working disk to the volume group (volume group) \u2013 the operation will take no more than 3 seconds. &nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. The command&nbsp;<strong>* vgreduce * \/dev\/sda<\/strong>&nbsp;\u2013 Remove the failed disk from the volume group. \u2013 The operation will take much more time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In fact, the VLM subsystem will transfer all sectors to a new disk, while nothing will need to be unmounted and disconnected. Monitoring the I \/ O subsystem will show almost 100% load on both disks for the entire copy period. In this case, there were 2 more non-LVM partitions (sda1 and sda2), which:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. you had to create and copy manually also needed &nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. reinstall the bootloader to the new disk. After all, sooner or later it will be necessary to reboot at least after updating the kernel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we looked at the current partition table using the sfdisk command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@localhost~# sfdisk -d \/dev\/sda<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># partition table of \/dev\/sda<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>unit: sectors<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/dev\/sda1 : start=     2048, size=      4096, Id=83\n\n\/dev\/sda2 : start=     6144, size=   2097152, Id=83, bootable\n\n\/dev\/sda3 : start=  2103296, size=1044381696, Id=8e<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3 partitions were created on a new disk, 2Mb, 1GB and all free space, and using fdisk (he calculates the free space of the last partition, unlike parted). The&nbsp;<strong>\/boot\/partition<\/strong>&nbsp;was unmounted<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# umount \/boot\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next, the contents of sections 1 and 2 were copied using the dd utility:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@localhost~# dd if=\/dev\/sda1 of=\/dev\/sdc1 status=progress<br>root@localhost~# dd if=\/dev\/sda2 of=\/dev\/sdc2 status=progress<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<strong>\/boot<\/strong>&nbsp;partition was mounted from a new disk<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# mount \/dev\/sdc2 \/boot\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then reinstalled the bootloader to a new disk.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# grub-install \/dev\/sdc<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then I partitioned 3 partitions as a physical LVM volume.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# pvcreate \/dev\/sdc3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Was added this newest section to the volume group<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# vgextend centos \/dev\/sdc3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to look at what we have with a group of volumes<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@localhost~# vgdisplay <br>\n  --- Volume group ---<br>\n  VG Name               centos<br>\n  System ID             <br>\n  Format                lvm2<br>\n  Metadata Areas        1<br>\n  Metadata Sequence No  3<br>\n  VG Access             read\/write<br>\n  VG Status             resizable<br>\n  MAX LV                0<br>\n  Cur LV                2<br>\n  Open LV               2<br>\n  Max PV                0<br>\n  Cur PV                1<br>\n  Act PV                1<br>\n  VG Size               978,00 GiB<br>\n  PE Size               4,00 MiB<br>\n  Total PE              250368<br>\n  Alloc PE \/ Size       127488 \/ 498,00 GiB<br>\n  Free  PE \/ Size       127488 \/ 498,00 GiB<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally removed our \u201cdying\u201d drive from the group<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>root@localhost~# vgreduce centos \/dev\/sda3<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This operation lasts the longest. As a result, the check is issued again:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@localhost ~]# vgdisplay \n\n  --- Volume group ---\n\n  VG Name               centos\n\n  ----------\/\/----------------------\n\n  VG Size               498,00 GiB\n\n  PE Size               4,00 MiB\n\n  Total PE              127488\n\n  Alloc PE \/ Size       127488 \/ 498,00 GiB\n\n  Free  PE \/ Size       0 \/ 0   <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The old disk is removed from the volume group and can be disconnected.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>If you have a Linux server without a hardware RAID controller that you\u2019d never want to shut down, and one of the disks starts to fail. \u00a0If a minimum o&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1118,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,20],"tags":[],"class_list":["post-1020","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-server","category-system-admin"],"read_time":3,"_links":{"self":[{"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/posts\/1020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/comments?post=1020"}],"version-history":[{"count":28,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/posts\/1020\/revisions"}],"predecessor-version":[{"id":1120,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/posts\/1020\/revisions\/1120"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/media\/1118"}],"wp:attachment":[{"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/media?parent=1020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/categories?post=1020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostry.com\/blog\/wp-json\/wp\/v2\/tags?post=1020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}