2022-02-12

Acer SPIN 5 (SP513-55N, SP513-41N)安裝Ubuntu/Linux MINT Cinnamon 20.3

想要支援平版型筆電, MINT裝Cinnamon版本會友善一點,MATE/XFCE的支援度差一點,但後面會講解法。 

1.開機時按F2進BIOS,
在Main頁面按ctrl+s呼叫出隱藏選項,
將SATA Mode=> AHCI, trackpad => PS2(待會會再改回來),
在Security將TPM關閉,
在Boot頁面將Secure Boot關閉(要先在Security頁面設Supervisor Password才能改),
Boot priority order 設為要用來安裝Ubuntu/Mint的USB。

2.開始安裝Mint,安裝時個人是分成三個分割區:
EFI => 550mb (UEFI開機載入需要此分割區)
SWAP=> 5120mb
剩下的都格式化為ext4並 mount 給 /

3.裝完後,修改 /etc/default/grub:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pci=nocrs" #加入pci=nocrs
GRUB_SAVEDEFAULT=true
GRUB_DEFAULT=saved
GRUB_TIMEOUT=3

修改完執行 sudo update-grub

3.打開更新管理員執行更新,若是intel版本,AX210網卡需5.10+ kernel,AX200需5.1+ kernel。若是amd版本,附的應該是都MT7921聯發科網卡,需要5.12+ kernel,但我建議把聯發科卡換成intel網卡,就算弄到能上網一樣是真心爛(掉包降速斷線等)。

重開機,進BIOS把trackpad改回IC2,開機時在選單選擇用最新的kernel開機。

4.調整自動旋轉
= 若是Cinnamon =:
進 管理/顯示器/設定,選擇Hi-DPI啟用fractional scaling,fractional scaling選150%
安裝touchscreen旋轉時的xinput修正:
sudo apt-get install x11-touchscreen-calibrator

Cinnamon其中有一個"自動螢幕旋轉",請保持停用狀態,不然啟用的話,螢幕設定不知怎的都無法正常保存。

= 若是MATE/XFCE =:
桌面設定一樣改 Hi-DPI
sudo apt-get install x11-touchscreen-calibrator
xrandr --output eDP --scale 1.5x1.5
sudo apt install autorandr
autorandr --save work

不管哪個版本,自動旋轉請改用自動偵測script (https://askubuntu.com/a/1375561),可放到開機自動啟動:

sudo apt install iio-sensor-proxy inotify-tools

==================================
#!/bin/bash
# Auto rotate screen based on device orientation
monitor-sensor | \
while IFS= read -r str; do
  if [[ $str =~ orientation\ changed:\ (.*)$ ]]; then
    case "${BASH_REMATCH[1]}" in
    normal)
      xrandr --output eDP --rotate normal ;;
    bottom-up)
      xrandr --output eDP --rotate inverted ;;
    right-up)
      xrandr --output eDP --rotate right ;;
    left-up)
      xrandr --output eDP --rotate left ;;
    esac
  fi
done
=================================

5.調整firefox滑動及steam縮放,修改/etc/environment,加入:
MOZ_USE_XINPUT2=1 #firefox,並把firefox設定中的平滑捲動取消
# GDK_SCALE=2 #steam,不過建議在啟動steam時加在指令前面就好

6.調整java介面縮放,修改 ~/.profile,加入:
#java ui scale
export _JAVA_OPTIONS='-Dsun.java2d.uiScale.enabled=true  -Dsun.java2d.uiScale=2'

7.fcitx輸入文字時,候選字(preedit)視窗(fcitx-qimpanel)過小:

譬如用的是ubutnu-grey主題,那麼就修改:
sudo vi /usr/share/fcitx-qimpanel/skin/ubuntu-grey/fcitx_skin.conf

FontSize=36
CandFontSize=36

若是用default佈景,那就修改:
sudo vi /usr/share/fcitx/skin/default/fcitx_skin.conf

