Diskless / remote boot with Open-iSCSI

本文介绍如何通过Open-iSCSI实现无盘系统的远程启动。主要步骤包括:创建包含所需模块的initrd文件、配置TFTP服务器,并提供详细的实践指导。

Diskless / remote boot with Open-iSCSI

Contents

  [hide]

[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:

  • create an initrd which will connect the iSCSI node
  • configure your tftp server, so that your machine starts properly via PXE/tftp

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:

  • load all needed modules, like:
    • network card modules (e1000, tg3, mii, 8139too, e100, depending on the card you use etc.)
    • filesystem modules (jbd, ext3, depending on the filesystem you use)
    • SCSI modules (scsi_mod, sd_mod)
    • Open-iSCSI modules (scsi_transport_iscsi, libiscsi, iscsi_tcp)
  • mount /proc and /sys
  • bring a network interface up
  • initiate a iSCSI session with iscsistart
  • mount your filesystem
  • switch to a new root
  • execute /sbin/init from a new root


[edit]Preparing initrd

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

  • create a directory for your Open-ISCSI-aware initrd:
mkdir initrd
  • create all needed directories:
cd initrd
mkdir -p bin dev etc lib/modules proc sys sysroot
ln -s bin sbin
  • copy the following binaries to bin/:
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.


  • copy shared libraries to lib/; you will find the shared libraries with ldd tool, for example:
# 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)


  • after all binaries and libraries are copied to correct places, verify if you didn't forget anything with chroot command - you may get a similar "no name" prompt (it's OK, since there are no users in that initrd), and all binaries should be able to start:
# cd initrd
# chroot .
[I have no name!@localhost /]# mount --help     
(...)
  • create needed nodes in dev/ (with mknod tool, or just copy them from your /dev):
