This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
public:techstuff:raid [2012/08/21 13:51] – Deleted by PageMove plugin nathan | public:techstuff:raid [2020/04/25 13:05] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Raid ====== | ||
+ | The tool we use to do raid is called mdadm. Some useful commands are: | ||
+ | * Show information about this raid device | ||
+ | sudo mdadm --detail / | ||
+ | |||
+ | * Show information about raid state, according to the kernel | ||
+ | |||
+ | cat / | ||
+ | |||
+ | ===== General Raid Operations ===== | ||
+ | |||
+ | ==== Drive needs to be readded ==== | ||
+ | |||
+ | sudo mdadm --manage /dev/md0 --re-add / | ||
+ | |||
+ | ==== Add new Drive ==== | ||
+ | |||
+ | add the new disk to the collection and grow the array | ||
+ | |||
+ | mdadm --add /dev/md0 /dev/sd[X] | ||
+ | mdadm --grow /dev/md0 --raid-devices=4 # if there were three disks in the array before, and you've just added the fourth. | ||
+ | |||
+ | ==== Start the Array ==== | ||
+ | |||
+ | mdadm --assemble --scan | ||
+ | mdadm -R /dev/md0 | ||
+ | |||
+ | ==== Swap a Drive ==== | ||
+ | |||
+ | To swap out a disk with a new one in the array run: | ||
+ | mdadm /dev/md0 --add / | ||
+ | |||
+ | ==== Adding an Array to mdadm.conf ==== | ||
+ | |||
+ | mdadm --examine --scan >> / | ||
+ | |||
+ | ==== Permanently remove a drive from an array ==== | ||
+ | |||
+ | mdadm /dev/md1 --remove <raid element> | ||
+ | mdadm --zero-superblock <raid element> | ||
+ | | ||
+ | |||
+ | ===== Optimizing the Filesystem ===== | ||
+ | |||
+ | Note: this only applies to striping such as raid 0, 5, 6. | ||
+ | |||
+ | To ensure maximum speeds from the array do the following. | ||
+ | |||
+ | * Use to obtain the 'RAID stride' | ||
+ | |||
+ | dumpe2fs < | ||
+ | |||
+ | * Run the following command and note the 'Chunk Size' | ||
+ | |||
+ | sudo mdadm --detail <raid device> | ||
+ | |||
+ | * https:// | ||
+ | * Stride size = [RAID chunk size] / [Filesystem block size] | ||
+ | * Stripe width = [ Stride size ] * [ Number of data-bearing disks] | ||
+ | |||
+ | sudo tune2fs -E stride=128, | ||
+ | |||
+ | ===== Adding drive to Raid Array with GPT Partiton ===== | ||
+ | |||
+ | * We need a bios boot partition and an Raid partition | ||
+ | |||
+ | < | ||
+ | $ parted /dev/sdx | ||
+ | (parted) mklabel gpt | ||
+ | (parted) mkpart primary 1049KB 3146KB | ||
+ | (parted) set 1 bios_grub on | ||
+ | (parted) mkpart primary 3146kB 2000GB | ||
+ | (parted) print free | ||
+ | Model: ATA WDC WD20EARX-00Z (scsi) | ||
+ | Disk /dev/sdd: 2000GB | ||
+ | Sector size (logical/ | ||
+ | Partition Table: gpt | ||
+ | |||
+ | Number | ||
+ | 17.4kB | ||
+ | | ||
+ | | ||
+ | 2000GB | ||
+ | </ | ||
+ | |||
+ | * Next you need to install grub to the disk. | ||
+ | |||
+ | < | ||
+ | $ grub-install --recheck /dev/sdx | ||
+ | Installation finished. No error reported. | ||
+ | </ | ||
+ | |||
+ | * Finally we need to add the drive to the array. | ||
+ | |||
+ | < | ||
+ | $ sudo mdadm /dev/md0 --manage --add /dev/sdd2 | ||
+ | mdadm: added /dev/sdx2 | ||
+ | $ sudo mdadm --detail --misc /dev/md0 | ||
+ | /dev/md0: | ||
+ | Version : 1.2 | ||
+ | Creation Time : Sat Mar 31 13:09:17 2012 | ||
+ | Raid Level : raid5 | ||
+ | Array Size : 3906776064 (3725.79 GiB 4000.54 GB) | ||
+ | Used Dev Size : 1953388032 (1862.90 GiB 2000.27 GB) | ||
+ | Raid Devices : 3 | ||
+ | Total Devices : 4 | ||
+ | Persistence : Superblock is persistent | ||
+ | |||
+ | Update Time : Sun May 13 03:40:38 2012 | ||
+ | State : clean | ||
+ | | ||
+ | Working Devices : 4 | ||
+ | | ||
+ | Spare Devices : 1 | ||
+ | |||
+ | | ||
+ | Chunk Size : 512K | ||
+ | |||
+ | Name : zoidberg: | ||
+ | UUID : a69274c7: | ||
+ | | ||
+ | |||
+ | Number | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | </ | ||
+ | |||
+ | * At this point the disk is a hot spare. To expand the array onto it you'll need to run the following. | ||
+ | |||
+ | < | ||
+ | |||
+ | ===== GRUB ===== | ||
+ | |||
+ | ==== Reinstall Grub with raid and lvm ==== | ||
+ | |||
+ | This is a guide to reinstall grub on an lvm and raid setup. My example includes a raid5 of 3 disks: | ||
+ | | ||
+ | /dev/sda | ||
+ | /dev/sdb | ||
+ | /dev/sdc | ||
+ | |||
+ | Let's start :) | ||
+ | |||
+ | * Run through the live disk install until you reach " | ||
+ | * Mount the root filesystem | ||
+ | |||
+ | mount / | ||
+ | |||
+ | * If you have a separate boot and usr partitions you will also need to do | ||
+ | |||
+ | mount / | ||
+ | mount / | ||
+ | |||
+ | * Bind mount the important filesystems | ||
+ | |||
+ | for i in /dev /dev/pts /proc /sys; do mount --bind $i /mnt$i; done | ||
+ | |||
+ | * Chroot into your now mounted install | ||
+ | |||
+ | chroot /mnt /bin/bash | ||
+ | |||
+ | * Ensure the assembled array matches your old mdadm.conf | ||
+ | |||
+ | cat / | ||
+ | mdadm --assemble --scan | ||
+ | |||
+ | * Ensure all you drives are listed in / | ||
+ | |||
+ | (hd0) / | ||
+ | (hd1) / | ||
+ | (hd2) / | ||
+ | |||
+ | * run update-grub to generate a new grub.cfg | ||
+ | |||
+ | update-grub | ||
+ | |||
+ | * Run grub-install on each disk to reinstall grub onto them. This should ensure that any of the disks can boot the machine | ||
+ | |||
+ | grub-install /dev/sda | ||
+ | grub-install /dev/sdb | ||
+ | grub-install /dev/sdc | ||
+ | |||
+ | * Finally, just to be nice, unmount all the filesystems | ||
+ | |||
+ | for i in /sys /proc /dev/pts /dev /mnt/boot /mnt/usr /mnt; do sudo umount /mnt$i; done | ||
+ | |||
+ | * Cross you fingers and reboot | ||
+ | |||
+ | reboot | ||
+ | |||
+ | ==== Extra Stuff ==== | ||
+ | |||
+ | === Debugging === | ||
+ | |||
+ | * Call grub-install with --debug | ||
+ | * Call grub-mkimage with --verbose | ||
+ | * Call grub-mkdevicemap with --verbose | ||
+ | * Call grub-mkconfig by calling it via bash like so: ''/ | ||
+ | |||
+ | === Building and installing your own grub image === | ||
+ | |||
+ | * This is the process grub-install should be doing for you. | ||
+ | |||
+ | grub-mkimage -O i386-pc --output=/ | ||
+ | biosdisk ext2 mdraid raid raid5rec lvm | ||
+ | |||
+ | * The names at the end are modules found is ''/ | ||
+ | |||
+ | * To install the image on /dev/sda run | ||
+ | |||
+ | grub-setup --verbose --directory=/ | ||
+ | |||
+ | ==== Speed up rebuid ==== | ||
+ | |||
+ | * Increase the target sync speed when the array is in use.< | ||
+ | |||
+ | * Increase the read ahead.< | ||
+ | |||
+ | * Increase the cache size to 32MiB< | ||
+ | |||
+ | ==== Bugs ==== | ||
+ | |||
+ | * When resizing some arrays you may get < | ||
+ | [ 4780.597961] md: couldn' |