Best Practice for applying updates and kernel patches

I have Packer config that is building an AWS Linux 2 AMI and during the Provisioning i’m doing a yum update -y

is this the best way to ensure the AMI has had both Kernel and OS updates?

@kneemaa That sound about right. I would also add a reboot in between (expect_disconnect, etc.) in case the kernel version updates. This ensures it boots into the new kernel, and then I can remove all older kernels.

I haven’t used expect_disconnect yet.

would i just need to add the following to my provisioner for after the step i do the update -y?

{
  "inline": "sudo reboot",
  "type": "shell",
  "expect_disconnect": true
},

Yes. Also, there should be a delay in the block (say 40-60 seconds) to let the machine boot amd be stable for the next ssh

I’ve been attempting this on packer 1.5.5 with the same as above (recently adding reboot into build process) and it seems to fail. I’ve tested the same above on RHEL7 and CentOS7 and also adding the pause_before and timeout and packer simply errors

amazon-ebs: /tmp/script_5489.sh: line 16: REBOOT: command not found
amazon-ebs: /tmp/script_5489.sh: line 16: REBOOT: command not found

also tried variations of reboot command like sudo shutdown -r now sudo systemctl reboot sudo /usr/sbin/{reboot..shutdown}

Any tips?

You could also test init 6. :man_shrugging:t3:

I did and same issue. then i figured out my problem, i had some verbose echo commands in prior task and it interpreted one as actual command due to a well (or poorly) placed semicolon. oops.

Oh man… Laughing out loud. :joy:

i should take up comedy