The Linux kernel includes native support for distributing swap space over several disks. Instead of setting up a RAID-0 device and directing swap to it, you simply add all swap partitions to /etc/fstab and use the swapon -a to activate them all. The kernel uses striping (RAID-0) for them. Here's a sample setup:
/dev/sda3 none swap sw /dev/sdb3 none swap sw /dev/sdc3 none swap sw
Setting up RAID for normal file systems such as /var, /home or /usr is quite simple. After you have partitioned your disks, instruct the RAID subsystem on how to organize the partitions. This information is copied to /etc/mdtab for later activation. It can be done by issuing the following command:
mdcreate -c4k raid0 /dev/md0 /dev/sda1 /dev/sdb1\ /dev/sdc1
If you want to use RAID level 1, 4 or 5, you have to use an additional configuration file that reflects the disk setup as shown in Listing 1. These levels are more complicated and need a special signature on top of the compound device. This signature is generated by the mkraid command. The remaining setup looks like this:
mkraid /etc/raid/raid5.conf mdcreate raid5 /dev/md1 /dev/sdd1 /dev/sde1\ /dev/sdf1 /dev/sdg1 /dev/sdh1
Now two RAIDs have been created; the first consisting of three partitions, while the second uses five of them. Depending on the data to be stored on them, different chunk sizes have been selected. The next step is to activate these devices with the command:
mdadd -arFrom now on, you may refer to /dev/md0 and /dev/md1 as block devices that may contain your file systems. In order to use these devices, issue this command during the boot sequence. Please check out the startup sequence of your distribution. Some of them (e.g., Debian) have already included this line.
After the kernel knows how disks are organized, you can create your file system on the new devices and add them to /etc/fstab as usual.
The use of RAID for the root file system is a bit tricky. The problem is LILO can't read and boot the kernel if it is not in a linear fashion on the disk (as it is on EXT2 or MSDOS file systems). The solution is to put the kernel on a different partition with a normal file system and activate RAID after the kernel is booted.
This way, LILO would boot the kernel, but the kernel itself would be unable to mount the root file system because its RAID subsystem isn't initialized yet. Now you're in trouble, right? No.
For late 2.1.x kernels, a kernel parameter can be used to load the kernel from a RAID.
md=< <fault level>,dev0,dev1,...,devn
This needs to be added to LILO using the append= option or directly at the LILO prompt during boot stage. You'll find more information in Documention/md.txt in the Linux source tree.
For stable kernels (2.0.x) and “not so late” development kernels (2.1.x), you need a mechanism to call some programs after the kernel is loaded but before it tries to mount the root file system. This refers at least to mdadd.
The only way to achieve this is to use the initial RAM disk, also known as initrd. General information about initrd may be found in Documentation/initrc.txt inside the kernel source tree.
You will most likely have to compile your own kernel, although you can try the one included with your distribution if it contains all facilities. You'll need to add modules support to the described solution. However, additional kernel compilation options are needed for the described setup and are shown in Listing 2. Additionally, you have to include support for your SCSI card, etc. If you're uncertain about the options, refer to the Kernel-HOWTO and use ? to display a description of the referenced driver.
If the Linux kernel uses initrd, it mounts the given RAM disk as root file system and executes /linuxrc if found. Then the kernel continues its boot process and mounts the real root file system. The old initrd root will be moved to /initrd if that directory is available or will be unmounted if not. If it is only moved, the RAM disk remains in memory. So on systems with little memory, you should get the kernel to remove it entirely when it is no longer needed.
The initrd file is a “simple” root disk, containing all the files needed for executing the /linuxrc file. If it is a shell script, it includes a working shell and all tools used in this script. In order to execute programs, it also includes a working libc with ld.so and tools. Alternatively, you can link the included programs statically and don't need a shared libc. Since this doesn't save any space, it is not necessary.
After RAID has been initialized from /linuxrc, you must tell the kernel where its new root file system resides. At that time, it may be configured to use initrd as the root file system. Fortunately, our fellow kernel hackers have designed another easy interface to set the root file system.
This facility makes use of the /proc file system. The device number of the new root file system must be sent (use echo) to /proc/sys/kernel/real-root-dev, and the kernel continues with that setting after /linuxrc completes.
As LILO normally isn't able to boot from a non-linear block device (such as RAID), you must reserve a small partition with the kernel and initial RAM disk on it. I've decided to use a 10MB partition as /boot. Binaries can be stored in this partition and it can be accessed from a rescue floppy. I wonder why one should use this since Linux is so stable, but for the sake of security it may be a good idea.
10MB is plenty of space for one kernel and a RAM disk of approximately 1MB in size. Currently, my system uses only 2.5MB of this space, so plenty of playing room is available. Due to the fact that /boot uses the normal file system (e.g., EXT2), you can use /etc/lilo.conf to point to /boot/vmlinuz in your setup.
Now you need to decide what to do in your /linuxrc script. Basically, activate RAID and tell the kernel where your root file system resides. Listing 3 shows an example /linuxrc program.
Any block device can be used as the root file system. In the given example, 0x900 is used. This stands for major number 9 and minor number 0, which is the encoding for /dev/md0.
Next, make a list of binaries and additional files needed, including some device files in /dev. To get the /linuxrc script working, you need /dev/tty1. Other necessary devices depend on your /etc/mdtab file. You will need at least /dev/md0.
The above example uses these binaries: ash, mount, umount and mdadd. These files are also needed: mdtab, fstab, mtab and passwd.
The mdtab file I use is shown in Listing 4. For my file, these block devices must be created on the initial RAM disk: /dev/hda2, /dev/hda4, /dev/hdb2, /dev/hdb4, /dev/md0, /dev/md1, /dev/md2 and /dev/md3. Use the mknod command to create these device files. You'll find their major and minor numbers by investigating your /dev directory or by reading Documentation/devices.txt from the kernel's source directory. The following commands create tty1 and md0:
mknod dev/tty1 c 4 1 mknod dev/md0 b 9 0
The best way to create the initial RAM disk is to create the directory /tmp/initrd and install everything you need in it. Once you have done that, determine the used disk space (du -s), then create the initrd file. The following commands will create an initial RAM disk 1MB in size. To use it, your kernel must include support for the loopback device.
dd if=/dev/zero of=/tmp/initrd.bin bs=1024k\ count=1 mke2fs /tmp/initrd.bin mount -o loop /mnt /tmp/initrd.binSince dynamically linked binaries are used, the Linker and the dynamic libraries must also be installed, at least /lib/libc*.so, /lib/ld-linux.so.2, /lib/ld-2.0.*.so and an appropriate /etc/ld.so.config file—appropriate means that /lib should be the only line in the file. Create a new library cache /etc/ld.so.cache file with the command
ldconfig<\!s>-r<\!s>/tmp/initrdand install the needed binaries in appropriate directories: /sbin or /bin.
Don't forget to create the /proc directory, or the mount will fail. The fstab and mtab files can be empty and read-only, but must exist on the initial RAM disk. No program will attempt to write to these two files. For the /etc/passwd file, it's sufficient to include only the root user.
After you have copied everything from /tmp/initrd to the RAM disk mounted at /mnt (see above), unmount it (e.g., with the command umount /mnt) and move the file to /boot/initrd.bin. Now tell LILO to load the kernel and the RAM disk, using a record in /etc/lilo.conf similar to the one shown in Listing 5.
Issue the lilo command, and you are almost done. Since the RAID subsystem is now configured at boot stage before any /etc/init.d scripts are issued, you should disable the mdadd call in the /etc/init.d scripts.
This setup implies you have a running Linux system installed on some non-RAID disk. At least install a small base system on your swap partitions, compile the kernel on a different machine, set up RAID on the appropriate machine, move the files and continue installation afterwards.
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?
|Designing Electronics with Linux||May 22, 2013|
|Dynamic DNS—an Object Lesson in Problem Solving||May 21, 2013|
|Using Salt Stack and Vagrant for Drupal Development||May 20, 2013|
|Making Linux and Android Get Along (It's Not as Hard as It Sounds)||May 16, 2013|
|Drupal Is a Framework: Why Everyone Needs to Understand This||May 15, 2013|
|Home, My Backup Data Center||May 13, 2013|
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- another very interesting
42 min 59 sec ago
- Reply to comment | Linux Journal
2 hours 36 min ago
- Reply to comment | Linux Journal
9 hours 30 min ago
- Reply to comment | Linux Journal
9 hours 46 min ago
- Favorite (and easily brute-forced) pw's
11 hours 37 min ago
- Have you tried Boxen? It's a
17 hours 29 min ago
- seo services in india
22 hours 1 min ago
- For KDE install kio-mtp
22 hours 2 min ago
- Evernote is much more...
1 day 2 min ago
- Reply to comment | Linux Journal
1 day 8 hours ago