2019年2月16日 星期六

Kindle 換字體

Kindle 官方在新版本的 Firmware 5.9.6 之後,正式讓用戶使用自訂的字型。
查一下自己的Kindle,Firmware Version: 5.10.2 (3374490058),已具有自訂字型的功能。

說明參見
Kindle自訂字型操作步驟與簡轉繁字型連結

NotoSansCJKTC思源黑體 多字重 簡轉繁
NotoSansCJKtc_CHS2CHT_V.05.6 (將一對一對應的簡體字替換成正體字型的檔案)

安裝字型
只要把檔案準備好、Kindle接好USB,把檔案存入 fonts 資料夾就可以了(根目錄下的fonts,不是system/fonts),接著打開一本KF8格式的書,點擊主選單的【Aa】就能看到自訂字型選項。

必須把格式轉成 AZW3 格式,即支援KF8標準。

原來的字體,類似細明,會有凸起,看起來不漂亮。


改成 Noto Sans CJK 字型後,比較舒服點。

Kindle/fonts/Readme.txt 中的說明

===============
10. 简体中文
===============

您现在可以将自己喜欢的字体安装到 Kindle 上,从而在阅读电子书时选用。

您安装的字体必须是 OpenType (OTF) 或 TrueType (TTF) 字体,而其他字体格式均不支持。此外,字体通常以字体集的形式可用,且每种字体可能包含数个不同的文件,分别为不同的字体样式。例如,常规、斜体、粗体,粗斜体等每种样式各为一个文件。我们建议您安装字体集所含的全部文件以获得最佳阅读体验。受支持的字体文件应具有以下扩展名之一:.ttf、.otf 或 .ttc 。

字体安装的具体步骤如下:

1. 若字体以压缩文件(如 ZIP 文件)格式打包,请用您喜欢的文件解压程序将文件解压缩

2. 将字体文件复制到 Kindle 上的“fonts”文件夹

3. 将 Kindle 从电脑上断开连接

4. 除 Kindle 字体外,您现在还可以选择自定义字体,从【显示设置】(Aa) 菜单中操作即可

从【显示设置】(Aa) 菜单中选择了自定义字体后,Kindle 将以该字体显示多数电子书的内容。如果某部书的内容不能以该字体显示,Kindle 将使用系统默认字体。这种情况发生的原因可能是该字体不支持书中的文字或该字体已损坏。

亚马逊尊重他人的知识产权。对于使用您上传到 Kindle 的任何字体,您都将负责确保已获得必要的授权和许可。使用 Kindle 上的字体上传功能,即表示您同意使用上传的字体不会侵犯或违反任何第三方的权益,并且对于因您使用上传字体所造成的任何索赔,您都将赔偿亚马逊的损失。

如需更多帮助,请访问:https://amzn.to/2rMrqOy

2019年2月3日 星期日

使用 xrdp 遠端登入 Linux (Gentoo)

想要遠端登入 Linux 的圖形界面,雖然可以使用 XDMCP 使用來,但是若想連到 firewall 後面的 Linux,則必須透過 Guacamole,然而 Guacamole 只支援 vnc 和 rdp 的圖形界面。依過去的使用經驗,vnc 的圖形界面用起來,不是很順暢。網路上有人開發 xrdp,可透過 rdp 的 protocol 來連線 Linux 的圖形界面,雖然它還是要借助於 vnc 的功能,但用起來比較方便。

使用摘要

要使用 xrdp,首先找到及下載 overlay,安裝 xrdp 及 xorgxrdp,啟動 service 後,再修改 home 目錄下的 .xinitrc,即可透過 rdp 連線,啟動自己想用的視窗環境。

安裝與討論

接下來討論自己安裝、使用、和測試所碰到的問題,以及解決的辦法,並且在確認後,反應給 overlay 的維護者。這主要是留作供自己參考,各位有興再看,沒空就跳過。

