/srv/irclogs.ubuntu.com/2023/07/07/#cloud-init.txt

DP21Hi all. If you don't mind have a question regarding cloud-init + AWS + vendor data. I am trying to add custom configuration to the new Amazon Linux 2023 AMI that uses cloud-init 22.2. The case is absolutely the same as in the bug https://bugs.launchpad.net/cloud-init/+bug/1913461 that should have been fixed in version 22.4, but AWS doesn't have15:51
DP21that version and I guess won't have it for a while because Amazon linux 2023 uses python3.9.15:51
DP21In short the case is the following:15:51
DP211. We create custom image based on Amazon Linux 202315:51
-ubottu:#cloud-init- Launchpad bug 1913461 in cloud-init "Need jinja templating in config files" [Wishlist, Fix Released]15:51
DP212. We can't use user-data to the customization, because that will be done by users of the AMI15:51
DP213. So, the best way to add these customization is to use /etc/cloud/cloud.cfg.d/ config file, BUT in the version of cloud-init that we have we can't use jijna placeholders for the Datasource to get meta-data15:51
DP214. At the same time we can't upgrade cloud-init to the latest version15:51
DP21I want to clarify the possibility to use vendor data in the AWS environment. Is there any way or example how to supply vendor data to AWS instance? Maybe there is a way to put them locally?15:51
DP21Thanks,15:51
falcojrDP21: unfortunately, vendor data can only be provided by the vendor, which in this case is EC2. It would get fetched directly from their metadata service and not something that can be simulated locally15:56
falcojrif you're creating a custom image, is there a reason you can't upgrade cloud-init within that image? 22.4 works on python 3.915:57
meenadocs Bug? https://github.com/canonical/cloud-init/issues/422916:27
-ubottu:#cloud-init- Issue 4229 in canonical/cloud-init "Broken link to the hacking document" [Open]16:27
DP21falcojr  thanks for the reply. That was my guess. As for the upgrade of cloud-init:16:28
DP211. I am not sure what customizations has AWS added to their build of cloud-init (if any) and what issue that can cause in future16:28
DP212. I was surprised not to found RPM for that particular version of cloud-init. For example at https://rpmfind.net/linux/rpm2html/search.php?query=cloud-init it looks like Fedora (base of Amazon Linux 2023) have skipped versions 22.3 and 22.4.16:28
DP21But yeah, maybe to build custom rpm is the way16:28
damjanhi all, I have cloud-init with: mounts: [ [ /dev/sda2, /mnt ], [ /dev/sda1, /mnt/efi ] ], and cloud-init creates the proper fstab our of that config, and then calls `mount -a`. alas, mount -a fails since the /mnt/efi mount point does not exist.16:29
damjanone solution would be to call for ex. `systemctl start mnt-efi.mount` (for each new mount, instead of mount -a) since that also makes sure the target mountpoint exists16:30
damjanshould I propose a PR on github?16:31
damjanor is there a better solution16:31
damjan… the usage of systemctl, would of course be conditional on systemd16:31
minimaldamjan: why does /mnt/efi i not exist?16:32
damjanminimal: both sda2 and sda1 are empty FSs just created by fs_setup:16:33
minimalminimal: that doesn't indicate though why a mount of /mnt/efi fails however...16:33
minimalcan you pastebin (or similar) your user-data?16:34
damjanminimal: `mount -a` doesn't know to create the mount point /mnt/efi16:34
damjanminimal: sure, https://github.com/gdamjan/archvm-auto-install/blob/main/imds/user-data16:34
minimalI've never had that sort of problem before with disk_setup/fs_setup/mount16:39
minimaldamjan: let me spin up a VM with similar config that I have used16:44
damjanah I see what happens. /mnt/efi is created, BUT then /dev/sda2 is mounted over /mnt so now that's hidden16:46
minimaldamjan: yeah I saw about to suggest that lol16:46
minimaldoes /dev/sda2 appear before /dev/sda1 in the /etc/fstab?16:47
damjanyes16:47
minimalso I'd expect it to mounted first16:47
damjanit is16:47
damjanbut the code is a bit weird. I think it creates the targets dir before it tries to mount anything16:48
minimaloh, right, I thought you meant "mount -a" was doing them in wrong order16:48
damjanhere's the log file https://paste.rs/TTyT716:49
minimalrather it is that cc_mounts is creating /mnt/efi dir before /mnt is mounted? yeah I don't think it is smart enough to cater for that16:49
minimaldamjan: this seems to create each mountpoint dir if it doesn't exist: https://github.com/canonical/cloud-init/blob/main/cloudinit/config/cc_mounts.py#L57516:55
minimalhowever it is before any "mount -a": https://github.com/canonical/cloud-init/blob/main/cloudinit/config/cc_mounts.py#L58216:56
minimaland https://github.com/canonical/cloud-init/blob/main/cloudinit/config/cc_mounts.py#L60616:57
damjanyeah16:58
damjando you have an idea what the best approach would be in solving the issue?17:00
minimaldamjan: do the mounts via runcmd instead? (including "rmdir /mnt/efi" before mounting /mnt and "mkdir /mnt/efi" after mounting /mnt)17:21
damjanyeah I can do that :)17:23
damjanhm, perhaps cloud-init can use the X-mount.mkdir option17:59
damjanand forgo its own `mkdir`s18:04
minimaldamjan: that would probably not be supported by BSD and also some Linux distros like Alpine that use Busybox mount18:04
damjanhey wait, I can add that as the 4th param to mounts:18:06
damjanminimal: indeed18:06
minimalI'm going to add a note to the cc_mounts docs about the mount-inside-another-mount issue18:08
damjanyou can mention the `X-mount.mkdir option` for util-linux distros18:09
minimalok18:12
damjanps. I did test it, and it works, https://github.com/gdamjan/archvm-auto-install/blob/main/imds/user-data#L2618:59
damjanalas, I might switch to a script that does explicit sfdisk, it gives me more control on the partitioning19:10
minimaldamjan: for GPT partitions cc_disk_setup is (from memory) using sgdisk not sfdisk19:16
damjanbut it only gives me option for partition size in percentages19:17
minimalnot disputing that, just pointing out that sfdisk is used by it for MBR/BIOS and sgdisk for GPT19:18
meenadoes anything still use MBR?19:19
minimalmeena: BIOS-only systems, also people who want to create non-boot MBR partitioned disks (i.e. less than 2TB) for whatever reason19:21
minimalI can create a VM with a 2nd disk of 1TB and then decide whether I want it MBR/BIOS or GPT partitioned, either is perfectly valid to do19:22
damjansfdisk can do gpt these days, so it's fine19:25
DP21falcojr Once again thanks for the answer. I built rpm for Amazon Linux 2023 of version 22.4 and can confirm that jinja templates work for cfg files. Also just for the history rpm build on Amazon Linux 2023 fails because fix for the "udev/rules.d" path inside setup.py for Redhat doesn't work properly. AmazonLinux 2023 doesn't have file19:42
DP21"/etc/redhat-release" that is used to determinate Redhat family for that particular fix. Below is part of setup.py code19:42
DP21```19:42
DP21if not platform.system().endswith("BSD"):19:42
DP21    RULES_PATH = LIB19:42
DP21    if os.path.isfile("/etc/redhat-release"):19:42
DP21        RULES_PATH = "/usr/lib"19:42
DP21    data_files.extend(19:42
DP21        [19:42
DP21            (19:42
DP21                ETC + "/NetworkManager/dispatcher.d/",19:42
DP21                ["tools/hook-network-manager"],19:42
DP21            ),19:42
DP21            (ETC + "/dhcp/dhclient-exit-hooks.d/", ["tools/hook-dhclient"]),19:42
DP21            (RULES_PATH + "/udev/rules.d", [f for f in glob("udev/*.rules")]),19:42
DP21            (19:42
DP21                ETC + "/systemd/system/sshd-keygen@.service.d/",19:42
DP21                ["systemd/disable-sshd-keygen-if-cloud-init-active.conf"],19:42
falcojrDP21: for multi-line pastes, please use a pastebin service19:43
falcojrpaste.ubuntu.com is one19:43
DP21got it19:43
meenaminimal: I'm too poor / broke to have ever seen a 2 TB disk 19:49
minimalmeena: not even a virtual one? lol20:19
damjanright, easy `qemu-img create -f qcow2 arch-vm.img 20T` :D20:46
meenaminimal: nope 20:48
meenadamjan: will i be able to actually fill that on my laptop with 400? G disk space?20:49
minimalvirtually fill it, yupe ;-)20:50

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!