Squirrel Hole

江心一庐


  • Home
  • Archive
  • Categories
  • Tags
  • 我 | I
  •  

© 2025 白色乌鸦|White Crow

Theme Typography by Makito

Proudly published with Hexo

Build Diskless Fedora

Posted at 2020-05-24 making 

Recently, I work on analysing large fluorescence microscope image. I want to use laboratory computers while are Windows-installation but free. To minimize hardware change, I boot linux kernel from a USB key, and mount root from NFS. Compared with fully diskless system which loads linux kernel from other TFTP, booting from USB Key are much easier to use in different computer without extra network setting. Finally, when I need to more computation power, I just power off non-busy computers, then booting from USB key.

I almost follow fedora magazine's post How to Build a Netboot Server and this to solve password issue. We need to set server and client. In server( just a running fedora for daily use), I export a NFS for diskless system root folder.

1
2
3
4
5
6
7
8
9
10
sudo dnf install -y nfs-utils
mkdir /firefly
echo "/friefly -fsid=0,rw,sec=sys,root_squash" > /etc/exports
# I don't close SELinux, but nfs still work
# add an exception for NFS service
firewall-cmd --add-service nfs
firewall-cmd --runtime-to-permanent
exportsfs -vr
systemctl enable nfs-server.service
systemctl start nfs-server.service

Then we just install a minimal system image into NFS folder.

1
2
3
sudo -i
dnf -y --releasever=32 --installroot=/firefly install fedora-release systemd\
passwd rootfiles sudo dracut dracut-network nfs-utils vim-minimal dnf
We disable hostonly mode so that the initramfs image will work on a wider set of hardware platforms and we need to add support for networking and NFS.
1
2
3
echo 'hostonly=no' > /firefly/etc/dracut.conf.d/hostonly.conf
echo 'add_dracutmodules+=" network nfs "' > /firefly/etc/dracut.conf.d/netboot.conf
dnf -y --installroot=/firefly install kernel
Other configures
1
2
3
4
#Disable logging to the console:
echo 'kernel.printk = 0 4 1 7' > /firefly/etc/sysctl.d/00-printk.conf
MY_CLIENT_HOSTNAME=firefly
echo $MY_CLIENT_HOSTNAME > /firefly/etc/hostname

I don't follow fedora magazine post to set read-only mode and use RAM as storage. I want my diskless system keep all changes.

I was trouble in password error for many days at the first time: password update fail and never match new password. I mistake to use ro parameter in NFS, which export a read-only NFS. Another mistake is SELinux issues, which cause failure to reset password.

1
2
3
4
5
6
restorecon /firefly/etc/passwd* /firefly/usr/bin/passwd
sudo systemd-nspawn -D /firefly sh -c "
# Set root password to fedora and create user fedora.
yes fedora | passwd
useradd -m -s /bin/bash fedora
yes fedora | passwd fedora

Now, we can prepare to create boot loader using iPXE. Download and compile iPXE.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
git clone http://git.ipxe.org/ipxe.git $HOME/ipxe
# create a special startup script for our bootloader:
cat << 'END' > $HOME/ipxe/init.ipxe
#!ipxe

prompt --key 0x02 --timeout 2000 Press Ctrl-B for the iPXE command line... && shell ||

dhcp || exit
set prefix file:///linux
chain ${prefix}/boot.cfg || exit
END
# Enable the “file” download protocol:
echo '#define DOWNLOAD_PROTO_FILE' > $HOME/ipxe/src/config/local/general.h
# Buld the boot loader
sudo dnf groupinstall -y "C Development Tools and Libraries"
cd $HOME/ipxe/src
make clean
make bin-x86_64-efi/ipxe.efi EMBED=../init.ipxe
# You should build it in an UEFI system. I fail to build in a BIOS system.
Then copy boot loader and kernel image to an FAT16/32 formatted USB Key.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
IPXE_FILE="$HOME/ipxe/src/bin-x86_64-efi/ipxe.efi"
mkdir -p $HOME/esp/efi/boot
mkdir $HOME/esp/linux
cp $IPXE_FILE $HOME/esp/efi/boot/bootx64.efi
DEFAULT_VER=$(ls -c /firefly/lib/modules | head -n 1)
MY_DNS1=x.x.x.x
MY_DNS2=x.x.x.x
MY_NFS4=sword.xxx.xxx
cat << END > $HOME/esp/linux/boot.cfg
#!ipxe

kernel --name kernel.efi \${prefix}/vmlinuz-$DEFAULT_VER initrd=initrd.img ro ip=dhcp rd.peerdns=0 nameserver=$MY_DNS1 nameserver=$MY_DNS2 root=nfs4:$MY_NFS4:/firefly console=tty0 console=ttyS0,115200n8 audit=0 selinux=0 quiet
initrd --name initrd.img \${prefix}/initramfs-$DEFAULT_VER.img
boot || exit
END

#Copy the Linux kernel and its associated initramfs
cp $(find /fc28/lib/modules -maxdepth 2 -name 'vmlinuz' | grep -m 1 $DEFAULT_VER) $HOME/esp/linux/vmlinuz-$DEFAULT_VER
cp $(find /fc28/boot -name 'init*' | grep -m 1 $DEFAULT_VER) $HOME/esp/linux/initramfs-$DEFAULT_VER.img
Our resulting directory layout should look like this, and we need to copy all files inside esp into EFI system partition on USB Key:
1
2
3
4
5
6
7
8
9
10
11
12
esp/
├── efi
│   └── boot
│   └── bootx64.efi
└── linux
├── boot.cfg
├── initramfs-5.6.11-300.fc32.x86_64.img
├── initramfs-5.6.13-300.fc32.x86_64.img
├── vmlinuz-5.6.11-300.fc32.x86_64
└── vmlinuz-5.6.13-300.fc32.x86_64

3 directories, 6 files

At the end, boot your USB key and have a lots of fun.

More reading:

https://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/nfs https://wiki.gentoo.org/wiki/Diskless_nodes/zh-cn

 Previous post: 乡音 | My Hometown's Dialect Next post: Play around with HP ML350 G6 

© 2025 白色乌鸦|White Crow

Theme Typography by Makito

Proudly published with Hexo