Archive

Archive for the ‘Ubuntu’ Category

Linux RAID

November 18th, 2009 azlon Comments off

Recently one of the guys that works next to me got me hooked on ripping full DVDs instead of converting them to XviD (AVI) format. The pros include the video quality is better and you get all the special features. Cons are that each DVD is between 4 and 8GB for 4-6 shows.

I was already running out of space on my 2x 1TB drives so I decided to go all out and build a server with 4x 1TB drives and 2x 500GB drives. I made the 4x 1TB drives into a RAID-5 for a total of 3TB usable space but with redundancy so I don’t lose all my content if one of the drives fails. The 500GB drives were put into a RAID-1 (mirrored) which is where I keep my pictures and important documents.

Once the server was up and running I wanted to be able to share those drives with my Windows machines so I could watch the movies/TV shows in any room from Media Center. This was another issue since Windows doesn’t nativly support the ext file system which Linux uses. For this I ended up using Samba for simple network sharing, and mkfs.ntfs which allows Linux to read/write NTFS file systems.

Digging around the internet it took me about 2 days to get all the information about how to get the system working exactly how I wanted it. Here are the steps I followed.

Part 1: Creation of the RAID

Start by installing all of the required software

$ sudo apt-get install samba
$ sudo apt-get install mdadm
$ sudo apt-get install mkfs.ntfs

Samba is for user authenticated sharing made simple. Mdadm is used to create and manage the RAID systems and mkfs.ntfs allows Linux to read/write to an NTFS system.

Next we need to find out what disks are available and what their labels are. This is needed for when the RAID is actually created. For this tutorial I will be showing the steps for making a 4TB RAID-5 (4x 1TB HDDs).

Start by finding out which drives we will be using.

$ cat /proc/diskstats

This command will display the hard drives connected to the computer. For this tutorial I will be using /dev/sda, /dev/sdb, /dev/sdc, and /dev/sdd.

Next run fdisk for each of the drives to partition, set type to RAID, and format.

$ fdisk /dev/sda

Press nспални and enter to create a new logical partition. Remember the cylinders used because each disk needs to be the exact same size. Next press p for primary partition and 1 to create partition 1. Next it will ask you for the start and stop partitions. Just accept the default for both. Next press t for type and fd for RAID. This defines the drive as part of a RAID. Finally press w to write the changes to the drive.

Repeat these steps for the other drives (sdb, sdc, and sdd).

Once you have all of the drives partitioned and defined as a RAID you need to create the software RAID in Linux.

To do this run the following command:

$ sudo madadm --create --verbose /dev/md0 --level=5 --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1

This will create the RAID in /dev/md0 as a level 5 using 4 drives which are sda1, sdb1, sdc1 and sdd1 (the 1 at the end specifies the partition on the drive).

Now the RAID is being built. This will take a long, LONG time. I like to let this run overnight and continue the next morning. Keep in mind that the bigger the drives, the longer this process will take. You can watch the process status by typing:

$ watch cat /proc/mdstat

Now we need to tell mdadm to manage the RAID. Most sites I read said I only needed to run the command with sudo, but I found that I had to run it as root (sudo -i).

$ sudo -i
$ mdadm --detail --scan >> /etc/mdadm/mdadm.conf

The RAID array is now created and located in /dev/md0. Now we need to format the drive. Normally you would format it using ext3 (mkfs -j) or something similar but since we want to easily access it from our Windows machines we will need to format it with the NTFS file system. Follow the prompts as they are pretty self explanitory. When asked how to format it, choose quick instead of full.

$ sudo mkfs.ntfs /dev/md0

Now the RAID is created, formatted and ready to use. To start accessing it we first need to mount it. I like to put mine in my media folder. Replace RAID5 with whatever you want it to be called.

$ sudo mkdir /media/RAID5

Now we want it to mount automatically when we boot, right? I use gedit but you can also use nano.

$ sudo gedit /etc/fstab

Add this line to the bottom of the file:

/dev/md0 /media/RAID5 auto defaults 0 3

Now when you reboot the drive will be mounted. To mount it immediately instead of restarting type:

$ mount -a

Copy any files you want to the drive. All files will be backed up across the drives so if one fails you don’t loose all of your information.

Part 2:  Folder Sharing

All finished right? Not quite. We still need to be able to access this from our windows machines over the network. Start by setting a network user/pass for the drives. This is usually set to the same user/pass as the current user that is logged in. I didn’t want this since I was running MyMovies which requires all network folders to have the same user/pass.

First turn off user share only so that we can share folders that we don’t own. This way you don’t have to log in as root every time you want to share a folder.

$ sudo gedit /etc/samba/smb.conf

Find [global] and below that enter usershare owner only = false. Now you can share any folder you want to.

Start by making a new username for the shared drive.

Next set the shared folder password for that user (replace $USER with the username if it is different than the current username which is logged in). Leave the password blank if you want to use the same password for that username. If you want a different password than what they log in with, replace <password> with it. Here is the guide which may answer any questions.

$ sudo smbpasswd -a $USER <password>

Now share the folder

Part 3: Copying Files

http://sonniesedge.co.uk/?p=80

http://mywheel.net/blog/index.php/software-raid-in-ubuntu/

Categories: Blog, Ubuntu, Video Tags: , , , ,