Ubuntu 22.04 Upgrade Guide & Notes

tags: Ubuntu

Backups

  • backup your home directories data
  • make sure your social accounts, such as facebook account or gmail account, can be verified from other devices

Upgrade System Packages

Make sure there is at least 166Mb of available spaces in boot directory

  • If the boot directory is still not enough during the upgrade, you can change the compression method from lz4 to xz through the initramfs.conf configuration file.
    • /etc/initramfs-tools/initramfs.conf
1
COMPRESS=xz

Download iso file & Upgrades

  • To avoid upgrade failure, you can also use the ventoy tool to reinstall the operating system. It is recommended to download the ISO file of the operating system

Upgrade Commands

1
2
3
4
5
6
7
8
9
sudo apt list --upgradable
sudo apt update && sudo apt upgrade -y
sudo reboot
lsb_release -a
sudo ufw allow 1022/tcp
sudo ufw reload
sudo ufw status
sudo apt install update-manager-core
sudo do-release-upgrade -d

Check your upgrade result

1
2
lsb_release -a
uname -mrs

Take Away

About the system directories

  • /root: recommended to use the same root directory for the upgrade.

    • perform the operating system upgrade in the same root directory, because keep the old directory there may be conflicts after the upgrade.
  • /boot: The autoremove command will remove packages that are no longer needed in an installed package. These packages are usually packages that were previously installed and are no longer needed.

1
sudo apt autoremove

References

https://www.youtube.com/watch?v=PtJXKdejbV0

Xiaomi 7 Root on windows

tags: 小米 刷機

小米刷機步驟

註冊小米帳號,綁定手機號

  • 這一步驟需要預先把sim卡裝到想要刷機的小米手機上
  • 註冊後的手機號碼需要等168小時(一週之後)才有辦法進行下一個步驟

OEM解鎖

  • 在關於手機的選單下,連續點擊MIUI版本,成為開發人員
  • 切回上個選單中的更多設定會多出開發者選項
    • 點進開發者選項後,會有裝置解鎖狀態,可以查看目前手機的解鎖狀態
  • 進入開發者模式,開啟OEM解鎖與啟用USB偵錯

下載小米官方解鎖工具

  • 使用一開始註冊的小米帳號登入小米官方解鎖工具
    • 登入後將手機關機後,長按關機鍵與聲音鍵下進入fastboot模式
    • 此時小米官方解鎖工具的解鎖按鈕會由灰色轉為可以點擊的狀態,即可解鎖小米手機

問題排除

  • 確認adb連線是否正常

    • usb連接上手機後,執行adb devices確認是否能正常取得裝置的資訊
  • 進入fastboot模式,將手機用USB連接上電腦後左上角出現press any key to shutdown

    • 如在Windows系統下以系統管理員身份執行下方的指令,或更換成USB 2.0的設備就可以解決這個問題
1
2
3
4
5
@echo off
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags\18D1D00D0100" /v "osvc" /t REG_BINARY /d "0000" /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags\18D1D00D0100" /v "SkipContainerIdQuery" /t REG_BINARY /d "01000000" /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags\18D1D00D0100" /v "SkipBOSDescriptorQuery" /t REG_BINARY /d "01000000" /f
pause

參考資料

PM Tool Excalidraw

tags: tool

PM開源工具免登入,支援多人協作

中文手寫風格設定

下方的範例是使用雲林黑體,如果想調整成其他中文字體格式,可以點擊chinese fonts查看其他不同的字體設定

1
2
3
4
5
6
7
8
{
[
"proxy" : [
"https://excalidraw.com/Virgil.woff2",
"https://github.com/yuleshow/chinese-fonts/blob/master/%E9%9B%B2%E6%9E%97%E9%BB%91%E9%AB%94/YunlinSans-Bold.ttf?raw=true"
]
]
}

debian update err on docker container

tags: docker

在使用docker debian的image時,第一次在build container,還能正常update。
然而,調整DockerFile之後重build,卻沒有辦法正常update,反而出現 Could not connect to security.debian.org:80 (127.0.0.1). - connect (111: Connection refused)的錯誤訊息

Err:1 http://deb.debian.org/debian bullseye InRelease

出現這個問題,只要做下面這兩個動作:

調整docker的預設dns設定

  • /etc/docker/daemon.json
1
2
3
{
"dns": ["8.8.8.8"]
}

重啟docker服務

1
sudo service docker restart

參考網址

https://medium.com/@faithfulanere/solved-docker-build-could-not-resolve-archive-ubuntu-com-apt-get-fails-to-install-anything-9ea4dfdcdcf2

Ubuntu ReInstall Guide

tags: ubuntu

為了在ubuntu執行line程式(exe檔),裝了wine移除之後發現藍芽還有telegram沒有辦法正常開啟,決定重新安裝ubuntu,順手記錄一下這次處理的過程

