Neither NFS nor LDAP support disconnected operation: i.e., when the
laptop cannot reach the servers, it will not be able to access any
NFS-mounted directories, nor will it be able to perform user lookups.
Basically, it will be stuck.
A couple of workarounds could be the following.
Instead of mouting home directories via NFS, you could keep local
directories an use
unison to synchronize
them with the one on the central server. You can run unison from
cron, guarded by a test that aborts operation if the server is
unreachable. This post on
AskUbuntu
and this other
one
provide a discussion on the topic of synchronization and some useful
suggestions.
Regarding the user authentication/authorization problem, solutions
revolve around using the libnss-db
as a source for user
information:
Install libnss-db
, then configure /etc/nsswitch.conf
to look up
the db
source in addition to the regular files
:
passwd: files db
group: files db
shadow: files db
The db
source files are located in /var/lib/misc
(/var/lib/misc/passwd.db
etc.). You can then keep a master copy
of these files on your central server and synchronize the clients
with rsync
+cron
. Disadvantages: there are no ready-made
management scripts to manage the db files on the server (that I know
of), plus you incur a synchronization delay and have to setup a way
for rsync
to connect to the master server.
The nss-updatedb
and libpam-ccreds
packages provide a cleaner
way to set this up: with nss-updatedb
you can recreate locally the
passwd.db
and group.db
, whereas the shadow
information is
managed by libpam-ccreds
. Instructions how to set these up can be
found in the README
files accompanying the packages.
So it seems I finally solved it. It's both easy and riddled with bugs and obstacles. Answer is yes - use early-commands. But truth is in the details, so detailed answer it is.
First of all, prepare the rest of your environment, you can see my other post about detailed steps I went through to do BIOS/UEFI PXE boot of 20.04 and 20.10:
https://askubuntu.com/a/1292097/1080682
Now when you get your environment working correctly (good luck), let's do the custom autoinstall based on config changes served via HTTP mid install.
So if you follow the guide I posted on the link, I kept my Ubuntu user-data here :
/var/www/html/ubuntu-server-20.04.1/user-data
Modify the file with something like this (note I've shortened it for readability):
#cloud-config
autoinstall:
version: 1
refresh-installer:
update: yes
apt:
<apt stuff>
identity:
hostname: pxe-client
password: $6$zN/uHJD1rEXD/ETf$q8CoBt3xXmBT37RslyWcpLT1za4RJR3QEtosggRKN5aZAAf6/mYbFEQO66AIPm965glBXB1DGd0Sf.oKi.Rfx/
realname: pxe
username: pxe
keyboard: {layout: hr, toggle: toggle, variant: ""}
early-commands:
- curl -G -o /autoinstall.yaml http://10.10.2.1/user-data -d "mac=$(ip a | grep ether | cut -d ' ' -f6)"
locale: en_US
network:
network:
version: 2
ethernets:
eth0:
dhcp4: yes
dhcp6: no
Now, this user-data can be real basic, all we need really is for it to have network enabled and that one-liner curl
in early-commands
. IP 10.10.2.1
is local IP of my HTTP server (also my PXE server, as I serve other config files and ISO images and all that through it, but doesn't matter).
Use whatever you want to modify and serve this file based on the request. Way it is being done above with curl you will actually request from server something like this:
GET /user-data?mac=fa:fa:fa:00:0e:07
The part fa:fa:fa:00:0e:07
is what server sends after querying it's own interfaces. If you have multiple interfaces you'll maybe need to tweak the script, or make sure only one interface is up during early install steps.
I'm planning to use that via PHP + MySQL, and after fetching it in PHP using $_GET["mac"]
do something like SELECT * FROM autoinstall-configs WHERE mac = '$_GET["mac"]';
and from data in database table build the new autoinstall.yaml
and serve it back to subiquity.
Anyway, your reply has to NOT HAVE the line autoinstall:
!!
Here is minimal example of what HTTP/PHP will reply, I changed just hostname and username, and modified it so it passes subiquity syntax checks, oh and excluded early command not to get stuck in loop:
version: 1
refresh-installer:
update: yes
apt:
<apt stuff>
identity:
hostname: php-client
password: $6$zN/uHJD1rEXD/ETf$q8CoBt3xXmBT37RslyWcpLT1za4RJR3QEtosggRKN5aZAAf6/mYbFEQO66AIPm965glBXB1DGd0Sf.oKi.Rfx/
realname: php
username: php
keyboard: {layout: hr, toggle: toggle, variant: ""}
locale: en_US
network:
network:
version: 2
ethernets:
eth0:
dhcp4: yes
dhcp6: no
ssh:
allow-pw: true
install-server: true
late-commands:
- poweroff
To make it clear, here is the diff of the two files:
diff /var/www/html/ubuntu-server-20.04.1/user-data /var/www/html/user-data
1,3d0
< #cloud-config
<
< autoinstall:
16c13
< hostname: pxe-client
---
> hostname: php-client
18,19c15,16
< realname: pxe
< username: pxe
---
> realname: php
> username: php
21,22d17
< early-commands:
< - curl -G -o /autoinstall.yaml http://10.10.2.1/user-data -d "mac=$(ip a | grep ether | cut -d ' ' -f6)"
So it's almost the same, just not. These changes (removal of autoinstall:
and early-commands:
) is required to pass on to rest of installation. You can test other tweaks on your own.
After that installation will continue with whatever new info was served via answer to request /user-data?mac=<installer-mac-address>
.
This is now opening door to further possibilities of making your own web management for your VMs or server farms, or whatever. No longer do you need hand crafted user-data file for every server or group of servers. You can send them each their unique config, so including exact static IP address, partition sizes, different hostname, password, etc.
Canonical, if you pick an idea from this, put me in the credits at least :)
Case closed, cheers!
Best Answer
User settings are stored in the Home folder by design. So, if you copy your
/home/your-username
to your new computer, you should be fine......but there are caveats:
--preserve=mode
switch (usingcp
) or-p
(usingtar
)You can find the current userID and groupID by executing
id
. For example, to change the userID of user "your-username", runsudo usermod --uid 1234 your-username
. To change the groupID, you have to runsudo groupmod --gid 1234 your-username
.Settings (Firefox profile, appearance, ...) are often stored in hidden folders (or files). Hidden folders/files are prefixed with a dot, like
.mozilla
for Firefox (and other Mozilla applications).As security is not an issue, and you want to have the copying job done as fast as possible, I suggest a combination of the netcat and tar programs. Both applications are installed by default. Make sure that the firewalls on both computers allows ingoing access to destination port 8888 (source computer) and outgoing to destination port 8888 (target computer). Put the nettop next to the computer so you can run the commands quickly.
On the source computer, you need to have the traditional netcat program installed (a.k.a. Swiss Army Knife, not the BSD one). To do so, install the
netcat-traditional
package. You may also want to configure the traditional netcat program as default. Commands to install netcat-traditional and use it as default:On the source computer, type the next command in a terminal (do not press Enter yet):
Explanation:
cz
creates such a packed file ("tarball")-C/home $(whoami)
changes the working directory to/home
and puts your username folder. Alternative, you can type youryour-username
folder in the tarballnc
(netcat) is used for setting up connections between machines easily-l
: Listening mode, allows other machines to connect to the current machine-p 8888
: Listens on port 8888 (randomly chosen number, it could be any other number higher than 1024 as well)-w 10
: quit netcat after 10 seconds silence. You must connect to this source computer within this time.Now go to the target computer (nettop). To add the files to the target machine, type (do not run it yet):
192.168.1.2
is the IP address of the source computer. To get its IP address, run:ifconfig
on the source machine8888
is the port number as entered on the source machinexzp
: extracts the GZip-compressed tarball while preserving permissions.-C/home
: extracts theyour-username
folder to/home/your-username
-v
switch to the tar command for verbose extraction, so you can get an idea of the progress. This could slow down the copy process because every file has to be printed.Now go to the source computer, press Enter to run the server command. Quickly switch to your nettop and press Enter to run the client command.
If you have any questions, just use the comment field below.