Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
single system boot image
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
srd
n00b
n00b


Joined: 13 Apr 2010
Posts: 38

PostPosted: Tue Apr 13, 2010 12:57 am    Post subject: single system boot image Reply with quote

Anyone familiar with how one might setup a few diskless nodes using a single system image? Or any known packages similar to openssi that work with gentoo? I'd like to have a single file system from which all diskless nodes boot as opposed to the gentoo diskless howto which is a complete copy of a file system per node, terribly inefficient.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21631

PostPosted: Tue Apr 13, 2010 4:13 am    Post subject: Reply with quote

Make the server export the diskless root read-only so that no clients can accidentally mutate it. Configure all clients via DHCP. If you have any per-machine configuration, consider using an initramfs that can overmount a host-specific tmpfs with the relevant files before it begins booting the shared /sbin/init.
Back to top
View user's profile Send private message
srd
n00b
n00b


Joined: 13 Apr 2010
Posts: 38

PostPosted: Wed May 05, 2010 1:38 am    Post subject: Reply with quote

Diskless root read-only? I have /usr, /var, etc... on separate partitions as well, so I assume you mean those too since the diskless nodes need them as well.

How do you handle p/ machine configuration files like:
- /etc/hosts
- diskless nodes that store pid files in the same location /var/run/my-app/my-app.pid
- each node having it's own set of init scripts from rc-update

Can you elaborate on how to do the per-machine configuration a bit more using initramfs. I've not done this before.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21631

PostPosted: Wed May 05, 2010 2:31 am    Post subject: Reply with quote

Yes, for safety, you should make every shared export read-only. You could probably find a way to make multiple machines coexist with all of them writing to the exports, but it is unnecessary complexity.

You do not need /etc/hosts to be per-machine. Instead, let all systems have the same file and have it name all the machines.
You have two options for directories under /var. If you do not need to persist their contents, you could use a tmpfs for the area, and have the initramfs create the directory layout. If you want to persist the contents, or if you have insufficient RAM to create such a setup, you could give each machine a private /var on the server. Regardless, you can use a tmpfs for /var/run, /var/lib/init.d, and any other areas where the system writes files that are only meaningful until the system reboots.
For init scripts, /etc/conf.d settings, and any other situations where you need a truly per-machine configuration, you will need to have those prepared during boot. If an entire directory is per-machine, you can mount a tmpfs there and place contents accordingly. If only a few files need to be specialized, replace that file on the server with a symlink that will point to a location that is overmounted with per-machine state.

