From afbbb031d39baca2d32a031d73d5ec6406264cfc Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 28 May 2026 15:46:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BD=BB=E5=BA=95=E7=BB=95=E8=BF=87=20U?= =?UTF-8?q?buntu=20WSL=20OOBE=20=E4=BA=A4=E4=BA=92=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ubuntu OOBE 检查 UID>=1000 的普通用户是否存在 - 创建占位用户 wsluser (uid=1000) 满足检查 - 删除 OOBE profile.d 脚本 - /etc/wsl.conf 单一 [user] 块覆盖写入 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- claude-dev-stack/deploy.ps1 | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/claude-dev-stack/deploy.ps1 b/claude-dev-stack/deploy.ps1 index 9a3f1a6..1ac5e51 100644 --- a/claude-dev-stack/deploy.ps1 +++ b/claude-dev-stack/deploy.ps1 @@ -136,24 +136,28 @@ if ($distroInstalled) { } # ── Step 1b: 首次 OOBE 处理 & 设置 root 为默认用户 ────────── -# Ubuntu 首次安装会停在 OOBE 要求创建用户;用 --root 启动可跳过 -Write-Info "初始化 WSL2 发行版(确保 root 可用)..." -$oobeDone = $false -for ($i = 0; $i -lt 3; $i++) { - wsl -d $WSL_DISTRO --user root -- bash -c "exit 0" 2>$null - if ($LASTEXITCODE -eq 0) { $oobeDone = $true; break } - Start-Sleep 3 -} -if (-not $oobeDone) { - # 触发 OOBE 完成(无交互,接受默认) - wsl -d $WSL_DISTRO -- bash -c "exit 0" 2>$null - Start-Sleep 5 -} +# Ubuntu OOBE 检测:若无 UID≥1000 的普通用户则弹交互提示 +# 解决方案:创建占位用户满足检查 + wsl.conf 设 default=root +Write-Info "初始化 WSL2(跳过 OOBE,设置 root 为默认用户)..." +$initCmd = @' +# 创建占位用户,满足 Ubuntu OOBE "至少有一个真实用户" 的检查 +id wsluser &>/dev/null || useradd -m -s /bin/bash -u 1000 wsluser -# 写入 /etc/wsl.conf(完整覆盖,避免重复块) -$wslConfContent = "[boot]`nsystemd=false`n`n[user]`ndefault=root`n" -wsl -d $WSL_DISTRO --user root -- bash -c "printf '[boot]\nsystemd=false\n\n[user]\ndefault=root\n' > /etc/wsl.conf" 2>$null -Write-OK "/etc/wsl.conf 已写入 (default=root, systemd=false)" +# 覆盖写入 /etc/wsl.conf(单一 [user] 块,避免重复冲突) +printf '[boot]\nsystemd=false\n\n[user]\ndefault=root\n' > /etc/wsl.conf + +# 禁用 Ubuntu OOBE 自动运行脚本(如存在) +rm -f /etc/profile.d/01-wsl-oobe.sh 2>/dev/null || true +rm -f /usr/lib/ubuntu-advantage/ua-messaging.service 2>/dev/null || true +true +'@ +# 用 --user root 初始化 rootfs(本身也会跳过 OOBE 交互) +wsl -d $WSL_DISTRO --user root -- bash -c "exit 0" 2>$null +Start-Sleep 2 +# 写入配置 +$b64Init = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($initCmd)) +wsl -d $WSL_DISTRO --user root -- bash -c "echo '$b64Init' | base64 -d | bash" 2>$null +Write-OK "/etc/wsl.conf 已写入 (default=root),占位用户已创建" # 重启使 wsl.conf 生效 wsl --terminate $WSL_DISTRO 2>$null