ISCSI/Boot

From ArchWiki
< ISCSI
Revision as of 14:29, 29 April 2011 by Hsuanyeh (talk | contribs)
Jump to navigation Jump to search


Server / Target Setup

You can set up an iSCSI target with any hosting server OS. You may follow below procedure if you use Arch Linux as the hosting server OS.

You will need iscsi-kernel and iscsi-usr from the AUR, make sure you've got the dependencies.

wget http://aur.archlinux.org/packages/iscsitarget-kernel/iscsitarget-kernel.tar.gz
wget http://aur.archlinux.org/packages/iscsitarget-usr/iscsitarget-usr.tar.gz

tar xzvf iscsitarget-kernel.tar.gz
tar xzvf iscsitarget-usr.tar.gz

cd iscsitarget-kernel
makepkg
pacman -U iscsitarget-kernel...pkg.tar.xz

cd ../iscsitarget-usr
makepkg
pacman -U iscsitarget-usr...pkg.tar.xz

Create the Target

Modify /etc/iet/ietd.conf accordingly

Hard Drive Target

Target iqn.2010-06.ServerName:desc
Lun 0 Path=/dev/sdX,Type=blockio

File based Target

Use "dd" to create a file of the required size, this example is 10GB.

dd if=/dev/zero of=/root/os.img bs=1G count=10
Target iqn.2010-06.ServerName:desc
Lun 0 Path=/root/os.img,Type=fileio

Start server services

/etc/rc.d/iscsi-target start

Also you can "iscsi-target" to DAEMONS in /etc/rc.conf so that it starts up during boot.


Client / Initiator Setup

Install over iSCSI

Note: For running shell commands during install press Template:Keypress+Template:Keypress to switch between ttys.
Note: If you use Virtualbox, press Template:Keypress+Template:Keypress to switch between ttys, where Template:Keypress is normally the Template:Keypress key.

Download Arch Linux ISO image [1] and boot Arch Linux using the ISO image. After Arch Linux is booted, login as "root" and type "/arch/setup" to bring up the installer. Either use net as the install source or manually ifconfig and dhcp.

Now before you continue to "Prepare Hard Drive(s)" install open-iscsi and connect to target.

Be sure to your servers IP address, Name, etc.

wget http://aur.archlinux.org/packages/open-iscsi/open-iscsi.tar.gz

tar xzvf open-iscsi.tar.gz

cd open-iscsi

pacman -Sy

pacman -S patch make gcc

makepkg --asroot

pacman -U open-iscsi...pkg.tar.xz

modprobe iscsi_tcp

iscsistart -i iqn.2010-06.ClientName:desc -t iqn.2010-06.ServerName:desc -g 1 -a 192.168.1.100

During the above procedures, if "pacman -Sy" asks you to upgrade pacman, answer "no" otherwise pacman may fail to install patch, make, and gcc, which are essential to the compilation of the open-iscsi source.

If you want to make sure that your iSCSI target is up and running, you may start "iscsid" and check whether the iSCSI target is available.

# iscsid
# iscsiadm -m discovery -t sendtargets -p <server-IP>

Continue to prepare the hard drive, using the iSCSI target drive. It is suggested that you manually create a partition that uses the entire iSCSI target drive.

Note: When you "Manually Configure block devices, filesystems and mountpoints" make sure that you use UUID. This way there won't be any issues booting if the number of devices changes (/dev/sda /dev/sdb ...) by adding or removing hard drives, usb thumb drives, etc... or booting it on different machines.
Note: It is recommended that you NOT include swap on the iSCSI drive when creating the partitions, you can just ignore the warning.

Before you "Configure System" you must install open-iscsi to the "future" root filesystem, and download and install the hook for booting from iSCSI. This should be done after all selected packages are installed.

Create these hook files, replacing the IP, etc. You may create these hook files after open-iscsi is installed to the "future" root filesystem.

1. /mnt/lib/initcpio/install/iscsi: It should look like the following.

# vim: set ft=sh:

install ()
{
    MODULES="iscsi_tcp libiscsi libiscsi_tcp scsi_transport_iscsi crc32c $(checked_modules "/drivers/net/") "
    BINARIES="/sbin/iscsistart"
    FILES=""
    SCRIPT="iscsi"
}

help ()
{
cat <<HELPEOF
  This hook allows you to boot from an iSCSI target.
HELPEOF
}

2. /mnt/lib/initcpio/hooks/iscsi: It should look like the following.

# vim: set ft=sh:

run_hook ()
{
    modprobe iscsi_tcp
    ifconfig eth0 192.168.1.101 netmask 255.255.255.0 broadcast 192.168.1.255
    sleep 10
    iscsistart -i iqn.2010-06.ClientName:desc -t iqn.2010-06.ServerName:desc -g 1 -a 192.168.1.100
}

If you want to use dhcp for the above script, you may try to replace the "ifconfig" line with "dhcpcd eth0".

Now, you can install open-iscsi into the "future" root filesystem.

mv open-iscsi...pkg.tar.xz /mnt/root

chroot /mnt/ /bin/bash

cd /root/

pacman -U open-iscsi...pkg.tar.xz

Now you can create the above hook files by pasting the above scripts.

nano /lib/initcpio/install/iscsi

nano /lib/initcpio/hooks/iscsi

exit

Now you are ready to "Configure System." Most of the configuration files can remain unchanged.

Add "iscsi" to the HOOKS in /etc/mkinitcpio.conf. The "mkinitcpio" will generate a new kernel image after you are done with "Configure System."

Note: If you plan on booting this installation of Arch on machines with nic cards that require different modules, remove "autodetect" from HOOKS
Note: Rebuilding the initial ramdisk will take some time if autodetect is removed from HOOKS

When configuring grub find the lines for Arch that are

root (hdX,0)

and change to

root (hd0,0)