Colocation,
building a server, and installing Linux OS. 2008 Project Notes |
Comments 1) Buying Server 2) Building Server 3) Linux Webserver --What is.. --Location --Tech Talk --Reseller --Router --Switch --KVM --Firewall --Power |
Linux.......Drive partitions
First, lets go over some basics. Unless you are a power user with unmatched skill at playing with devices, your software RAID linux solution will not support HotSwap. And most likely your onboard built in SATA controller does not either. That is okay, you can still hot swap drives, you will just have to 're-add' them to your array.
I searched high and low for a tutorial on how to set up a webserver with a raid 1 array and a hot spare, all bootable. No real tutorial is out there and the few that are there are very vague and do not deal with bootable partitions. As far as I know, this is the only tutorial like it online...whoo hooo.
In this section I shall show you:
- How to set up your raid 1 array Mirror and hot spare
- how to add LVM for partitioning
- How to re-add drives to your array after losing them
- Make all drives in your array bootable
- Make sure your bios works for you.
- How to add a blank Drive to your Array to replace a broken one
Before install, I had to go into the bios and change the settings of my onboard sata card. I called the manufacturer to make sure what to do, you should too. Default settings are not always cool. I changed this onboard device from compatible to enhanced and then enabled AHCI. This is very important to do or you could have small issues with your drives later, or even right away.
Note 2: It takes a long time for the two drives of the mirror array to sync up the first time. Hour or more. So do not be surprised and just let it do it. Once it is done the comp will be faster and work fine. Just takes a while and actually does it during set up.
Once you have started the install, you eventually come to a screen that asks about partitions. Assuming this is your first install this is what you will do.
1- No matter what option you pick for partitions on the drop down, make sure all drives are selected and you have clicked the box next to review your partitions Then click next. This will bring you to the partitioning section of the installation program.
2- Inside the box with all the drives listed you will see a whole bunch of preset partitions. Selecting any LVM groups/volumes first, start deleting these partitions. Then start deleting any partitions listed on the drives until they all say 'free space'.
So far, so good, easy huh?
3- Click the RAID button and select add raid partition. Deselect all drives except you first one 'sba' or the a drive. Select fixed size of 100 or 102MB. Click okay
4- Do the same thing as # 3 except for the following. Select 'use remaining space' instead of fixed space. Click okay.
5- Now click the RAID button again and select 'clone' option. In the screen that comes up you will have two boxes. The left box has your drive sdahighlighted. Using the ctrl button, highlight your b and c drive in the rigth box by clicking on them. Click okay.
6- at this point you will now see all three drives listed, each with two raid partitions, one of 100MB and the other with all remaining space.
7- Click RAID button again. Select 'make raid device'. You should use the dropdown to select /boot as the mount, make sure you select RAID1 from the drop down, and uncheck all but the 3 100MB raid partitions in the list of drives that shows up. Make sure you select '1' for SPARES. Click okay.
8- Click RAID again. Select 'make raid device'. This time using the second drop down, select Physical drive or LVM/PV. Select RAID 1, There should only be 3 drives listed in the drive area, and all should have a lot of space on them. Make sure you select '1' for SPARES Click okay.
You should now have two RAID devices listed above your list of hard drives. Good. Almost there.
9- Select the LVM button (next to the raid button). This will bring up the LVM selection process and will automatically deal with your RAID device with the physical drive setting. This will make a LVM group. There should be an 'add' button where you can press that and start adding partitions inside of it. When done adding partitions, you can then click okay.
Note: Adding partitions can be difficult to know what to do, but with LVM you can always go back later in Linux and move them around in size, add them, or even delete them without redoing the entire raid. You can even leave free space if you like.
What I did....
/ (root) 4 gb - this is the guys of the kernel and stuff
/tmp 4gb temp files uploaded, lots of room incase server is busy
/home all remaining space (about 214 gb) - this is for user websites and stuff
/usr - 4gb, believe this to be for extra software and stuff for later add ons
swap 4gb incase server gets overloaded, swap memory kicks in
/var 10gb logs, mail, and other stuff here, room for growth
These amounts are not a science, just a guess. No one knows except you what you need, and you will not know that until you start running the server a lot.
Okay, we now have a RAID1 array, with one spare drive. Each disk has a boot and a large area partition in it. Click 'next' and if there are no errors, continue with installation.
At this point, go to my 'Installing Packages' link to see what to do about a webserver. Then come back after installation complete.
After installation is done you will notice two of the drives are running like crazy. What is happening is the b drive is becoming the mirror drive and the data is being migrated to the raid partitions. In the 250 GB hard drives that I used this took an hour. Do not DICK AROUND WITH YOUR DRIVES until all this is done, just walk away and come back later. You can opt to do other things with linux at this time, just do not mess with the drives.
Commands: You can use a command line ' cat /proc/mdstat ' and it will show you the progress and show all the drives. This is good and checks whether all three are there or not. It has a acsii meter to show you when it will be done migrating. There should be a '(S)' by one of the drives for each raid device you have (in this case two).
Making them all bootable - You want to make them bootable. Why? If one fails, the other drives will take over and the spare will come to life. But if you reboot the machine it will hang and not boot. Stupid to have the array this way, so it will take some modifications to make this a good failsafe array.
The quick unexplained method first.
From the root prompt, type " grub ", then follow
the example below
grub>find /grub/stage1
(this will list your drives like (hd0,0), (hd1,0), etc)
For b and c drives repeat the three commands
below
Grub>device (hd0) /dev/sdb
Grub>root (hd0,0)
Grub>setup (hd0)
( but add sdc where sdb is to do c drive.)
For
full discourse, go here (Dell expert tells us how to do it!!)
upon reboot, your drives are now all bootable in case one fails..
BIG CAUTION: You should wait until the drives 1 and 2 finish mirroring. Then do the grub for drive 2. Drive 3 may or may not work with grub. If it does not for some reason I think you may have to copy the files and directories from the boot raid partition to the 3rd drive (since nothing was ever copied to it to begin).
Adding a drive back into the mix if you pulled it out via hot swap
So, you pulled a drive out to check the hot swap. Guess what, it is not recognized by the array anymore and is ignored. This is a good way to check if the hotspare is working. But now what do you do with the drive you put back in?
Each drive is labeled sda, sdb, sdc on my system. There are two raid devices on the array, one a boot and one the big physical one. on mine they are labeled as md0 and md1 (0 and 1). So when we are working on a raid on a drive we would say sbc2 (second raid device on 'c'..sbc drive).
Assuming the sda drive is our functioning one, and I took out both b and c drives, we will add b and c back in the mix.
mdadm /dev/md0 --add /dev/sdb1
mdadm /dev/md1 --add /dev/sdb2
The sdb drive should immediately start its migration. Should
take about an hour depending on your system.
Now add the spare back in., sbc.
mdadm /dev/md0 --add /dev/sdc1
mdadm /dev/md1 --add /dev/sdc2
Doing ' cat /proc/mdstat ' will show you all three drives are there, one with the (S) for spare and the other in the middle of migrating.
Now you have your RAID array set up, have LVM partitions you can adjust later as you need them, can recover from pulled out disks, and all disks are now bootable. Congratulations, you are done with the whole disk thing.
Final Issue. Adding a new drive into the mix to replace broken one
So, you pulled a drive out because it was broken and need to replace it. You also want it to be part of the mirror array and need to copy the partitions of the existing one to it before you add it to the array. Sounds frightening.
1- take out old drive and make sure the other two are mirroring, the new drive you will add will be the hotspare now. (this is called rotation by the way)
2- Insert new drive.
3- in the command prompt, type fdisk -l (that is an L). This should give you a list of drives and partitions. The new disk should be there too with one partition or none. This will give you the 'drive designation' if you do not know it.
4- CAUTION Make sure before you do number 5 that you now which drive is the new one sda, sdb, or sdc
5- type " sfdisk -d /dev/sda | sfdisk /dev/sdb " This is supposed to copy the partition table from disk a to disk b (insert your actual drives for a and b inthe example).
6- use fdisk -l to see if the new drive has all the proper partitions.
7- if everything is fine, use the above method via mdadm to add the new 'spare' into the array. It should automatically make it the spare drive.
Using the new drive for the spare ensures the older drives are used as much as possible until you replace them and your back ups will be tip top and not a very old drive. Rotation works like tires for your car. Would you like your spare tire to be a brand new radial ready to go 60,000 miles or a retreaded old worn tire ready to get you to the gas station to replace it? I would feel better having the new tire so I do not have to worry when I use it.