Boxstarter – breaking infinite reboot loop

1. Introduction

Boxstarter is a great tool for configuring your machine without any user interaction. I’ve been using it for a while now, however recently I’ve noticed that for no apparent reason it wasn’t able to finish the execution of provisioning script as it stuck in infinite reboot loop. Is was quite frustrating for me, that is why I’ve decided to investigate the problem. Here are my findings.

2. Detecting pending reboots

If you dive into Boxstarter source code you will notice that script responsible for checking if reboot is necessary uses Get-PendingReboot cmdlet. By default Boxstarter doesn’t export it, so if you want to see what it does you have to add following line in your Boxstarer script

Calling the Get-PendingReboot cmdlet will give you an information about mandatory reboots. In my case, the output looked as follows
getpendingreboot
As you can see RebootPending flag is set to true and the reason is that the value of PendingFileRenVal property is not null. Basically, in most of the cases, a restart is indeed required however, some applications leave information about pending reboot in the registry (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations) and operating system (in some cases) never cleans this up.
As a result Get-PendingReboot indicates that reboot is required and Boxstarter falls into infinite restart loop.
pendingfilerenameoperationsframe

3. Fixing the problem

The obvious solution is to remove that value from the registry key manually. However this approach didn’t work for me, basically because the registry value somehow was added at the beginning of execution of my script. That is why, I’ve decided to modify my script and add a function which clears undesirable pending file renames of my choice.

As you can see I am taking current value of PendingFileRenameOperations and remove the entries which I know that will stay there forever. Calling that function as the very first step of my installation script solved the problem and I was able to successfully restore my machine from Boxstarter script
fullscrtipt

pendingfilerenameoperationsclearedframe

Entire Boxstarter script can be found here.

Boxstarter – breaking infinite reboot loop