Difference between revisions of "Diskless system"

From ArchWiki
Jump to: navigation, search
(NFS)
m (Style fixes.)
Line 24: Line 24:
 
Install ISC {{Pkg|dhcp}} and configure it:
 
Install ISC {{Pkg|dhcp}} and configure it:
  
{{hc|/etc/dhcpd.conf|<nowiki>
+
{{hc|/etc/dhcpd.conf|2=
 
allow booting;
 
allow booting;
 
allow bootp;
 
allow bootp;
Line 48: Line 48:
 
     }
 
     }
 
}
 
}
</nowiki>}}
+
}}
  
 
{{Note|{{ic|next-server}} should be the address of the TFTP server; everything else should be changed to match your network}}
 
{{Note|{{ic|next-server}} should be the address of the TFTP server; everything else should be changed to match your network}}
Line 64: Line 64:
 
=== Network storage ===
 
=== 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 {{ic|copyonwrite}} mode to do so, which ends up discarding all writes on client disconnect. In some situations however, this might be highly desirable.
+
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 will need to use the {{ic|copyonwrite}} mode to do so, which ends up discarding all writes on client disconnect. In some situations however, this might be highly desirable.
  
 
==== NFS ====
 
==== NFS ====
Line 70: Line 70:
 
Install {{Pkg|nfs-utils}} on the server.
 
Install {{Pkg|nfs-utils}} on the server.
  
You'll need to add the root of your Arch installation to your [[NFS]] exports:
+
You will need to add the root of your Arch installation to your [[NFS]] exports:
  
 
{{hc|/etc/exports|2=
 
{{hc|/etc/exports|2=
Line 89: Line 89:
 
[arch]
 
[arch]
 
     exportname = /srv/arch.img
 
     exportname = /srv/arch.img
     copyonwrite = false}}
+
     copyonwrite = false
 +
}}
  
 
{{Note|Set {{ic|copyonwrite}} to true if you want to have multiple clients using the same NBD share simultaneously; refer to {{ic|man 5 nbd-server}} for more details.}}
 
{{Note|Set {{ic|copyonwrite}} to true if you want to have multiple clients using the same NBD share simultaneously; refer to {{ic|man 5 nbd-server}} for more details.}}
  
Start '''nbd''' systemd service.
+
Start {{ic|nbd}} systemd service.
  
 
== Client installation ==
 
== Client installation ==
Line 125: Line 126:
 
Trivial modifications to the {{ic|net}} hook are required in order for NFSv4 mounting to work (not supported by {{ic|nfsmount}}--the default for the {{ic|net}} hook).
 
Trivial modifications to the {{ic|net}} hook are required in order for NFSv4 mounting to work (not supported by {{ic|nfsmount}}--the default for the {{ic|net}} hook).
  
  # sed s/nfsmount/mount.nfs4/ "$root/usr/lib/initcpio/hooks/net" | tee "$root/usr/lib/initcpio/hooks/net_nfs4"
+
  # sed s/nfsmount/mount.nfs4/ "$root/usr/lib/initcpio/hooks/net" > "$root/usr/lib/initcpio/hooks/net_nfs4"
  # cp $root/usr/lib/initcpio/install/{net,net_nfs4}
+
  # cp $root/usr/lib/initcpio/install/net{,_nfs4}
  
 
The copy of {{ic|net}} is unfortunately needed so it does not get overwritten when {{pkg|mkinitcpio-nfs-utils}} is updated on the client installation.
 
The copy of {{ic|net}} is unfortunately needed so it does not get overwritten when {{pkg|mkinitcpio-nfs-utils}} is updated on the client installation.
Line 132: Line 133:
 
Edit {{ic|/etc/mkinitcpio.conf}} and add {{ic|nfsv4}} to {{ic|MODULES}}, {{ic|net_nfs4}} to {{ic|HOOKS}}, and {{ic|/usr/bin/mount.nfs4}} to {{ic|BINARIES}}.
 
Edit {{ic|/etc/mkinitcpio.conf}} and add {{ic|nfsv4}} to {{ic|MODULES}}, {{ic|net_nfs4}} to {{ic|HOOKS}}, and {{ic|/usr/bin/mount.nfs4}} to {{ic|BINARIES}}.
  
 
+
Next, we [[chroot]] into our install and run ''mkinitcpio'':
Next, we [[chroot]] into our install and run mkinitcpio:
+
  
 
  # arch-chroot "$root" /bin/bash
 
  # arch-chroot "$root" /bin/bash
 
  # mkinitcpio -p linux
 
  # mkinitcpio -p linux
