Diskless / remote boot with Open-iSCSI

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search

Contents

[edit] Background

It is possible to start a diskless machine remotely using Open-iSCSI on the client side. You have to take care of these things:

This HOWTO explains how to set up your system so that it boots a diskless station using PXE/tftp and Open-iSCSI.

[edit] Creating initrd

Below some theory; for practical examples, see downloads section.

Your initrd has to do the following things:


[edit] Preparing initrd

Note that the below instruction use common tools from your favourite distribution. You may create a similar initrd with busybox/uClibc.

mkdir initrd
cd initrd
mkdir -p bin dev etc lib/modules proc sys sysroot
ln -s bin sbin
bash  cat  chroot  echo  ifconfig  insmod  iscsistart  mount  sleep

You can do it with a following command:

which bash cat chroot echo ifconfig insmod iscsistart mount sleep | xargs -i{} cp {} bin/

If your distribution doesn't ship iscsistart (most distros don't), you have to compile open-iscsi yourself - you'll find there iscsistart.


# ldd bash
       linux-gate.so.1 =>  (0xb7fa6000)
       libtermcap.so.2 => /lib/libtermcap.so.2 (0xb7f9d000)
       libdl.so.2 => /lib/libdl.so.2 (0xb7f99000)
       libc.so.6 => /lib/i686/libc.so.6 (0xb7e6a000)
       /lib/ld-linux.so.2 (0xb7fa7000)


# cd initrd
# chroot .
[I have no name!@localhost /]# mount --help     
(...)
console  sda  sda1  sda2


#!/bin/bash
 
# Load modules
# You may only need to load the network card modules you will use
# To find module dependencies, you can use "modinfo" tool
 
echo "Loading jbd.ko module"
insmod /lib/modules/jbd.ko
# On some kernels, you will need mbcache module if it is not in the kernel
echo "Loading mbcache.ko module"
insmod /lib/modules/mbcache.ko
echo "Loading ext3.ko module"
insmod /lib/modules/ext3.ko
 
echo "Loading libcrc32c.ko module"
insmod /lib/modules/libcrc32c.ko
echo "Loading crc32c.ko module"
insmod /lib/modules/crc32c.ko
 
# Network card modules - start
echo "Loading mii.ko module"
insmod /lib/modules/mii.ko
echo "Loading 8139too.ko module"
insmod /lib/modules/8139too.ko
 
echo "Loading e100.ko module"
insmod /lib/modules/e100.ko
 
echo "Loading e1000.ko module"
insmod /lib/modules/e1000.ko
 
echo "Loading tulip.ko module"
insmod /lib/modules/tulip.ko
 
echo "Loading tg3.ko module"
insmod /lib/modules/tg3.ko
# Network card modules - end
 
echo "Loading scsi_mod.ko module"
insmod /lib/modules/scsi_mod.ko
echo "Loading sd_mod.ko module"
insmod /lib/modules/sd_mod.ko
 
echo "Loading scsi_transport_iscsi.ko module"
insmod /lib/modules/scsi_transport_iscsi.ko
echo "Loading libiscsi.ko module"
insmod /lib/modules/libiscsi.ko
echo "Loading iscsi_tcp.ko module"
insmod /lib/modules/iscsi_tcp.ko
 
 
# Mount /proc and /sys
echo Mounting /proc filesystem
mount -t proc /proc /proc
 
echo Mounting sysfs
mount -t sysfs /sys /sys
 
# We need to extract four command line parameters form /proc/cmdline:
# iscsi_i_ip - local initiator IP address/netmask (i.e. 192.168.111.168/255.255.255.192)
# iscsi_i    - local initiator name (InitiatorName)
# iscsi_t    - remote target name (TargetName)
# iscsi_a    - iSCSI target IP address
 
# Read the kernel cmdline
CMDLINE=$(cat /proc/cmdline)
 
# Find out IP/NETMASK first
TEMPVAR=${CMDLINE#*iscsi_i_ip=}
ISCSI_I_IP=${TEMPVAR%% *}
 
# Find InitiatorName
TEMPVAR=${CMDLINE#*iscsi_i=}
ISCSI_I=${TEMPVAR%% *}
 
# Find TargetName
TEMPVAR=${CMDLINE#*iscsi_t=}
ISCSI_T=${TEMPVAR%% *}
 
# Find iSCSI target IP address
TEMPVAR=${CMDLINE#*iscsi_a=}
ISCSI_A=${TEMPVAR%% *}
 
 
# Bring the network interface up
ifconfig eth0 ${ISCSI_I_IP%/*} netmask ${ISCSI_I_IP#*/}
 
# Connect the iSCSI drive
iscsistart -i "$ISCSI_I" -t "$ISCSI_T" -g 1 -a $ISCSI_A
 
mount -o ro /dev/sda2 /sysroot
 
echo Switching to new root
cd /sysroot
 
# Uncomment "bash" below, and comment out "exec ..." if you are having booting problems.
# It will give you a bash shell with limited tools.
exec chroot . sh -c 'exec /sbin/init'
#bash

[edit] Creating initrd with cpio

Now that you have all the files ready, create initrd image:

find ./ | cpio -H newc -o > ../initrd.cpio
cd ..
gzip -9 initrd.cpio
mv initrd.cpio.gz initrd.img


Next, copy initrd.img to your tftp server.

[edit] Configuring tftp server

Add something like that to a pxelinux.cfg/default file to initiate a remote boot by hand (not recommended):

LABEL remote1
   KERNEL remote/vmlinuz-2.6.17-5mdv
   APPEND initrd=remote/initrd.img iscsi_i=iqn.2007-01.com.example:server.remote1 iscsi_i_ip=10.1.1.165/255.255.255.192 iscsi_t=iqn.2007-01.com.example:storage.remote1 iscsi_a=10.1.1.180

You have to add these parameters to APPEND line appropriately:


It is recommended that you add the above entry to a pxelinux.cfg/aa-bb-cc-dd-ee-ff file; aa-bb-cc-dd-ee-ff being the MAC address of the PC you want to boot remotely with Open-iSCSI / PXE.


[edit] Downloads

Go to downloads page.


[edit] Additional info / troubleshooting

See diskless iSCSI troubleshooting page.


[edit] Contact

For general Open-iSCSI info, please ask at open-iscsi mailing list.
If you wish to contact me directly, write me an email: Tomasz Chmielewski <tch (at) wpkg (dot) org>.


Keywords: Open-iSCSI remote boot, diskless, iSCSI, Xen, tftp, PXE, network boot

Personal tools
Namespaces
Variants
Actions
Navigation
ideas?
Toolbox