要安裝 xrdp,必須透過 overlay,我是自己建立自己用的 overlay。安裝後的提示,必須再裝 net-misc/tigervnc (要加上 use flag: server, xorgmodule ) 或 net-misc/x11rdp。不過,x11rdp 已不維護,請改裝 xorgxrdp。關於 xorgxrdp,於後討論。
 * Messages for package net-misc/xrdp-0.9.8:

 * Various session types require different backend implementations:
 * - sesman-Xvnc requires net-misc/tigervnc[server,xorgmodule]
 * - sesman-X11rdp requires net-misc/x11rdp 
在重新安裝系統時,安裝 xrdp 會自動拉進相關的 package。安裝 xorgxrdp 則必須先安裝  x11-base/xorg-server。

安裝以後,啟動 service。
# systemctl enable xrdp
# systemctl enable xrdp-sesman
# systemctl start xrdp
# systemctl start xrdp-sesman 
然後,可以下指令測試一下。
$ rdesktop -g 1024x768 localhost 
連線後,顯示登入的畫面

Session,選擇 Xvnc,登入後,會經由 /etc/xrdp/startwm.sh 啟動視窗,預設呼叫 /etc/X11/xinit/xinitrc,假若沒有設定環境變數 XSESSION,則會啟動 twm。
因此必須安裝 twm 才能測試。注意,至少要安裝 xterm,twm 才能成功啟動。

假若把 startwm.sh 改成直接執行  /usr/bin/startxfce4,則會出現下面的錯誤。
若是執行 openbox 或 icewm,則可以啟動。

本以為在 xrdp 中,無法使用 Xfce4,後來才察覺是因為在本機測試,本機的環境已是 Xfce4-session,導致無法再次啟動 一個 Xfce4-session,才出現上述錯誤。因為錯誤資訊找不到,在這上面轉了好多時間。

注意,使用 Xfce4,只能登入一次,不能本機和遠端同時登入。

後來,用遠端機器測試,就可以正常啟動 Xfce4 了。下圖是透過 Guacamole 登入 Linux 的畫面。


關於啟動 window manager 的判斷,測試 startx,確認 .xsession 及 .xsessionrc 沒有作用,.xinitrc 優先於 XSESSION。
根據此測試結果,針對 /etc/xrdp/startwm.sh 做了一些修正,修正後如下。
#!/bin/sh

# try hard to respect Gentoo's wm choice
. /etc/profile
[ -f /etc/rc.conf ] && . /etc/rc.conf
export XSESSION

userinitrc=$HOME/.xinitrc
if [ -f $userinitrc ]; then
    . $userinitrc
else
    . /etc/X11/xinit/xinitrc
fi

exit 1
這樣可以在自己的 .xinitrc 設定要啟動的 Desktop Enviroment,例如
#!/bin/sh

export LANG=zh_TW.UTF-8
export LC_ALL=zh_TW.UTF-8

fbpanel &
# 注意 openbox 的後面不能接 & 
/usr/bin/openbox 

啟動 IceWM
#!/bin/sh

/usr/bin/icewm-session

或是呼叫 /usr/bin/startxfce4 啟動 Xfce4。這個修正和 overlay 的作者反應,已併入其中,自己以後就不用再修改了。

啟動 xfce4,.xinitrc 的內容如下

#!/bin/sh

exec dbus-launch --sh-syntax startxfce4

前面提到,xrdp 可以透過 xorgxrdp 來連線。經測試,使用 xorgxrdp,假如直接斷線而未登出,再連線會進入原來的連線狀態。或者,已經有一個連線,再以同一個 ID 進入建立新連線時,會關掉原來的連線。這就像在 Windows XP 之類的個人 OS 使用一樣。


不過這個透過 xorgxrdp 連線,折騰了好久才成功。

