2022年11月25日 星期五

start application on windows 10 startup

 首先要將 UAC 關掉



接下來建立一個搜尋 "工作排程器", 執行之後, 在右邊的選項選擇"建立工作"

在建立的新工作中, 三個頁面分別填入需要的選項







2022年11月8日 星期二

在 RPi 上用 TinyCore 建立一個簡單的 sftp server

 TinyCore 的好處是, 系統跑起來之後, 都在 RAM 中,

所以不會一直存取 MicroSD or USB flash drive, 以免固定讀取

同樣的地方造成 NAND 壽命出問題.

TinyCore 的網站在 http://www.tinycorelinux.net/


建立 server 的步驟有 :

1. create TinyCore system on MicroSD card :

    先從 TinyCore 網站下載 RPi 的 image, RPi 只有一種選擇,

    不像 x86 有三種 image 選擇.

    下載的 piCore-xx-x-x.zip 反解壓成 .img 檔案後,

     用 dd 或者 rufus 將 image 寫到 MicroSD card 上.

2. create extra storage space :

    將做好的 microSD card 在 RPi 上開機後, login : rc, passwd : piCore

    接下來用 fdisk 看系統的分割 :

Disk /dev/mmcblk0: 59 GB, 63218647040 bytes, 123473920 sectors

1929280 cylinders, 4 heads, 16 sectors/track

Units: sectors of 1 * 512 = 512 bytes


Device       Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type

/dev/mmcblk0p1    128,0,1     127,3,16          8192     139263     131072 64.0M  c Win95 FAT32 (LBA)

/dev/mmcblk0p2    128,0,1     639,3,16        139264     172031      32768 16.0M 83 Linux

可以直接將剩餘的空間都新增為 mmcblkp3
Device       Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/mmcblk0p1    128,0,1     127,3,16          8192     139263     131072 64.0M  c Win95 FAT32 (LBA)
/dev/mmcblk0p2    128,0,1     639,3,16        139264     172031      32768 16.0M 83 Linux
/dev/mmcblk0p3    1023,3,16   1023,3,16       172032  123473919  123301888 58.7G 83 Linux

    然後 format 成 ext4, 在 /opt/bootlocal.sh 增加一行以在開機時 mount 起來
mount -o nodev,noexec /dev/mmcblk0p3 /mnt/mmcblk0p3  

    做完改變之後, 可以下 "filetool.sh -b" 將改變存回 mydata.tgz 中,
    下次開機才會有這次的修改.    
    接下來 "mkdir /mnt/mmcblk0p3"

3. 設定使用者, 範例為 "newuser"
    - 增加新使用者, 下命令 "adduser -s /bin/false -G staff newuser", 下完之後
      還要設定密碼
    - 到 /home 下, 先移除掉 newuser 目錄, 再 "ln -s /mnt/mmcblk0p3 newuser",
      因為要將 newuser 目錄改成是 SSD 空間
     - 在 /mnt/mmcblk0p3 目錄下, create "upload" 目錄, 並且把 owner 跟 group, 
        mode, 設定為 newuser 可以寫資料的設定
     - 另外要檢查一下 /home 的權限, 要是 755 才能讓 sshd 的 internal-sftp 進入
     最後再下 "filetool.sh -b" 將所有改變寫回 mydata.tgz, 下次開機才有作用

4. 設定 ssh 為無法 login, 只能 sftp
    修改 /usr/local/etc/sshd_config, 增加底下內容
Match User newuser
ChrootDirectory /home/newuser
ForceCommand internal-sftp
AllowTcpForwarding no

   修改好之後, 將 "usr/local/etc/ssh/ssh_config" 加入 /opt/.filetool.lst 最後一行,
   並且做 "filetool.sh -b"

7. 設定為 static IP
    新增 /opt/eth0.sh 檔案, 內容為 :
#!/bin/sh

# If you are booting Tiny Core from a very fast storage such as SSD / NVMe Drive and getting 
# "ifconfig: SIOCSIFADDR: No such Device" or "route: SIOCADDRT: Network is unreachable"
# error during system boot, use this sleep statemet, otherwise you can remove it -
sleep .2

# kill dhcp client for eth0
sleep 1
if [ -f /var/run/udhcpc.eth0.pid ]; then
 kill `cat /var/run/udhcpc.eth0.pid`
 sleep 0.1
fi

# configure interface eth0
ifconfig eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255 up
route add default gw 192.168.0.254
echo nameserver 192.168.0.254 > /etc/resolv.conf
  然後 chmod 755 /opt/eth0.sh, 
  修改 /opt/bootlocal.sh, 將 "/opt/eth0.sh &" 加到最後一行
  做 filetool.sh -b,  將修改存回, 下次開機 bootlocal.sh 中呼叫 eth0.sh,
  先將 udhcp kill 掉, 在設定 static ip

