
Booting SystemRescueCd from the network using NBD devices
Hi,
Well I work with this solution for LTSP servers but also thinclients made with debian... It didn't consume a lot of memory and it light for the network.
Tree files are added in the intrd (but present in the squashfs file) :usr/sbin/nbd-client
lib/modules/2.6.31.12-std135/kernel/drivers/block/nbd.ko
The MY_HWOPTS variable's was modified in the etc/initrd.defaults file :
Code:
...
MY_HWOPTS='modules pata sata scsi usb firewire dmraid mdadm fs net nbd'
...
Create the etc/modules/nbd filecontain only "nbd"
The modifications of init script in the intramCode:
455a456,473
> # connect the NBD device
> sysresccd_nbdboot()
> {
> REAL_ROOT="nbd"
> NBD_DEVICE="/dev/nbd0"
>
> good_msg 'Executing nbd-client /dev/nbd0 to access nbd root'
> NBD_SERVER=$(echo "${NBD_ROOT}" | sed 's/:.*//')
> NBD_PORT=$(echo "${NBD_ROOT}" | sed 's/.*://')
>
> # connect nbd device
> /usr/sbin/nbd-client "${NBD_SERVER}" "${NBD_PORT}" "${NBD_DEVICE}" -persist
>
> # mount rofs
> mkdir /rofs
> mount ${NBD_DEVICE} /rofs
> }
>
489a508
> NBD_ROOT=''
574a594,598
> nbdroot\=*)
> NBD_ROOT=`parse_opt "${x}"`
> LOADNET='1'
> CDROOT='0'
> ;;
758a783,788
> # ---- don't load the nbd modules which is time consuming if nbd not involved
> if [ -z "${NBD_ROOT}" ]
> then
> rm -f /etc/modules/nbd
> fi
>
786c816
< if [ -n "${NETBOOT}" ]
---
> if [ -n "${NETBOOT}" ] || [ -n "${NBD_ROOT}" ]
1130a1164,1169
> # create the nbd device on demand
> if [ -x /usr/sbin/nbd-client ] && [ -n "${NBD_ROOT}" ]
> then
> sysresccd_nbdboot # boot with nbd device
> fi
>
1220c1259
< elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "http" ] || [ "${REAL_ROOT}" = "tftp" ]
---
> elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "http" ] || [ "${REAL_ROOT}" = "tftp" ] || [ "${REAL_ROOT}" = "nbd" ]
1231c1270
< if [ "${CDROOT}" = '1' ] && [ "${got_good_root}" = '1' ]
---
> if [ "${CDROOT}" = '1' ] && [ "${got_good_root}" = '1' ] || [ "${REAL_ROOT}" = "nbd" ]
1507a1547,1554
> # If cdroot is unset determine and nbdboot is define try to mount root
> if [ ${CDROOT} = '0' ] && [ "${REAL_ROOT}" = "nbd" ]
> then
> mkdir /rwfs
> mount -t tmpfs tmpfs /rwfs
> mount -t aufs -o dirs=/rwfs=rw:/rofs=ro aufs ${NEW_ROOT}
> fi
>
ltsp-server:/var/lib/tftpboot/sysrcd/initram_custom# diff -cB init.ORI init
*** init.ORI 2010-02-20 16:38:34.000000000 +0100
--- init 2010-02-20 18:13:28.000000000 +0100
***************
*** 453,458 ****
--- 453,476 ----
echo "netconfig1: ${ipcmd_add} --> ${res}"
}
+ # connect the NBD device
+ sysresccd_nbdboot()
+ {
+ REAL_ROOT="nbd"
+ NBD_DEVICE="/dev/nbd0"
+
+ good_msg 'Executing nbd-client /dev/nbd0 to access nbd root'
+ NBD_SERVER=$(echo "${NBD_ROOT}" | sed 's/:.*//')
+ NBD_PORT=$(echo "${NBD_ROOT}" | sed 's/.*://')
+
+ # connect nbd device
+ /usr/sbin/nbd-client "${NBD_SERVER}" "${NBD_PORT}" "${NBD_DEVICE}" -persist
+
+ # mount rofs
+ mkdir /rofs
+ mount ${NBD_DEVICE} /rofs
+ }
+
# Clean input/output
exec >${CONSOLE} <${CONSOLE} 2>&1
[ ! -f /dev/urandom ] && busybox mknod /dev/urandom c 1 9 2>/dev/null
***************
*** 487,492 ****
--- 505,511 ----
CMDLINE="$(cat /proc/cmdline)"
CDROOT='1'
+ NBD_ROOT=''
REAL_ROOT=''
SETKMAP=''
MINISHELL=''
***************
*** 572,577 ****
--- 591,601 ----
NETBOOT=`parse_opt "${x}"`
LOADNET='1'
;;
+ nbdroot\=*)
+ NBD_ROOT=`parse_opt "${x}"`
+ LOADNET='1'
+ CDROOT='0'
+ ;;
subdir\=*)
SUBDIR=`parse_opt "${x}"`
;;
***************
*** 756,761 ****
--- 780,791 ----
rm -f /etc/modules/net
fi
+ # ---- don't load the nbd modules which is time consuming if nbd not involved
+ if [ -z "${NBD_ROOT}" ]
+ then
+ rm -f /etc/modules/nbd
+ fi
+
# ---- load modules listed in MY_HWOPTS if /lib/modules exists
if [ -d '/lib/modules' ]
then
***************
*** 783,789 ****
good_msg "Performing the network configuration..."
# ---- force dhcp if booting via pxe and no static configuration specified
! if [ -n "${NETBOOT}" ]
then
if ! cat /proc/cmdline | busybox grep -q -E 'eth[x0-9]{1,2}=[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
then
--- 813,819 ----
good_msg "Performing the network configuration..."
# ---- force dhcp if booting via pxe and no static configuration specified
! if [ -n "${NETBOOT}" ] || [ -n "${NBD_ROOT}" ]
then
if ! cat /proc/cmdline | busybox grep -q -E 'eth[x0-9]{1,2}=[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
then
***************
*** 1128,1133 ****
--- 1161,1172 ----
/bin/lvm vgchange -ay
fi
+ # create the nbd device on demand
+ if [ -x /usr/sbin/nbd-client ] && [ -n "${NBD_ROOT}" ]
+ then
+ sysresccd_nbdboot # boot with nbd device
+ fi
+
while true
do
while [ "${got_good_root}" != '1' ]
***************
*** 1217,1223 ****
echo -n 'boot() :: '
read REAL_ROOT
got_good_root=0
! elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "http" ] || [ "${REAL_ROOT}" = "tftp" ]
then
got_good_root=1
else
--- 1256,1262 ----
echo -n 'boot() :: '
read REAL_ROOT
got_good_root=0
! elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "http" ] || [ "${REAL_ROOT}" = "tftp" ] || [ "${REAL_ROOT}" = "nbd" ]
then
got_good_root=1
else
***************
*** 1228,1234 ****
fi
done
! if [ "${CDROOT}" = '1' ] && [ "${got_good_root}" = '1' ]
then
# CD already mounted; no further checks necessary
break
--- 1267,1273 ----
fi
done
! if [ "${CDROOT}" = '1' ] && [ "${got_good_root}" = '1' ] || [ "${REAL_ROOT}" = "nbd" ]
then
# CD already mounted; no further checks necessary
break
***************
*** 1505,1510 ****
--- 1544,1557 ----
fi
fi
+ # If cdroot is unset determine and nbdboot is define try to mount root
+ if [ ${CDROOT} = '0' ] && [ "${REAL_ROOT}" = "nbd" ]
+ then
+ mkdir /rwfs
+ mount -t tmpfs tmpfs /rwfs
+ mount -t aufs -o dirs=/rwfs=rw:/rofs=ro aufs ${NEW_ROOT}
+ fi
+
verbose_kmsg
# ------------------------------- chroot -------------------------------
So, for the nbd-server you can use a file ...Code:
# /etc/nbd-server/config
[generic]
user = nbd
group = nbd
listenaddr = 172.16.0.1
[partimage]
exportname = /mnt/cdrom/sysrcd.dat
port = 2000
... or a commandCode:
root@sysresccd /root % nbd-server 2000 /mnt/cdrom/sysrcd.dat
In the default file of /tftpboot/pxelinux.cfg/default you can find :Code:
default rescuecd
append initrd=initram-nbd.igz setkmap=fr nbdroot=172.16.0.1:2000
Copy necessary files to /tftpboot directory :
/mnt/cdrom/isolinux/rescuecd
/mnt/cdrom/isolinux/initram-nbd.igz
Configure and start the dhcp and tftp serverStart your thins-clients
@+