From cd24ecb63ba4856731d736dd726e287dc3b34ea8 Mon Sep 17 00:00:00 2001 From: Hanwen Date: Thu, 20 Mar 2025 12:50:40 -0700 Subject: [PATCH 1/2] Clean resolv.conf if it's not managed by system 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` speed 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 --- cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh b/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh index 2943b51f38..00f98efc16 100644 --- a/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh +++ b/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh @@ -20,5 +20,10 @@ if [ "${ID}${VERSION_ID}" == "centos7" ]; then rm -f /etc/sysconfig/network-scripts/ifcfg-eth0 fi +# Clean resolv.conf if it's not managed by system +if [ ! -L "/etc/resolv.conf" ]; then + echo -n > /etc/resolv.conf +fi + find /var/log -type f -exec /bin/rm -v {} \; touch /var/log/lastlog From d5e0a5938bc89b8fed85cfb76295f26c9aa49882 Mon Sep 17 00:00:00 2001 From: Hanwen Date: Thu, 20 Mar 2025 13:25:01 -0700 Subject: [PATCH 2/2] 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 --- cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh b/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh index 00f98efc16..bb14fa8e53 100644 --- a/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh +++ b/cookbooks/aws-parallelcluster-platform/files/ami_cleanup.sh @@ -22,7 +22,7 @@ fi # Clean resolv.conf if it's not managed by system if [ ! -L "/etc/resolv.conf" ]; then - echo -n > /etc/resolv.conf + sed -i '/^nameserver/d' /etc/resolv.conf fi find /var/log -type f -exec /bin/rm -v {} \;