Shared folders in CentOS7 guests fail to mount after an unexpected Windows11 host reboot because the VirtualBox Guest Additions kernel module is not automatically reloaded into the running kernel. This occurs when the host system loses power or crashes, leaving the guest OS with a stale state where the necessary
vboxfs driver is unloaded but the mount points remain configured. To resolve this, you must manually reload the kernel module and remount the shares within the guest environment.
Understanding the Root Cause
The issue stems from how Linux handles loadable kernel modules during a sudden shutdown. When a Windows11 host reboots unexpectedly, the VirtualBox hypervisor does not send a graceful ACPI shutdown signal to the CentOS7 guest. Consequently, the guest operating system terminates abruptly without unmounting filesystems cleanly. Upon the next boot, the
vboxsf (VirtualBox Shared Folder) kernel module may not be loaded into memory, even though the shared folder configuration exists in the guest settings.
Without the active kernel module, the
mount -a command or Vagrant's automatic mounting process fails silently or throws errors related to missing device types. This is distinct from permission issues or network problems; it is strictly a driver availability problem. The guest knows *what* to mount, but lacks the *engine* (
vboxfs) required to interpret the VirtualBox shared folder protocol.
Why It Happens on Windows11 Hosts
Windows11 hosts often use fast startup features or aggressive power-saving modes that can lead to non-graceful exits for virtual machines. If the host machine freezes or is forced off via the power button, the VirtualBox process terminates immediately. The CentOS7 guest, running inside that process, does not get the chance to execute its own shutdown scripts, which normally ensure clean unmounting and module state preservation. This asymmetry between the host's abrupt exit and the guest's expectation of a clean cycle creates the "zombie" mount point state.
Immediate Remediation Steps
To fix the current broken state, you need to access the CentOS7 terminal directly, either through the VirtualBox GUI console or SSH if available. Do not rely on Vagrant to fix this automatically until the underlying kernel issue is resolved.
- Verify the Module Status: Run the following command to check if the
vboxsf module is loaded:
lsmod | grep vboxsf
If this returns nothing, the module is not present in the kernel space.
- Load the Kernel Module Manually: Force the kernel to load the shared folder driver by executing:
sudo modprobe vboxsf
This command inserts the vboxsf module into the running kernel. You should see no output if successful, or an error if the module is corrupted.
- Remount the Shared Folders: Once the module is loaded, attempt to mount all defined shares:
sudo mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
Replace vagrant and /vagrant with your specific share name and mount point if different. The uid and gid options ensure correct file ownership for the default user.
After these steps, verify that files are accessible in the target directory. If they are, the immediate crisis is resolved. However, to prevent recurrence, you must address the persistence layer.
Ensuring Persistence Across Reboots
Simply loading the module manually every time is not sustainable. You need to ensure that CentOS7 loads
vboxsf automatically at boot time, especially after unexpected resets.
Configure Initramfs
The most robust solution involves adding the module to the initial RAM filesystem configuration. This ensures the driver is available early in the boot process, before the root filesystem is fully mounted.
- Create a Configuration File: Create a new file in the
/etc/modules-load.d/ directory. Use the following command to create and edit the file:
sudo nano /etc/modules-load.d/virtualbox.conf
- Add the Module Name: Inside this file, add a single line containing the module name:
vboxsf
Save and close the file.
- Update Initramfs: Regenerate the initramfs image to include this change. On CentOS7, use:
sudo dracut --force
This step rebuilds the boot image with the new module inclusion.
By updating
dracut, you guarantee that the
vboxsf module is loaded regardless of how the previous session ended. This method is superior to relying solely on systemd services because it operates at the kernel level, independent of higher-level service states.
Preventive Measures for Vagrant Users
While the manual fix addresses the technical failure, Vagrant users can implement safeguards to minimize the impact of host instability.
Graceful Shutdown Scripts
Ensure that your Vagrantfile explicitly requests a graceful halt. Although this doesn't prevent crashes, it helps maintain consistency during normal operations. Add or verify the following in your
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: <<-SHELL
echo 'vboxsf' >> /etc/modules-load.d/virtualbox.conf
dracut --force
SHELL
end
This provisioner runs once during
vagrant up, setting up the persistence layer permanently. It eliminates the need for manual intervention after future reboots.
Host Power Management
On the Windows11 host, disable "Fast Startup" in the Control Panel under Power Options. Fast Startup hibernates the kernel state rather than performing a full cold boot, which can sometimes interfere with VirtualBox's ability to reset the VM state cleanly. Additionally, ensure that VirtualBox is updated to the latest version compatible with your Windows11 build, as newer versions have improved ACPI handling for abrupt termination scenarios.
For more information on resolving boot failures related to machine mismatches, see
VirtualBox: Guest Machines Mismatched - Vagrant Boot Failure. If you encounter permission errors after successfully mounting, refer to
Sharing Permissions for Shared Folders in VirtualBox on Windows 10 and Ubuntu 20.
Frequently Asked Questions
What if the modprobe command fails?
If
modprobe vboxsf fails with a "module not found" error, your Guest Additions installation is likely corrupted or incomplete. You must reinstall the VirtualBox Guest Additions ISO within the CentOS7 guest and run the installer script again. Ensure you have the
kernel-devel package installed before attempting the rebuild.
Does this issue affect other Linux distributions?
Yes, any Linux distribution using VirtualBox shared folders can experience this if the host crashes. However, CentOS7 is particularly susceptible because it uses older init systems and stricter module loading policies compared to newer distros like Ubuntu 22.04, which may handle transient module states more gracefully.
Can I use systemd instead of modprobe?
You can create a systemd service to load the module, but it is less reliable than the
/etc/modules-load.d/ approach for this specific scenario. Systemd services start after the basic system initialization, whereas
modules-load.d ensures the kernel has the driver ready as soon as possible. Stick to the
dracut method for maximum stability.
Why does Vagrant say "No guest additions were detected?"
This error usually appears during
vagrant up if the Guest Additions are not installed correctly. In the context of our issue, the additions are installed but the module is just not loaded. Check the VirtualBox menu under "Devices" > "Insert Guest Additions CD Image" to verify the presence of the ISO, then mount and install it from within the guest terminal.
Is there a way to detect this issue automatically?
You can write a simple cron job or a systemd timer that checks for the existence of the
vboxsf module periodically. If the module is missing, the script can trigger
modprobe vboxsf and
mount -a. However, fixing the root cause via
dracut is a one-time permanent solution that makes such monitoring unnecessary.