Ever since I installed an SSD in my Macbook Pro I have been finding ways to move more and more stuff off of my laptop hard drive. I wanted to move a bunch of rarely needed stuff to a network share at my house including most of my music library. Ideally I also wanted to be able to play the network stored music from my laptop when on my home wifi.
There are a lot of network attached storage options out there now but they are a bit expensive and have arbitrary limitation mixtures in the software. Plus Lindsey was not keen on me spending more money on gadgets.
Instead I looked at the random gear I had around the house and was able to quickly get raided network storage setup for no cost that is more flexible than most of what you can buy. Nothing new here, this is a pretty familiar setup. It just worked out well for me so wanted to share.
I had the following to work with:
- An old Dell laptop purchased about 4-5 years ago. 2GB of ram, I don’t know any of the other specs.
- The cheap WRT54GS Linksys router I was already using at the house.
- A couple 500 GB external hard drives.
That isn’t much but I imagine many people have a similar combination just lying around. Most of my extra gear (including the last desktop I owned) got absorbed when the company was starting up.
Here’s the steps to set this up for yourself.
[1] Put DD-WRT on the router
The big items I wanted were reserved DHCP (so I could reserve an IP for the new “server”) and VPN (so I could connect remotely to my home network). DD-WRT offers both of these along with loads of additional features. It makes the stock Linksys firmware look like garbage in comparison.
My WRT54GS is an especially cheap router with a tiny amount of memory so I had to install the pared down “micro” version of DD-WRT but it still works great.
For help and information on DD-WRT go visit their site. You can enter your specific router model number and get the exact files you need along with specific instructions. Its really easy to do.
[2] Put Arch Linux on the laptop
Arch Linux is a preference thing but I do believe it is the best Linux distribution. I use it on all of our servers at work now and am glad Sean told me about it. Since in this setup I am creating a dedicated server out of the old laptop and don’t plan to ever use it directly Arch is a perfect fit - just do a base install. No need for x windows or any of that cruft. Arch makes installing things so incredibly easy. In 95% of the cases the steps are to grab the software with pacman, add it to the DAEMONS array in rc.conf (if its something that should start on its own on reboot), and then start it.
Obviously you can use a different Linux distribution if you would prefer but subsequent content below assumes Arch.
To get Arch or to view their fantastic wiki and documentation go to archlinux.org.
At this point I gave the Arch server’s mac address an IP reservation in DD-WRT. That’s optional but I would highly recommend either doing that or using a static IP.
[3] Connect external drives to laptop and raid them
SSH into the Arch server and plug the drives in. The faster the hard drive connection the better but honestly for stuff you are going over a network for it doesn’t really matter. Your laptop hard drive is probably going to be /dev/sda and your plugged in external drives are probably going to be /dev/sdb and /dev/sdc. I am making that assumption in the following, you can ls -l /dev/sd* to verify what is showing up. On my machine the external drives showed up as “storage” (for the group permission) while the laptop drive was “disk”.
Install mdadm with pacman -Sy mdadm. This is for the software raid. Also install parted with pacman -Sy parted. This is what I use for partitioning instead of fdisk. For more information about mdadm read the wikipedia page which has good tutorials and more information in the external links section.
Now, assuming /dev/sdb and /dev/sdc for the external drives as mentioned above do the following. This is all done as root.
- Partition the first drive. Type
parted /dev/sdband you will get the parted prompt. - From the parted prompt type
mklabel gpt. - Type
mkpart primary 0 100%. - Type
quitto leave the parted prompt. - Now partition the second external drive in the same way (just do
parted /dev/sdcand repeat the steps). - Create your raid array with
mdadm --create --verbose /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1. This is creating a raid 1 with 2 drives. - Now format your new raid array with
mkfs.ext3 -b 4096 /dev/md0. This will format with the ext3 file system but you could use whatever you wanted instead just as well. - Create a directory wherever you want for mounting the new raided disk. I used
/var/raid_array. That would becd varandmkdir raid_array. - Mount the new disk with
mount /dev/md0 /var/raid_array. The raided disk should be usable now. Do adf -hto make sure it mounted and verify the usable space is what you expected. - Edit
/etc/fstaband add a line containing/dev/md0 /var/raid_array auto defaults 0 1to ensure the new disk gets mounted on reboot. You can obviously change those mount parameters to whatever values you prefer. - If you want, do some benchmarking and consider bumping up readahead on your new raid array. See my last post for information about that and how important it can be. BUT, if these are USB-connected external drives no need to waste time tuning. With software raid at least the OS knows there are two drives involved and so will tune up your readhead to 512. Just wanted to mention it as generally when setting up a raid array (or any decent hard drive) you want to be aware of that setting.
In the above I was assuming the external drives were the same size. If they are not then in the “mkpart” command use a fixed MB amount or smaller percentage for the second number instead of 100%. You could then separately partition any remaining space so it is at least usable if not in the raid.
The above uses raid 1 but mdadm can handle a lot of different configurations, just tweak the “–level” and “–raid-devices” parameters as needed.
At this point you have a raid array usable at /var/raid_array on the laptop “server”.
[4] Setup samba
Your new raid array wouldn’t be much use if you couldn’t easily access it. Use samba to set it up as a network share that all of your home computers can see or use. I’d recommend checking out the consistently awesome Arch Wiki for samba instructions. As with all things Arch, installation and configuration is very straight forward and cruft free. Your mileage may vary on other distributions.
[5] Finish up
From here you can setup whatever you like. Here is what I did.
- Setup an iTunes share so my music on the network just shows up when I am at home. You can do this by setting up a daapd server, check out the wikipedia article about daap for an overview of what it is. There is unfortunately not an Arch Wiki article for this so here are the steps if interested.
- Grab the needed software with
pacman -Sy mt-daapdandpacman -Sy dbus. - Edit
/etc/mt-daapd/mt-daapd.conf. Set the “mp3_dir” to the root location of your music and the “servername” to your server name. You will probably want to add more extensions to “extensions”. I added “.m4a,.m4p,.aac”. - Add dbus, avahi-daemon, and mt-daapd (in that specific order) to the DAEMONS array in rc.conf.
- Start them up in that order with
/etc/rc.d/dbus start,/etc/rc.d/avahi-daemon start, and/etc/rc.d/mt-daapd start. - That is it. Your music should show up in iTunes as a shared library with whatever name you set as “servername” in mt-daapd.conf.
- Setup a backup script that pushes select important items up to s3 each week. I used s3sync to do this but you can use whatever you like. s3sync is straight forward and easy to use in command line scripts. Here is the s3sync site and here is a blog post that describes usage well.
- Setup a basic monitoring script, particularly to watch the status of your raid. You can use
mdadm --detail /dev/md0to get the status of your drives and write a script to parse out the pieces you want. Since this is software raid with random external hard drives you aren’t going to get a nice red LED telling you when a drive is dead. Have it check each morning and email you if things are busted up. If you are sending email in your scripts do apacman -Sy postfixfirst.
Conclusion
The above may look like a lot of steps but it really is more straight forward than it seems. With Arch especially, getting things setup is a snap. This is a cheap solution and isn’t going to be a screamer on performance but it offers a lot of advantages:
- Cost $0 if you have an old laptop and a couple hard drives.
- Even though its a cheap solution you still have complete features (raid, networked, iTunes share, plus whatever else you install on the server).
- Can be easily expanded with additional drives, software raid in general offers a lot of flexibility and easy monitoring.
- Laptops actually make decent home servers because they have batteries in them - power outtages aren’t a big deal. On the other hand, your external hard drives will still die so maybe not a huge advantage.
- You have a actual machine on top of the drives so you can easily add whatever server software you want. You can use it as an SSH tunnel, web server, whatever.