使用 xorgxrdp 無法登入的問題,可參考這個討論 [BUG/MITIGATION] XRDP/Xorg not starting correctly。意思為 /etc/xrdp/sesman.ini 中關於 [Xorg] 的設定,會呼叫 Xorg 指令,即 /usr/bin/Xorg,而其會呼叫 /usr/libexec/Xorg.wrap,而後者只允許 console users 執行。
$ setpriv --no-new-privs Xorg :10 -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp -logfile .xorgxrdp.%s.log
/usr/libexec/Xorg.wrap: Only console users are allowed to run the X server

$ Xorg :10 -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp -logfile .xorgxrdp.%s.log
/usr/libexec/Xorg.wrap: Only console users are allowed to run the X server

$ cat /usr/bin/Xorg
#!/bin/sh
#
# Execute Xorg.wrap if it exists otherwise execute Xorg directly.
# This allows distros to put the suid wrapper in a separate package.

basedir=/usr/libexec
if [ -x "$basedir"/Xorg.wrap ]; then
 exec "$basedir"/Xorg.wrap "$@"
else
 exec "$basedir"/Xorg "$@"
fi

$ ls -l /usr/libexec/Xorg*
-rwxr-xr-x 1 root root 2361128 12月 17 15:32 /usr/libexec/Xorg
-rws--x--x 1 root root   10296 12月 17 15:32 /usr/libexec/Xorg.wrap

修正,將 /etc/xrdp/sesman.ini 的 Xorg 改成  /usr/libexec/Xorg 即可順利啟動。
此項修正亦反應給原 overlay 的維護者,加入其 ebuild 中。

還有,使用 xrdp 從遠端連線,不需要啟動 gdm 或 kdm。

無法解除 Screen Saver 

當太久沒有動作時,進入螢幕保護時,會無法解除,不知如何是好。後來找到方法,從遠端登入,把 xscreensaver 殺掉即可。
$ ps -ax | grep save
17209 ?        S      0:00 xscreensaver -no-splash
19226 pts/1    S+     0:00 grep --colour=auto save
ajax@gentoo-tst ~ $ kill 17209


CentOS 設定

CentOS 的設定相對簡單,只要安裝,啟動後即可。但它的 Xrdp 只開 XVnc,必須修改 /etc/xrdp/xrdp.ini。

;   
; Session types
;   

; Some session types such as Xorg, X11rdp and Xvnc start a display server.
; Startup command-line parameters for the display server are configured
; in sesman.ini. See and configure also sesman.ini.
[Xorg]
name=Xorg
lib=libxup.so
username=ask
password=ask
ip=127.0.0.1
port=-1
code=20

[Xvnc]
name=Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=-1
#xserverbpp=24
#delay_ms=2000
; Disable requested encodings to support buggy VNC servers
; (1 = ExtendedDesktopSize)
#disabled_encodings_mask=0
; Use this to connect to a chansrv instance created outside of sesman
; (e.g. as part of an x11vnc console session). Replace '0' with the
; display number of the session
#chansrvport=DISPLAY(0)

修改後,重新啟動 xrdp 即可。


在 Ubuntu 使用

Ubuntu 20.04 LTS,直接下指令 apt-get install xrdp 即可。但 login 後,/etc/xrdp/startwm.sh 是呼叫 /etc/X11/Xsession 決定要啟動何者視窗。

因此下指令 echo "xfce4-session" > ~/.xsession,再用遠端桌面登入即可。


2019年1月16日 星期三

CentOS + Vmware Workstation Server

因為在 Gentoo Linux 上,設定 Vmware Workstation Server 不太直接,決定在 CentOS 上裝,測試一下,問題在那。

分別測了 CentOS 6 和 7,裝好 CentOS 後,執行下列指令,以便順利安裝 Vmware Workstation Server。
yum update
yum groupinstall "GNOME Desktop"
systemctl set-default graphical.target
重新開機後,繼續安裝發展工具,以便裝 kernel module。

yum groupinstall "Development tools"
yum install kernel-headers
yum install kernel-devel

