0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntu 24.04でautoinstallのユーザー作成のタイミングがおかしい?

0
Posted at

Ubuntu 24.04でautoinstallのユーザー作成のタイミングがおかしい?

環境:

  • ubuntu-24.04.3-live-server-amd64.iso

late-commandsセクションでユーザーのホームディレクトリに書き込めない

「初回起動時に必要なものをユーザーのホームディレクトリに置いときたいな」と思ったとします。

とりあえず公式ドキュメントを読んで確認してみます。
Autoinstall configuration reference manual

late-commands
Shell commands to run after the installation has completed successfully and any updates and packages installed, just before the system reboots.

「それじゃインストールの最後の段階で処理する late-commands セクションで処理すればいいな」ということで、こんなことを思いつくわけです。

  late-commands:
    - curtin in-target -- echo "some scripts" > /home/hoge/some.sh

ところが/home/(user)ディレクトリが存在しないのでこれはfailします。

identity
Configure the initial user for the system. This is the only configuration key that must be present (unless the user-data section is present, in which case it is optional).

「あれ、システムのイニシャライズ段階で設定する、って書いてるけどもしかして user-data セクションと記述間違ってるとかか?」ということで user-data セクションも確認しておきます。

user-data
The main difference is the timing of user creation. While users specified using the identity section are created during the installation, users created using cloud-init user-data will be created on first boot.

「identityがインストール時でuser-dataが初回起動時って書いてあるよなぁ。。。」ということでちょっと確認してみます。

identityパターンとuser-dataパターン

  late-commands:
    - echo "Crash Now !" > /crash/now

存在しない場所に書き込もうとすることで意図的にエラーを起こしてここでシェルに入れるようにします。

identityパターン

#cloud-config
autoinstall:
  version: 1
  locale: "en_US.UTF-8"
  keyboard:
    layout: "jp"
    variant: ""
  source:
    id: ubuntu-server
  network:
    version: 2
    ethernets:
      eth0:
        dhcp4: true
        dhcp6: false
  storage:
    layout:
      name: lvm
      sizing-policy: all
  identity:
    realname: 'JohnDoe'
    username: scott
    password: '$1$edVbOZhg$dL64ivYHhIs2f0Uc7XyeH1'
    hostname: JohnDoe
  late-commands:
    - echo "Crash Now !" > /crash/now

ident.png

資料によってまちまちですが、どうもこの環境では /target/etc/cloud/cloud.cfg.d/99-installer-cfg に事前定義した設定と同じ設定があるようです。

user-dataパターン

#cloud-config
autoinstall:
  version: 1
  locale: "en_US.UTF-8"
  keyboard:
    layout: "jp"
    variant: ""
  source:
    id: ubuntu-server
  network:
    version: 2
    ethernets:
      eth0:
        dhcp4: true
        dhcp6: false
  storage:
    layout:
      name: lvm
      sizing-policy: all
  user-data:
     users:
       - name: scott2
         gecos: 'JohnDoe2'
         passwd: '$1$edVbOZhg$dL64ivYHhIs2f0Uc7XyeH1'
         groups: adm, cdrom, dip, lxd, plugdev, sudo
         shell: /bin/bash
         lock_passwd: False
  late-commands:
    - echo "Crash Now !" > /crash/now

user.png

こちらの環境でも /target/etc/cloud/cloud.cfg.d/99-installer-cfg に事前定義した設定と同じ設定があるようです。

どういうことぉ?

/target 配下のディレクトリにあるという事は、次回起動時にcloud-initがこれを使用して初期化処理をすると思われます。
そして内容が同じように見えるので、ほぼ同じ処理になるものと思われます。
ということは、たぶん「ドキュメントの記載が間違っている」のではないかと思われます。

念のためログも確認

identityパターン

log.png

user-dataパターン

log2.png

さてどうしたものか

ログを見ても実行されるタイミングは同じであるように見えるので、どっちに指定しても同じ処理に落ち着くような気がします。
ただそれぞれ指定できる項目が異なるので、そこで用途の差異があるのかなと思われます。

  • ほとんどデフォルト値でいい場合
    • identity セクションにすれば詳細は省略できるので、こっちを使う方がいいと思われます
  • 細かく制御したい場合
    • user-data セクションのほうが詳細に設定できるので、こっちを使うといいと思われます
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?