bash on windows可以升級為16.04嗎?

我升級失敗了

$ sudo do-release-upgrade
[screen is terminating]


這個問題我Google了半天,終於成功升級。

查證中發現,下面這樣用 Ubuntu 的自動升級在 Bash on Windows 會失敗的:

sudo aptitude install update-manager-core
sudo do-release-upgrade

因此需要用類似Debian的升級方法,我主要參考的是 Upgrade Ubuntu on Windows from 14.04 to 16.04 : windowsinsiders

下面我整理一下各個步驟:

1. 獲取全局root許可權

$ sudo -s
# 然後輸入密碼

2. 把所有包升級至 14.04 (trusty) 的最新版

$ aptitude update
$ aptitude full-upgrade -y

3. 更改更新源為 16.04 (xenial)

# 方法一:修改初始的更新源文件
# 備份初始的源文件為sources.list.ORIG,將sources.list里的"trusty"全替換為"xenial"。
$ sed -i.ORIG s/trusty/xenial/g /etc/apt/sources.list

# 方法二(推薦):把更新源直接改為國內的阿里雲Ubuntu(xenial)鏡像,這樣會很快
# 編輯更新源文件
$ vim /etc/apt/sources.list
# 清空文件後粘貼如以下代碼:
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
# :wq 保存退出

4. 備份並新建空文件夾 /etc/apt/sources.list.d/

註:bash剛裝好時這個文件夾是空的,若如此可跳過這一步

$ mv /etc/apt/sources.list.d/ /etc/apt/sources.list.d.ORIG/
$ mkdir /etc/apt/sources.list.d/

5. 升級至 16.04 (xenial)

$ aptitude update
$ aptitude safe-upgrade -y
# 注1:升級過程中會提示你重啟服務(restart services),選yes
# 注2:還會出現文件衝突,保留當前版本(current version)即可,輸入N

6. 把所有包升級至 16.04 (xenial) 的最新版,並重裝丟失的aptitude包,最後清理無用包

$ apt-get dist-upgrade
$ apt-get install aptitude
$ apt-get autoremove

7. 至此已經順利升級至 16.04 (xenial) 了,但你會發現像原來那樣使用sudo命令會報錯:

# 重啟Bash,在非root許可權下測試
$ sudo apt-get update
sudo: no tty present and no askpass program specified

# 此後用sudo只能這麼用:
$ sudo -S apt-get update

如果你裝錯了,或者想退回 Ubuntu 14.04 (trusty),把Linux子系統卸載重裝即可:

&> lxrun /uninstall /full /y
&> lxrun /install

最後,引用一句話:

So when will the newer Ubuntu 16.04 LTS release be available? In a recent comment, Microsoft』s Rich Turner explained: 「We have to add some additional capabilities to make it work well, but we are looking at 16.04 support for a future release.

微軟自認為這個 Bash on Ubuntu on Windows 還不夠穩定,所以暫不支持官方升級,這樣強行升級會有什麼後果,那就不好說了,大家湊合用吧。


現在別急著亂動,MS官方已經確認,明年年初的Win10RS2將會讓WSL內置的Ubuntu升級到16.04LTS


Build 14936

For general Windows information on build 14936 visit the Windows Blog.
To track or report an issue visit our Github page.

Note: WSL will install Ubuntu version 16.04 (Xenial) instead of Ubuntu 14.04 (Trusty) in an upcoming release. This change will apply to Insiders installing new instances (lxrun.exe /install or first run of bash.exe). Existing instances with Trusty will not be upgraded automatically. Users can upgrade their Trusty image to Xenial using the do-release-upgrade command.

Bash on Ubuntu on Windows


Windows10 1703版本已經可以通過

sudo do-release-upgrade

進行升級了.升級的過程也比較簡單.


發現一個神器 GitHub - RoliSoft/WSL-Distribution-Switcher: Scripts to replace the distribution behind Windows Subsystem for Linux with any other Linux distribution published on Docker Hub.

------

升級方法 Upgrade Trusty to Xenial · Issue #482 · Microsoft/BashOnWindows · GitHub

替換為ArchLinux的方法 plans for alternative distributions: e.g. Fedora, ArchLinux, etc? · Issue #8 · Microsoft/BashOnWindows · GitHub

---

然而並沒有完全成功 Upgrade Trusty to Xenial · Issue #482 · Microsoft/BashOnWindows · GitHub

打開zsh後遇到和上一個方法相同的問題(作死重新試過以後發現沒有問題了)

Ok, so heres the final state of things on my end. From a brand new install of Bash on build 14379, ran the
following:
sudo su
apt‐get update
apt‐get upgrade
apt‐get dist‐upgrade
apt‐get autoremove
sudo do‐release‐upgrade ‐f DistUpgradeViewNonInteractive ‐d
As noted, it still gets stuck at a Y/N prompt. Pressed Ctrl+C and ran:
echo yourpasswordhere | sudo ‐S dpkg ‐‐configure ‐a
apt‐get update
apt‐get upgrade
apt‐get dist‐upgrade
apt‐get autoremove

--------失敗了------------

自問自答作死中,來自 https://gist.github.com/anonymous/21fc9043b1ee3fa3660cd4d513ee67d5

# Upgrade all the packages to the latest versions
aptitude update
aptitude full-upgrade -y

# Update our sources, save the original as /etc/apt/sources.list.ORIG
# This step is REQUIRED, otherwise the instructions below will not upgrade a
# single package.
sed -i.ORIG s/trusty/xenial/g /etc/apt/sources.list

# Backup the /etc/apt/sources.list.d/ folder and create an empty one.
# This will disable all Third Party/Launchpad PPA repositories.
# These repositories can be re-enabled after a successful upgrade.
mv /etc/apt/sources.list.d/ /etc/apt/sources.list.d.ORIG/
mkdir /etc/apt/sources.list.d/

# Upgrade your box--the easy part.
aptitude update
aptitude safe-upgrade -y

# Now for the scary one--see below.
apt-get dist-upgrade


Windows 10 Preview Build 14936 以後的的版本已經內置16.04,我上個月自動升級後發現內核升級了。


還是有不少包有兼容性問題,我果斷還是開hyper v裝了個ubuntu server1604來測試部署環境


推薦閱讀:

Windows 10的Photos為什麼這麼慢?
你有那些珍藏多年的win10簡約1920x1080壁紙?
Windows Phone 應用會在 2015 年下半年迎來爆發么?
windows10多顯示器設置不同的縮放比例很模糊是為什麼?
Mac OS X 有機會戰勝 Windows 嗎?

TAG:Ubuntu | Windows10 | WindowsSubsystemforLinux |