Skip to content

Commit 17a93ba

Browse files
Remove nameserver from resolv.conf at the end of AMI build
The conditional statement avoids cleaning if the `/etc/resolv.conf` is a symbolic link. It is a symbolic link when it is managed by other systems. Cleaning the `/etc/resolv.conf` speeds up instance launch because it wouldn't try to use name server from the AMI creation environment. The delay was shown in `/var/log/cloud-init.log`: ``` 2025-03-19 16:00:07,721 - util.py[DEBUG]: Resolving URL: http://169.254.169.254 took 40.099 seconds 2025-03-19 16:00:07,721 - util.py[DEBUG]: Resolving URL: http://[fd00:ec2::254] took 0.000 seconds 2025-03-19 16:00:17,731 - util.py[DEBUG]: Resolving URL: http://instance-data.:8773 took 10.010 seconds ``` Example content of `/etc/resolv.conf`: ``` cat /etc/resolv.conf # Generated by NetworkManager search ec2.internal nameserver 192.168.0.2 ``` Signed-off-by: Hanwen <[email protected]>
1 parent d6e6d24 commit 17a93ba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fi
2222

2323
# Clean resolv.conf if it's not managed by system
2424
if [ ! -L "/etc/resolv.conf" ]; then
25-
echo -n > /etc/resolv.conf
25+
sed -i '/^nameserver/d' /etc/resolv.conf
2626
fi
2727

2828
find /var/log -type f -exec /bin/rm -v {} \;

0 commit comments

Comments
 (0)