yum install epel-release
yum groupinstall xfce

chmod +x VMware-Workstation-Full-10.0.6-2700073.x86_64.bundle
./VMware-Workstation-Full-10.0.6-2700073.x86_64.bundle
==> 在 CentOS 7 下,無法執行,因為改成 systemd 的管理

vmware-installer -u vmware-workstation



# cat /usr/lib/vmware/hostd/docroot/client/clients.xml
<ConfigRoot>
  <clientConnection id="0000">
    <authdPort>902</authdPort>
    <version>6</version>
    <exactVersion>6.0.0</exactVersion>
    <patchVersion>1.0.0</patchVersion>
    <apiVersion>dev</apiVersion>
    <downloadUrl>@@HOSTCLIENT_URL_WIN@@</downloadUrl>
    <flexClientVersion>6.0.0</flexClientVersion>
  </clientConnection>
</ConfigRoot>

# chkconfig --list
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off 1:off 2:off 3:off 4:off 5:off 6:off
network        0:off 1:off 2:on 3:on 4:on 5:on 6:off
vmware          0:off 1:off 2:on 3:on 4:off 5:on 6:off
vmware-USBArbitrator                 0:off 1:off 2:on 3:on 4:off 5:on 6:off
vmware-workstation-server 0:off 1:off 2:on 3:on 4:off 5:on 6:off

參考
https://slackblogs.blogspot.com/2015/04/vmware-workstation-10-on-linux-kernel.html

cp /usr/lib/vmware/modules/source/vmnet.tar /usr/lib/vmware/modules/source/vmnet_org.tar
tar xvf  /usr/lib/vmware/modules/source/vmnet_org.tar
vi vmnet-only/netif.c

vmnet-only/netif.c:468:7:
- dev->trans_start = jiffies;
+ netif_trans_update(dev);

tar cvf /usr/lib/vmware/modules/source/vmnet.tar vmnet-only/
vmware-modconfig --console --install-all

vmnet-only/netif.c:464:7: error: ‘struct net_device’ has no member named ‘trans_start’
    dev->trans_start = jiffies;

https://www.visibil.it/blog/2017/10/5/vmware-workstation-12-and-centos-7


https://www.unixmen.com/install-vmware-10-centos-7/
https://stackoverflow.com/questions/24921593/installation-of-vmware-workstation-10-0-1-on-centos-7
http://www.voidcn.com/article/p-ofiwnxuj-bmb.html
https://communities.vmware.com/thread/484273

vmware-modconfig --console --install-all

在 CentOS 7
目的,想用 ESXi client 來連
12 可以連上,必須用一般使用者身分

11
Vmware workstation 可以連上,netif.c 要改,exactVersion>6.0.0</exactVersion
ESXi client 不能連
32 bit guest 可以開,64 bit guest 不能開機

10
vmware-workstation-server 無法啟動,netif.c 要改

2019年1月8日 星期二

洋垃圾 Xeon E5-2660 使用

和小孩換來一套  Xeon(R) CPU E5-2660 的系統,使用華南 X79 主機板 V 2.47,原來跑得好好的,不曉得碰到什麼,就壞了,無法開機。無法確定只是主機板壞掉,或是 CPU 也壞了,只好上網先買一張新板子來試,若不行,就只好再買 CPU 了。

在露天花了一些時間搜尋,找到一定比較便宜,而且和原來的板子比較接近的產品。因為急著想知道結果,就直接約下班去當面交易。

新版的板子,比舊的好很多,支援 PCI-e 的 SSD,這樣我手邊多的 Intel 600P SSD 就能派上用場了。Intel 600P SSD 的 [連續寫入速度] 只有 560MB/s,可是 [連續讀取速度] 有 1775MB/s,是 SATA界面 SSD 的3倍,爽度 3倍。可惜,裝了散熱片後,和顯卡略干涉,只好挪顯卡。另外,USB 3.0 接頭的位置也改了,接線不用接得老遠。