# exit
 
  
 
==== NBD ====
 
==== NBD ====
  
The {{AUR|mkinitcpio-nbd}} package needs to be installed on the client. Build it with '''makepkg''' and install it:
+
The {{AUR|mkinitcpio-nbd}} package needs to be installed on the client. Build it with ''makepkg'' and install it:
  
 
  # pacman --root "$root" --dbpath "$root/var/lib/pacman" -U mkinitcpio-nbd-0.4-1-any.pkg.tar.xz
 
  # pacman --root "$root" --dbpath "$root/var/lib/pacman" -U mkinitcpio-nbd-0.4-1-any.pkg.tar.xz
Line 165: Line 164:
 
  # arch-chroot /srv/arch grub-mknetdir --net-directory=/boot --subdir=grub
 
  # arch-chroot /srv/arch grub-mknetdir --net-directory=/boot --subdir=grub
  
Luckily for us, grub-mknetdir creates prefixes for all currently compiled/installed targets, and the {{pkg|grub}} maintainers were nice enough to give us both in the same package, thus grub-mknetdir only needs to be run once.
+
Luckily for us, grub-mknetdir creates prefixes for all currently compiled/installed targets, and the {{Pkg|grub}} maintainers were nice enough to give us both in the same package, thus grub-mknetdir only needs to be run once.
  
Now we create a trivial grub configuration:
+
Now we create a trivial GRUB configuration:
  
{{hc|# vim "$root/boot/grub/grub.cfg"|2=<nowiki>
+
{{hc|# vim "$root/boot/grub/grub.cfg"|2=
 
menuentry "Arch Linux" {
 
menuentry "Arch Linux" {
 
     linux /vmlinuz-linux quiet add_efi_memmap ip=:::::eth0:dhcp nfsroot=10.0.0.1:/arch
 
     linux /vmlinuz-linux quiet add_efi_memmap ip=:::::eth0:dhcp nfsroot=10.0.0.1:/arch
 
     initrd /initramfs-linux.img
 
     initrd /initramfs-linux.img
}</nowiki>}}
+
}
 +
}}
  
[[GRUB]] dark-magic will {{ic|<nowiki>set root=(tftp,10.0.0.1)</nowiki>}} automatically, so that the kernel and initramfs are transferred via TFTP without any additional configuration, though you might want to set it explicitly if you have any other non-tftp menuentries.
+
[[GRUB]] dark-magic will {{ic|1=set root=(tftp,10.0.0.1)}} automatically, so that the kernel and initramfs are transferred via TFTP without any additional configuration, though you might want to set it explicitly if you have any other non-tftp menuentries.
  