6. 設定 firewall, 不讓其他 port 的連線進入
   安裝 iptables
   tce-load -wi iptables.tcz

   在 /opt/bootlocal.sh 中加入

iptables -A INPUT -p tcp -s localhost -m tcp -m multiport ! --dports 22,80 -j ACCEPT

iptables -A INPUT -p tcp -m tcp -m multiport ! --dports 22,80 -j DROP


   或者一個更完整的, 編輯為 iptable.sh,
#!/bin/sh
# Block all incoming/outgoing traffic except for ssh

iptables -Z # zero counters
iptables -F # flush (delete) rules
iptables -X # delete all extra chains

# Set default filter policy to DROP
iptables -P INPUT   DROP
iptables -P OUTPUT  DROP
iptables -P FORWARD DROP

# Allow DNS
#iptables -A INPUT --proto udp --sport 53 --jump ACCEPT
#iptables -A OUTPUT --proto udp --dport 53 --jump ACCEPT
#iptables -A OUTPUT --proto tcp --dport 53 --jump ACCEPT

# Allow unlimited traffic on loopback (localhost)
iptables -A INPUT  -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Allow ssh (22)
iptables -A INPUT  -p tcp -m multiport --dports 22 -j ACCEPT

# Continue accepting packets after connection is established (and moved to some random >1024 port)
iptables -A INPUT --match state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT --match state --state ESTABLISHED,RELATED -j ACCEPT

7. 只允許某個 ip 連進來的連線
    設定 sshd_config, 加入
AllowUsers remoteUserA@xx.xx.xx.xx
    或者直接
AllowUsers *@yy.yy.yy.yy

8. 擋掉某些 IP 的連線嘗試
    如果有某些 IP 一直來嘗試連線, 好像 sshd_config 無法擋掉(只能 allow),
    就要另外安裝 tcp_wrapper.tcz, 用 hosts.allow/hosts.deny 來擋,
    但是 Tiny Core 的 tcp wrapper 沒將 sshd link 到 lib
    (用 ldd `which sshd` | grep libwrap
      測試, 如果沒有印出 link, 就是沒 link)
    先安裝 tcp_wrappers.tcz
    tce-load -wi tcp_wrappers.tcz

    就會有 hosts.allow, hosts.deny, tcpd.
    將 tcpd 加入開機會跑的程式,
    然後 hosts.deny 加入
    ALL: xxx.xxx.xxx.0/24

    就可以將某些 IP 的連線都拒絕掉


如果 sshd 的 sftp 登入有問題, 可以設定 sshd_config 中的 loglevel 為 DEBUG3, 
並且將 tiny core 的 syslogd 跑起來, 就可以在 /var/log/messages 中找到
登入失敗的原因



2022年9月19日 星期一

QNAP TR-004 使用心得

 QNAP TR-004 DAS 裡面用的是 JMicron chip,

使用心得 :

- 用 software configure 與直接 DIP SW 的 hardware RAID configure 基本上相同作用, 用 hardware RAID 只是將固定的 configuration 寫入吧, software configuration 可以透過軟體, 去設定比較不同的形態(例如兩台, 兩台 各組成 RAID1)

- 切換 RAID mode 時, 要切換 DIP SW 到 independent mode, 按 SET button, 之後切換到想要的 RAID mode DIP SW 後, 再按一次 SET button, 猜測應該是藉由切換到 independent mode 時, 會將 RAID mode 的資料洗掉

- 切換新的 RAID 5 mode 之後, 機器應該需要好幾天建立 RAID 5 checksum 機制, 所以在做好之前, 硬碟會一直動作(硬碟燈幾秒會閃一下或兩下). 在做完之前, 如果傳輸資料到 RAID, 速度大概只有 50MB/sec 左右. 目前等 RAID5 checksum 做完後, 再測看看速度是否可以上到 100MB/sec

- 結果應該不是 RAID5 本身需要建立的問題, 應該是傳輸檔案如果都只有 100MB 或不到, 算是小檔案傳輸, 速度就會在 40-80MB/sec 之間, 要傳好幾 GB 的情況, 速度才會有 100MB/sec 已上.

2021年12月12日 星期日

Denon 與一些擴大機品牌無法再接收 internet radio 問題

 根據網路上的訊息,

一些擴大機的 internet radio 應該都是使用 vtune 的服務,

由 vtune 提供一堆整理過的 internet radio 的列表/搜尋,