新買的是華南 X79 主機板 V 2.49,它的手冊只有薄薄幾頁,可是已經比 V2.47 只有薄薄一張黑白印刷的說明書,進步很多了。雖然這板子用的人很多,要找說明書還真難找。這次就先把它掃描留存起來,以供日後參考。






Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz,顯示 16 個 threads,看起來就爽。不過是好幾年前的產品,效能不到 2018 年 CPU 的一半。像在 Gentoo 下,emerge 一個龐大的 package,如 sys-devel/llvm 或 dev-qt/qtwebengine,就要多一倍的時間。但也別太要求效能,這本來就是當初給伺服器用的,比較適合架站,同時跑多個 VM (Virtual Machine)。


2018年12月28日 星期五

Gentoo 使用 soft raid

參考 https://wiki.gentoo.org/wiki/Complete_Handbook/Software_RAID

要加上 kernel modules
raid0, 或其他的

移除舊的 disk array
mdadm --stop /dev/md0
mdadm --remove /dev/md0
建立由 2 顆硬碟構成 mirror 的 disk array
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdd1 /dev/sde1
蠻奇怪的,原先並未先建立 partition,直接用 /dev/sdd 及 /dev/sde,建好的 array 會不見,查到的一些資料,是用 /dev/sdd1 及 /dev/sde1,那就試試看先建 partition,再建 raid。
這裡有人討論使用整顆硬碟與分割區來建立 raid 的差別,What's the difference between creating mdadm array using partitions or the whole disks directly

檢視 disk array 建立的進度
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] 
md0 : active raid1 sde1[1] sdd1[0]
      7813893440 blocks super 1.2 [2/2] [UU]
      [=>...................]  resync =  6.2% (489861248/7813893440) finish=678611.9min speed=179K/sec
      bitmap: 58/59 pages [232KB], 65536KB chunk

unused devices: <none>