console  sda  sda1  sda2


  • create the init file (don't forget to chmod 755 init); place it in the root of your initrd directory; note we load some modules here - you have to copy the modules to /lib/modules/ in your initrd; here's the example init file which detects kernel command line parameters like initiator name, target IP etc.:
#!/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:

  • initrd - initrd image, for example, initrd=remote/initrd.img
  • iscsi_i_ip - local initiator IP address/netmask (i.e. 192.168.111.168/255.255.255.192), for example, iscsi_i_ip=10.1.1.165/255.255.255.192
  • iscsi_i - local initiator name (InitiatorName), for example, iscsi_i=iqn.2007-01.com.example:server.remote1
  • iscsi_t - remote target name (TargetName), for example, iscsi_t=iqn.2007-01.com.example:storage.remote1
  • iscsi_a - iSCSI target IP address, for example, iscsi_a=10.1.1.180


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.


--------------------------------------------------------------------------- KeyError Traceback (most recent call last) File /media/HUAWEI/DATA1/miniconda3/lib/python3.9/site-packages/xarray/backends/file_manager.py:211, in CachingFileManager._acquire_with_cache_info(self, needs_lock) 210 try: --> 211 file = self._cache[self._key] 212 except KeyError: File /media/HUAWEI/DATA1/miniconda3/lib/python3.9/site-packages/xarray/backends/lru_cache.py:56, in LRUCache.__getitem__(self, key) 55 with self._lock: ---> 56 value = self._cache[key] 57 self._cache.move_to_end(key) KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('/media/HUAWEI/LiangY/CMIP6 /EC-SSP585/EC-Earth3-Veg-LR/tas_day_EC-Earth3-Veg-LR_ssp585_r1i1p1f1_gr_2015.nc',), 'a', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), 'b83b1a10-00f8-4c63-be21-47c0644fb6e5'] During handling of the above exception, another exception occurred: PermissionError Traceback (most recent call last) Cell In[30], line 41 38 aligned_model_data = model_data.reindex_like(obs_data, method='nearest') 40 # 保存对齐后的模式数据到新的 NetCDF 文件 ---> 41 aligned_model_data.to_netcdf('/media/HUAWEI/LiangY/CMIP6 /EC-SSP585/EC-Earth3-Veg-LR/tas_day_EC-Earth3-Veg-LR_ssp585_r1i1p1f1_gr_2015.nc') 43 print("对齐后的模式数据已保存到新的 NetCDF 文件中。") File /media/HUAWEI/DATA1/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py:2329, in Dataset.to_netcdf(self, path, mode, format, group, engine, encoding, unlimited_dims, compute, invalid_netcdf) 2326 encoding = {} ... File src/netCDF4/_netCDF4.pyx:2521, in netCDF4._netCDF4.Dataset.__init__() File src/netCDF4/_netCDF4.pyx:2158, in netCDF4._netCDF4._ensure_nc_success() PermissionError: [Errno 13] Permission denied: '/media/HUAWEI/LiangY/CMIP6 /EC-SSP585/EC-Earth3-Veg-LR/tas_day_EC-Earth3-Veg-LR_ssp585_r1i1p1f1_gr_2015.nc' Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
10-01
我的另外一段代码有时也报错,应怎样解决 Traceback (most recent call last): File "/home/aqm-py/src/aqm_kongjiantu_city.py", line 361, in <module> plot_kongjiantu_city(wrfout_files, output_dir) File "/home/aqm-py/src/aqm_kongjiantu_city.py", line 320, in plot_kongjiantu_city main_analysis(idxNc, output_dir, region_code, region_name) File "/home/aqm-py/src/aqm_kongjiantu_city.py", line 215, in main_analysis plot_rain_face(ds, ax, lon, lat, fig, zorderidx) File "/home/aqm-py/src/aqm_package/plot_rain_face.py", line 10, in plot_rain_face rainc = ds['RAINC'].values ^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/dataarray.py", line 797, in values return self.variable.values ^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/variable.py", line 556, in values return _as_array_or_item(self._data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/variable.py", line 336, in _as_array_or_item data = np.asarray(data) ^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/indexing.py", line 579, in __array__ return np.asarray(self.get_duck_array(), dtype=dtype) ^^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/indexing.py", line 943, in get_duck_array duck_array = self.array.get_duck_array() ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/indexing.py", line 897, in get_duck_array return self.array.get_duck_array() ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/indexing.py", line 737, in get_duck_array array = self.array[self.key] ~~~~~~~~~~^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 116, in __getitem__ return indexing.explicit_indexing_adapter( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/core/indexing.py", line 1129, in explicit_indexing_adapter result = raw_indexing_method(raw_key.tuple) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/anaconda3/envs/wrf-env/lib/python3.11/site-packages/xarray/backends/netCDF4_.py", line 129, in _getitem array = getitem(original_array, key) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "src/netCDF4/_netCDF4.pyx", line 5079, in netCDF4._netCDF4.Variable.__getitem__ File "src/netCDF4/_netCDF4.pyx", line 6051, in netCDF4._netCDF4.Variable._get File "src/netCDF4/_netCDF4.pyx", line 2164, in netCDF4._netCDF4._ensure_nc_success RuntimeError: NetCDF: HDF error
最新发布
11-04
简述以下 redis 参数作用 timeout 1500 port 9030 tcp-keepalive 1000 masterauth rI0DncoAFMSXOEnBCQbCUIlSV0j22Ewv client-output-buffer-limit normal 0 0 0 slave 0 0 0 pubsub 33554432 8388608 60 requirepass rI0DncoAFMSXOEnBCQbCUIlSV0j22Ewv maxmemory 15884901888 zset-max-ziplist-entries 128 min-slaves-max-lag 10 active-defrag-cycle-max 75 replica-read-only yes pidfile /home/dba/redis9030/pay-redis-bn/data/redis.pid hz 10 aof-use-rdb-preamble yes bind 10.67.68.10 repl-diskless-sync-delay 5 hash-max-ziplist-value 64 slave-ignore-maxmemory yes list-compress-depth 0 databases 16 latency-monitor-threshold 0 hash-max-ziplist-entries 512 proto-max-bulk-len 536870912 maxclients 4096 lazyfree-lazy-eviction no hll-sparse-max-bytes 3000 active-defrag-threshold-lower 10 stream-node-max-entries 100 slowlog-max-len 128 zset-max-ziplist-value 64 cluster-slave-no-failover no unixsocket cluster-announce-bus-port 0 lua-time-limit 5000 cluster-replica-validity-factor 10 appendonly no slowlog-log-slower-than 10000 save active-defrag-ignore-bytes 104857600 cluster-slave-validity-factor 10 cluster-announce-ip activerehashing yes stream-node-max-bytes 4096 slave-lazy-flush no rdb-save-incremental-fsync yes list-max-ziplist-size -2 replica-announce-port 0 daemonize yes cluster-replica-no-failover no activedefrag no aof-load-truncated yes no-appendfsync-on-rewrite yes min-replicas-max-lag 10 repl-disable-tcp-nodelay yes loglevel notice cluster-migration-barrier 1 maxmemory-policy allkeys-lfu aof-rewrite-incremental-fsync yes slave-announce-port 0 lfu-decay-time 1 min-replicas-to-write 0 replica-lazy-flush no maxmemory-samples 5 stop-writes-on-bgsave-error yes dir /home/dba/redis9030/pay-redis-bn/data dbfilename dump.rdb min-slaves-to-write 0 repl-diskless-sync no syslog-facility local0 repl-timeout 60 dynamic-hz yes repl-ping-replica-period 10 replica-priority 100 slave-read-only yes auto-aof-rewrite-percentage 100 logfile /home/dba/redis9030/pay-redis-bn/log/redis.log cluster-require-full-coverage yes slaveof notify-keyspace-events rdbcompression yes lfu-log-factor 10 tcp-backlog 511 protected-mode yes lazyfree-lazy-expire no replica-announce-ip slave-serve-stale-data yes unixsocketperm 0 repl-ping-slave-period 10 replica-ignore-maxmemory yes appendfsync always watchdog-period 0 cluster-node-timeout 5000 repl-backlog-size 50000000 lazyfree-lazy-server-del no active-defrag-threshold-upper 100 active-defrag-max-scan-fields 1000 replica-serve-stale-data yes auto-aof-rewrite-min-size 67108864 client-query-buffer-limit 1073741824 rdbchecksum yes slave-announce-ip cluster-announce-port 0 repl-backlog-ttl 3600 slave-priority 100 supervised no set-max-intset-entries 512 active-defrag-cycle-min 5
09-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值