細かいところで Debian 12 と Ubuntu 24.04 には違いがあり、たとえば /etc/resolv.conf なんですが、Ubuntu では 最小インストールでも systemd-resolved を使うので /etc/resolv.conf へは直接値を書き込んでも systemd-resolved が上書きします。このため Debian 12 用のインストールスクリプトを変更する必要が若干ですがあります。
今回は簡易インストールで iSCSI root にて起動することを主題に置いたので、systemd-resolved については削除し、iSCSI root で最小限の Ubuntu 環境を作成するようにしました。また、initramfs-toolsも Ubuntu では debootstrap ではインストールされないので、これは追加でインストールしています。
とはいえ、大まかな流れは同じなので、dhcp サーバと apache2 および ipxe メニューについては割愛していますので、これらについては以前の投稿を参考にしてください。
なお、作業は Debian 12 で行いましたが、Ubuntu 向けの debootstrap deb 玉を 引っ張ってきて展開し、スクリプトを配置すると Debian 上でも Ubuntu 24.04 の debootstrap も OK でした。
また、今回は ipoib インターフェースは一枚で iBFT の情報の受け渡しに問題がないことを前提としています。さらに、オンボードの NIC は BIOSで Disableにして有効なインターフェースは ipoib 一枚だけを使用する事を前提としています。
以下設定詳細です。
今回は簡易インストールで iSCSI root にて起動することを主題に置いたので、systemd-resolved については削除し、iSCSI root で最小限の Ubuntu 環境を作成するようにしました。また、initramfs-toolsも Ubuntu では debootstrap ではインストールされないので、これは追加でインストールしています。
とはいえ、大まかな流れは同じなので、dhcp サーバと apache2 および ipxe メニューについては割愛していますので、これらについては以前の投稿を参考にしてください。
なお、作業は Debian 12 で行いましたが、Ubuntu 向けの debootstrap deb 玉を 引っ張ってきて展開し、スクリプトを配置すると Debian 上でも Ubuntu 24.04 の debootstrap も OK でした。
また、今回は ipoib インターフェースは一枚で iBFT の情報の受け渡しに問題がないことを前提としています。さらに、オンボードの NIC は BIOSで Disableにして有効なインターフェースは ipoib 一枚だけを使用する事を前提としています。
以下設定詳細です。
#### disk image
# on target i51 ( Debian 12 )
# apache2 の設定などについては以前の投稿を参照してください。
#apt-get install targetcli-fb qemu-utils tftpd-hpa apache2
REL=noble
IMG=ub2404.amd64.01.img
tNAME=ub2404-amd64-01
tHOSTNAME=i51
tADDR=10.1.40.51
tBASE=iqn.1868-01.com.example
iHOSTNAME=sv113
NBD=nbd4
MP=/media/${tNAME}
SRV=/srv/deb03
TFTP=/srv/tftp
mkdir -p ${SRV}
cd ${SRV}
dd if=/dev/zero of=${IMG} bs=1024k count=32768
modprobe -av nbd
qemu-nbd -f raw -c /dev/${NBD} /$SRV/${IMG}
# パーティションの作成(非対話モード)
echo -e "g\nn\n\n\n+1G\nt\nuefi\nn\n\n\n\nw\n" | fdisk /dev/${NBD}
# 確認
fdiks -l /dev/${NBD}
############################
### イメージの初期化とパッケージのインストール等
mkfs.vfat /dev/${NBD}p1
mkfs.xfs -f /dev/${NBD}p2
P2_UUID=`xfs_admin -u /dev/${NBD}p2 | cut -d' ' -f 3`
mkdir -p ${MP}
mount /dev/${NBD}p2 ${MP}
mkdir -p ${MP}/boot/efi
mount /dev/${NBD}p1 ${MP}/boot/efi
cd ${MP}/boot/efi
mkdir -p ${MP}/boot/efi/EFI/ubuntu
mkdir -p ${TFTP}/ubuntu
cd ${TFTP}/ubuntu
wget https://releases.ubuntu.com/noble/ubuntu-24.04.2-netboot-amd64.tar.gz
tar xzpf ubuntu-24.04.2-netboot-amd64.tar.gz
cp -a amd64/bootx64.efi ${MP}/boot/efi/EFI/ubuntu/bootnetx64.efi
cat > ${MP}/boot/efi/EFI/ubuntu/grub.cfg <<EOF
search.fs_uuid ${P2_UUID} root hd0,gpt2
set prefix=(\$root)/boot/grub
configfile \$prefix/grub.cfg
EOF
cd ${TFTP}/ubuntu
mkdir wrk
cd
wget http://launchpadlibrarian.net/707897502/debootstrap_1.0.134ubuntu1_all.deb
ar -x debootstrap_1.0.134ubuntu1_all.deb
tar xzpf data.tar.gz
cp -a ${TFTP}/ubuntu/wrk/usr/share/debootstrap/scripts/noble /usr/share/debootstrap/scripts/noble
cd ${MP}
#debootstrap --arch=amd64 noble . http://archive.ubuntu.com/ubuntu/
debootstrap --arch=amd64 noble . http://ftp.riken.go.jp/Linux/ubuntu/
# debootstrap では足りないパッケージ等を半自動でインストール・設定
cat > root/and-so-on.sh <<EOF
apt-get install -y --no-install-recommends linux-image-generic initramfs-tools xfsprogs openssh-server open-iscsi dbus zstd grub-efi-amd64
apt-get install -y --no-install-recommends locales console-setup
# set root password
passwd
# change hostname
echo ${tNAME} > /etc/hostname
# setup locales
dpkg-reconfigure locales
# setup console
dpkg-reconfigure console-setup
# setup keyboard layout
dpkg-reconfigure keyboard-configuration
# workaround for /etc/resolv.conf
dpkg -P systemd-resolved
# add ipv4 nameservers
echo nameserver 10.1.1.64 > /etc/resolv.conf
echo nameserver 10.1.1.65 >> /etc/resolv.conf
# workaround for /etc/apt/sources.list
echo deb http://ftp.riken.go.jp/Linux/ubuntu noble main universe > /etc/apt/sources.list
apt-get update
apt-get install -y --no-install-recommends xterm
exit
EOF
cd ${MP}
mount -t proc proc proc/
mount -t sysfs sysfs sys/
mount --rbind /dev dev/
chroot . bash root/and-so-on.sh
cat > root/grb-inst.sh <<EOF
grub-install --target=x86_64-efi --efi-directory=/boot/efi --boot-directory=/boot --uefi-secure-boot /dev/${NBD}
mv /boot/grub/grub.cfg /boot/grub/grub.cfg.bkup
EOF
chroot . bash root/grb-inst.sh
# time stamp が最も新しい vmlinuz ファイルをカーネルバージョンとして使用する
KVER=`cd ${MP}/boot && ls -rt vmlinuz-*-generic | tail -n 1 | sed 's/vmlinuz-//g' | sed 's/-generic//g'`
# 2025/05/22:修正 amd64 で grub にてシリアルコンソールを使用する場合、terminal_output に "console"を指定するだけでよく、指定しなくともデフォルトで 115200/8w/pn/s1/port0 で通信でき、serialの設定を省略できるようです。
cat > ${MP}/boot/grub/grub.cfg <<EOF
#以下4行不要
#insmod seriaを
#serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
#terminal_input --append console serial
#terminal_output --append console serial
#以下2行追加
terminal_input --append console
terminal_output --append console
set default="0"
set timeout=20
menuentry 'Ubuntu ( ${KVER} )'{
linux /boot/vmlinuz-${KVER}-generic root=UUID=$P2_UUID rw ip=::::::dhcp iscsi_auto rootfstype=xfs rootwait console=tty0 console=ttyS0,115200n1
initrd /boot/initrd.img-${KVER}-generic.iscsi
}
EOF
#### ターゲット設定
targetcli /backstores/fileio create ${tNAME} ${SRV}/${IMG}
targetcli /iscsi create ${tBASE}:${tHOSTNAME}.${tNAME}
targetcli /iscsi/${tBASE}:${tHOSTNAME}.${tNAME}/tpg1/luns create /backstores/fileio/${tNAME}
targetcli /iscsi/${tBASE}:${tHOSTNAME}.${tNAME}/tpg1/acls create ${tBASE}:${iHOSTNAME}
targetcli / saveconfig
################################################
#### initramfs-toolsの設定その1(chroot下)
cd ${MP}
chroot .
cd /root
mkdir -p initrd_iscsi
cd initrd_iscsi
cp -a /etc/initramfs-tools/modules modules.orig
cat >> /etc/initramfs-tools/modules <<EOF
ib_core
ib_cm
ib_uverbs
ib_umad
iw_cm
rdma_cm
rdma_ucm
mlx4_core
mlx4_ib
mlx5_core
mlx5_ib
ib_mthca
ib_ipoib
iscsi_ibft
EOF
###################################################
#### initramfs-toolsの設定その2(引き続きchroot下)
cd /root/initrd_iscsi
cp -a /usr/share/initramfs-tools/init init.orig
cp -a init.orig init
##-------------- save as init.diff
--- init.orig 2025-02-07 10:26:12.000000000 +0000
+++ init 2025-04-18 05:33:58.782430208 +0000
@@ -308,11 +308,11 @@
case "$IP6" in
""|none|off) ;; # Do nothing
*)
- configure_networking
+ echo skipping configure_networking
esac
;;
*)
- configure_networking
+ echo skipping configure_networking
esac
maybe_break bottom
##--------------
apt-get install patch
patch < init.diff
cp -a init /usr/share/initramfs-tools/init
## local-top iscsi の編集
cp -a /usr/share/initramfs-tools/scripts/local-top/iscsi local-top.iscsi.orig
cp -a local-top.iscsi.orig local-top.iscsi
## save as local-top.iscsi.diff
##--------------
--- local-top.iscsi.orig 2023-12-14 13:08:38.000000000 +0000
+++ local-top.iscsi 2025-04-18 19:51:57.261036787 +0000
@@ -330,7 +330,49 @@
exit 0
fi
-do_iscsi_login
+iscsistart -f | grep -v \# > /run/iscsi-vars
+
+iface=`cat /run/iscsi-vars | grep iface.net_ifacename | cut -d' ' -f3`
+
+i=$iface
+
+if [ -e /sys/class/net/$i/carrier ]; then
+ ip link set dev $i up && interface_up=`cat /sys/class/net/$i/carrier`
+else
+ interface_up=""
+fi
+echo
+echo awainting for interface $i up
+count=0
+while [ "$interface_up" == "0" -o ! -n "$interface_up" ] && [ $count -lt 30 ]
+ do
+ echo interface_up: $interface_up
+ if [ -e /sys/class/net/$i/carrier ]; then
+ ip link set dev $i up && interface_up=`cat /sys/class/net/$i/carrier`
+ else
+ interface_up=""
+ fi
+ if [ "$interface_up" == "1" ];then
+ echo $i is up
+ fi
+ count=$((count + 1))
+ sleep 5
+done
+
+if [ "$iface" == "$i" ]; then
+ iscsistart -N
+else
+ address=`cat /run/iscsi-vars | grep iface.ipaddress | cut -d' ' -f3`
+ plength=`cat /run/iscsi-vars | grep iface.prefix_len | cut -d' ' -f3`
+ ip addr add $address/$plength dev $i
+fi
+
+gateway=`cat /run/iscsi-vars | grep iface.gateway | cut -d' ' -f3`
+ip route add default via $gateway dev $i
+
+iscsistart -b
+
+#do_iscsi_login
udevadm settle
##--------------
patch < local-top.iscsi.diff
cp -a local-top.iscsi /usr/share/initramfs-tools/scripts/local-top/iscsi
## scripts nfs の編集
cp -a /usr/share/initramfs-tools/scripts/nfs scripts.nfs.orig
cp -a scripts.nfs.orig scripts.nfs
## save as scripts.nfs.diff
##--------------
--- scripts.nfs.orig 2025-04-18 05:35:42.231434432 +0000
+++ scripts.nfs 2025-04-18 05:37:26.865566958 +0000
@@ -36,7 +36,7 @@
# parse nfs bootargs and mount nfs
nfs_mount_root_impl()
{
- configure_networking
+ echo skipping configure_networking
# get nfs root from dhcp
if [ "${NFSROOT}" = "auto" ]; then
@@ -105,7 +105,7 @@
nfs_mount_fs_impl()
{
- configure_networking
+ echo skipping configure_networking
if [ -z "${NFSOPTS}" ]; then
NFSOPTS="-o retrans=10"
##--------------
patch < scripts.nfs.diff
cp -a scripts.nfs /usr/share/initramfs-tools/scripts/nfs
####################################
#### initrd.imgの生成(引き続きchroot下で)
cd /root/initrd_iscsi
KVER=`cd /boot && ls -rt vmlinuz-*-generic | tail -n 1 | sed 's/vmlinuz-//g' | sed 's/-generic//g'`
cat > updt-${KVER}.sh <<EOF
cp -a init /usr/share/initramfs-tools/init
cp -a local-top.iscsi /usr/share/initramfs-tools/scripts/local-top/iscsi
cp -a scripts.nfs /usr/share/initramfs-tools/scripts/nfs
update-initramfs -k ${KVER}-generic -c -b .
mv initrd.img-${KVER}-generic initrd.img-${KVER}-generic.iscsi
cp initrd.img-${KVER}-generic.iscsi ${MP}/boot
EOF
chmod +x updt-${KVER}.sh
./updt-${KVER}.sh
##############################################
# 後片付け
# exit from chrooted env and clean up
exit
cd ${MP}
umount proc/
umount sys/
mount -o remount --make-rslave dev/
umount -R dev/
cd
umount ${MP}/boot/efi
umount ${MP}
qemu-nbd -d /dev/${NBD}
設定は以上です。起動に成功すると以下のようになります。
#uname -a Linux ub2404-amd64-01 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux # iscsiadm -m session tcp: [1] 10.1.40.51:3260,1 iqn.1868-01.com.example:i51.ub2404-amd64-01 (non-flash) # ls -la /dev/disk/by-path | grep sdc$ lrwxrwxrwx 1 root root 9 4月 18 19:58 ip-10.1.40.51:3260-iscsi-iqn.1868-01.com.example:i51.ub2404-amd64-01-lun-0 -> ../../sdc # df Filesystem 1K-blocks Used Available Use% Mounted on tmpfs 3232988 1664 3231324 1% /run /dev/sdc2 32438272 2368680 30069592 8% / tmpfs 16164924 0 16164924 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock efivarfs 512 88 420 18% /sys/firmware/efi/efivars tmpfs 3232984 8 3232976 1% /run/user/0Ubuntu でも iPXE でセキュアブートはできるよ、というお話でした。今回は以上です。それでは。
コメント
コメントを投稿