前言
最新換了新筆電,結果硬件配置太新,Ubuntu18.04、Linux Mint19裝上後都有問題,無耐又回到了Windows10,現在就只能折騰win10的Linux子系統了(不喜歡虛擬機),儘量在win10上折騰出一個好用的工作環境出來吧 ~
Contents
- 安裝Linux子系統
- 使用ssh遠程登錄Linux子系統
- 安裝MyDock和TranslucentTB
- /mnt目錄下掛載的文件系統默認權限爲777的問題
- win10家庭版啓用hyper-v虛擬化技術安裝virtualbox
- win10 virtualbox啓動虛擬機失敗
- linux和win10跨系統開發git倉庫文件權限的問題
- 更換阿里軟件源
- VMware Workstation 與 Device/Credential Guard 不兼容
安裝Linux子系統
- 在控制面板裏打開
啓用或關閉windows功能
- 勾選
適用於Linux的Windows子系統
- 確定安裝並重啓
- 應用商店搜索
Linux
安裝Ubuntu18.04
使用ssh遠程登錄Linux子系統
- 安裝ssh
$: sudo apt install ssh
- 修改sshd配置
# 備份sshd配置文件
$: sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config-bak
# 修改內容
ListenAddress 0.0.0.0 # 取消註釋
#StrictModes yes #加註釋
PasswordAuthentication yes # 允許密碼登錄
- 啓動ssh
$: service ssh start
- 如果提示
sshd error: could not load host key
,執行:
$: sudo rm /etc/ssh/ssh*key
$: sudo dpkg-reconfigure openssh-server
- win10商店安裝Termius(
ssh客戶端工具
)
安裝MyDock和TranslucentTB
MyDock
MyDock是一款能讓Windows系統用上Dock欄的軟件,毛玻璃效果很棒,可自定製程度也很高。
TranslucentTB
TranslucentTB是一款能使Windows10系統任務欄透明化的小工具,支持毛玻璃透明效果。
/mnt目錄下掛載的文件系統默認權限爲777的問題
在 Insider Build 17063 中,wsl加入了DrvFs功能,在WSL和Windows文件系統中充當橋樑,使WSL的文件權限可以支持更多的Metadata和更多的Mount選項。詳細介紹看這裏 Chmod/Chown WSL Improvements。
使用簡單命令就可以用drvfs重新mount硬盤:
$: sudo umount /mnt/c
$: sudo mount -t drvfs C: /mnt/c -o metadata
或者使用添加umask和fmask等參數:
$: sudo mount -t drvfs C: /mnt/c -o metadata,uid=1000,gid=1000,umask=22,fmask=111
但是每次使用時手動mount也太麻煩了,這時正好用上另一個新特性 Automatically Configuring WSL。把下面automount的選項添加到/etc/wsl.conf文件中就可以了。
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = false
現在重啓WSL的console, windows硬盤上的文件和文件夾都擁有正常權限了。但是坑還沒有完,如果這時用mkdir命令創建一個空文件夾,就會發現新的文件夾還是777權限。這可能是wsl的一個bug (Issue 1801, Issue 352),console默認的umask值仍然是0000。work-around的方法是在.profile、.bashrc、.zshrc或者其他shell配置文件中重新設置一下umask。
#Fix mkdir command has wrong permissions
if grep -q Microsoft /proc/version; then
if [ "$(umask)" == '0000' ]; then
umask 0022
fi
fi
win10家庭版啓用hyper-v虛擬化技術安裝virtualbox
win10家庭版是沒有帶hyper-v客戶端的,需要自己用腳本安裝
- 創建hyper-v安裝可執行腳本
hyper-v_setup.cmd
,右鍵以管理員來運行
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
重啓後hyper-v已經安裝,按下
win + q
快捷鍵輸入啓用和關閉windows功能
,然後檢查hyper-v是否已經勾選安裝重啓進入bios(按下
F2 或 Del 或 Esc 或 F12
鍵),將Intel Virtual Technology
設置爲enable
,啓用bios的虛擬化功能
win10 virtualbox啓動虛擬機失敗
virtualbox啓動虛擬機報錯Raw-mode is unavailable courtesy of Hyper-V
- 按下
win + x
選中以管理員啓動命令行 - 檢查hypervisor狀態:
bcdedit
- 如果
hypervisorlaunchtype
一行顯示爲auto
的話,將它禁用
bcdedit /set hypervisorlaunchtype off
- 重啓電腦打開virtualbox查看是否正常運行
linux和win10跨系統開發git倉庫文件權限的問題
有時候新克隆下的倉庫無端地就有文件的修改(git status
),查看git狀態,發現是文件權限變動的問題:
$: git diff file
old mode 100644
new mode 100755
=> 原因:Linux和Win10文件系統權限管理的問題
=> 解決:設置git忽略文件系統權限衝突的問題
# 全局
$: git config --global core.filemode false
# 位於單個倉庫目錄下
$: git config core.filemode false
更換阿里軟件源
- 備份
/etc/apt/sources.list
- 編輯替換爲阿里源(
Ubuntu 18.04
)
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
- 更新軟件
$: sudo apt update
$: sudo apt upgrade
VMware Workstation 與 Device/Credential Guard 不兼容
open powershell in admin mode.
# close and reboot
> bcdedit /set hypervisorlaunchtype off
# if you want to reopen it sometime
> bcdedit /set hypervisorlaunchtype auto