Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users are not persistent when customizing Ubuntu Server 22.04. #101

Closed
dandrei279 opened this issue Oct 3, 2022 · 7 comments
Closed

Users are not persistent when customizing Ubuntu Server 22.04. #101

dandrei279 opened this issue Oct 3, 2022 · 7 comments
Assignees
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@dandrei279
Copy link

Describe the bug

When customizing an Ubuntu Server image, the users created in the virtual environment are not present after installation.

To Reproduce

  • Start from Ubuntu Server 22.04.1
  • Create a dummy user
  • Install MariaDB

Expected behavior
The user created (dummy) as well the mysql user should be present

$ grep mysql /etc/passwd
mysql:x:108:113:MySQL Server,,,:/nonexistent:/bin/false
$ grep dummy /etc/passwd
dummy:x:1000:1000:,,,:/home/dummy:/bin/bash

Actual behavior
The users that were created using CUBIC live environment are not present after installation

$ grep dummy /etc/passwd
$ echo $?
1
$ grep mysql /etc/passwd
$ echo $?
1

OS Information:

  • OS/Distro Name: Ubuntu
  • OS Version Ubuntu 20.04.3 LTS

Cubic Information:

  • Cubic Version: 2022.01.69
  • ISO Customizing: ubuntu-22.04.1-live-server-amd64.iso
  • Download Link: Ubuntu Server 22.04.1
@dandrei279 dandrei279 added the bug Something isn't working label Oct 3, 2022
@PJ-Singh-001 PJ-Singh-001 added help wanted Extra attention is needed question Further information is requested and removed bug Something isn't working labels Oct 7, 2022
@PJ-Singh-001
Copy link
Owner

I removed the "bug" label because Cubic does not do anything with your users or configurations.

You will need to figure out how to configure your users so that they are available after installation. This usually entails creating the correct files in the correct locations while you are customizing your OS in Cubic's Terminal page.

I added the tags "question" and "help wanted". Hopefully someone who has done this can chime in and help.

Also, may be this question may be helpful: #47

@PJ-Singh-001
Copy link
Owner

@dandrei279,

Did you have any luck with the procedure outlined here?

@dandrei279
Copy link
Author

In Ubuntu 20.04 this works as expected (i.e. users are created and they are available after ISO installation).
However in Ubuntu 22.04 this is not the case. After adding the users, they are visible in the virtual environment, but not after ISO installation.

Due to different behavior for different versions of Ubuntu I added the bug label

The quick workaround is to use a post-install script to create the users.

@PJ-Singh-001
Copy link
Owner

Ok. I’ll test this on my end using the 22.04 ISO you linked to in your question. Please give me some time to get back to you, since I am busy with other stuff.

@PJ-Singh-001
Copy link
Owner

Since you are customizing the Ubuntu Server ISO, I suspect this issue may be the same as #106, where changes made in Cubic are lost once the customized OS is installed.

@PJ-Singh-001 PJ-Singh-001 self-assigned this Oct 18, 2022
@PJ-Singh-001
Copy link
Owner

You can use Cloud-init to (re)create the user(s) during installation.

