WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Additional BOOT codes to support persistent custom user account TinyCore  (Read 5130 times)

Offline Len

  • Newbie
  • *
  • Posts: 14
I needed to implement a multi-user environment with persistent user data across reboots.  In addition, I needed to preserve UIDs across my net booted TinyCore system and my NFS system.  I originally started by remastering with an updated /etc/passwd, /etc/shadow, /etc/group, and /etc/sudoers but decided that something more generic would be helpful... hopefully this is helpful to others as well.

I assume you know how to extract and repackage (aka Remaster) TinyCoreLinux... if not, check out the wiki:
http://wiki.tinycorelinux.net/wiki:remastering

1. extract the current tree from core.gz (I used version 4.7.6)
2. apply the attached patch file
   cd /my_temp_extracted_tree_root_directory/etc/init.d
   cp tc-config tc-config_ORIGINAL  (make a backup copy, just in case)
   patch -i tc-config-path
3. remaster the changed tree
4. boot from the remastered image with additional user and uid boot code options
   e.g. user=bob uid=1024
5. once the system boots, you should see that you are user "bob" with uid of 1024
   ~$ whoami
   bob
   ~$ id
   uid=1024(bob) gid=50(staff) groups=50(staff)
6. At this point, to make your "bob" user account persistent, you need to back up some user related files.  The easiest way is to add this to your mydata.tgz... I assume you have persistence working.
      ~$ sudo vi /opt/.filetool.lst
      ADD THE FOLLOWING LINES to your .filetool.lst
         etc/passwd
         etc/shadow
         etc/group
         etc/sudoers
      Now, force a backup
      ~$ filetool.sh -b
7. DONE -- you should now be able to reboot, and re-use the bob user account with uid 1024.  You need to still provide the boot codes (user=bob uid=1024).

The patch added the new boot code "uid=XXX" which is optional, but when specified tries to set the uid of the user.  This boot code is only effective when the "user=" is also present.  The values for uid must be greater than 999 and less than 65534.

The patch also added a new boot code "NOPERSISTENTUSER" which can be used to restore the boot time user information (from the core.gz image) by overwriting any restored user information.

Though I outlined how to use these changes with mydata.tgz, one could also configure a system which uses shutdown.sh (and bootsync.sh) to persist the user information.  Beware of restoring the /etc/sudoers file as you will need sudo cp the saved files back into the running file system but sudo may fail if the file is being overwritten.... I can't recall the details so I leave that up to another brave soul to test and report back.  Regardless, the changes in my patch should handle the restoration occurring from either mydata.tgz or from bootsync.sh (or even bootlocal.sh).



« Last Edit: May 05, 2013, 08:42:00 PM by Len »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11020
The patch has a lot of copy-paste. The merging block would not be acceptable as is.

That aside, could you elaborate why the boot code & setup is necessary? Shouldn't it be enough to have the full setup restored via backup or other means?
The only barriers that can stop you are the ones you create yourself.

Offline Len

  • Newbie
  • *
  • Posts: 14
Hi curaga,

The patch is not really necessary, as TinyCore already provides a mechanism for starting up as another user (current boot code "user=").  In retrospect, perhaps I titled this subject incorrectly ... maybe it should be "Additional boot codes to enhance custom user accounts".

I think what the patch really provides is the ability to specify a UID at boot time.  This is helpful if you're NFS mounting your home directory and want to preserve the file ownership.  Specifically, I needed a way to net boot 2 tinycore systems which NFS mounted the home directory for my user account and my wife's user account.
      TinyCore#1: "user=len uid=1009"
      TinyCore#2: "user=wife uid=1010"

With the current tc-config option of:
      TinyCore#1: "user=len"
      TinyCore#2: "user=wife"
both systems would assign UID=1000 to the two different accounts.  Since NFS operates on UID/GID for files, this causes a clash of file ownership (that is, both users files are owned by the same UID). In addition, UID of 1000 was assigned to a different account on my NFS server.

The rest of the patch can be broken up into 3 additional parts:
1. enhance the addUser function to support the UID boot code.
2. allow for merging of user account related files if they've been restored from persistent store.
3. allow ignoring of restored user account related files (in case something's wrong with the currently backed up user accounts).

Finally, I tried to generalize these changes to maintain the flexibility of TinyCore as much as possible.
« Last Edit: May 06, 2013, 12:06:26 PM by Len »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11020
Thanks, that makes the goals clearer.

Though, I would've just used the user= bootcode, and let the backup overwrite the passwd/group files. The uid shouldn't matter if the home dir already exists, as nothing is chowned then, and for the extension loading and later, the proper uid would already be in place.
The only barriers that can stop you are the ones you create yourself.

Offline Len

  • Newbie
  • *
  • Posts: 14
curaga,

I just did some more testing on my part -- I think that the point #2 I had listed above in my previous reply to you is not needed.  To make a long story even longer, I was thinking ahead to possibly using parts of my passwd and shadow files from my Linux server to keep the current user accounts sync'd between the TinyCore clients and my Linux server.  A more friendly way to do this might be to use some other auth method such as LDAP, but that might be a lot farther down the road, if I even continue to pursue this...

I think that the addition of "uid=" is still a usable enhancement as it alleviates problems with multiple users simultaneously active on NFS mounted home directories AND in the additional case that NFS server might have conflicting UIDs from TinyCore's preferred 1000 for the next created user account.

With that in mind, I've attached a new patch which only includes the addition of the "uid=" boot code.  Perhaps the best thing to do is to lock this thread and create a new one with a more appropriate subject of "New Boot Code to support UID"?