{{Note|Modify your kernel line as-necessary, refer to [[#Pxelinux]] for NBD-related options}}
+
{{Note|Modify your kernel line as-necessary, refer to [[Syslinux#Pxelinux|Pxelinux]] for NBD-related options}}
  
 
==== Pxelinux====
 
==== Pxelinux====
Line 187: Line 187:
 
==== NBD root ====
 
==== NBD root ====
  
In late boot, you'll want to switch your root filesystem mount to both {{ic|rw}}, and enable {{ic|<nowiki>compress=lzo</nowiki>}}, for much improved disk performance in comparison to [[NFS]].
+
In late boot, you'll want to switch your root filesystem mount to both {{ic|rw}}, and enable {{ic|1=compress=lzo}}, for much improved disk performance in comparison to [[NFS]].
  
{{hc|# vim "$root/etc/fstab"|<nowiki>
+
{{hc|# vim "$root/etc/fstab"|2=
 
/dev/nbd0  /  btrfs  rw,noatime,discard,compress=lzo  0 0
 
/dev/nbd0  /  btrfs  rw,noatime,discard,compress=lzo  0 0
</nowiki>}}
+
}}
  
 
==== Program state directories ====
 
==== Program state directories ====
Line 205: Line 205:
 
It would be best to configure software that has some sort of state/database to use unique state/database storage directories for each host. If you wanted to run [http://puppetlabs.com/ puppet], for example, you could simply use the {{ic|%H}} specifier in the puppet unit file:
 
It would be best to configure software that has some sort of state/database to use unique state/database storage directories for each host. If you wanted to run [http://puppetlabs.com/ puppet], for example, you could simply use the {{ic|%H}} specifier in the puppet unit file:
  
{{hc|# vim "$root/etc/systemd/system/puppetagent.service"|<nowiki>
+
{{hc|# vim "$root/etc/systemd/system/puppetagent.service"|2=
 
[Unit]
 
[Unit]
 
Description=Puppet agent
 
Description=Puppet agent
Line 219: Line 219:
 
[Install]
 
[Install]
 
WantedBy=multi-user.target
 
WantedBy=multi-user.target
</nowiki>}}
+
}}
  
 
Puppet-agent creates vardir and ssldir if they do not exist.
 
Puppet-agent creates vardir and ssldir if they do not exist.
Line 239: Line 239:
 
  # cp -r "$root/boot" /srv/boot
 
  # cp -r "$root/boot" /srv/boot
  
You'll then need to umount $root before you start the client.
+
You will then need to umount {{ic|$root}} before you start the client.
  
 
  # umount "$root"
 
  # umount "$root"
Line 247: Line 247:
 
== See also ==
 
== See also ==
  
[https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt kernel.org: Mounting the root filesystem via NFS (nfsroot)]
+
* [https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt kernel.org: Mounting the root filesystem via NFS (nfsroot)]
 
+
* [http://www.syslinux.org/wiki/index.php/PXELINUX syslinux.org: pxelinux FAQ]
[http://www.syslinux.org/wiki/index.php/PXELINUX syslinux.org: pxelinux FAQ]
+

Revision as of 12:21, 11 November 2013

Summary help replacing me
Detailed explanation of diskless system setup.
Related
NFS
NFS Troubleshooting
PXE
Mkinitcpio#Using_net

From Wikipedia:Diskless node

A diskless node (or diskless workstation) is a workstation or personal computer without disk drives, which employs network booting to load its operating system from a server.

Server configuration

First of all, we must install the following components:

  • A DHCP server to assign IP addresses to our diskless nodes.
  • A TFTP server to transfer the boot image (a requirement of all PXE option roms).
  • A form of network storage (NFS or NBD) to export the Arch installation to the diskless node.
Note: dnsmasq is capable of simultaneously acting as both DHCP and TFTP server. For more information, see the dnsmasq article.

DHCP

Install ISC dhcp and configure it:

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

authoritative;

option domain-name-servers 10.0.0.1;

option architecture code 93 = unsigned integer 16;

group {
    next-server 10.0.0.1;

    if option architecture = 00:07 {
        filename "/grub/x86_64-efi/core.efi";
    } else {
        filename "/grub/i386-pc/core.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

RFC 4578 defines the "Client System Architecture Type" dhcp option. In the above configuration, if the PXE client requests an x86_64-efi binary (type 0x7), we appropriately give them one, otherwise falling back to the legacy binary. This allows both UEFI and legacy BIOS clients to boot simultaneously on the same network segment.

Start ISC DHCP systemd service.

TFTP

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

Set the TFTP root to /srv/arch/boot. See Tftpd server for installation and configuration.

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 will need to use the copyonwrite mode to do so, which ends up discarding all writes on client disconnect. In some situations however, this might be highly desirable.

NFS

Install nfs-utils on the server.

You will need to add the root of your Arch installation to your NFS exports:

/etc/exports
/srv       *(rw,fsid=0,no_root_squash,no_subtree_check)
/srv/arch  *(rw,no_root_squash,no_subtree_check)

Next, start NFS services: rpc-idmapd rpc-mountd.

NBD

Install nbd and configure it.

# vim /etc/nbd-server/config
[generic]
    user = nbd
    group = nbd
[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 systemd service.

Client installation

Next we will create a full Arch Linux installation in a subdirectory on the server. During boot, the diskless client will get an IP address from the DHCP server, then boot from the host using PXE and mount this installation as its root.

Directory setup

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

# truncate -s 1G /srv/arch.img
# mkfs.btrfs /srv/arch.img
# export root=/srv/arch
# mkdir -p "$root"
# mount -o loop,discard,compress=lzo /srv/arch.img "$root"
Note: Creating a separate filesystem is required for NBD but optional for NFS and can be skipped/ignored.

Bootstrapping installation

Install devtools and arch-install-scripts, and run mkarchroot.

# pacstrap -d "$root" base mkinitcpio-nfs-utils nfs-utils
Note: In all cases mkinitcpio-nfs-utils is still required. ipconfig used in early-boot is provided only by the latter.

Now the initramfs needs to be constructed.

NFS

Trivial modifications to the net hook are required in order for NFSv4 mounting to work (not supported by nfsmount--the default for the net hook).

# sed s/nfsmount/mount.nfs4/ "$root/usr/lib/initcpio/hooks/net" > "$root/usr/lib/initcpio/hooks/net_nfs4"
# cp $root/usr/lib/initcpio/install/net{,_nfs4}

The copy of net is unfortunately needed so it does not get overwritten when mkinitcpio-nfs-utils is updated on the client installation.

Edit /etc/mkinitcpio.conf and add nfsv4 to MODULES, net_nfs4 to HOOKS, and /usr/bin/mount.nfs4 to BINARIES.

Next, we chroot into our install and run mkinitcpio:

# arch-chroot "$root" /bin/bash
# mkinitcpio -p linux

NBD

The mkinitcpio-nbdAUR package needs to be installed on the client. Build it with makepkg and install it:

# pacman --root "$root" --dbpath "$root/var/lib/pacman" -U mkinitcpio-nbd-0.4-1-any.pkg.tar.xz

You will then need to append nbd to your HOOKS array after net; net will configure your networking for you, but not attempt a NFS mount if nfsroot is not specified in the kernel line.

Client configuration

In addition to the setup mentioned here, you should also set up your hostname, timezone, locale, and keymap, and follow any other relevant parts of the Installation Guide.

Bootloader

GRUB

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

Notes: (Discuss in Talk:Diskless system#)

Though poorly documented, GRUB supports being loaded via PXE.

# pacman --root "$root" --dbpath "$root/var/lib/pacman" -S grub

Create a grub prefix on the target installation for both architectures using grub-mknetdir.

# arch-chroot /srv/arch grub-mknetdir --net-directory=/boot --subdir=grub

Luckily for us, grub-mknetdir creates prefixes for all currently compiled/installed targets, and the grub maintainers were nice enough to give us both in the same package, thus grub-mknetdir only needs to be run once.

Now we create a trivial GRUB configuration:

# vim "$root/boot/grub/grub.cfg"
menuentry "Arch Linux" {
    linux /vmlinuz-linux quiet add_efi_memmap ip=:::::eth0:dhcp nfsroot=10.0.0.1:/arch
    initrd /initramfs-linux.img
}

GRUB dark-magic will set root=(tftp,10.0.0.1) automatically, so that the kernel and initramfs are transferred via TFTP without any additional configuration, though you might want to set it explicitly if you have any other non-tftp menuentries.

Note: Modify your kernel line as-necessary, refer to Pxelinux for NBD-related options

Pxelinux

Pxelinux is provided by syslinux, see here for detail.

Additional mountpoints

NBD root

In late boot, you'll want to switch your root filesystem mount to both rw, and enable compress=lzo, for much improved disk performance in comparison to NFS.

# vim "$root/etc/fstab"
/dev/nbd0  /  btrfs  rw,noatime,discard,compress=lzo  0 0

Program state directories

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

Reason: systemd can apparently be told to not use persistent logging, and does this by default anyway then /var/log is tmpfs (Discuss in Talk:Diskless system#)

You could mount /var/log, for example, as tmpfs so that logs from multiple hosts don't mix unpredictably, and do the same with /var/spool/cups, so the 20 instances of cups using the same spool don't fight with each other and make 1,498 print jobs and eat an entire ream of paper (or worse: toner cartridge) overnight.

# vim "$root/etc/fstab"
tmpfs   /var/log        tmpfs     nodev,nosuid    0 0
tmpfs   /var/spool/cups tmpfs     nodev,nosuid    0 0

It would be best to configure software that has some sort of state/database to use unique state/database storage directories for each host. If you wanted to run puppet, for example, you could simply use the %H specifier in the puppet unit file:

# vim "$root/etc/systemd/system/puppetagent.service"
[Unit]
Description=Puppet agent
Wants=basic.target
After=basic.target network.target

[Service]
Type=forking
PIDFile=/run/puppet/agent.pid
ExecStartPre=/usr/bin/install -d -o puppet -m 755 /run/puppet
ExecStart=/usr/bin/puppet agent --vardir=/var/lib/puppet-%H --ssldir=/etc/puppet/ssl-%H

[Install]
WantedBy=multi-user.target

Puppet-agent creates vardir and ssldir if they do not exist.

If neither of these approaches are appropriate, the last sane option would be to create a systemd generator that creates a mount unit specific to the current host (specifiers are not allowed in mount units, unfortunately).

Client boot

NBD

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

Reason: When using COW on the server, the clients all effectively have read-only mounts of the original filesystem; it should theoretically be safe to do a read-write mount on the NBD server (Discuss in Talk:Diskless system#)

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. /srv/boot).

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

You will 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 /srv/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

See also