Once you have identified the directories which need to be customized, you need to add a block to your initramfs /init that will place a writable filesystem on those directories. You can use a tmpfs if writing to the disk is not allowed, as in this scenario. The initramfs then must populate the resulting area. The easiest way to do this would be with a pre-made tarball on the server. To take a hint from pxelinux, consider having the initramfs search for a tarball named after the MAC address of the primary interface:ip l show dev $(ip r | gawk '/default via / { print $5; }') | gawk '/link\/ether / { print $2; }'. If such a tarball is not found, begin stripping off octets or otherwise simplifying the name until you reach a default name that will hold the fallback configuration used by machines which have no specific instructions.
Code:
mount -o ro -t nfs 192.168.0.1:/diskless/per-machine/ /mnt/pm
defnic=$(ip r | gawk '/default via / { print $5; }')
mac=$(ip l show dev $defnic | gawk '/link\/ether / { print $2; }')
# Convert to pxelinux style
mac=${mac//:/-}
for f in $mac default; do
  if [ -f /mnt/pm/$mac.tar ]; then
    tar -x -f /mnt/pm/$mac.tar
    break
  fi
done
umount /mnt/pm
You can add more branches to look up the IP address and try to use it as well. It may be convenient to move this to a helper script or a subroutine, so that you can bail out of a complex search easily.
Back to top
View user's profile Send private message
srd
n00b
n00b


Joined: 13 Apr 2010
Posts: 38

PostPosted: Thu May 13, 2010 9:37 pm    Post subject: Reply with quote

I'm at the point of trying to mount the per machine directories of diskless clients from a single gentoo image, but having problems for directories such as /var/run, /var/lib/init.d. I do not need to persist the files contents across boots, and am trying to use tmpfs for this directory and have initramfs create the directory layout.

I've installed initramfs using this link ... http://en.gentoo-wiki.com/wiki/Initramfs#Kernel_Configuration ... and the init file in my cpio archive looks like this ...
Code:

#!/bin/busybox sh

mount -t proc none /proc
mount -t sysfs none /sys

mount -o ro /dev/sda3 /mnt/root

umount /proc
umount /sys

exec switch_root /mnt/root /sbin/init


I have a question for the switch_root line above. Here's my pxelinux.cfg/default file ...
Code:

DEFAULT /bzImage
APPEND ip=dhcp ro rootfstype=nfs root=/dev/nfs nfsroot=192.168.10.10:/diskless

Since this specifies where nfsroot is, why does initramfs's init file have to switch root locations? Or does it? And I'm guessing what I have there is wrong since I have nothing in /mnt/root. The root fs I'm trying to mount is located under /diskless and it seems to be that it's already mounted.

Is the initramfs's init file also where I should mount tmpfs for /var, /tmp, etc...? I tried adding the following lines but these didn't seem to help. Also, would dirs like /var/run/utmp be automatically created, or do I need to list all these dirs under /var in the directory layout of an initramfs archive?
Code:

mount -n -t tmpfs tmpfs /var
mount -n -t tmpfs tmpfs /tmp


Here's a link to more details on what I've currently got put in place as I'm having a hard time getting this working ... https://forums.gentoo.org/viewtopic-t-827880.html
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21631

PostPosted: Fri May 14, 2010 2:44 am    Post subject: Reply with quote

srd wrote:
Code:
#!/bin/busybox sh

mount -t proc none /proc
mount -t sysfs none /sys

mount -o ro /dev/sda3 /mnt/root

umount /proc
umount /sys

exec switch_root /mnt/root /sbin/init
This is a bit wasteful. You do not need proc or sys mounted in order to mount the local hard disk as a root volume. Of course, you do not actually want to mount the local hard disk at all.
srd wrote:
Since this specifies where nfsroot is, why does initramfs's init file have to switch root locations? Or does it? And I'm guessing what I have there is wrong since I have nothing in /mnt/root. The root fs I'm trying to mount is located under /diskless and it seems to be that it's already mounted.
Although technically possible, mixing an initramfs and nfsroot like this is unnecessary and looks a bit odd. An initramfs is required if the kernel cannot mount root on its own. For the case of NFS root over unsecured IP, as you have here, an initramfs is unnecessary. You should instead place all of your custom code in the initial process run out of the NFS root.
srd wrote:
Is the initramfs's init file also where I should mount tmpfs for /var, /tmp, etc...? I tried adding the following lines but these didn't seem to help.
You should mount the tmpfs on the directory that you want to be locally maintained. The commands you show are correct, but since you put them in the initramfs, you probably mounted on the directories inside the initramfs. You can either mount the tmpfs from a process launched out of the NFS root or mount them in their NFS-relative directory. Going with your earlier initramfs, you would mount the tmpfs on /mnt/root/tmp, since that will become /tmp after the switch_root.
srd wrote:
Also, would dirs like /var/run/utmp be automatically created, or do I need to list all these dirs under /var in the directory layout of an initramfs archive?
A tmpfs is created empty. While it is possible that other system initscripts will create some or all of the structure required, it would be safest to assume that you must create all such structure yourself. Placing those directories in an initramfs is possible, but suboptimal. The simplest solution would be to store on the NFS root a tarball containing the required structure, and have the client unpack that tarball into the tmpfs before transferring control to the system initscripts.
Back to top
View user's profile Send private message
srd
n00b
n00b


Joined: 13 Apr 2010
Posts: 38

PostPosted: Sat May 15, 2010 1:17 am    Post subject: Reply with quote

So I think I'm starting to understand a lot of this. I've got a /linuxrc file in my initramfs.img.gz that looks like this …
Code:

#!/bin/busybox sh

mount -n -t tmpfs tmpfs /tmp
mount -n -t tmpfs tmpfs /var
mount -n -t tmpfs tmpfs /var/log
mount -n -t tmpfs tmpfs /var/run
mount -n -t tmpfs tmpfs /var/lock
mount -n -t tmpfs tmpfs /var/lib/init.d
mount -n -t tmpfs tmpfs /var/lib/init.d                       

cd /etc && tar cfj /tmp/etc.tar.gz2 *
mount -n -t tmpfs tmpfs /etc

tar xfj /tmp/etc.tar.bz2 -C /etc

exec /sbin/init < /dev/console > /dev/console 2>&1


I mount my per-machine directories and populate an /etc dir for each node. So while I've got the normal directory layout of /proc, /sys, bin, etc… along w/ busybox laid out in my initramfs.img.gz, I think my problem is that root is being mounted on top of this because when I boot my client, it's still giving me read-only errors on files that should be writable like /var, etc ..., and when I 'cat /proc/mounts' on the client, I see none of these mounted.

Can you offer some advice for where I might be going wrong? I'm not sure how to get the real_root mounted and then have these things mounted on top of that.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21631

PostPosted: Sat May 15, 2010 2:17 am    Post subject: Reply with quote

The simplest approach is to quit using an initramfs. Move that /linuxrc into the root of the NFS export, load no initramfs at all, and use the init= parameter on the kernel command line to run your linuxrc before the main init.

As an alternative, you could mount the NFS root as the first step in your /linuxrc, then do the statements you showed, but with the paths rooted at the NFS root. For example:
Code:
#!/bin/busybox sh

# Hard code this for simplicity.  You could also extract this from
# /proc/cmdline if you want more flexibility.
nfsroot=10.0.0.2:/srv/diskless

# initramfs mount point where we will mount the NFS root.  This must
# already exist.
r=/mnt/root
# Mount root
mount -n -t nfs $nfsroot $r
# Mount tmp
mount -n -t tmpfs tmpfs $r/tmp
# Mount var
cd $r/var
mount -n -t tmpfs tmpfs $r/var
# Populate tmpfs var with directories from tarball on NFS var
tar -C $r/var -x -f seed-var.tar
cd $r/var
# Mount sub tmpfs's.  The mount points must be created as a side effect
# of unpacking seed-var.tar
mount -n -t tmpfs tmpfs log
mount -n -t tmpfs tmpfs run
mount -n -t tmpfs tmpfs lock
mount -n -t tmpfs tmpfs lib/init.d
cd $r/etc
mount -n -t tmpfs tmpfs /etc
# High magic.  It is left as an exercise to the reader why this works
# and is not useless.
tar -c -f - . | tar -C $r/etc -x -f -
cd $r
# Switch from initramfs root to NFS root
exec /bin/busybox switch_root $r /sbin/init < dev/console > dev/console 2>&1

Untested. Use at your own risk, but it shows the general concept.
Back to top
View user's profile Send private message
Rexilion
Veteran
Veteran


Joined: 17 Mar 2009
Posts: 1044

PostPosted: Sat May 15, 2010 2:24 pm    Post subject: Reply with quote

A long shot but ehm:

Can't you just use unionfs from mm?

I mean, create multiple overlay's of the same base system with minor modifications on another FS for each node? And then share each directory? This also allows you to mutate the main image without affecting other systems.
Back to top
View user's profile Send private message
srd
n00b
n00b


Joined: 13 Apr 2010
Posts: 38

PostPosted: Mon May 17, 2010 9:45 pm    Post subject: Reply with quote

I checked into it, and I could change out my kernel to work w/ one for unionfs, but I thought it better that if I can understand what's going on at the low level, then maybe one day I'll check into unionfs once I understand all this as I'm sure unionfs probably abstracts a lot of the same.

Last edited by srd on Tue May 18, 2010 12:12 am; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum