Installing Arch Linux with Software RAID and SSH

Posted on December 9th, 2008


I’ve recently installed arch linux.

It seems fast since It’s lightweight and simple.

I referred the documentations below and modified to adjust my system.

http://wiki.archlinux.org/index.php/Installing_with_Software_RAID_or_LVM#Partition_the_Hard_Drives

http://wiki.archlinux.org/index.php/SSH#Installing_OpenSSH

Here is what I’ve done for installing arch linux with software RAID1 and SSH

Outline

Just to give you an idea of how all this will work, I’ll outline the steps. The details for these will be filled in below.

  1. Boot the Installer CD
  2. Partition the Hard Drives
  3. Create the RAID Redundant Partitions
  4. Create and Mount the Main Filesystems
  5. Install and Configure Arch
  6. Install Grub on the Primary Hard Drive
  7. Unmount Filesystems and Reboot
  8. Install Grub on the Alternate Boot Drives
  9. Archive your Filesystem Partition Scheme

Procedure

Boot the Installer CD

First, load all your drives in the machine. Then boot the Arch Linux 0.7 Full installation CD.

At the syslinux boot prompt, hit enter: we want to use the SCSI kernel, which has support for RAID and LVM built in.

So far, this is easy. Don’t worry, it gets harder.

Partition the Hard Drives

We’ll use fdisk to do this partitioning. We want to create 3 partitions on each of the three drive:

Partition 1 (/boot): 100MB, type FD, bootable
Partition 2 (swap): 8000MB, type FD

Partition 3 (/): : 70GB, type FD (rest space)

First run:

# fdisk /dev/sda

/dev/sda1 make it bootable 100MB size
/dev/sda2 (SWAP) twice ram size
/dev/sda3 / (rest of space to root /)

change type to "fd" "Linux raid autodetect" on all 3 partitions

“w”  write the changes

this is it for sda partitioning.

Create the same exact partitions on each disk. If a group of partitions of different sizes are assembled to create a redundant RAID partition, it will work, but the redundant partition will be in multiples of the size of the smallest one, leaving the rest of the allocated drive space to waste.

You could use

sfdisk -d /dev/sda | sfdisk /dev/sdb

fdisk /dev/sdb <– confirm it looks like sda

Load the RAID Modules

Before using mdadm, you need load the modules for the RAID levels you’ll be using. In this example, we’re using levels 1, so we’ll load this. You can ignore any modprobe errors like "cannot insert md-mod.ko: File exists". Busybox’s modprobe can be a little slow sometimes.

# modprobe raid1

Create the RAID Redundant Partitions

Now that you’ve created all the physical partitions, you’re ready to set up RAID. The tool you use to create RAID arrays is mdadm.

To create /dev/md3 (/):

# mdadm --create --verbose /dev/md3 --level=1 --raid-devices=2 /dev/hda3 /dev/hdb3

To create /dev/md1 (/boot):

# mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/hda1 /dev/hdb1

To create /dev/md2 (swap):

# mdadm --create --verbose /dev/md2 --level=1 --raid-devices=2 /dev/hda2 /dev/hdb2

At this point, you should have working RAID partitions. When you create the RAID partitions, they need to sync themselves so the contents of all three physical partitions are the same on all three drives. The hard drives lights will come on as they try to sync up. You can monitor the progress by typing:

# cat /proc/mdstat

You can also get particular information about, say, the root partition by typing:

# mdadm --misc --detail /dev/md3

You don’t have to wait for synchronization to finish — you may proceed with the installation while syncronization is still occurring. You can even reboot at the end of the installation with synchronization still going.

you need to enable RAID support . RAID1 in this case.

# modprobe raid1

Create and Mount the Filesystems

To create /boot:

# mkfs.ext3 /dev/md1

To create swap space:

# mkswap /dev/md2
# mkswap /dev/md2

To create /:

# mkfs.ext3 /dev/md3

Now, mount the boot and root partitions where the installer expects them:

# mount /dev/md3 /mnt
# mkdir /mnt/boot
# mount /dev/md1 /mnt/boot

We’ve created all our filesystems! And we’re ready to install the OS!

Install and Configure Arch

This section doesn’t attempt to teach you all about the Arch Installer. It leaves out some details here and there for brevity, but still seeks to be basically follow-able. If you’re having trouble with the installer, you may wish to seek help elsewhere in the Wiki or forums.

Here’s the walkthrough:

  • Type /arch/setup to launch the main installer.
  • Select < OK > at the opening screen.
  • Select 1 CD_ROM to install from CD-ROM (or 2 FTP if you have a local Arch mirror on FTP).
  • If you have skipped the optional step (Create and Mount the Filesystems) above, and haven’t created a fileystem yet, select 1 Prepare Hard Drive > 3 Set Filesystem Mountpoints and create your filesystems and mountpoints here
  • Now at the main menu, Select 2 Select Packages and select all the packages in the base category, as well as the mdadm and lvm2 packages from the system category. Note: mdadm & lvm2 are included in base category since arch-base-0.7.2.
  • Select 3 Install Packages. This will take a little while.
  • Select 4 Configure System:

