Difference between revisions of "User:Buhman"

From ArchWiki
Jump to: navigation, search
(Client Configuration)
(merged)
Line 1: Line 1:
[[Category:Boot process]]
 
[[Category:File systems]]
 
[[Category:Networking]]
 
{{Article summary start}}
 
{{Article summary text|Detailed explanation of a PXE booted Arch installation with networked root filesystem.}}
 
{{Article summary heading|Related}}
 
{{Article summary wiki|NFS}}
 
{{Article summary wiki|PXE}}
 
{{Article summary wiki|Mkinitcpio#Using_net Using net}}
 
{{Article summary end}}
 
  
This allows you to
 
 
==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).
 
 
===DHCP===
 
 
Install ISC {{pkg|dhcp}}.
 
 
{{bc|# pacman -Syu dhcp}}
 
 
Configure ISC DHCP.
 
 
{{hc|# vim /etc/dhcpd.conf|2=
 
<nowiki>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;
 
    }
 
}</nowiki>}}
 
 
{{Note|{{ic|next-server}} should be the address of the TFTP server; everything else should be changed to match your network}}
 
 
Start ISC DHCP.
 
 
{{bc|# systemctl start dhcpd}}
 
 
Or if you use {{pkg|sysvinit}},
 
 
{{bc|# rc.d start dhcpd}}
 
 
===TFTP===
 
 
{{hc|# vim /etc/xinetd.d/tftp|<nowiki>
 
service tftp
 
{
 
    per_source = 11
 
    socket_type = dgram
 
    protocol = udp
 
    user = root
 
    server = /usr/sbin/tftpd
 
    server_args = /mnt/arch/boot
 
    wait = yes
 
    cps = 100 2
 
}</nowiki>}}
 
 
===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 disconnected. In some situations however, this might be highly desirable.
 
 
====NFS====
 
 
Install {{pkg|nfs-utils}} on the server.
 
 
{{bc|# pacman -Syu nfs-utils}}
 
 
You'll need to add the root of your arch installation to your NFS exports.
 
 
{{hc|# vim /etc/exports|2=
 
/mnt/arch *(rw,fsid=0,no_root_squash,no_subtree_check,async)
 
}}
 
 
Start {{ic|rpcbind}}, {{ic|nfs-common}}, and {{ic|nfs-server}}.
 
 
{{bc|# rc.d start rpcbind nfs-common nfs-server}}
 
 
Add them to the {{ic|DAEMONS}} array in [[rc.conf]] if you'd like this to happen on boot.
 
 
Additional information can be found in the [[NFS]] article.
 
 
====NBD====
 
 
Install {{pkg|nbd}}.
 
 
{{bc|# pacman -Syu nbd}}
 
 
Configure nbd.
 
 
{{hc|# vim /etc/nbd-server/config|2=
 
[generic]
 
[arch]
 
    exportname = /mnt/arch.img
 
    copyonwrite = false}}
 
 
{{note|Set {{ic|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.}}
 
 
==Client installation==
 
 
===Directory setup===
 
 
Create a [[Wikipedia: Sparse file|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).
 
 
{{bc|1=
 
# truncate -s 5G /mnt/arch.img
 
# mkfs.ext4 /mnt/arch.img
 
# mkdir -p /mnt/arch
 
# mount /mnt/arch.img /mnt/arch}}
 
 
{{Note|Creating a separate filesystem is required for NBD but optional for NFS and can be skipped/ignored}}
 
 
First, create a directory that will contain the Arch installation; replace {{ic|/mnt/arch}} with wherever you'd like to put your installation.
 
 
{{bc|1=
 
<nowiki>
 
# export root=/mnt/arch
 
# mkdir -p "$root/{proc,sys,run,tmp}"
 
# mkdir -p "$root/dev/{pts,shm}"
 
</nowiki>}}
 
 
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.
 
 
{{bc|# mkdir -p "$root/var/lib/pacman"}}
 
 
===Bootstrapping installation===
 
 
Mount the Linux API filesystems.
 
 
{{bc|1=
 
# 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. Of particular interest is {{ic|mkinitcpio-nfs-utils}}; this is the dark sorcery that will mount our root filesystem from the NFS server during early-boot.
 
 
{{bc|# pacman -Syu --root "$root" --dbpath "$root/var/lib/pacman" base base-devel --arch x86_64}}
 
 
Replace {{ic|x86_64}} with {{ic|i686}} as appropriate for your target hardware.
 
 
Next, edit {{ic|"$root/etc/mkinitcpio.conf"}} and add {{ic|nfs}} to the {{ic|MODULES}} array, and add {{ic|net}} after {{ic|udev}} to the {{ic|HOOKS}} array.
 
 
{{hc|# vim "$root/etc/mkinitcpio.conf"|2=
 
MODULES="nfs"
 
HOOKS="base udev '''net''' autodetect filesystems"}}
 
 
{{Note|Add {{ic|nbd}} after the {{ic|net}} hook if you are using NBD.}}
 
 
The initramfs now needs to be rebuilt; the easiest way to do this is chroot.
 
 
{{bc|1=
 
# chroot "$root" /bin/bash
 
(chroot) # mkinitcpio -p linux
 
# exit}}
 
 
Finally, cleanup by unmounting all of the virtual filesystems we mounted earlier.
 
 
{{bc|1=
 
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#Set_the_host_name|hostname]], [[Timezone#Time_Zone|timezone]], [[Locale#Setting_system-wide_locale|locale]], and [[KEYMAP|keymap]].
 
 
===Pxelinux===
 
 
Install {{pkg|syslinux}}.
 
 
{{bc|1=
 
# pacman -Syu syslinux}}
 
 
Copy the pxelinux bootloader (provided by the syslinux package) to the boot directory of the client.
 
 
{{bc|1=
 
# cp /usr/lib/syslinux/pxelinux.0 "$root/boot"
 
# mkdir "$root/boot/pxelinux.cfg"}}
 
 
We also created the {{ic|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 {{ic|default}} configuration.
 
 
{{hc|# vim "$root/boot/pxelinux.cfg/default"|<nowiki>
 
default linux
 
 
label linux
 
kernel vmlinuz-linux
 
append initrd=initramfs-linux.img rootfstype=nfs root=/dev/nfs nfsroot=10.0.0.1:/mnt/arch,v4,rsize=16384,wsize=16384 ip=:::::eth0:dhcp
 
</nowiki>}}
 
 
Or if you are using NBD, use the following append line:
 
 
{{bc|<nowiki># append initrd=initramfs-linux.img root=/dev/nbd0 nbd_host=10.0.0.1 nbd_name=arch ip=:::::eth0:dhcp</nowiki>}}
 
 
{{Note|You will need to change {{ic|nbd_host}} and/or {{ic|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.
 
 
{{hc|# vim "$root/etc/fstab"|2=
 
none    /          none
 
none    /dev/pts    devpts    gid=5,mode=620    0 0}}
 
 
===Late-boot networking===
 
 
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.
 
 
The following workaround involves running the dhcpcd DHCP client on start-up with the {{ic|-s}} option to use the existing kernel DHCP auto-configured IP address instead of requesting a new one.
 
 
{{hc|# vim "$root/etc/conf.d/dhcpcd"|2=<nowiki>
 
DHCPCD_ARGS=" -s $(ifconfig eth0 | grep -o '[0-9]*\.[0-9\.]*' | head -n1)"</nowiki>}}
 
 
{{hc|# vim "$root/etc/rc.conf"|2=<nowiki>
 
NETWORK_PERSIST="yes"</nowiki>}}
 
 
==Client boot==
 
 
If all goes right, you should see the network card get an IP address from the server, then connect and boot the kernel. After the initial kernel messages, you should either see Arch Linux boot, or a "killed init" message.
 

Revision as of 14:35, 9 October 2012