Automated storage engine for mounting, managing, and browsing Linux ext4 external SSDs natively on Windows 11 using WSL2, Direct SMB, and AutoHotkey.
Windows 11 cannot natively read or mount ext4 filesystems without third-party drivers. This engine bridges the gap by leveraging Hyper-V block device attachment (wsl --mount), guest ext4 optimization (noatime,nodiratime,errors=remount-ro), and loopback Direct SMB (port 445), orchestrated by event-driven AutoHotkey monitoring.
STORAGE LIFECYCLE ENGINE
+----------------------------+ +----------------------------+ +----------------------------+
| USB PLUG EVENT | ---> | HARDWARE BUS DETECT | ---> | WSL ATTACH & KEEP-ALIVE |
| (DBT_DEVNODES_CHANGED) | | (22ms in-memory query) | | (noatime, nodiratime, fsck)|
+----------------------------+ +----------------------------+ +----------------------------+
|
v
+----------------------------+ +----------------------------+ +----------------------------+
| SAFE EJECT / PULL | <--- | EXPLORER AUTO-REDIRECT | <--- | PURE DIRECT SMB 445 |
| (Lazy umount & flush) | | (Redirect to "This PC") | | (net use P: mapped OK) |
+----------------------------+ +----------------------------+ +----------------------------+
- Windows 11 with WSL2 installed (
wsl --install). - Ubuntu (or Debian) WSL2 guest distro.
- AutoHotkey v1.1 (running via
StartupScript.exe).
Open your WSL terminal (wsl -d Ubuntu) and install Samba and e2fsprogs:
sudo apt update && sudo apt install -y samba e2fsprogsCreate the mount point:
sudo mkdir -p /mnt/pixel_ssdAdd your Samba user (match credentials configured in ssd_config.json):
sudo useradd -M -s /usr/sbin/nologin wsluser 2>/dev/null
sudo smbpasswd -a wsluser
# Enter password (e.g. wslpassword123)Edit /etc/samba/smb.conf (sudo nano /etc/samba/smb.conf):
[global]
workgroup = WORKGROUP
server string = %h server (Samba, Ubuntu)
netbios name = WSLUBUNTU
disable netbios = yes
smb ports = 445
log file = /var/log/samba/log.%m
max log size = 1000
logging = file
panic action = /usr/share/samba/panic-action %d
server role = standalone server
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
[PixelSSD]
comment = Linux ext4 Backup SSD Mount
path = /mnt/pixel_ssd
browseable = yes
read only = no
guest ok = no
valid users = wsluser
force user = root
create mask = 0777
directory mask = 0777Install the mount helper script inside Ubuntu:
sudo cp /mnt/<drive>/path/to/AutoHotKey/AllScripts/PowerShell/mount_pixel_ssd.sh /usr/local/bin/mount_pixel_ssd.sh
sudo chmod +x /usr/local/bin/mount_pixel_ssd.shRestart Samba:
sudo service smbd restart-
Discover Your SSD Hardware Model: Run this in PowerShell to see your external USB drives and models:
Get-Disk | Where-Object BusType -eq 'USB' | Select-Object Number, FriendlyName, Model, BusType, Size
-
Configure Your Drive: Copy
ssd_config.json.exampletossd_config.json(this file is gitignored):Copy-Item "ssd_config.json.example" "ssd_config.json"
Edit
ssd_config.jsonwith your disk model filter, drive letter, and credentials:{ "disk": { "modelFilter": ["YourDiskModel", "VendorName"], "busType": "USB", "minSizeGB": 200, "maxSizeGB": 300 }, "wsl": { "distro": "Ubuntu", "mountPoint": "/mnt/pixel_ssd", "volumeLabel": "my_backup_volume" }, "smb": { "shareName": "PixelSSD", "driveLetter": "P:", "driveLabel": "Linux Backup SSD", "username": "wsluser", "password": "wslpassword123" }, "explorer": { "openFolder": "my_backup_volume\\DCIM\\Camera" }, "tasks": { "mountTask": "WSL_Mount_PixelSSD", "unmountTask": "WSL_Unmount_PixelSSD" } } -
Register Elevated Tasks (One-Time Setup): Double-click
Install_WSL_Mount_Tasks.bat(or open the AutoHotkey tray menu -> "Additional Scripts" -> "Ext4SsdManager" -> "Register Zero-UAC Tasks"). Approve the Windows UAC elevation prompt once. This registersWSL_Mount_PixelSSDandWSL_Unmount_PixelSSDin Windows Task Scheduler, allowing future automated mounts with zero UAC prompts. -
Configure Local AutoHotkey Paths (Optional Overrides): In
AllScripts/LocalPaths.ahk(gitignored, seeLocalPaths.ahk.example):EXT4_SSD_MODEL_SUBSTRINGS := "YourDiskModel,VendorName" EXT4_SSD_DRIVE_LETTER := "P:" EXT4_SSD_LABEL := "Linux Backup SSD" EXT4_SSD_TARGET_PATH := "my_backup_volume\DCIM\Camera"
| File | Type | Purpose |
|---|---|---|
ssd_config.json.example |
Git Tracked | Open-source JSON configuration template. |
ssd_config.json |
Gitignored | Active workstation configuration (credentials, hardware filters). |
ssd_common.ps1 |
Helper Script | Shared module providing Get-SSDConfig and Find-TargetSSD. |
mount_wsl_ssd.ps1 |
Orchestrator | Attaches disk, suppresses RAW drive letter, probes port 445, maps drive, and launches Explorer. |
unmount_wsl_ssd.ps1 |
Teardown | Redirects open Explorer tabs to "This PC", unmaps drive, flushes WSL attachments, and executes PnP safe removal. |
wsl_mount_elevated.ps1 |
Elevated Action | Helper executed by WSL_Mount_PixelSSD Task Scheduler action. |
wsl_unmount_elevated.ps1 |
Elevated Action | Helper executed by WSL_Unmount_PixelSSD Task Scheduler action (signals completion via flag). |
setup_scheduled_tasks.ps1 |
Installer | Registers elevated tasks in Task Scheduler without quote bugs. |
Install_WSL_Mount_Tasks.bat |
Batch Helper | Self-elevating batch installer for one-click setup. |
mount_pixel_ssd.sh |
Bash Script | Guest mount helper (noatime,nodiratime,errors=remount-ro) with fsck.ext4 -p. |
run_silent.exe |
GUI Launcher | Native Windows GUI runner (CREATE_NO_WINDOW) for zero-focus background PowerShell execution. |
SilentLauncher.cs |
C# Source | Source code for run_silent.exe preserving raw command line quotes. |
ARCH_AND_GOTCHAS.md |
Architecture | Deep-dive documentation on UASP SCSI, kernel SMB hangs, UTF-16LE, Hyper-V faults, and safe eject. |
- Instant RAW Suppression: Removes Windows RAW drive letter assignments before AutoPlay can suggest formatting the drive.
- Kernel MUP Hang Elimination: Non-blocking DLL checks and fast port probing eliminate the 30-second Windows freeze on dead network shares.
- WSL2 Idle VM Shutdown Defense: Background
sleep infinitykeepalive holds the VM open while mounted. - Broken Window Prevention: Active Explorer tabs viewing the drive are automatically navigated to "This PC" before unmounting.
- Dirty Detach Recovery: If the drive is abruptly unplugged,
fsck.ext4 -pautomatically replays the journal on the next insertion.
When the external SSD is suddenly unplugged without unmounting:
- Hardware Drop Notification: Windows broadcasts
WM_DEVICECHANGE(0x0007/0x8004). - Instant Bus Verification: The AutoHotkey watcher executes a 22ms in-memory WMI query confirming physical removal.
- Graceful Windows Teardown:
- Every active Explorer tab viewing the drive or its subfolders is redirected to "This PC", preventing Windows "Location is not available" error popups.
net use P: /delete /yinstantly severs the network mapping, eliminating Windows kernelMUP.SYSdead-share hangs.
- Clean Linux State: Ubuntu runs a lazy unmount (
umount -l) to release filesystem descriptors, and Hyper-V releases the detached physical drive record. - Flag Reset: Any manual ejection flags are cleared automatically because the drive is physically absent.
When the drive is plugged back in later:
- Hardware Arrival: Windows signals device arrival (
0x0007/0x8000). - Model Match: AutoHotkey detects the target SSD on the USB bus.
- Elevated Hyper-V Attach: The registered zero-UAC Task Scheduler job attaches the drive to WSL2 and strips Windows RAW drive letters.
- Safe Journal Replay: The guest Linux helper executes
/sbin/fsck.ext4 -pbefore mounting, repairing any pending journal transactions caused by the abrupt disconnect. - Direct SMB Mapping: Direct SMB 445 connects, maps
P:, and launches Explorer directly to your target directory. - Zero Manual Action Required: No keypresses or commands are needed. The system mounts automatically.
When you press Win+Alt+U (or open the AutoHotkey tray menu -> "Additional Scripts" -> "Ext4SsdManager" -> "Eject Pixel SSD Safely"):
- Open Explorer tabs are safely navigated to "This PC".
net use P: /deleteunmaps the drive letter immediately.- Guest helper
/usr/local/bin/unmount_pixel_ssd.shruns lazy-unmount and stops Samba. - Elevated Task Scheduler action
WSL_Unmount_PixelSSDdetaches\\.\PHYSICALDRIVE*from Hyper-V and writes%TEMP%\wsl_unmount_done.flag. unmount_wsl_ssd.ps1waits for the flag barrier, then invokes native Win32CM_Request_Device_EjectW(cfgmgr32.dll) on the parent USB device node with adaptive retry backoff.- Windows cuts power to the USB device and displays the native "Safe to Remove Hardware" notification.
- An ejection marker (
%TEMP%\pixel_ssd_ejected.flag) prevents the watchdog from re-mounting the drive until physically re-plugged.
When clicking the Windows taskbar "Safely Remove Hardware" icon instead of using the hotkey:
- Windows initially attempts removal, finds Hyper-V's open SCSI handle, and begins to display the modal: "Problem Ejecting USB Attached SCSI (UAS) Mass Storage Device: This device is currently in use."
- The
AutoResolveEjectConflictroutine inExt4SsdManager.ahkintercepts the#32770dialog within 400ms and closes it viaWinClose. - Displays a non-intrusive status tooltip: " in use by WSL. Safely unmounting and ejecting..." (default: "Linux Backup SSD in use by WSL...").
- Invokes
unmount_wsl_ssd.ps1, which unmounts Ubuntu, detaches from WSL, synchronizes via completion flag, and invokesCM_Request_Device_EjectW. - Safe removal completes on that single action, and Windows displays its native "Safe to Remove Hardware" toast.