I am attempting to specify a preseed/late_command as a shell script that enables the systemd tmp.mount unit. Executing of a shell script in late_command fails with error code 127 indicating confusingly that /bin/sh doesn't exist on the target. What do I need to modify here to run a late_command shell script on the target?
My ubuntu-server-custom.seed contains:
d-i preseed/late_command string cp \ -a /cdrom/preseed/tmp_mount.sh /target/usr/sbin/; \ chroot /target '/bin/sh /usr/sbin/tmp_mount.sh --need-target-bash --preseed-late-command';(Note: newlines only added here for readability. The --flags to sh are hijacked from )
Also tried:
in-target '/bin/sh /usr/sbin/tmp_mount.sh';with same error message and exit code.
/preseed/tmp_mount.sh exists on the ISO.
tmp_mount.sh looks like:
#!/bin/bash
/bin/cp -aT /usr/share/systemd/tmp.mount /etc/systemd/system/tmp.mount
/bin/chmod 644 /etc/systemd/system/tmp.mount
/bin/sed -i -r 's/^Options=.*/Options=mode=1777,noatime,noexec,nodev,nosuid,size=4G/g' /etc/systemd/system/tmp.mount
/bin/systemctl unmask tmp.mount
/bin/systemctl enable tmp.mount
/bin/echo 'tmpfs /tmp tmpfs mode=1777,noatime,noexec,nodev,nosuid,size=4G 0 0' >> /etc/fstab
/bin/echo 'tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0' >> /etc/fstabBooting from ISO errors with:
Execution of preseeded command failed with error code 127.
I am able to push through the boot process and log in. Examining /var/log/installer/syslog I see:
I can also confirm that the script does actually exist on the target:
$ file /usr/sbin/tmp*
/usr/sbin/tmp_mount.sh: Bourne-Again shell script...So what's wrong here?
1 Answer
I was able to get this working with some minor adjustments to the late_command invocation:
- Use
in-targetrather thanchroot /target - Remove trailing semicolon (possible this was being interpreted as part of file name but not sure)
- Make sure to add executable bits (don't see why this should be required when it is invoked through
sh, but hey, whatever works)
End result from preseed:
d-i preseed/late_command string \ cp -a /cdrom/preseed/tmp_mount.sh /target/usr/sbin/; \ in-target chmod 700 /usr/sbin/tmp_mount.sh; \ in-target /bin/sh /usr/sbin/tmp_mount.shNote that this will leave /usr/sbin/tmp_mount.sh present on the target filesystem. (I've chosen deliberately to leave it there.) You could remove it in a final in-target /bin/rm /usr/sbin/tmp_mount.sh if wanted.