{"id":966,"date":"2016-12-19T23:20:40","date_gmt":"2016-12-19T23:20:40","guid":{"rendered":"http:\/\/tpodolak.com\/blog\/?p=966"},"modified":"2016-12-29T19:37:34","modified_gmt":"2016-12-29T19:37:34","slug":"boxstarter-breaking-infinite-reboot-loop","status":"publish","type":"post","link":"https:\/\/tpodolak.com\/blog\/2016\/12\/19\/boxstarter-breaking-infinite-reboot-loop\/","title":{"rendered":"Boxstarter &#8211; breaking infinite reboot loop"},"content":{"rendered":"<h3>1. Introduction<\/h3>\n<p><a href=\"http:\/\/boxstarter.org\/\">Boxstarter<\/a> is a great tool for configuring your machine without any user interaction. I&#8217;ve been using it for a while now, however recently I&#8217;ve noticed that for no apparent reason it wasn&#8217;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&#8217;ve decided to investigate the problem. Here are my findings.<\/p>\n<h3>2. Detecting pending reboots<\/h3>\n<p>If you dive into <i>Boxstarter<\/i> source code you will notice that script responsible for checking if reboot is necessary uses <a href=\"https:\/\/github.com\/mwrock\/boxstarter\/blob\/master\/Boxstarter.Bootstrapper\/Get-PendingReboot.ps1\"> Get-PendingReboot <\/a> cmdlet. By default <i>Boxstarter<\/i> doesn\u2019t export it, so if you want to see what it does you have to add following line in your <i>Boxstarer<\/i> script<\/p>\n<pre lang=\"ps\">\r\nImport-Module (Join-Path $Boxstarter.BaseDir Boxstarter.Bootstrapper\\Get-PendingReboot.ps1) -global -DisableNameChecking\r\n<\/pre>\n<p>Calling the <i>Get-PendingReboot<\/i> cmdlet will give you an information about mandatory reboots. In my case, the output looked as follows<br \/>\n<a href=\"\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/GetPendingReboot.png\" rel=\"attachment wp-att-969\"><img decoding=\"async\" src=\"\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/GetPendingReboot.png\" alt=\"getpendingreboot\" width=\"783\" class=\"aligncenter size-full wp-image-969\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/GetPendingReboot.png 783w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/GetPendingReboot-150x48.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/GetPendingReboot-300x95.png 300w\" sizes=\"(max-width: 783px) 100vw, 783px\" \/><\/a><br \/>\nAs you can see <i>RebootPending<\/i> flag is set to true and the reason is that the value of <i>PendingFileRenVal<\/i> 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 (<i>HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\PendingFileRenameOperations<\/i>) and operating system (in some cases) never cleans this up.<br \/>\nAs a result <i>Get-PendingReboot<\/i> indicates that reboot is required and <i>Boxstarter<\/i> falls into infinite restart loop.<br \/>\n<a href=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsFrame.png\" rel=\"attachment wp-att-971\"><img decoding=\"async\" src=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsFrame.png\" alt=\"pendingfilerenameoperationsframe\" width=\"1209\" class=\"aligncenter size-full wp-image-971\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsFrame.png 1209w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsFrame-150x50.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsFrame-300x100.png 300w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsFrame-1024x340.png 1024w\" sizes=\"(max-width: 1209px) 100vw, 1209px\" \/><\/a><\/p>\n<h3>3. Fixing the problem<\/h3>\n<p>The obvious solution is to remove that value from the registry key manually. However this approach didn\u2019t work for me, basically because the registry value somehow was added at the beginning of execution of my script. That is why, I&#8217;ve decided to modify my script and add a function which clears undesirable pending file renames of my choice. <\/p>\n<pre lang=\"ps\">\r\nfunction Clear-Known-Pending-Renames($ignoredRenames){\r\n    $regKey = \"HKLM:SYSTEM\\CurrentControlSet\\Control\\Session Manager\\\"\r\n    $regProperty = \"PendingFileRenameOperations\"\r\n    $pendingReboot = Get-PendingReboot\r\n\r\n    Write-BoxstarterMessage \"Current pending reboot $($pendingReboot | Out-String)\"\r\n    \r\n    if($pendingReboot.PendFileRename){\r\n\r\n        $output = $pendingReboot.PendFileRenVal | %{$_ -split [Environment]::NewLine} | ? { \r\n            $current = $_\r\n            ![string]::IsNullOrWhiteSpace($current) -and ($ignoredRenames | ? { $current.StartsWith($_)  } ).Length -eq 0 } | Get-Unique\r\n\r\n        if($output -eq $null){\r\n            $output = @()\r\n        }\r\n        \r\n        Set-ItemProperty -Path $regKey -Name $regProperty -Value ([string]::Join([Environment]::NewLine, $output))\r\n        Write-BoxstarterMessage \"Updated pending reboot $(Get-PendingReboot | Out-String)\"\r\n    }\r\n}\r\n<\/pre>\n<p>As you can see I am taking current value of <i>PendingFileRenameOperations<\/i> 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 <i>Boxstarter<\/i> script<br \/>\n<a href=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/FullScrtipt.png\" rel=\"attachment wp-att-968\"><img decoding=\"async\" src=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/FullScrtipt.png\" alt=\"fullscrtipt\" width=\"787\"  class=\"aligncenter size-full wp-image-968\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/FullScrtipt.png 787w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/FullScrtipt-150x131.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/FullScrtipt-300x263.png 300w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/a><\/p>\n<p><a href=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsClearedFrame.png\" rel=\"attachment wp-att-970\"><img decoding=\"async\" src=\"\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsClearedFrame.png\" alt=\"pendingfilerenameoperationsclearedframe\" width=\"933\" class=\"aligncenter size-full wp-image-970\" srcset=\"https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsClearedFrame.png 933w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsClearedFrame-150x63.png 150w, https:\/\/tpodolak.com\/blog\/wp-content\/uploads\/2016\/12\/boxstarter-breaking-infinite-reboot-loop\/PendingFileRenameOperationsClearedFrame-300x126.png 300w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/a><\/p>\n<p>Entire Boxstarter script can be found <a href=\"https:\/\/github.com\/tpodolak\/InstallBox\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction Boxstarter is a great tool for configuring your machine without any user interaction. I&#8217;ve been using it for a while now, however recently I&#8217;ve noticed that for no apparent reason it wasn&#8217;t able to finish the execution of provisioning script as it stuck in infinite reboot loop. Is was quite frustrating for me, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[314,313],"tags":[315,316],"class_list":["post-966","post","type-post","status-publish","format-standard","hentry","category-boxstarter","category-powershell","tag-boxstarter","tag-powershell"],"_links":{"self":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/comments?post=966"}],"version-history":[{"count":22,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/966\/revisions"}],"predecessor-version":[{"id":997,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/posts\/966\/revisions\/997"}],"wp:attachment":[{"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/media?parent=966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/categories?post=966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tpodolak.com\/blog\/wp-json\/wp\/v2\/tags?post=966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}