Recently I decided to invest in another harddisk for my atom system. That system, I built up almost two years ago, has become the central system in my home network, serving as a fileserver to host my personal data, some git repositories etc., streaming server and since I switched to a cable internet connection it also serves as a router/firewall.Originally, I bought that disk to backup some data, of the systems in the network, but I realized that all data on this system were hosted on a single 320GB 2,5″ disk and it became clear to me, that, in absense of a proper backup strategy, I at least should provide some redundancy.
So I decided, once the disk was in place, that the whole system should move to a RAID1 over the two disks. Basically this is not that hard as it may seem at a first glance, but I had some problems due to a new sector size in some recent harddisks, which is called Advanced Format.
But lets begin from the start. The basic idea of such a migration is:
- Install mdadm with apt-get. Make sure to answer ‚all‘ to the question which devices need to be activated in order to boot the system.
- Partition the new disk (almost) identical.Because the new drive is somewhat bigger that wouldn’t make sense, but at least the two partitions which should be mirrored on the second disk, need to be identical.Usually this is achieved easily by using
sfdisk -d /dev/sda | sfdisk /dev/second/sdb
In this case, it wasn’t that easy. But I will come to that in a minute.
- Change the type of the partitions to ‚FD‘ (Linux RAID autodetect) with fdisk
- Erase evidence of an eventual old RAID from the partitions, which is probably pointless on a brand-new disk, but we want to be sure:
mdadm –zero-superblock /dev/sdb1mdadm –zero-superblock /dev/sdb2
- Create two DEGRADED raid1 arrays from the partitions:
mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sdb1 missingmdadm –create /dev/md1 –level=1 –raid-devices=2 /dev/sdb2 missing
- Create filesystem on the first raid device, which will become /boot.
- Mount that filesystem somewhere temporary and move the contents of /boot to it:
mount /dev/md0 /mnt/somewhere
- Unmount /boot, edit fstab to mount /boot from /dev/md0 and re-mount /boot (from md0)
- Create mdadm configuration with mdadm and append it to /etc/mdadm/mdadm.conf:
mdadm –examine –scan >> /etc/mdadm/mdadm.conf
- Update the initramfs and grub (no manual modification needed with grub2 on my system)and install grub into the MBR of the second disk.
update-initramfs -uupdate-grubgrub-install /dev/sdb
- The first point to pray: Reboot the system to verify it can boot from the new /boot.
- Create a physical volume on /dev/md1:
- Extend the volume group to contain that device:
- Move the whole volume group physically from the first disk to the degraded RAID:
(Wait for it to complete… takes some time 😉
- Reduce first disk from the VG:
- Prepare it for addition to the RAID (see step 3 and 4) and add it:
mdadm –add /dev/md0 /dev/sda1mdadm –add /dev/md1 /dev/sda2
- Hooray! Watch into /proc/mdstat. You should see that the RAID is recovering.
- When recovery is finished pray another time and hope that system is still booting with it running from the RAID entirely. If it does: Finished 🙂
Now to the problem with the advanced format:There is some action taking place with the hardware vendors to move to a new sector size. Physically my new device has a size of 4096 bytes per sector. Somewhat different to the 512 bytes disks used to have the last decade.
Logically it still has 512 bytes per sector. As far as I understand this is achieved by placing 8 logical sectors into one physical sector, so when partitioning a new disk the alignment of the disk has to be so that partitions start in a sector which is a multiple of 8.
That, obviously, wasn’t the case with the old partitioning on my first disk. So I had to manually create partitions by specifying start points manually and making sure they are dividable by 8.Otherwise fdisk would complain about the layout on the disk.This does not work with cfdisk, because it does not accept manual alignment parameters and unfortunately the partitions it creates do have a wrong alignment. So good old fdisk and some calculations how many sectors are needed and where to start, to the rescue.
So the layout is now:
Device Boot Start End Blocks Id System
/dev/sdb1 2048 291154 144553+ fd Linux raid autodetect
/dev/sdb2 291160 625139334 312424087+ fd Linux raid autodetect