I customized ubuntu-22.04.1-live-server-amd64.iso in Cubic version 2022.12.74 on Ubuntu Ubuntu 22.04.1 LTS running kernel 5.15.0-56-generic.

  1. On Cubic's Terminal page, customize Ubuntu Server 22.04.

    apt update
    apt upgrade
    # Install software such as MariaDB, tree, etc.
    apt install tree
    
  2. Navigate to the Options page. On the Preseed tab, and add two new Cloud-init configuration files.

    preseed/meta-data

    preseed/meta-data

    1. Click on the preseed" folder

    2. Click the "Create new file" button in the headerbar.

    3. Create a new file named meta-data.

    4. Leave this file blank!

      Preseed Tab

    preseed/user-data

    1. Click on the preseed folder

    2. Click the "Create new file" button in the headerbar.

    3. Create a new file named user-data.

    4. Use the following example to add contents to the new user-data file in Cubic:

      In your case, you will need a user named mysql. Make sure your users are assigned to the correct groups. For example, your mysql user probably does not need to belong to the admin and sudo groups.

      #cloud-config
      autoinstall:
        version: 1
        interactive-sections:
          # Prompt the user to verify the identity information
          # during installation.
          - identity
          # Prompt the user to verify the storage information
          # during installation.
          - storage
        user-data:
          # Make sure the "user-data" section appears before the "identity"
          # section, otherwise these users will not be created.
          users:
            - name: user1
              gecos: User One
              groups: [admin,sudo]
              # Allow the sudo user to execute admin commands without being
              # prompted for the sudo password.
              # sudo: ALL=(ALL) NOPASSWD:ALL
              lock_passwd: false
              shell: /bin/bash
              # The password is "test". This hash was generated using:
              # mkpasswd --method=SHA-512 test
              passwd: $6$mYqmcUmrs9lHbcx8$TOPg7z2DMmhJTpBSX/8AsuT4HMy9HOvKUL/Lisv/X3Frn0gUwPUBUz8pmT2cvjlSSRvgDHopwXl.fK0FuWD7n1
            - name: user2
              gecos: User Two
              groups: [admin,sudo]
              # Allow the sudo user to execute admin commands without being
              # prompted for the sudo password.
              # sudo: ALL=(ALL) NOPASSWD:ALL
              lock_passwd: false
              shell: /bin/bash
              # The password is "test". This hash was generated using:
              # mkpasswd --method=SHA-512 test
              passwd: $6$mYqmcUmrs9lHbcx8$TOPg7z2DMmhJTpBSX/8AsuT4HMy9HOvKUL/Lisv/X3Frn0gUwPUBUz8pmT2cvjlSSRvgDHopwXl.fK0FuWD7n1
            - name: user3
              gecos: User Three
              groups: [admin,sudo]
              # Allow the sudo user to execute admin commands without being
              # prompted for the sudo password.
              # sudo: ALL=(ALL) NOPASSWD:ALL
              lock_passwd: false
              shell: /bin/bash
              # The password is "test". This hash was generated using:
              # mkpasswd --method=SHA-512 test
              passwd: $6$mYqmcUmrs9lHbcx8$TOPg7z2DMmhJTpBSX/8AsuT4HMy9HOvKUL/Lisv/X3Frn0gUwPUBUz8pmT2cvjlSSRvgDHopwXl.fK0FuWD7n1
        identity:
          hostname: cubic3
          username: psingh
          # The user is prompted to enter a password when identity is listed
          # as an interactive section.
          # password: IGNORED
      
      preseed/user-data
  3. On the Options page, click on the Boot tab to edit the boot configuration files.

    boot/grub/grub.cfg

    1. Add autoinstall "ds=nocloud;s=/cdrom/preseed/" as shown:

      menuentry "Try or Install Ubuntu Server" {
          set gfxpayload=keep
          linux	/casper/vmlinuz boot=casper autoinstall "ds=nocloud;s=/cdrom/preseed/"  ---
          initrd	/casper/initrd.gz
      }
      
      boot/grub/grub.cfg

    boot/grub/loopback.cfg

    1. Add autoinstall "ds=nocloud;s=/cdrom/preseed/" as shown:

      menuentry "Try or Install Ubuntu Server" {
          set gfxpayload=keep
          linux	/casper/vmlinuz boot=casper autoinstall "ds=nocloud;s=/cdrom/preseed/"  ---
          initrd	/casper/initrd.gz
      }
      
      boot/grub/loopback.cfg`

    WARNING: THE PARAMETER autoinstall WILL CAUSE THE INSTALLER TO AUTOMATICALLY RUN WITHOUT PROMPTING THE USER, AND THIS WILL OVERWRITE THE ENTIRE DISK WHEN A USER BOOTS INTO THE CUSTOMIZED USB/ISO!

    Use Cloud-init at your own risk. To avoid this problem, make sure you have interactive-sections listed in the cloud-config (preseed/user-data file) to prompt the user for information, as in the example above, so there is an opportunity for the user to abort the installation. Also, test your ISO in a virtual machine (such as VirtualBox) to make sure it behaves the way you expect.

  4. As you can see, the users created by Cloud-init were present after installation.

    I recommend disconnecting your network during installation, so the installer uses package versions you setup in Cubic, instead of updating them automatically from the Internet. This also makes the installation proceed much faster.

    Installed Server with Users

@PJ-Singh-001 PJ-Singh-001 changed the title Users are not persistent Users are not persistent when customizing Ubuntu Server 22.04. Dec 10, 2022
@PJ-Singh-001
Copy link
Owner

Closing this issue with the solution provided above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants