Difference between revisions of "Diskless system"

From ArchWiki
Jump to: navigation, search
(Undo revision 234642 by Mihanson (talk))
(Undo revision 234640 by Mihanson (talk))
Line 16: Line 16:
  
 
===DHCP===
 
===DHCP===
{{Note|{{pkg|dnsmasq}} can provide both DHCP and TFTP eliminating the need for a separate TFTP package. See the [[https://wiki.archlinux.org/index.php/PXE#DHCP_.2B_TFTP| PXE wiki page]] for information on setting this up.}}
 
  
 
Install ISC {{pkg|dhcp}}.
 
Install ISC {{pkg|dhcp}}.

Revision as of 23:41, 7 December 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Merge-arrows-2.pngThis article or section is a candidate for merging with PXE.Merge-arrows-2.png

Notes: needs to be rewritten into sub-articles; duplicated information (Discuss in Talk:Diskless system#)

Contrast to the official installation guide, which concentrates on an arch installation on local storage, here the installation is to be placed on network storage.

Server configuration

You will need a DHCP server to setup networking, as well as a TFTP server to transfer the boot image (a requirement of all PXE option roms). Unlike PXE which is designed for quick-and-dirty/temporary setups to boot installation media, here you're actually doing a network installation, which is more-permanent, and thus calls for doing things properly.

DHCP

Install ISC dhcp.

# pacman -Syu dhcp

Configure ISC DHCP.

# vim /etc/dhcpd.conf
allow booting;
allow bootp;

authoritative;

option domain-name-servers 10.0.0.1;

group 
{
    next-server 10.0.0.1;
    filename "pxelinux.0";

    subnet 10.0.0.0 netmask 255.255.255.0 {
        option routers 10.0.0.1;
        range 10.0.0.128 10.0.0.254;
    }
}
Note: next-server should be the address of the TFTP server; everything else should be changed to match your network

Start ISC DHCP.

# systemctl start dhcpd

TFTP

The TFTP server will be used to transfer the kernel, initramfs, and pxelinux to the client.

Install tftp-hpa.

# pacman -Syu tftp-hpa
Note: Change /srv/arch/boot to /mnt/boot if you're going to use NBD, because you'll be unable to mount your root filesystem while in use

Configuration

Copy the tftp unit files in /usr/lib/systemd/system to /etc/systemd/system; the former gets overwritten when systemd is updated. The systemd article talks in more detail about customizing unit files.

# cp /usr/lib/systemd/system/tftpd.s* /etc/systemd/system/

Next we tell tftpd where the tftp root is: /srv/arch/boot.

# vim /etc/systemd/system/tftpd.service
[Unit]
Description=hpa's original TFTP daemon

[Service]
ExecStart=/usr/sbin/in.tftpd -s /srv/arch/boot/
StandardInput=socket
StandardOutput=inherit
StandardError=journal

Start tftpd :

# systemctl enable tftpd.socket
# systemctl start tftpd.socket

Network storage

The primary difference between using NFS and NBD is while with both you can in fact have multiple clients using the same installation, with NBD (by the nature of manipulating a filesystem directly) you'll need to use the copyonwrite mode to do so, which ends up discarding all writes on client disconnected. In some situations however, this might be highly desirable.

NFS

Warning: Due to lack of support in mkinitcpio-nfs-utils, Archlinux is currently unable to boot from a NFSv4 share.

Install nfs-utils on the server.

# pacman -Syu nfs-utils

You'll need to add the root of your arch installation to your NFS exports:

# vim /etc/exports
/srv/arch *(rw,no_root_squash,no_subtree_check,sync)
Note: If you're not too worried about losing data if the server crashes, replacing sync with async will give you a speed boost.

Next start NFS.

# systemctl start rpc-mountd.service rpc-statd.service

Additional information can be found in the NFS article.

NBD

Install nbd.

# pacman -Syu nbd

Configure nbd.

# vim /etc/nbd-server/config
[generic]
[arch]
    exportname = /srv/arch.img
    copyonwrite = false
Note: Set copyonwrite to true if you want to have multiple clients using the same NBD share simultaneously; refer to man 5 nbd-server for more details.

Start nbd.

# systemctl start nbd

Client installation

Directory setup

Create a sparse file of at least 5 gigabytes, and create an ext4 filesystem on it (you can of course also use a real block device or LVM if you so desire).

# truncate -s 5G /srv/arch.img
# mkfs.ext4 /srv/arch.img
# mkdir -p /srv/arch
# mount /srv/arch.img /mnt/arch
Note: Creating a separate filesystem is required for NBD but optional for NFS and can be skipped/ignored, but consider the subtree_check option in the latter case.

First, create a directory that will contain the Arch installation; replace /srv/arch with wherever you'd like to put your installation.

# export root=/srv/arch
# mkdir -p $root/{proc,sys,run,tmp}
# mkdir -p $root/dev/{pts,shm}

This also creates the directories that will be used for the API filesystem mountpoints later. Next we create the directory that pacman stores its database.

# mkdir -p "$root/var/lib/pacman"

Bootstrapping installation

Note: You can also use arch-chroot and pacstrap from arch-install-scripts rather than chroot and pacman directly

Mount the Linux API filesystems.

# mount -t proc proc "$root/proc" -o nosuid,noexec,nodev
# mount -t sysfs sys "$root/sys" -o nosuid,noexec,nodev
# mount -t devtmpfs udev "$root/dev" -o mode=0755,nosuid
# mount -t devpts devpts "$root/dev/pts" -o mode=0620,gid=5,nosuid,noexec

Install the essential packages needed.

# pacman -Syu --root "$root" --dbpath "$root/var/lib/pacman" base base-devel --arch x86_64

Replace x86_64 with i686 as appropriate for your target hardware.

You'll need to install either mkinitcpio-nfs-utils or mkinitcpio-nbdAUR depending on whether you are using NFS or NBD.

Next, edit "$root/etc/mkinitcpio.conf" and add nfsv3 to the MODULES array, and add net after udev to the HOOKS array.

# vim "$root/etc/mkinitcpio.conf"
MODULES="nfsv3"
HOOKS="base udev net autodetect filesystems"
Note: Add nbd after the net hook if you are using NBD.

The initramfs now needs to be rebuilt; the easiest way to do this is chroot.

# chroot "$root" /bin/bash
(chroot) # mkinitcpio -p linux
(chroot) # exit

Finally, cleanup by unmounting all of the virtual filesystems we mounted earlier.

# umount \
    "$root/dev/pts" \
    "$root/dev" \
    "$root/sys" \
    "$root/proc"

Client configuration

In addition to the setup mentioned here, you should also set up your hostname, timezone, locale, and keymap.

Pxelinux

Install syslinux.

# pacman -Syu syslinux

Copy the pxelinux bootloader (provided by the syslinux package) to the boot directory of the client.

# cp /usr/lib/syslinux/pxelinux.0 "$root/boot"
# mkdir "$root/boot/pxelinux.cfg"

We also created the pxelinux.cfg directory, which is where pxelinux searches for configuration files by default. Because we don't want to discriminate between different host MACs, we then create the default configuration.

# vim "$root/boot/pxelinux.cfg/default"
default linux

label linux
kernel vmlinuz-linux
append initrd=initramfs-linux.img ip=::::::dhcp nfsroot=10.0.0.1:/srv/arch

Or if you are using NBD, use the following append line:

append initrd=initramfs-linux.img ip=::::::dhcp nbd_host=10.0.0.1 nbd_name=arch
Note: You will need to change nbd_host and/or nfsroot, respectively, to match your network configuration (the address of the NFS/NBD server)

The pxelinux configuration syntax identical to syslinux; refer to the upstream documentation for more information.

The kernel and initramfs will be transferred via TFTP, so the paths to those are going to be relative to the TFTP root. Otherwise, the root filesystem is going to be the NFS mount itself, so those are relative to the root of the NFS server.

VFS mountpoints

Add hacks to your fstab for the root filesystem and devpts.

# vim "$root/etc/fstab"
none    /           none
none    /dev/pts    devpts    gid=5,mode=620    0 0

Late-boot networking

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Should no longer be necessary (Discuss in Talk:Diskless system#)

This is to prevent the client from trying to reconnect the network and killing itself. Any disconnect of the network and your client will freeze.

One way to fix this is by running dhcpcd with the -s option to use the existing lease obtained in early-boot instead of requesting a new one.

# vim "$root/etc/conf.d/dhcpcd"
DHCPCD_ARGS=" -s $(ifconfig eth0 | grep -o '[0-9]*\.[0-9\.]*' | head -n1)"
# vim "$root/etc/rc.conf"
NETWORK_PERSIST="yes"

Multiple clients and /var

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: (Discuss in Talk:Diskless system#)

If you're running multiple clients from the one NFS server (e.g. for a Beowulf Cluster), it's important that each client has its own /var. You can export a directory for each of your hosts and mount the directory early in the boot process:

Initscripts

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: initscripts is deprecated (Discuss in Talk:Diskless system#)

Create something similar to the following file:

/etc/rc.d/functions.d
mount_var() {
  status "Mounting /var" mount -o v3,nolock 10.0.0.1:/srv/arch-vars/$(hostname) /var
  if (( $? )); then
    echo "There is no /var directory for this node on the server. The node will not work correctly without one."
    while true; do
      sleep 1m
    done
  fi
}
add_hook sysinit_end mount_var

Client boot

NBD

If you're using NBD, you'll need to umount the arch.img before/while you boot your client.

This makes things particularly interesting when it comes to kernel updates. You can't have your client filesystem mounted while you're booting a client, but that also means you need to use a kernel separate from your client filesystem in order to build it.

You'll need to first copy $root/boot from the client installation to your tftp root (i.e. /mnt/boot).

# cp -r "$root/boot" /mnt/boot

You'll then need to umount $root before you start the client.

# umount "$root"
Note: To update the kernel in this setup, you either need to mount /mnt/boot using NFS in fstab on the client (prior to doing the kernel update) or mount your client filesystem after the client has disconnected from NBD

References

kernel.org: Mounting the root filesystem via NFS (nfsroot)

syslinux.org: pxelinux FAQ