重裝前準備

  • 備份家目錄
    • 不需要將群組以及權限複製過去
1
sudo rsync -aP --no-p --no-g --chmod=ugo=rwX /home/$USER/ /media/$USER/backup_dir
  • 備份應用程式:
1
2
3
4
5
6
# backup
sudo dpkg --get-selections > package.list

#restore
sudo dpkg --set-selections < package.list
sudo apt-get dselect-upgrade

配置

  • 如果要沿用之前的home目錄,需要將home目錄在加入回這次安裝的項目中,注意不要選到格式化的選項
    • 原本用途的選項是不使用此分割區,調整成ext4日誌式檔案系統

  • 三磁區會被格式化,分別是swap、boot和root
    • 需要注意格式化的選項是被勾起的狀態
    • swap分區無法被勾選起來

安裝後

  • 比較麻煩的是之後要使用root權限逐一將應用程式安裝回來

  • 調整語系與輸入法設定

  • 調整筆電音效設定
1
2
3
4
echo "options snd-hda-intel dmic_detect=0" | sudo tee -a
/etc/modprobe.d/alsa-base.conf
echo "options snd-hda-intel model=laptop-amic enable=yes" | sudo tee -a
/etc/modprobe.d/alsa-base.conf

做完這幾步就大功告成拉。

謝謝大家耐心的看完這篇教學,有任何想法也歡迎留言喔。

Rootless Docker

tags: docker-compose gitpod
  • 一般container執行起來的時候,會是用root的權限在container執行各種檔案的操作
    • 當離開container之後,會發現volume建立的那些檔案都沒有辦法編輯
      • ls -al列出volume底下那些在container建立的檔案都會是root的權限
      • 為了解決這個問題,就需要改用rootless進入container進行後續的操作,但執行npm install會發現又需要root權限…
  • 解決方式有幾種
    • 使用rootless docker(-userns-remap flag),實作方式可以參考下方experimenting-with-rootless-docker的連結
    • 使用docker volume將使用者與群組volume到container環境(要注意需要設定read-only,以免改到本地的群組設定),可以參考using-current-user-when-running-container-in-docker-compose的連結
    • docker build image的時候,使用環境變數將當前登入的使用者與群組也一併新增上去,這是本篇文章採用的作法

Dockerfile

  • 設定環境變數
    • 如果USER_ID和GROUP_ID兩者都沒有設定會被設定為1001
  • 切換root使用者
  • 從環境變數中取得群組編號,並建立群組
  • 新增current_user到image
  • 工作路徑設定為workspace
  • 設定User為current_user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
FROM gitpod/workspace-full

# @see https://dev.to/visuellverstehen/docker-docker-compose-and-permissions-2fih

# Define build arguments
ARG USER_ID
ARG GROUP_ID
ARG USER

# Define environment variables
ENV USER_ID=$USER_ID
ENV GROUP_ID=$GROUP_ID
ENV USER_ID=${USER_ID:-1001}
ENV GROUP_ID=${GROUP_ID:-1001}
ENV CURRENT_USER=$USER

# output message
RUN echo "${CURRENT_USER} is added ${USER_ID} ${GROUP_ID}"

# https://github.com/gitpod-io/workspace-images/blob/master/full/Dockerfile
# RUN as root user
USER root

# Add group and user based on build arguments
RUN addgroup --gid ${GROUP_ID} ${CURRENT_USER}
RUN adduser --disabled-password --gecos '' --uid ${USER_ID} --gid ${GROUP_ID} ${CURRENT_USER}

# npm install permission
RUN sudo chown -R ${USER_ID}:${GROUP_ID} "/home/gitpod/.npm"
RUN sudo chown -R ${USER_ID}:${GROUP_ID} "/home/gitpod/.nvm"

# INSTALL net-tools
RUN apt-get update && apt-get install net-tools

# Set user and group of working directory
WORKDIR /workspace

# RUN as current user
USER ${CURRENT_USER}

docker-compose.yaml

  • 將Dockerfile所需的環境變數在build的階段傳入進來
  • 如果image有設定工作路徑,docker-compose就可以不用另外設定工作路徑
  • 指定對外的port與volume位置
  • 開啟互動模式:(這樣設定完成之後即使下docker-compose up -d沒有服務正在執行,container也不會馬上斷掉)
    • stdin: true
    • tty: true
  • 在container建立起來的時候,執行post-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: '3.2'

services:

hexo-local:
build:
context: .
dockerfile: ./Dockerfile
args:
USER_ID: $USER_ID
GROUP_ID: $GROUP_ID
USER: $USER
working_dir: /workspace # change working directory
volumes:
- ${PWD}:/workspace
ports:
- '8101:80'
stdin_open: true # https://stackoverflow.com/questions/36249744/interactive-shell-using-docker-compose
tty: true
command: sh /workspace/post-install.sh

常用指令

1
2
3
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
export USER=$(whoami)
  • source & build image
