{"id":641,"date":"2012-08-23T12:46:13","date_gmt":"2012-08-23T11:46:13","guid":{"rendered":"http:\/\/blogs.gentoo.org\/scarabeus\/?p=641"},"modified":"2017-12-22T10:23:41","modified_gmt":"2017-12-22T09:23:41","slug":"migrating-disk-layout-from-mess-to-raid1","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/scarabeus\/2012\/08\/23\/migrating-disk-layout-from-mess-to-raid1\/","title":{"rendered":"Migrating disk layout from mess to raid1"},"content":{"rendered":"<p>Imagine you are dumb guy like me, first what I did was to set up 3 1TB disks into one huge LVM copied data on it and then found out that grub2 needs more free space before the first partition to be able to load the LVM module and boot. For a while I solved this with external USB token plugged in the motherboard. But I said no more!<\/p>\n<p>I bought two 3TB disks to deal with the situation, and this time I decided to do everything right and add UEFI boot instead of normal good old booting.<\/p>\n<h2>Disk layout<\/h2>\n<pre>Model: ATA ST3000VX000-9YW1 (scsi)\r\nDisk \/dev\/sda: 3001GB\r\nSector size (logical\/physical): 512B\/4096B\r\nPartition Table: gpt\r\nDisk Flags: \r\n\r\nNumber  Start   End     Size    File system  Name     Flags\r\n 1      17.4kB  512MB   512MB   fat32        primary\r\n 2      512MB   20.0GB  19.5GB               primary\r\n 3      20.0GB  30.0GB  9999MB  xfs          primary\r\n 4      30.0GB  3001GB  2971GB  xfs          primary<\/pre>\n<p>So as you can see I created 4 partitions. First is special case and it must be always created for EFI boot. Create it larger than 200 megs, up to 500, which should be enough for everyone.<\/p>\n<p>The disk layout must be set up in parted as we want GPT layout (just google how to do it, it is damn easy to use), It accept both values like 1M, 1T and percetage like 4% to specify the resulting partition size.<\/p>\n<h2>Setting up the RAID<\/h2>\n<p>We just create simple nodes and plug \/dev\/sda2-4 and \/dev\/sdb2-4 to them. Prior creating the RAID make sure you have RAID support in your kernel.<\/p>\n<pre>for i in {2..4}; do mknod \/dev\/md${i} b 9 ${i}; mdadm --create \/dev\/md${i} --level=1 --raid-devices=2 \/dev\/sda${i} \/dev\/sdb${i}; done<\/pre>\n<p>After these commands are executed we have to watch mdstat until it is prepared (note that you can work with the md disks in the meantime, just the setting of the RAID will be slower as you will be writting on the named disks.<\/p>\n<p>After we check the mdstat and see that all the disks are ready for play:<\/p>\n<pre>croot@htpc: ~ # cat \/proc\/mdstat \r\nPersonalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] [faulty] \r\nmd4 : active raid1 sda4[0] sdb4[1]\r\n      2900968312 blocks super 1.2 [2\/2] [UU]\r\n      \r\nmd3 : active raid1 sda3[0] sdb3[1]\r\n      9763768 blocks super 1.2 [2\/2] [UU]\r\n      \r\nmd2 : active raid1 sda2[0] sdb2[1]\r\n      19030679 blocks super 1.2 [2\/2] [UU]<\/pre>\n<p>we can proceed with data copying.<\/p>\n<h2>Transfering the data and setting up the system<\/h2>\n<pre>mkfs.ext4 \/dev\/md2 ; mkfs.xfs \/dev\/md3 ; mkfs.xfs \/dev\/md4 # create filesystems\r\nmkdir -p \/mnt\/newroot\/{home,var} # create the folder struct (home and var are actually the md3 and md4 so prepare the folders for them\r\nmount \/dev\/md2 \/mnt\/newroot\r\nmount \/dev\/md3 \/mnt\/newroot\/var\r\nmount \/dev\/md4 \/mnt\/newroot\/home<\/pre>\n<p>Now that we are ready we will use rsync to transfer living system and data (WARNING: shutdown everything that temper with data (like ftp\/svn\/git services). Only thing we are going to loose is few lines of syslog and other log services.<\/p>\n<pre>rsync -av \/home \/mnt\/newroot\/home # no -z as we don't need to compress\r\nrsync -av \/var \/mnt\/newroot\/var\r\nrsync -av \/ --exclude '\/home' --exclude '\/dev' --exclude '\/lost+found' --exclude '\/proc' --exclude '\/sys' --exclude '\/var' --exclude '\/mnt' --exclude '\/media' --exclude '\/tmp' \/mnt\/newroot\/ # copy all relevant stuff to newroot\r\nmkdir -p \/mnt\/newroot\/{dev,proc,sys,mnt,media,tmp}\r\n<\/pre>\n<p>After the transfer you need to edit \/etc\/fstab to reflect new disk layout. Update kernel (if needed to support new RAID layout) and update \/etc\/defaults\/grub if you did RAID like me to contain domdadm line for default command.<\/p>\n<h2>Preparing new boot over UEFI<\/h2>\n<p>On your machine you need to create usb dongle which supports UEFI boot (you need to be uefi booted to setup UEFI [fcking hilarious]).<\/p>\n<p>We need to download <a href=\"http:\/\/archlinux.mirror.dkm.cz\/pub\/archlinux\/iso\/archboot\/\">latest archboot iso 64bit<\/a> (gentoo minimal didn&#8217;t contain this lovely feature).<br \/>\nGrab some usb disk and plug it into our machine. We will format it to 32b fat: mkfs.vfat -F32 \/dev\/[myusb] , mount somewhere and copy the ISO image content to the usb folder (you can enter it in mc and just F5 it if you are lazy like me, but it is working with tar, p7zip or whatever else). Shutdown the computer, unplug old disks and with manic laughter turn the machine again on.<\/p>\n<p>To boot the uefi just open boot list menu and select the disk which has UEFI around its name. It will open grub2 menu where you just select first option. We should be then welcomed by lovely arch installer. Not caring about it switch to another console and open terminal. Setup again the arrays using mdadm &#8211;assemble.<\/p>\n<pre>for i in {2..4}; do mknod \/dev\/md${i} b 9 ${i}; mdadm --assemble \/dev\/md$i \/dev\/sda${i} \/dev\/sdb${i}; done<\/pre>\n<p>Then just proceed with mounting them somewhere to \/mnt and chroot like you would do new gentoo install. Exact steps:<\/p>\n<pre>modprobe efivars # load the efi tool variables\r\nmkdir -p \/mnt\/newroot\/{home,var} # create the folder struct (home and var are actually the md3 and md4 so prepare the folders for them\r\nmount \/dev\/md2 \/mnt\/newroot\r\nmount \/dev\/md3 \/mnt\/newroot\/var\r\nmount \/dev\/md4 \/mnt\/newroot\/home\r\nmount -o rbind \/dev \/mnt\/newroot\/dev\r\nmount -o rbind \/sys \/mnt\/newroot\/sys\r\nmount -t proc none \/mnt\/newroot\/proc\r\nchroot \/mnt\/newroot \/bin\/bash\r\n. \/etc\/profile\r\nenv-update\r\n<\/pre>\n<p>Now that we are in chroot we just install grub2 with GRUB_PLATFORMS=&#8221;efi-64&#8243;. After that we proceed easily by following <a href=\"http:\/\/wiki.gentoo.org\/wiki\/GRUB2#UEFI.2FGPT\">wiki article<\/a>.<\/p>\n<p>Unmount the disk, reboot the system, unplug the flasdrive, &#8230;, profit?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Imagine you are dumb guy like me, first what I did was to set up 3 1TB disks into one huge LVM copied data on it and then found out that grub2 needs more free space before the first partition to be able to load the LVM module and boot&#8230;. <a class=\"continue-reading-link\" href=\"https:\/\/blogs.gentoo.org\/scarabeus\/2012\/08\/23\/migrating-disk-layout-from-mess-to-raid1\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":116,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[8],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/posts\/641"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/users\/116"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":10,"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/posts\/641\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/scarabeus\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}