2020年4月30日 星期四

BUFFALO HD-PNTU3 1TB USB 3.0 隨身硬碟拆解及換硬碟

BUFFALO巴比祿HD-PNTU3 1TB USB 3.0~隨身硬碟使用時不慎拉壞USB接座→想要修好原本接座讓硬碟繼續使用

外殼用翹開的,很容易翹壞。

不支援 trim 指令,因此只能使用傳統硬碟,不能用 SSD。不是通透的 USB 界面,看不到原來的硬碟資訊,原來的分割區會不見,要重建。



2020年4月29日 星期三

KY-888 3孔 HUB + Giga 網路卡

KY-888,在網拍用 350買到,網路上有人兩年前在 ebay 用 7美元買到。
網拍的上架時間為 2017-10-01,所以大約是3年前的產品。

缺點 - 沒有任何指示燈,不清楚連線了沒。尤其是網路的 RJ45 接頭,沒有習慣的燈號。但最大的優點,就是便宜,比 PChome 便宜約 200元,就用吧,終究這東西只是暫時使用。

外觀及拆開的照片,在標籤貼紙下面,有2顆螺絲。拆的時候硬翹,把裡面的塑膠柱翹斷了。還好兩端空的位置很長,用膠帶綁一綁就好了。


USB HUB 晶片,GenesysLogic 的晶片,基本上就是 4port 的 HUB 控制器,其中一個 port 用來連網路界面,剩3個可用。

Realtek 的螃蟹卡 RTL 8153,產品描述「Integrated 10/100/1000m Ethernet controller for usb applications」,是專為 USB 開發的晶片。

Ethernet 驅動晶片。

USB 3.0界面,有8條連接線。


在 Linux 下用 dmesg 看的訊息
[93681.197529] usb 1-1: new high-speed USB device number 53 using xhci_hcd
[93681.325911] usb 1-1: New USB device found, idVendor=05e3, idProduct=0610, bcdDevice= 6.54
[93681.325917] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[93681.325920] usb 1-1: Product: USB2.1 Hub
[93681.325922] usb 1-1: Manufacturer: GenesysLogic
[93681.329863] hub 1-1:1.0: USB hub found
[93681.330132] hub 1-1:1.0: 4 ports detected
[93681.692640] usb 2-1: new SuperSpeed Gen 1 USB device number 105 using xhci_hcd
[93681.707574] usb 2-1: New USB device found, idVendor=05e3, idProduct=0626, bcdDevice= 6.54
[93681.707579] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[93681.707581] usb 2-1: Product: USB3.1 Hub
[93681.707583] usb 2-1: Manufacturer: GenesysLogic
[93681.711581] hub 2-1:1.0: USB hub found
[93681.711896] hub 2-1:1.0: 4 ports detected
[93681.987606] usb 2-1.4: new SuperSpeed Gen 1 USB device number 106 using xhci_hcd
[93682.000171] usb 2-1.4: New USB device found, idVendor=0bda, idProduct=8153, bcdDevice=30.00
[93682.000177] usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=6
[93682.000180] usb 2-1.4: Product: USB 10/100/1000 LAN
[93682.000182] usb 2-1.4: Manufacturer: Realtek
[93682.000184] usb 2-1.4: SerialNumber: 000001
[93682.079954] usb 2-1.4: reset SuperSpeed Gen 1 USB device number 106 using xhci_hcd
[93682.123448] r8152 2-1.4:1.0 eth0: v1.09.9
[93682.191725] r8152 2-1.4:1.0 enp0s20f0u1u4: renamed from eth0
[93682.228349] IPv6: ADDRCONF(NETDEV_UP): enp0s20f0u1u4: link is not ready
[93682.428357] userif-2: sent link down event.
[93682.428367] userif-2: sent link up event.

Linux 的 kernel 的 driver 設定,
title: Realtek RTL8152/RTL8153 Based USB Ethernet Adapters (USB_RTL8152)
symbol: CONFIG_USB_RTL8152:
desc: 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.


2020年4月27日 星期一

使用 Linux 備份/還原 Windows OS

在以前,是用 Ghost 來複製系統,但使用 Linux 亦可備份/還原 Windows OS。對於 Linux 系統當然也是沒問題,可以用此方法。

參考 How can I clone/backup/restore Windows 10 from Linux?

分割區回復後,出現無法開機的處理
0xc0000225 Error Code on Windows 10 [Fixed]

在經過多次失敗後,最後終於成功。上面的解決辦法只適用於 MSDOS(MBR) 的磁碟分割表(partition table),使用 GPT  磁碟分割表,在執行 "bootrec /fixboot" 會出現 "存取被拒" 的錯誤訊息,解決辦法參考下面連結
windows10 Bootrec /Fixboot 存取被拒(Access Is Denied)

原始文章

I have just successfully finished the described scenario of backing up Windows 10 from Linux to a file and restoring them on a new drive.
With the old disk zero free space from Windows by doing
zdelete -z c:
using SDelete. 針對 Linux 的 ext2、ext3、ext4,則可用 zerofree 指令。

