2020年5月10日 星期日

Gentoo - 安裝在 ASUS VivoBook 14

辦公室為了疫情異地辦公買了筆電,ASUS VivoBook 14 - x412f。現在的筆電都強迫中獎,安裝微軟的 OS,這年代是裝 Windows 10。其實微軟早就強迫學校按人頭買了 Windows 作業系統的授權,這等於是剝兩次皮。

不過,我只想用 Linux,只有在用 Words 文件才回 Windows。

備份原 Windows OS

以前都用 Ghost 來備份/還原系統,現在找不到 Ghost 了。在網路上找到使用 Linux 備份磁碟的分割區的作法,使用的是 Ubuntu 20。

原來筆電的分割區
                          Disk: /dev/nvme0n1
         Size: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
       Label: gpt, identifier: 709EF8B9-4D28-4BF4-8326-A960661C0460

Device         Start    End   Sectors  Size Type
/dev/nvme0n1p1  2048 534527 532480  260M EFI System  
/dev/nvme0n1p2 534528 567295 32768   16M Microsoft reserved
/dev/nvme0n1p3 567296  998881934 998314639  476G Microsoft basic data
/dev/nvme0n1p4 998883328 1000214527 1331200  650M Windows recovery environ

首先要備份磁碟的 patition table,此磁碟採用 gpt 分割表,備份說明如下
## Backup GPT table
dd if=/dev/sda of=GPT_TABLE bs=1 count=A

## Restore GPT table
dd if=GPT_TABLE of=/dev/sdb bs=1 count=A
partprobe /dev/sdb 
其中 A 為:
A=(128*B)+1024
# B 為分割區的數目
B=parted -ms /dev/sda print |tail -1|cut -b1

# parted -ms /dev/nvme0n1 print | tail -1 | cut -b1
=> 4 => B (總共4個分割區)

A = 128*4+1024 = 1536 (計算出的 count 值)

實際備份的指令
# 備份 GPT partition table
dd if=/dev/nvme0n1  of=GPT_TABLE bs=1 count=1536
# 依續備份4個分割區,使用 lz4 壓縮
dd if=/dev/nvme0n1p1 bs=1M status=progress | lz4 > ./nvme0n1p1.lz4
## 列出備份的檔案 # ls -lh
total 38G
-rw-r--r-- 1 root root 1.5K May  4 04:01 GPT_TABLE
-rw-r--r-- 1 root root  18M May  4 04:03 nvme0n1p1.lz4
-rw-r--r-- 1 root root  17M May  4 04:04 nvme0n1p2.lz4
-rw-r--r-- 1 root root  37G May  4 04:27 nvme0n1p3_nz.lz4
-rw-r--r-- 1 root root 494M May  4 06:00 nvme0n1p4.lz4


安裝 Gentoo Linux

BIOS 有做一些修改
Security boot,改 disable,不然 EFI 會無法啟動
SATA mode ,改ACHI,不然在 Linux 下看不到硬碟

原打算從頭安裝,照著說明,安裝到可以啟動 OS,也裝好 Xorg Server,這樣一天就過去了,離可以正常使用還好久。

後來把筆電帶回家,依照上述方法,把家裡使用的 Gentoo Linux 的 partition table 和 root system 備份出來,然後還原到筆電。還原指令如下,
lz4 -dc nvme0n1p4.lz4 | dd of=/dev/nvme0n1p4 bs=1M status=progress
nvme0n1p4 為主要的系統分割區,壓縮檔約 70GB,還好 copy 到隨身碟的速度夠快,搞到半夜終於可以進入系統了。

不過,因為只複製主系統的分割區,啟動區的 kernel,在主系統上沒有對應的 driver module,因此無法正常開機。重新編譯後就可以正常了。

為此特別買了 USB 的網卡,使用的晶片為 Realtek 的螃蟹卡 RTL 8153,產品描述「Integrated 10/100/1000m Ethernet controller for usb applications」,是專為 USB 開發的晶片。要 enable Kernel 的設定 CONFIG_USB_RTL8152,資訊如下


CONFIG_USB_RTL8152:

This option adds support for Realtek RTL8152 based USB 2.0
10/100 Ethernet adapters and RTL8153 based USB 3.0 10/100/1000
Ethernet adapters.

To compile this driver as a module, choose M here: the
module will be called r8152.

Symbol: USB_RTL8152 [=y]
Type : tristate
Prompt: Realtek RTL8152/RTL8153 Based USB Ethernet Adapters
Location:
-> Device Drivers
-> Network device support (NETDEVICES [=y])
-> USB Network Adapters (USB_NET_DRIVERS [=y])
Defined at drivers/net/usb/Kconfig:99
Depends on: NETDEVICES [=y] && USB_NET_DRIVERS [=y]
Selects: MII [=y]


無線網路的晶片為 "Realtek Semiconductor Co., Ltd. RTL8822CE 802.11ac PCIe Wireless Network Adapter",其 driver 為 rtw88 和 rtwpci。


Touchpad 的驅動

已經習慣使用 Trackpoint 當滑鼠,所以使用外接的 ThinkPad 鍵盤。但筆電攜帶方便,不想一直使用外接鍵盤。直到某天沒外接鍵盤,發現滑鼠竟然不會動,花了好久的功夫才弄起來。在 Ubuntu 下可以正常運作,就互相比對,看是那裡的問題。後來發現 Asus 是使用 Elan (義隆) 的 TouchPad 模組,透過 I2C 界面連接。除了要有 Touchpad 的 driver,還必須有 I2C 的 driver。

使用 lspci -k 來檢視PCI界面使用的驅動程式,在我的 Gentoo 中,這個裝置沒有對應的 driver。
00:15.0 Serial bus controller [0c80]: Intel Corporation Serial IO I2C Host Controller
        Subsystem: ASUSTeK Computer Inc. Serial IO I2C Host Controller
00:15.1 Serial bus controller [0c80]: Intel Corporation Device 02e9
        Subsystem: ASUSTeK Computer Inc. Device 1de1


在 Ubuntu 中的 driver 如下
00:15.0 Serial bus controller [0c80]: Intel Corporation Serial IO I2C Host Controller
        Subsystem: ASUSTeK Computer Inc. Serial IO I2C Host Controller
        Kernel driver in use: intel-lpss
        Kernel modules: intel_lpss_pci
00:15.1 Serial bus controller [0c80]: Intel Corporation Comet Lake Serial IO I2C Host Controller
        Subsystem: ASUSTeK Computer Inc. Device 1de1
        Kernel driver in use: intel-lpss
        Kernel modules: intel_lpss_pci

在 Kernel 中把 intel_lpss_pci enable 之後,就成功驅動 i2c 控制器,Touchpad 可以正常運作了。後面的設定就較簡單了。

Touchpad 的 tap-to-click

Many users will desire the native 'tap-to-click" behavior for laptops with modern touchpads. Add the following Option lines to Xorg's libinput configuration section.
修改 /etc/X11/xorg.conf.d/40-libinput.conf
Section "InputClass" Identifier "libinput touchpad catchall" MatchIsTouchpad "on" MatchDevicePath "/dev/input/event*" Option "NaturalScrolling" "True" (scroll 方向同手指方向) Option "Tapping" "True" Option "TappingDrag" "True" Option "TappingButtonMap" "lmr" (enable middle click) Driver "libinput" EndSection


沒有留言:

張貼留言

網誌存檔