Booting SystemRescueCd from the network using NBD devices

Post there if you plan to contribute to this SystemCd
Post Reply
richard
Posts: 26
Joined: 17 Jun 2008, 08:05
Location: Cagnes-sur-Mer, France
Contact:

Booting SystemRescueCd from the network using NBD devices

Post by richard » 20 Feb 2010, 16:51

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: Select all

...
MY_HWOPTS='modules pata sata scsi usb firewire dmraid mdadm fs net nbd'
...



Create the etc/modules/nbd file
contain only "nbd"

The modifications of init script in the intram

Code: Select all

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: Select all

# /etc/nbd-server/config
[generic]
	user = nbd
	group = nbd
	listenaddr = 172.16.0.1
[partimage]
	exportname = /mnt/cdrom/sysrcd.dat
	port = 2000
... or a command

Code: Select all

[email protected] /root % nbd-server 2000 /mnt/cdrom/sysrcd.dat
In the default file of /tftpboot/pxelinux.cfg/default you can find :

Code: Select all

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 server

Start your thins-clients

@+

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: netboot with NBD

Post by admin » 21 Feb 2010, 21:21

Thanks for your contribution.

Boot from NBD will be useful for users who want to boot SystemRescueCd on a computer that has not enough memory to store a copy of sysrcd.dat during a network boot done with the default boot option. With NBD/NFS it's possible to boot from the network even if the client computer has less than 512 MB of RAM.

I have added all the requirements and modifications to SystemRescueCd-1.4.0-beta8.
There are modifications in the "init" script to make it simpler, and the boot option is called "nbdboot=ip:port" for consistency with the existing options.

For new users:
All you have to do is to install an NBD server somewhere on your network that provides a copy of "sysrcd.dat", and to boot SystemRescueCd-1.4.0-beta8 or more recent with the appropriate options ("nbdboot=ip:port" and the options such as "ethx" or "dodhcp") that are required to configure the network during the boot process. The client will configure its network, connect to the NBD server that provides sysrcd.dat, mount that file through the NBD device, and then complete the boot process.

You can read the Manual about booting from NBD for more details.

richard
Posts: 26
Joined: 17 Jun 2008, 08:05
Location: Cagnes-sur-Mer, France
Contact:

Re: Booting SystemRescueCd from the network using NBD device

Post by richard » 29 Jul 2010, 12:24

Hi,

For complete, I send you the modifications for automated the nbd server.

file /etc/conf.d/pxebootsrv

Code: Select all

34a35,36
> # Set to "yes" if you want this machine to act as an NBD server
> PXEBOOTSRV_DONBD="yes"
file /etc/init.d/pxebootsrv

Code: Select all

53a54,65
> 	if [ $PXEBOOTSRV_DONBD != "yes" ] && [ $PXEBOOTSRV_DONBD != "no" ]
> 	then
> 		eerror "Invalid value for PXEBOOTSRV_DONBD. Must be \"yes\" or \"no\" (lowercase)."
> 		return 1
> 	fi
> 
> 	if [ $PXEBOOTSRV_DONBD = "yes" ] && [ $PXEBOOTSRV_DONFSD = "yes" ]
> 	then
> 		eerror "You must choice between NFS or NBD server."
> 		return 1
> 	fi
> 
123a136,143
> 	# ---- start the NBD server
> 	if [ $PXEBOOTSRV_DONBD == "yes" ]
> 	then
> 		PXEBOOTSRV_DOHTTPD="no"
> 		/usr/bin/nbd-server $PXEBOOTSRV_LOCALIP:2000 /tftpboot/sysrcd.dat -r
> 		sed -i -e "s!scandelay=[1-9] netboot=[a-z=\/:\.0-9\/]*!scandelay=1 netboot=nbd://$PXEBOOTSRV_LOCALIP:2000!g" /tftpboot/pxelinux.cfg/default
> 	fi
> 
Bye,

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: Booting SystemRescueCd from the network using NBD device

Post by admin » 29 Jul 2010, 18:58

Thanks, change applied in sysresccd-1.6.0-beta

offsitenoc
Posts: 3
Joined: 01 Dec 2010, 08:07
Contact:

Re: Booting SystemRescueCd from the network using NBD device

Post by offsitenoc » 01 Dec 2010, 08:19

well its great information for me.

richard
Posts: 26
Joined: 17 Jun 2008, 08:05
Location: Cagnes-sur-Mer, France
Contact:

Re: Booting SystemRescueCd from the network using NBD device

Post by richard » 16 Jun 2013, 18:19

Hi,

I'll come again for NBD ;)
So, the version of nbd-client in the intram is 2.9.... and the package installed in system is nbd-3.2.