先把不要的檔刪一刪,再垃圾桶清乾淨。然後把刪除的磁區清成 '00',可以壓縮減小備份檔。
使用 lz4 壓縮,壓縮率較低,但速度快很多。

壓縮率 / 執行時間 的比較
gzip: 26.8% / 8.1s bzip2: 20.2% / 58.3s lz4: 35.6% / 1.3s

Get some live Linux USB to boot and backup MBR and partition table to a spare drive
dd if=/dev/sda of=/somewhere/mbr bs=512 count=63 
copy the boot partition to a file
dd if=/dev/sda1 bs=1M status=progress | lz4 > /somewhere/sda1.lz4
copy the system partition to a file
dd if=/dev/sda2 bs=1M status=progress | lz4 > /somewhere/sda2.lz4


備份分割區
dd if=/dev/sda of=GPT_TABLE bs=1 count=A

還原分割區
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

例如有 4 個分割區, 則 count (A) 的值為 1536

還原

 測試檔案的大小是否正確
# lz4 -v sda1.lz4 > /dev/null
*** LZ4 command line interface 64-bits v1.9.2, by Yann Collet ***
Warning : using stdout as default output. Do not rely on this behavior: use explicit `-c` instead ! 
sda1.lz4             : decoded 104857600 bytes  

Place the new disk into the computer, boot the live Linux again and restore the beginning of the disk
dd of=/dev/sda if=/somewhere/file.mbr
That gets you the same primary partition layout (partitions inside extended partition are stored somewhere else and will not be restored by doing this).
Now restore the two Windows partitions
dd of=/dev/sda1 bs=1M status=progress < lz4cat /somewhere/sda1.lz4
dd of=/dev/sda2 bs=1M status=progress < lz4cat /somewhere/sda2.lz4  
上述指令會出現 "-bash: 1z4cat: No such file or directory" 的錯誤,我不瞭解問題所在。Google 找到另外的指令下法,就可以了
lz4 -dc sda1.lz4 | dd of=/dev/sda1 bs=1M
lz4 -dc sda2.lz4 | dd of=/dev/sda2 bs=1M status=progress  
The drive didn't boot at this stage (grub complaining). So boot windows rescue disk or the installation media and select "repair". In Troubleshooting start cmd prompt and run
bootrec /fixmbr
At this stage I got the original Windows system to boot on the new bigger drive. I got 50% compression rate with both gzip and lz4 (with 70% full drive) but gzip was limited by the CPU speed (27MB/s in my case) while lz4 was not (480MB/s CPU limit, 180MB/s my backup drive limit).
My first try was with ntfsclone but that didn't produce bootable Windows (it was complaining of some missing files in \Windows\System32). I am not sure why it didn't work. At the end the dd + lz4 solution created smaller image than ntfsclone by itself. Your mileage may vary based on how full the disk is modulo bugs in ntfsclone - dd seems much easier to get right :-)

測試 Windows 7 的備份/還原

使用 Vmware Workstation 的 VM 測試,Linux 則是用 Ubuntu

磁碟 60GB,分割區如下
sda1 : 100MB
sda2: 59.9GB,使用 16.3GB

備份的檔案大小
# ls -lh
total 7.7G
-rw-r--r-- 1 root root  32K Apr 28 01:34 mbr
-rw-r--r-- 1 root root  14M Apr 28 01:34 sda1.lz4
-rw-r--r-- 1 root root 7.7G Apr 28 01:41 sda2.lz4

備份 sda2 的花費時間
real 5m18.318s
user 1m4.509s
sys 3m17.199s

還原測試
# time lz4 -d sda2.lz4 | dd of=/dev/sda2 bs=1M status=progress
Warning : using stdout as default output. Do not rely on this behavior: use explicit `-c` instead ! 
64157974528 bytes (64 GB, 60 GiB) copied, 228 s, 281 MB/s
14086+444198 records in
14086+444198 records out
64317554688 bytes (64 GB, 60 GiB) copied, 229.768 s, 280 MB/s

花費時間 real 3m49.786s
user 1m5.480s
sys 3m11.717s

還原之後,即可正常開機。

在 ASUS VivoBook 14 備份/還原 Windows 10

這台筆電的分割區如下
                          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

用 dd 指令還原 gpt 分割區失敗,只好用 cfdisk 手動建立,讓 start/end 的數字儘量一樣,不然失敗時,會不曉得是否為分割區不對所造成。其中 /dev/nvme0n1p3 的容量設到 476.0334G,勉強一致。

建立分割區後,使用 dd 指令還原各分割區的資料,其中476GB的分割區,要花費超過2個半小時,這比重新安裝的時間還久。但 dd 指令,就是要把每一個 byte 資料都寫回去才行啊,只好等囉。

資料還原後,必須重建 BCD (即 Boot Configuration Data),才能重新開機。這個有點順利,試了好幾次,差點放棄,還好最後成功開機了。

這台筆電 BIOS 中的 [SATA Mode] 有兩種,
[AHCI] 及 [Intel RST Premium With Intel Optane System Acceleration] (以下簡稱 RST)