檢視 disk array 的細節
# mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Fri Dec 28 21:58:07 2018
        Raid Level : raid1
        Array Size : 7813894464 (7451.91 GiB 8001.43 GB)
     Used Dev Size : 7813894464 (7451.91 GiB 8001.43 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Sat Dec 29 16:57:35 2018
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : bitmap

              Name : aj-i7:0  (local to host aj-i7)
              UUID : 6240fb09:05a34525:822baca9:8744a832
            Events : 13861

    Number   Major   Minor   RaidDevice State
       0       8       48        0      active sync   /dev/sdd
       1       8       64        1      active sync   /dev/sde

要把硬碟加回 disk array 時
mdadm /dev/md1 --re-add /dev/sda2
使用 mdadm --assemble 指令,可以重新 Assemble 先前建立的 array。

使用上,不用建立分割區,直接 mkfs.ext4 /dev/md0 即可。

使用的問題

剛開始使用,還不熟悉,常常不曉得 disk array 在那裡。
建好後,隔幾天又找不到 raid 了,
# mdadm --detail /dev/md0
mdadm: Array associated with md device /dev/md0 does not exist.
一直以為它又死了,再看 proc 的 status,卻又存在
# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] 
md127 : active (auto-read-only) raid1 sdd1[0] sde1[1]
      7813893440 blocks super 1.2 [2/2] [UU]
      bitmap: 0/59 pages [0KB], 65536KB chunk

unused devices: <none>
後來用 scan,終於找到了,不曉得怎麼改名了,改名的規則也不知是什麼。

# mdadm --detail --scan
ARRAY /dev/md/aj-i7:0 metadata=1.2 name=aj-i7:0 UUID=c984ff63:4925d7b3:d8922bdc:e9cc0d57

# ls -l /dev/md*
brw-rw---- 1 root disk 9,   0  2月 13 10:06 /dev/md0
brw-rw---- 1 root disk 9, 127  2月 13 10:06 /dev/md127

/dev/md:
總計 0
lrwxrwxrwx 1 root root 8  2月 13 10:06 aj-i7:0 -> ../md127

還在慢慢的適應這個玩意中。


Gentoo 使用 lm_sensors

參考 http://linux.vbird.org/linux_basic/0610hardware/0610hardware-fc4.php

# emerge -av sys-apps/lm_sensors

# sensors-detect
Scan for sensors of south bridges, CPUs or memory controllers
Intel digital thermal sensor...                             Success!
    (driver `coretemp')
Scan for Super I/O sensors
Found `Nuvoton NCT6793D Super IO Sensors'                   Success!
    (address 0x290, driver `nct6775')

probe the I2C/SMBus adapters now? (YES/no): 
Using driver `i2c-i801' for device 0000:00:1f.4: Kaby Lake (PCH)
Module i2c-dev loaded successfully.

Now follows a summary of the probes I have just done.
Driver `coretemp':
  * Chip `Intel digital thermal sensor' (confidence: 9)

Driver `nct6775':
  * ISA bus, address 0x290
    Chip `Nuvoton NCT6793D Super IO Sensors' (confidence: 9)

執行 etc-update,寫入設定檔,其所產生的 /etc/modules-load.d/lm_sensors.conf,。如下
# Generated by sensors-detect on Fri Dec 28 19:43:42 2018
coretemp
nct6775

要重新編譯 kernel,make xconfig 或 make menuconfig,加上下面兩個 driver module。
在 Device Drivers/Hardware Monitor Support 項目下
Intel Core/Core2/Atom temperature sensor (SENSORS_CORETEMP)
Nuvoton NCT6775F and compatibles (SENSORS_NCT6775)

 # make -j8 && make modules_install && make install

2018年12月21日 星期五

使用 rclone 同步雲端硬碟

原來是使用 net-misc/drive 的 Google Drive client 來同步 Google 的雲端硬碟。可是在使用 push 指令來 sync 整個目錄時,會一直出現很多個重複的目錄,例如
ds +- etc/a.txt
   +- etc/b.txt
   +- etc/....

好像也沒有辦法避免這種困擾,猜想在進行同步時,是可以平行上傳檔案,而 Google drive 是以 unique id 來代表,如下列網址代表 [我的雲端硬碟 > ds > etc] 的目錄
https://drive.google.com/drive/folders/1TNCFVIHv8wzcOvAt2q0xq7VL2TyFzJfe?ogsrc=32
後來,找到 rclone 這個程式,可以指定一次傳一個檔案,就可以解決上述問題。另外,這個程式看起來,更成熟完備一點。

sync 的指令
rclone sync "dspace.calendar/etc/" "gDspace:GET_proj/dspace_backup/dspace.calendar/etc" -v -u --fast-list -P --checkers 1 --transfers 1
要注意目錄的表示法,不然會 sync 到上一層或下層目錄。

備份的畫面
2018-12-22 10:53:35 INFO  : assetstore/11/01/26/110126386227520817426129509087509376115_dir/00001/TileGroup0/1-0-1.jpg: Copied (new)
2018-12-22 10:53:41 INFO  : assetstore/11/01/26/110126386227520817426129509087509376115_dir/00001/TileGroup0/1-1-0.jpg: Copied (new)
2018-12-22 10:53:43 INFO  : assetstore/11/01/26/110126386227520817426129509087509376115_dir/00001/TileGroup0/1-1-1.jpg: Copied (new)
Transferred:      694.862M / 1.385 GBytes, 49%, 213.906 kBytes/s, ETA 57m44s
Errors:                 0
Checks:               155 / 155, 100%
Transferred:          547 / 10549, 5%
Elapsed time:    55m26.3s
Transferring:
 *     assetstore/11/01/26/…TileGroup0/2-0-0.jpg: 100% /10.567k, 0/s, -


網誌存檔