8.觸控板多指手勢支援:
X11(後面指令以X11為主):
https://github.com/bulletmark/libinput-gestures
https://gitlab.com/cunidev/gestures

sudo apt install python3 python3-pip python3-venv python3-gi python-gobject meson wmctrl xdotool libinput-tools gettext appstream-util

sudo gpasswd -a $USER input
git clone https://github.com/bulletmark/libinput-gestures.git
cd libinput-gestures
sudo make install (or sudo ./libinput-gestures-setup install)
cp /etc/libinput-gestures.conf ~/.config/libinput-gestures.conf
newgrp input
libinput-gestures-setup autostart start


git clone https://gitlab.com/cunidev/gestures
cd gestures
meson build --prefix=/usr
ninja -C build
sudo ninja -C build install

之後再執行gestures程式調整要的多指手勢

若display server是Wayland的話,可參考:
https://extensions.gnome.org/extension/1253/extended-gestures/

9.指紋辨識(Fingerprint Reader),因為我用不到,而且加入方式也挺麻煩,跳過。

10. 修正外接麥克風(內建麥克風正常)無法收音問題:
修改 /etc/modprobe.d/alsa-base.conf
加入:
options snd-hda-intel model=alc255-acer,dell-headset-multi
(https://askubuntu.com/a/1307107)

11.取消進入休眠HIBERNATE (按F1似乎還是會進待機SUSPEND,但不會叫不醒了,也行…)
修改 /etc/systemd/logind.conf:
HandleSuspendKey=ignore

ref:
https://sciactive.com/2020/12/04/how-to-install-ubuntu-on-acer-spin-5-sp513-54n-for-the-perfect-linux-2-in-1/
https://wiki.archlinux.org/title/HiDPI

2021-10-03

安裝 jetbrains projector 並以 user systemd 方式啟動

 安裝很簡單,直接參考github官方網站:
https://github.com/JetBrains/projector-installer

設定:
projector config list
projector config  edit <APP_NAME>

憑證:
若有用let's encrypt,可直接用如下指令安裝,記得憑證過期一樣要再重安裝一次
(APP_NAME可能為IntelliJ或DataGrip,可參照 ~/.projector/configs):

projector install-certificate <APP_NAME> --certificate /etc/letsencrypt/live/<change.to.your.site.com>/fullchain.pem --key /etc/letsencrypt/live/<change.to.your.site.com>/privkey.pem;

以下補充如何以user systemd的方式自啟動,這樣ide點擊exit或reload時就會重新啟動,也不用登入tty,以下以新增 IntelliJ IDEA為例:
mkdir -p ~/.config/systemd/user/
vi ~/.config/systemd/user/idea.service
加入:
======================
[Unit]
Description=Jetbrains Projector - IDEA

[Service]
Type=simple
#注意這裡要改為用 run.sh 執行
ExecStart=%h/.projector/configs/IntelliJ/run.sh
Restart=always

[Install]
WantedBy=default.target
======================
再執行(以一般使用者身份執行即可)
systemctl --user start idea
systemctl --user status idea
systemctl --user enable idea
#不用tty登入也可reboot時自啟動
loginctl enable-linger <username> 

ref:
https://youtrack.jetbrains.com/issue/PRJ-298
https://wiki.archlinux.org/title/systemd/User#Automatic_start-up_of_systemd_user_instances

2021-09-16

WIN7的XP Mode導出vhd檔案並在VirtualBox(或VMware) 執行

 一、先確認你記得XP Mode的XMPUser密碼(先登出再登入試試),不然就是改為無密碼登入

二、確認將XP Mode關機(ctrl + alt +del 並選關機),確保不是在儲存狀態下

三、到XP Mode設定的硬碟一(Hard Disk 1)點選「修改(Modify)」並選「合併(Merge)」映像檔,此時會產出一個vhd檔案 

四、到VirtualBox(或VMware) 新建XP虛擬機,並指定剛剛產生的vhd檔

五、此時很可能會顯示「需啟動Windows XP」而鬼打牆無法登入,即使輸入key也一樣,先重開虛擬機並按F8進入安全模式

六、下載https://t.me/joinchat/JtV8PRmFFTeDZ_PHNVtC3g 此 tg群組內的 sp3 檔案(MEGA備份),解壓縮並放到虛擬機桌面

七、把剛解壓縮的system32資料夾內的檔案覆蓋到 C:\WINDOWS\system32,並再執行資料夾內的XP_Pro_SP3_OEM_to_VLK.reg,再重開機

八、此時很可能還會要您啟動,隨便找個VLK KEY輸入即可。
HCQ9D-TVCWX-X9QRG-J4B2Y-GR2TT

九、有些MIDI軟體在Virtualbox播放時聲音會產生嚴重卡頓,不管怎麼改設定都沒用,因此後來改用VMWare完全沒問題。

ref:
https://www.hanselman.com/blog/transferringmoving-a-vhd-from-windows-virtual-pc-windows-xp-mode-to-another-computer
https://hibest.tw/oem-to-vlk-windowsxp/

2021-09-13

老筆電X61出現Possible missing firmware...訊息

由於 linux-firmware 套件缺少了i915晶片一些韌體,導致每次更新kernel就會出現下列訊息:

update-initramfs: Generating /boot/initrd.img-5.4.0-84-generic
W: Possible missing firmware /lib/firmware/i915/tgl_dmc_ver2_04.bin for module i915
W: Possible missing firmware /lib/firmware/i915/skl_guc_33.0.0.bin for module i915
W: Possible missing firmware /lib/firmware/i915/bxt_guc_33.0.0.bin for module i915
W: Possible missing firmware /lib/firmware/i915/kbl_guc_33.0.0.bin for module i915
W: Possible missing firmware /lib/firmware/i915/glk_guc_33.0.0.bin for module i915
W: Possible missing firmware /lib/firmware/i915/kbl_guc_33.0.0.bin for module i915
W: Possible missing firmware /lib/firmware/i915/icl_guc_33.0.0.bin for module i915

缺韌體問題,就來這個網址下載這一包找找:
https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/

果然找到,補到 /lib/firmware/i915/ 內就 ok 了!

ref:

老電腦舊電腦用 usb 或 live cd無法用一般模式開機時

今天準備用linux mint重灌一台AMD phenom quad的老電腦,結果無法用第一個選項正常開機(畫面會hang住),用第二個選項Compatibility mode倒是可以。後來發現按tab修改第一個選單的開機參數,改用nomodeset就可以了:

Replace "quiet splash" with "nomodeset" and press Enter to boot.

原因是現在graphic driver是直接做在kernel,這樣開機畫面會比較"漂亮",但對某些顯卡會無法正常使用,因此用nomodeset讓kernel以bios模式開機,直到進x window後再載入顯卡driver。

ref:
https://linuxmint-installation-guide.readthedocs.io/en/latest/boot_options.html#nomodeset-boot-option
https://askubuntu.com/questions/207175/what-does-nomodeset-do

2021-09-11

安裝code-server

 code-server,也就是讓你可以自架雲端版的VS Code(或開源的VSCodium),可以像GitPod(基於Eclipse Theia)一樣用瀏覽器操作遠端vs code介面。

安裝可分三種方式(Linux based):

一、直接下載script安裝(自動安裝deb或rpm):curl -fsSL https://code-server.dev/install.sh | sh

二、手動下載deb或rpm安裝

三、安裝到雲端供應商

安裝上非常簡單,安裝完後,先執行code-server跑跑看,會出現連線網址及port(預設8080),按ctrl+c停止。

打code-server --help會顯示一些可用參數,若不想用參數可修改設定檔,設定檔用的參數名稱與執行命令的參數名稱都是一樣的,設定檔位置在 ~/.config/code-server/config.yaml,以下是範例(埠號10000,使用密碼及憑證):

bind-addr: 0.0.0.0:10000
auth: password
password: mypassword
cert: /path/to/your/fullchain.pem
cert-key: /path/to/your/privkey.pem

若設為 cert: false 會使用自簽憑證,若有正式憑證請把cert及cert-key檔案路徑打上去,
建議憑證一定要設,不然複製貼上等一些功能可能會有問題,免費憑證可以使用letsencrypt,參照cerbot官網並選擇平台照建議安裝即可。

還有一個問題就是預設的plugin maketplace並不是微軟的marketplace,而是open vsx,這是因為使用條款限制的關係而不能直接使用,若想切換成微軟的marketplace,可以新增環境變數,範例script如下(.sh):

#!/bin/bash
SERVICE_URL=https://marketplace.visualstudio.com/_apis/public/gallery ITEM_URL=https://marketplace.visualstudio.com/items CACHE_URL=https://vscode.blob.core.windows.net/gallery/index code-server > /dev/null 2>&1 &  echo "$!"

用以上script執行後會顯示執行的pid並背景執行,想要關閉程式的話,可直接kill -9 <pid>,若沒記下pid而清掉螢幕,就改用 ps -u username Sf | grep code-server 找出/usr/lib/code-server/lib/node /usr/lib/code-server...執行樹最上層的process pid,並用kill -15 <pid>停止程序。

若想用systemd的方式開機自動以某user身份執行的話,可用
sudo systemctl enable --now code-server@username

記得要更換extension marketplace的話,把以下變數設定加到
/lib/systemd/system/code-server@.service
的 [Service] 裡:
Environment=SERVICE_URL=https://marketplace.visualstudio.com/_apis/public/gallery Environment=ITEM_URL=https://marketplace.visualstudio.com/items Environment=CACHE_URL=https://vscode.blob.core.windows.net/gallery/index 

執行code-server加執行參數時,可寫在
~/.local/share/code-server/argv.json 或 ~/.config/code-server/config.yaml
但像要加上 enable-proposed-api 時,寫在config.yam只能指定單個extension,用list形式指定的話無法生效(bug?),只好改寫在 argv.json,譬如:
{"enable-proposed-api": ["genuitecllc.codetogether", "ms-toolsai.jupyter"]}

ref:
https://coder.com/docs/code-server/v3.12.0/collaboration#installing-the-codetogether-extension
https://code.visualstudio.com/api/advanced-topics/using-proposed-api#sharing-extensions-using-the-proposed-api
https://coder.com/docs/code-server/v3.12.0/FAQ#how-can-i-reuse-my-vs-code-configuration


2021-09-09

vscode的鳥bug,跑python預設都只會在powershell跑

在windows上,不管怎麼修改terminal default profile為command prompt(cmd),只要點右上的執行按鈕,就是只會用powershell執行python,而且還無法正常載入conda env環境(還是linux好)。

解決方式:

一、先用管理員進powershell執行 set-executionpolicy remotesigned

二、再到vscode建立python的launch.json,加入如下(參考開始選單中conda呼叫poweshell的捷徑參數修改):

"configurations": [

    {

        "name": "Python: 目前檔案",

        "type": "python",

        "request": "launch",

        "program": "${file}",

        "console": "integratedTerminal",

        "args": [

            "-ExecutionPolicy",

            "ByPass" ,

            "-NoExit",

            "-Command",

            "& 'C:\\Users\\User\\miniconda3\\shell\\condabin\\conda-hook.ps1' ; conda activate 'C:\\Users\\User\\miniconda3' "

        ]

    }

]

 ref:
https://stackoverflow.com/questions/54828713/working-with-anaconda-in-visual-studio-code
https://stackoverflow.com/questions/56450606/how-to-add-anaconda-powershell-to-vscode/61879466#61879466
https://docs.microsoft.com/zh-tw/powershell/scripting/dev-cross-plat/vscode/using-vscode?view=powershell-7.1#workspace-debugging