原來裝 Win 10 時,是設成 RST。但必須改成 AHCI,Linux 的 LiveDVD 才能看到 SSD。

還原後,我先用 Windows10 -1803 版本的 ISO,SATA 在 RST 模式下,也是看不到 SSD。切換成 AHCI,可以看到,但重建 BCD 時,在 "bootrec /fixboot" 指令時,出現 "存取被拒",還原失敗,然後放棄。

中間有用安裝 ISO 從頭裝起,但裝著裝著就厭煩起來,實在 越來越不喜歡 Windows 的囉唆,而且資訊不明,根本不知它在做什麼。

後來在學校下載新的 Windows10 - 1909 版本的 ISO,又再試一次。這次在 RST 模式下,可以看到 SSD 了,果然新版的才有 driver。 但重建 BCD 在 "bootrec /fixboot" 指令仍然出錯。就用這指令當關鍵字,果然搜尋到一堆結果。挑了一篇來看,照著做,YA,成功,可以重開了。


步驟大致如下
----------------------
用安裝 ISO 開機後,選擇 [Troubleshoot]。
然後在 menu 中選 [Command Prompt],在命令視窗中
執行下述 command:
Diskpart ==> 進入程式,執行下述 command:
    List disk       
    Sel disk 0       (選擇安裝 Win 10 的磁碟,在此選 0)
    List vol         (選擇開機磁區,通常為 FAT32,且沒有磁碟編號)
    Sel vol 4
    assign letter=V: (指定開機磁區為 V: 磁碟)
    Exit

在命令視窗中,繼續執行

 bcdboot C:\windows /s V: /f UEFI
-----------------------

完成,重新開機









2020年4月1日 星期三

小紅點 (Trackpoint) 延伸桿

在機械鍵盤加裝 trackpoint (亦稱指點桿或小紅點) (Mechanical keyboard with Trackpoint),要如何延伸小紅點的長度,是關鍵的一個步驟。最初是買 TEX Yoda 套件的零件來用,但沒單賣延伸桿,要買整套,價格不便宜,而且它的小紅點模組,做得不太好,整個桿子一搬就掉下來了。直到找到了防鬆脫螺帽,才有了比較好的解決方案。

首先,要在鍵盤的固定板,GHB鍵之間,鑽一個孔。孔徑 3mm,孔的中心對準GH鍵的下緣是較佳的位置。若偏下,B鍵要削掉比較多。若偏上,B鍵可能完全不用削,可是比較不對稱。

延伸桿是用 3mm的平頭螺絲,切成適當的長度,用AB膠黏到原來的帽座上。在鍵盤固定板上鑽的孔,直徑也是 3mm,不想把孔擴大,就把延伸縲絲的中間的螺紋磨掉,螺絲的中間段就變細了。

小紅帽的固定座,是用AB膠翻模,然後黏在防鬆脫螺帽上。再將帽座鎖在延伸螺絲上。因為它是防鬆脫的,稍微鎖緊,即可方便的使用。因為控制桿長度延伸了好幾倍,手指推起來省力多了,變得更好使用。

螺絲裁切後的總長度 16mm。

把螺絲中段的螺紋磨掉,減少螺絲的直徑,儘量減小鍵盤上挖的孔,儘量不要影響到原有電路。


螺絲突出鍵盤固定板 7mm,螺絲鎖上固定座後,帽座下緣離固定板 9mm。
螺帽黏上帽座,總長 7mm,裝上小紅帽後總長 11mm。
螺絲裝上帽座和小紅帽後,固定板以上,總高 15mm。小紅帽高度 6mm。



3D 列印

小紅帽的固定座,最先是用軟性油土翻模,如上面的照片,效果不好,會歪掉,勉強勘用。後來找到熱塑土,也叫水晶土,稍好一點,仍不盡理想。最後還是走上 3D列印之路。

最先是趁雙11打折,買了一台 XYZprinting 的 da Vinci mini w+,FDM 機器。研究如何建模,就開始試著畫力量感測器 (force sensor) 的固定座。實在是太小了,FDM 的機器無法精確的列印這麼小的零件。後來還是買光固化列表機 Phrozen Sonic Mini。

兩種列印機的成品比較,綠色是 FDM,灰色是光固化,紅色是原來的。FDM 的細節完全印不出來,也無法裝在力量感測器上。


下圖是用光固化印出的成品,使用 Onyx Rigid Pro410 樹脂。此樹脂印出的成品還蠻堅固的,試著用3D 印出整支延伸桿。但硬的材質就比較脆,而且磨一磨,如重複裝上和拆下,就會粉化,變得起初能穩定的固定,後來就會變得有點鬆,而且也不確定能用多久。後來改成只印上下端的固定座,中間仍用M3螺絲連接。使用網路購買的便宜油性瞬間膠,黏接面夠大,黏得還算牢,要拆下時,泡了熱水還要破壞樹脂的固定座,才能完全拆下。另外光固化列印可以印出細微的細節,就可以印出用來供黏結時定位的凸起和凹座,不用肉眼對正,最後老是歪一邊。



網誌存檔