Add the raid hook to the HOOKS list in /etc/mkinitcpio.conf (before ‘filesystems’, NOT after). See Configuring mkinitpcio using RAID for more details.

Edit your /etc/fstab to contain the entries:

/dev/md3                /       ext3        defaults        0       1
/dev/md2                swap    swap            defaults        0       0
/dev/md1                /boot   ext3        defaults        0       0

At this point, make any other configuration changes you need to other files.

Then exit the configuration menu.

Since you will not be installing Grub from the installer, select 7 Exit Install to leave the installer program.

Then specify the raid array you’re booting from in /mnt/boot/grub/menu.lst like:

 # Example with /dev/array/root for / & /dev/md1 for /boot:
   kernel /kernel26 root=/dev/md3 ro  md=1,/dev/hda1,/dev/hdb1 md=3,/dev/hda3,/dev/hdb3

Install Grub on the Primary Hard Drive (and save the RAID config)

This is the last and final step before you have a bootable system!

As an overview, the basic concept is to copy over the grub bootloader files into /boot/grub, mount a procfs and a device tree inside of /mnt, then chroot to /mnt so you’re effectively inside your new system. Once in your new system, you will run grub to install the bootloader in the boot area of your first hard drive. Then we save our new RAID configuration in /etc/mdadm.conf so it can be re-assembled automatically after we reboot.

Copy the GRUB files into place and get into our chroot:

# cp -a /mnt/usr/lib/grub/i386-pc/* /mnt/boot/grub
# sync
# mount -o bind /dev /mnt/dev
# mount -t proc none /mnt/proc
# chroot /mnt /bin/bash

At this point, you may no longer be able to see keys you type at your console. I’m not sure of the reason for this (NOTE: try “chroot /mnt /bin/<shell>”), but it you can fix it by typing reset at the prompt.

Once you’ve got console echo back on, type:

# grub

After a short wait while grub does some looking around, it should come back with a grub prompt. Do:

grub> root (hd0,0)
grub> setup (hd0)
grub> quit

Now you need to save our RAID configuration so it can be re-assembled automatically each time we boot. Previously, this was an unnecessary step in Arch because the RAID drivers were built in to the kernel. But when loaded after the kernel boots (as modules), arrays are not autodetected. Hence this configuration file.

The default /etc/mdadm.conf should be pretty much empty (except for a lot of explanatory comments). All you need to do is capture the output from an mdadm query command and append it to the end of mdadm.conf.

# mdadm -D --scan >>/etc/mdadm.conf

That’s it. You can exit your chroot now by hitting CTRL-D or typing exit.

Reboot

The hard part is all over! Now remove the CD from your CD-ROM drive, and type:

# reboot

Install Grub on the Alternate Boot Drives

Once you’ve successfully booted your new system for the first time, you will want to install Grub onto the other two disks (or on the other disk if you have only 2 HDDs) so that, in the event of disk failure, the system can be booted from another drive. Log in to your new system as root and do:

# grub
grub> device (hd0) /dev/hdb
grub> root (hd0,0)
grub> setup (hd0)
grub> device (hd0) /dev/hdc
grub> root (hd0,0)
grub> setup (hd0)
grub> quit

Installing OpenSSH

pacman -Sy openssh

Configuring the SSH server

To configure you must edit the configuration file:

su -c ‘nano /etc/ssh/sshd_config’

You may want to change the default port from 22 to any higher port (see security through obscurity).

Even though the port ssh is running on, could be detected by using a port-scanner like nmap, changing it will reduce the number of log entries caused by automated authentication attempts.

Allowing others in

Note: You have to adjust this file to remotely connect to your machine since the file is empty by default

To let other people ssh to your machine you need to adjust /etc/hosts.allow, add the following:

# let everyone connect to you sshd: ALL # OR you can restrict it to a certain ip sshd: 192.168.0.1 # OR restrict for an IP range sshd: 10.0.0.0/255.255.255.0 # OR restrict for an IP match sshd: 192.168.1.
Now you should check your /etc/hosts.deny for the following line and make sure it looks like this

ALL: ALL: DENY
That’s it. You can SSH out and others should be able to SSH in :)
To start using the new configuration, restart the daemon:

su -c ‘/etc/rc.d/sshd restart’

Managing SSHD Daemon

Just add sshd to the “DAEMONS” section of your /etc/rc.conf:

DAEMONS=(… … … … … sshd … … …)

To start/restart/stop the daemon, use the following:

/etc/rc.d/sshd {start|stop|restart}


You’re done! I hope you’ve succeeded in setting up Arch Linux on your server with RAID and SSH