但是 vtune 後來決定將服務變成要收費,

所以一堆擴大機的 internet radio 都變空了.

所以只要找到一個方式完全取代 vtune 的內容,

就可以讓原來的 internet radio 部分重生.

其中一個方式就是用 ycast

https://pypi.org/project/ycast/

可以在 raspberry pi 上灌 ycast 之後,

並且提供 DNS redirect 的方法,

將原本讀取 *.vtune.com 的 DNS 動作, 

都導到 raspberry pi 上

  • Yamaha AVRs: radioyamaha.vtuner.com (and optionally radioyamaha2.vtuner.com)
  • Onkyo AVRs: onkyo.vtuner.com (and optionally onkyo2.vtuner.com)
  • Denon/Marantz AVRs: denon.vtuner.com (and optionally denon2.vtuner.com)
  • Grundig radios: grundig.vtuner.com, grundig.radiosetup.com (and optionally grundig2.vtuner.com and grundig2.radiosetup.com)

再將擴大機的網路設定, 把 DNS server 指向 redirect 的機器


2021年11月23日 星期二

XBOX original remote on OSMC issue

 最主要的問題在於, 最新的 OSMC 19 做的一些改變 :

 (1). 換成用 gpio-ir-recv 及 gpio-ir-tx

 (2). lircd 的參數(原本從 hardware.conf 或 lirc_option.conf 指定)

   要將 driver 從 devinput 換成 default

  (1) 造成的影響, 會造成在 /boot/config.txt(或 config-user.txt) 中

  dtoverlay=lirc-rpi,...   的修改, 變成 

  dtoverlay=gpio-ir,...

  而這部分直接在 OSMC config->RPI config->hardware 中

  可以透過 UI 就可以修改

  (2) 造成的影響, 原本使用 raw 方式操作的程式,

  例如 mode2 或 irrecord, 收到的資料方式不同.

  所以如果用 devinput, 應該就是針對現成的格式 decode,

  例如 rc-5, 如果用 default, 就是用 raw timing. 因為

  xbox original remote 不是用標準格式可以解, 一定要走

  raw timing 方式, 不然就要搭配原本 xbox 的 IR 接收器,

  走 USB 進 RPi.


  有關於 devinput 及 default driver 的差別, 可以參考

https://stackoverflow.com/questions/62646773/lirc-driver-option-default-vs-devinput

   The devinput driver uses the kernel decoder, and feeds these decoded events to the lircd fifo. This fifo is what clients read from.

The default driver reads raw timing data from the kernel and makes it's own decoding using lircd.conf.

 In general, if the devinput driver works it could safely be used and is a simpler setup. The default driver is useful in contexts where the kernel decoding doesn't work for example when a remote isn't supported by the kernel or there is a need to send (blast) ir signals -- the latter cannot be done using the devinput driver. 

  Xbox original remote 的 config 檔, 可以參考

  https://forum.libreelec.tv/thread/12272-xbox-original-remote-on-kodi-leia-problems-to-create-keytable-no-events/ 


2021年4月6日 星期二

DVDStyler 無法 build 出 image 的問題

問題描述 : 

如果檔名有中文, 不管在 Win10 or Win7 下,

都會導致 build image 時, 呼叫 ffmpeg-vbr.bat 時有一些 error,

產生不了 vob, 因此無法產生最終 image.

解決方法:

編輯 ffmpeg-vbr.bat, 在檔案第一行加入

chcp 65001

原因解釋 :

直接開啟 MS-DOS 視窗, 內定的編碼(code page)

通常不是 ANSI, 就是 65000,

但是 DVDStyler 傳入的非 ANSI 字元, 為 UTF-8,

所以要將 code page 改為 65001(UTF-8),

這樣 ffmpeg-vbr 接到的路徑字串才正確.

2019年12月25日 星期三

compress DVD into 60fps mp4 file

the process to turn DVD into 60fps mp4 file is as follows :


The key point to the whole process is :
 - if you feed VOB into aviutl, it will not have audio output(using DVD2AVI to overcome)
  - if you feed VOB directly in MeGUI, there is no way to do 60fps conversion(using aviutl to do it)
  - if you feed VOB directly to MeGUI, File Indexer will parse the chapter information, and let you choose only a part of video to convert
  - there is no way to re-capsulize the output of aviutl for MeGUI. VFAPI can generate to capsulized AVI but it cannot be read by MeGUI. That's why we use UT video codec to generate loseless real AVI files for MeGUI.
  - DVD 720x480 is not 1:1 aspect ratio. We must enable advanced options in MeGUI config to assign 10:11 to correct the aspect ratio.