1
source env.sh && docker-compose build --no-cache
  • create container via docker-compose
1
docker-compose up -d
  • enter container
1
docker-composer exec hexo-local bash

docker debug技巧

  • image
    • echo可以確認環境變數是否帶入正確
  • container
    • docker run與interactive mode來
    • compose則可以設定tty和stdin為true來進入container
1
docker run --rm -it -v `pwd`:/workspace -p 8101:80 -u 0 gitpod/workspace-full

Reference

experimenting-with-rootless-docker

using-current-user-when-running-container-in-docker-compose

docker-&-docker-compose-and-permissions

Gitpod Env Settings & Tips Part 3

tags: yii gitpod

前情提要

延續前兩次的Gitpod和Docker Workflow介紹,這次補上環境變數三種設定方式,推薦使用第三種方式,使用docker-compose將環境變數的參數複寫原本Dockerfile的PHP_USER_ID設定。

知識點

  • docker images列出image id
  • docker inspect比對兩者環境變數的差異
  • dockerFile可以藉由args接收環境變數切換不同的版本
  • docker-compose config檢查是否環境變數設定正確
  • docker-compose build重新建立image

Build Flow

三種方法

法1:

  • 改DockerFile的Env

=> frontend/Dockerfile

1
2
3
4
5
6
7
8
9
FROM yiisoftware/yii2-php:7.2-apache
# FROM gitpod/workspace-full:latest

# Change document root for Apache
RUN sed -i -e 's|/app/web|/app/frontend/web|g' /etc/apache2/sites-available/000-default.conf

# Change PHP_USER_ID For Gitpod
ENV COMPOSER_ALLOW_SUPERUSER=1 \
PHP_USER_ID=33333

法2:

  • 使用docker-compose environment方法傳遞參數

=> docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
version: '3.2'

services:

frontend:
build:
dockerfile: Dockerfile
context: frontend
environment:
- COMPOSER_ALLOW_SUPERUSER=1
- PHP_USER_ID=33333

法3:(推薦作法)

  • 由docker-compose.yaml載入env檔案

=> env

1
2
3
## Apache
PHP_USER_ID=33333
COMPOSER_ALLOW_SUPERUSER=1

=> docker-compose.yml

1
2
3
4
5
6
7
8
9
10
version: '3.2'

services:

frontend:
build:
dockerfile: Dockerfile
context: frontend
env_file:
- .env

Reference

https://github.com/yiisoft/yii-base-web/issues/1

https://stackoverflow.com/questions/23836416/permission-issues-with-apache-inside-docker/35886387

Gitpod Guide For Apache2 Enviroment Part 1

tags: yii gitpod

前情提要

自從看了小馬介紹的gitpod的教學之後,覺得雲端IDE真是一個好東西,怎麼這麼晚才知道呢?經過幾次嘗試下來,發現以下的問題…

ISSUE

  • 直接用gitpod.io網址開啟github repo會有權限的問題
    • docker-compose建立的container,開啟頁面會有403的錯誤訊息

Root Cause

  • 原因是因為apache執行是用www-data的權限,而非gitpod
    • 進入container使用ps -aux檢查目前正在運行的process有哪些
  • gitpod官方才會因此告訴使用者建立專屬gitpod使用的Dockerfile,來解決這個問題

To be continued

欲知詳情,請待後續拆解…

Gitpod & Docker WorkFlow Part 2

tags: yii gitpod

前情提要

接續part 1提到的gitpod環境所遇到的問題,底下就列出幾個關鍵調整的地方

Gitpod WorkFlow

  • 開啟gitpod.io網址開啟空白專案
    • 使用git clone將專案複製到這個環境
    • 使用volumes
      • 將當前的user與group的設定複製到container環境
      • 設定專案所需環境變數
    • 調整dockerFile
      • 將環境變數相關的檔案複製到container中

Gitpod的Base Image和Full Workspace兩者之間的關係

  • gitpod image的dependency會長得像這樣

Reference

Code

  • frontend/apache2/000-default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<Directory /app/frontend/web/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /app/frontend/web

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory "/app/frontend/web/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

# use index.php as index file
DirectoryIndex index.php

# ...other settings...
# Apache 2.4
Require all granted

## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
  • dockerFile
1
2
3
4
FROM yiisoftware/yii2-php:7.2-apache

# Change document root for Apache
COPY /apache2/000-default.conf /etc/apache2/sites-available/000-default.conf
  • docker-compose.yml

這兩行為關鍵:

  • /etc/passwd:/etc/passwd:ro
  • /etc/group:/etc/group:ro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: '3.2'

services:
frontend:
build: frontend
ports:
- 20080:80
volumes:
# Re-use local composer cache via host-volume
- ~/.composer-docker/cache:/root/.composer/cache:delegated
# Mount source-code for development
- ./:/app
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
depends_on:
- mysql