It is a great enhancement for me, but since version 3.0 Network Block Device has defined an official port (10809 we can find this in /etc/services file) and when new style nbd syntax for server is setting a new syntax for the client is required.

The new syntax for the client is :

Code: Select all

nbd-client -N export_name server nbd_device
In the command line kernel arguments with the next modifications :

Code: Select all

KERNEL /sysrcd/rescue32 setkmap=fr netboot=nbd://192.168.0.1:sysrcd dostartx
For server :

Code: Select all

[sysrcd]
    exportname = /var/www/pxe/sysrcd/sysrcd.dat
I can suggest you this modifications :

Copy the binary /usr/sbin/nbd-client in the intram.igz file, to be consistent with the system version (and new options included).

init file in initram.igz

Code: Select all

1057a1058
>               OLD_STYLE_NBD=$(grep -c '^[0-9]*$' ${NBD_PORT})
1074,1079c1075,1090
<     if ! ${NBD_PROG} "${NBD_SERVER}" "${NBD_PORT}" "${NBD_DEVICE}" -persist
<     then
<         sysresccd_panic "Error: nbd-client failed to connect to ${NBD_SERVER}:${NBD_PORT}"
<     else
<         good_msg "nbd-client successfully connected to ${NBD_SERVER}:${NBD_PORT}"
<     fi
---
>               if [ ${OLD_STYLE_NBD} -gt 0 ]
>               then
>               if ! ${NBD_PROG} "${NBD_SERVER}" "${NBD_PORT}" "${NBD_DEVICE}" -persist
>               then
>                   sysresccd_panic "Error: nbd-client failed to connect to ${NBD_SERVER}:${NBD_PORT}"
>               else
>                   good_msg "nbd-client successfully connected to ${NBD_SERVER}:${NBD_PORT}"
>               fi
>               else
>               if ! ${NBD_PROG} -N "${NBD_PORT}" "${NBD_SERVER}" "${NBD_DEVICE}" -persist
>               then
>                   sysresccd_panic "Error: nbd-client failed to connect to ${NBD_SERVER}:${NBD_PORT}"
>               else
>                   good_msg "nbd-client successfully connected to ${NBD_SERVER}:${NBD_PORT}"
>               fi
>               fi
Best regards,

richard
Posts: 26
Joined: 17 Jun 2008, 08:05
Location: Cagnes-sur-Mer, France
Contact:

Re: Booting SystemRescueCd from the network using NBD device

Post by richard » 01 Mar 2014, 10:47

Hi,

I downloaded the last version (4.0.1). I needed to patch again the initial ramdisk.
Could you include these modifications into the next version (init + binary into initram.igz), please ?

Best regards,

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: Booting SystemRescueCd from the network using NBD device

Post by admin » 02 Mar 2014, 11:20

Thanks for your contributions. The nbd-client has been updated in the initramfs in sysresccd-4.1.0-beta004. Also the init scipt contains the new "-N" option. Can you please try ? If changes are required in specific files can you put a link to the full version ?

richard
Posts: 26
Joined: 17 Jun 2008, 08:05
Location: Cagnes-sur-Mer, France
Contact:

Re: Booting SystemRescueCd from the network using NBD device

Post by richard » 03 Mar 2014, 17:31

Ok, I have tested with the beta004, all work fine.

I had only tested the new syntax of NBD.

cschulzejn
Posts: 46
Joined: 08 Dec 2010, 13:07

Re: Booting SystemRescueCd from the network using NBD device

Post by cschulzejn » 25 Mar 2014, 10:27

I am running our PXE-Server with Debian Lenny amd64. Current nbd-server version is 3.2-4~deb7u4.

When using new SysRescCd 4.1.0 to connect to the server with oldstyle (via specific port) the nbd-server crashes.
Mar 25 10:23:12 server nbd_server[7445]: Negotiation failed/8a: Requested export not found
Mar 25 10:23:12 server nbd_server[7445]: Exiting.
Took me some time to figure it out. Maybe someone else is having this problem too.

PS: mixing the nbd-server config with old and new style works.

richard
Posts: 26
Joined: 17 Jun 2008, 08:05
Location: Cagnes-sur-Mer, France
Contact:

Re: Booting SystemRescueCd from the network using NBD device

Post by richard » 18 Sep 2015, 09:30

Hi,

I come back for nbd server ;)
So, for a perfect integration could you change this :

server configuration file /etc/nbd/config

Code: Select all

[generic]
[sysrcd]
    exportname = /tftpboot/sysrcd.dat
Kernel parameters (don't change)

Code: Select all

netboot=nbd://10.0.0.1:sysrcd
Could you update the squashfs file for include this file and just call the next command for start the nbd-server ?

Code: Select all

nbd-server -C /etc/nbd/config
Thanks,

Post Reply