Showing posts with label Linux 電腦. Show all posts
Showing posts with label Linux 電腦. Show all posts

Monday, 4 August 2014

Squeezebox Receiver / Touch 直駁 LMS (Logitech Media Server)

個多月前在Review33上見到Welborne兄話用 SB Touch 直駁 NAS 再用搖控選歌比經 wi-fi router 接駁好聲云云. 我看到後, 信會好, 但我心中即時有個問號: "好幾多?"

因為我信係會好, 只係好多少的問題, 既然我本身有隻 Cubieboard2 係度, 佢有 SATA port, 又夠簡單, 用嚟做 LMS 加隻 wifi dongle 俾 iPad 接入應該可以做到:

iPad (iPeng) <-> CB2 (LMS) <-> SBR (player)
就咁諗都可行, 於是就開工....

雖然諗就好似好簡單, 但原來執行上嚟有好多問道:
1. CB2 我係行緊 Voyage MPD (w/RT kernel), 但無LMS. 我要先學習如何在 Voyage Linux 上安裝 LMS
2. CB2 加 Wi-Fi USB dongle 不知如何攪. 已知係, 我的 Wi-Fi USB dongle 是 Realtek chip, 我以前 build RT kernel 時已經加入左 Realtek Wi-Fi chip 的 module, 所以 driver 應該是無問題的. 只是 Wi-Fi 的設定是個未知素.


在開始安裝前, 先接上一隻 hard disk, 並在 /etc/fstab 中加入 mount point 的動作, 例如:
mkdir -p /mnt/sata
echo "/dev/sda1 /mnt/sata ntfs defaults,noatime,ro,nls=utf8 0 0" >> /etc/fstab
試一試:
mount /media/sata
ls /media/sata
你也可以安裝 NFS / CIFS services, 把 mount point 設定成 read/write, 這樣以後加減歌可以經 network.


1. 安裝 LMS
不斷的 google, 試, 攪左兩三個星期, 我終於做到了, 原來因為 CB2 同 Rapsberry Pi 硬件上係好近似, 所以其實只要用番 LMS for Pi 的 setup 便可:

Reference: http://allthingspi.webspace.virginmedia.com/lms.php

以上的是 copy-and-paste 自上面的網頁:
"1. Update some stuff and install some libraries. If you are prompted to reboot your Pi after this step, type reboot and hit enter.
sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get install libjpeg8 libpng12-0 libgif4 libexif12 libswscale2 libavcodec53
2. Download Logitech Media Server and install.
wget http://downloads.slimdevices.com/LogitechMediaServer_v7.7.2/logitechmediaserver_7.7.2_all.deb
sudo dpkg -i logitechmediaserver_7.7.2_all.deb
3. Stop the Logitech Media Server service.
sudo service logitechmediaserver stop
4. Download and extract some files used for this how-to guide to save you having to build everything yourself.
wget http://allthingspi.webspace.virginmedia.com/files/lms-rpi-raspbian.tar.gz
tar -zxvf lms-rpi-raspbian.tar.gz
5. Patch the bootstrap perl module.
sudo patch /usr/share/perl5/Slim/bootstrap.pm lms-rpi-bootstrap.patch
6. Move some files into place, create symbolic links, refresh dynamic linker bindings.
sudo mv arm-linux-gnueabihf-thread-multi-64int /usr/share/squeezeboxserver/CPAN/arch/5.14/
sudo mv libmediascan.so.0.0.0 libfaad.so.2.0.0 /usr/local/lib
sudo mv /usr/share/squeezeboxserver/Bin/arm-linux/faad /usr/share/squeezeboxserver/Bin/arm-linux/faad.old
sudo mv faad /usr/share/squeezeboxserver/Bin/arm-linux
sudo ln -s /usr/local/lib/libmediascan.so.0.0.0 /usr/local/lib/libmediascan.so
sudo ln -s /usr/local/lib/libmediascan.so.0.0.0 /usr/local/lib/libmediascan.so.0
sudo ln -s /usr/local/lib/libfaad.so.2.0.0 /usr/local/lib/libfaad.so
sudo ln -s /usr/local/lib/libfaad.so.2.0.0 /usr/local/lib/libfaad.so.2
sudo ldconfig
7. Fix some permissions.
sudo chown -R squeezeboxserver:nogroup /usr/share/squeezeboxserver/
8. Start the Logitech Media Server service.
sudo service logitechmediaserver start
Point your browser at "http://<pi ipaddress here>:9000" and configure the Logitech Media Server. After this you should be able to connect with a player, or if you want to use the same Pi to play the music as well as serve it, continue on........."

我不會安裝 squeezelite 因為不打算USB出DAC/DDC.

2. 設定 Wi-Fi
又攪左好耐(2星期), 最後發現原來 Voyage Linux 本身已經做好晒. 只要將 Wi-Fi dongle 插入, 再把想做的 setting 在 /etc/network/interfaces 中 uncomment 了, 再執行 service networking restart 便可.

做 Wi-Fi 的設定有好多好多種, 我會建議以下兩種二選一

2.1 Ad-hoc mode
Wifi ad-hoc mode 意思係建立一個小型 Wi-Fi network 作共享模式. 好處係簡單 setup, 壞處係 iPad 加入了 ad-hoc network 後便不能上網, 因為 ad-hoc 的機 (CB2 和 iPad) 都沒有接上 router network, 所以不能出 Internet.

如打算做 ad-hoc mode, 你的 interfaces file (/etc/network/interfaces) 的設定可以如下:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
  address 192.168.1.8
  netmask 255.255.255.0
  broadcast 192.168.1.255
#
# As ad-hoc
#
auto wlan0
iface wlan0 inet static
  address 10.1.10.1
  netmask 255.255.255.0
  broadcast 10.1.10.255
  up iwconfig wlan0 essid voyage-adhoc mode Ad-hoc

eth0 便是 (有線) LAN 的 interface. 這個用的 IP address 和 subnet 要和 SBR 一致. 如果你的 SBR 設定了 static IP, 咁你不用開 DHCP server. 但如果你的 SBR 是使用 dynamic IP, 咁你要在 CB2 上開啟 DHCP server. (DHCP server setup 會在下面提到)

wlan0 因為是 adhoc network, 它和其他 join 左這 adhoc network 的機 (如 iPad) 都一係要用 fix IP, 一係要有一個 DHCP server 派 IP. 請留意.

做了以上的設定, reboot / restart networking service 便可在 iPad 上見到有個 "voyage-adhoc" 的 ad-hoc network, 接上後再開 iPeng 便會見到 SBR.

2.2 Wi-Fi client mode
Wi-Fi client mode 意思係把 Wi-Fi dongle connect 到你家中已有的 Wi-Fi network. 這個的好處係你的 iPad 可以上網, 但因為把 Wi-Fi dongle 接到家中 Wi-Fi network, 在同一個 network 中多了 traffic, 對 CB2 的 Wi-Fi interface 的工作一定較多, 會有影響但未必聽得出.

如打算做 Wi-Fi client mode, 你的 interfaces file (/etc/network/interfaces) 的設定可以如下:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
  address 10.1.20.1
  netmask 255.255.255.0
  broadcast 10.1.20.255
auto wlan0
iface wlan0 inet static
  address 192.168.1.98
  netmask 255.255.255.0
  broadcast 192.168.1.255
  wpa-driver wext
  wpa-ssid {see_below}
  wpa-ap-scan 1
  wpa-proto RSN
  wpa-pairwise CCMP
  wpa-group CCMP
  wpa-key-mgmt WPA-PSK
  wpa-psk {see_below}
我的家是用 WPA2 的, 如果你的不是 WPA2, 請自行選擇合適的 WPA setting (在 /etc/network/interfaces 中把合適的 WPA setting  uncomment 便可.

"wpa-ssid" 填上你的 SSID
"wpa-psk" 要填上一個已經 encrypt 的 Wi-Fi 密碼, 你要打這個 linux command 去取得適合你家 network 的密碼:

wpa_passphrase MYSSID passphrase

例如你家的 network SSID 是 "my_wifi", Wi-Fi 密碼 (passphrase) 是 "password1234". 這樣便輸入

wpa_passphrase my_wifi password1234

再把它回來的字串貼在 "wpa-psk" 後面.

3. DHCP Server
原來開一個獨立 network 給 LMS <-> SBR 是需要有 DHCP server. 好在 Voyage Linux 本身已經有了一個小型 DHCP server service, 不過沒有啟動, 只要做以下的設定便可:

vi /etc/dnsmasq.more.conf
入到去會見到已經有一些不同的 interface 定了不同的 IP subnet 作為一旦開放 DHCP service 時的參考.
#dhcp-range=wlan0,10.1.10.10,10.1.10.250,24h
#dhcp-range=eth1,10.1.20.10,10.1.20.250,24h
#dhcp-range=eth2,10.1.30.10,10.1.30.250,24h
#dhcp-range=eth3,10.1.40.10,10.1.40.250,24h
dhcp-leasefile=/var/tmp/dnsmasq.leases

只要把你想要開 DHCP server 的 interface uncomment 左便可. 當然要留意 IP subnet 是否跟你在 /etc/network/interfaces 中的定義一至. 否則也會不能接上.

例如你想把 eth0 設定成有DHCP service, subnet 用 192.168.1.x, wlan0 也要有 DHCP servcice, subnet 用 10.1.20.x, 咁可以:
dhcp-range=eth0,192.168.1.10,192.168.1.250,24h
dhcp-range=wlan0,10.1.20.10,10.1.20.250,24h
dhcp-leasefile=/var/tmp/dnsmasq.leases

Reboot, or re-start dnsmasq 便可.

Reference: http://svn.voyage.hk/repos/voyage/branches/voyage-live/0.9.2/config/includes.chroot/README

相關Blog文:
Cubieboard2 with Logitech Squeezebox Media Server 入箱
摩改 Squeezebox Duet Receiver (上)
摩改 Squeezebox Duet Receiver (中)
摩改 Squeezebox Duet Receiver (下)
不用 Squeezebox Duet Controller 的方法 - Net::UDAP - SqueezeBox Receiver configuration tool

Saturday, 15 February 2014

Building custom (real-time) kernel for Atom (X86)

I found the sound quality really improved by using real time kernel after building real time kernel for Cubieboard2. Therefore I started working on real time kernel for my Atom PC.

I have a small form factor (about size of a 3.5" hard disk) Atom motherboard, the

Some highlights:
  • Atom MT2800 with fanless heatsink  
  • DDR3 SODIMM slot x 1
  • VGA, HDMI, LVDS
  • RTL8111E Gigabit Ethernet Adaptor x 2
  • Realtek ALC662 6ch Hi-def Audio on-board 
  • USB 2.0 x 6
When building custom kernel, I aim to build only those I needed for Voyage MPD, so I would like to build the following features:
  • CPU architecture select "Intel Atom" (which means some of the advance instruction sets not appeared in Atom will not be supported)
  • Real time support (Fully preemptive)
  • USB 2.0 controller and USB audio, no other USB device drivers will be built (such as USB network card, USB mouse, TV card, scanner, printer, etc)
  • No AGP, only PCI and PCIe controller
  • VGA only, no framebuffer, no 3D support.
  • SATA and SCSI (no legacy support like PATA)
  • IP v4 only without advance features like tunneling, multicast, etc
  • Driver (module) for realtek R8169 only (this is compatable with RTL8111E)
  • No virtualization support
  • No debugging / verbose support for every hardware!
I think that today's Linux kernel is very mature in the sense that building all the features in modules doesn't hurt the performance obviously. However, I believe that the system will still load those modules if it detects a hardware is supported, which will introduce some unnecessary latency inevitability. So the best way is not to provide those modules and not to build into the kernel core. Of course, the baseline is to have a kernel build that is bootable and be able to play music flawlessly. So I did compiling and testing the same kernel version with different combination of options on and off.

What I am trying is say is that, when you build your own kernel for a x86 PC, bare in mind that it may not success at once. You may need to turn the options on and off and try until you find one workable configuration with least number of modules loaded / built into the kernel.

Ok, let's start building the kernel!

First, get a disk drive (USB drive or SATA hard disk) with 4G (8G or more preferred) available. Load it with Voyage current version. You may refer to the "readme" of Voyage MPD, section 2 - "Installation" for the official setup guide. I used version 0.9.2:
http://svn.voyage.hk/repos/voyage/branches/voyage-live/0.9.2/config/includes.chroot/README

The official installation guide assumes you run on a Linux environment. If you don't have another Voyage MPD ready, the easiest way is to download Ubuntu 12.04 32bit live CD and run in Ubuntu Desktop.

When you have the Voyage MPD disk ready, try to boot it in your target machine and make sure it can boot up flawlessly. After that, you can start the following steps on the same machine, or you may boot the Voyage MPD on another faster PC (say an Intel i7) so that you can build kernel much faster.

1. Connect a LAN cable (with internet connection), power up. After boot up, login (username=root, password=voyage). Remount as "read/write" mode:
%remountrw

2. Set correct date/time (optional, do it if necessary)
For example, set new data to 2 Oct 2006 18:00:00, type the following command:
# date -s "2 OCT 2006 18:00:00"
3. Update application package database:
%apt-get update
(this would take a minute or two, depends on your Internet connection)

%apt-get upgrade
(this would take another 2 to 10 minutes, depends on your Internet connection)

4. Install the required packages:
%apt-get install wget build-essential libncurses5-dev openssl bc
 (this would take about 10 minutes or more, be patient)

5. Download a kernel version with RT project. Check here for the available real-time kernel patch versions first.
%cd (go to root's home directory)
https://www.kernel.org/pub/linux/kernel/projects/rt/

Then check the link for the corresponding kernel version in here:
https://www.kernel.org/pub/linux/kernel/v3.x/

In my case, I selected kernel version 3.10.27-rt25. Highlight and copy the URL for the kernel patch and paste the URL with wget command to download:
%wget https://www.kernel.org/pub/linux/kernel/projects/rt/3.10/patch-3.10.27-rt25.patch.xz
Extract it:
%unxz patch-3.10.27-rt25.patch.xz

And download the kernel source:
%wget --no-check-certificate https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.27.tar.gz
Extract it:
%tar xvzf linux-3.10.27.tar.gz
(a folder called "linux-3.10.27" under "/root" will be created)



6. Applies the real time kernel patch:
%cp patch-3.10.27-rt25.patch linux-3.10.27
%cd linux-3.10.27
%patch -p1 < patch-3.10.27-rt25.patch
(it would patch the kernel source in few seconds...)

7. Optional, but recommended, edit the "Makefile"
%nano Makefile
See the line starting with "EXTRAVERSION" (it should be the forth line), go to the end, add some text, say "-atom" (without quotes), the "extra version" just appended after the minor version.

Remember not to add a space "after" the text you added. You can have white space between the "=" and the first character of the text

Also optional, but recommended, copy the kernel configuration file that comes with Voyage MPD:
%cd /boot
%ls config*
You shall see a file named "config-3.x.x-voyage", just copy this file to the linux kernel source folder that you just made above and rename as ".config" (note that there is a dot before "config")
%cp config-3.10.11-voyage /root/linux-3.10.27/.config


8. Start kernel configuration menu:
%make menuconfig

You shall see a text mode menu with blue background. You (must) do the following changes in order to enjoy the real-time kernel:

Kernel Features -> Preemption Model
Change to "Fully Preemptible Kernel (RT)"

General setup -> RCU Subsystem, enables:
-Enable RCU priority boosting
-Offload RCU callback processing from boot-selected CPUs

Optional: As mentioned above, remove all the drivers and features that are not need. This could make the kernel and driver size smaller and minimize the change of CPU get bothered.
(Tips #1: Check the inline help page for explaination of the feature and the suggestion of keep or not

Tips #2: I found a web tutorial written by DevynCJohnson which is very comprehensive and useful. You may get more idea about what to include to kernel build after reading it:
http://www.linux.org/threads/%EF%BB%BFthe-linux-kernel-introduction.4203/
)
Update (Aug-4-2014): Please select 32-bit kernel if you are building for Voyage Linux. 64-bit kernel doesn't work on Voyage Linux.

Exit and save the configuration. (The configuration would be saved as ".config", a hidden file, under the root folder of the kernel source, i.e. under "/root/linux-3.10.27" in my case)

9. Start building kernel

%make -j2 all

this step will compile the kernel and create a compressed binary image of the kernel and also the loadable kernel modules. After the step, the kernel image can be found at arch/i386/boot/bzImage (for a x86 based processor) and kernel modules (i.e. those files ended with .ko) will be built.

Remember to use "-j" option if you are building on a multiple core CPU. "-j2" means running the build in two threads. You may use "-j4" if you have 4 core/virtual threads in total.

(this would take at 10 minutes up to 2 hours, depends on what you have selected to build and the CPU power)

10. Install to Voyage MPD disk
%make -j2 modules_install
The above command will make those kernel modules being copied to "/lib/modules/3.10.27-rt25")
%make -j2 install
The above command will build the SystemMap, vmlinuz, initrd and config files that appear in "/boot". It will also update the GRUB (the boot loader) to include the newly built kernel as option in the boot menu.


11. You may want to touch up the boot menu to make it more readable and remove unuse menu items. Just:
%nano /boot/grub/menu.lst

Important: The default kernel menu links the kernel images in the root folder. (/vmlinuz and /initrd.img), this two links were being redirected to the newly built kernel images after executing the "make install" command. So you should update the menu.lst file to make the link points to the ACTUAL files instead of the symbolic links.



12. Now you can reboot and you shall see the newly built kernel version as one of the boot options. Select it and see what happen. It may not boot successfully, especially if you didn't select most of the items. If it just can't boot up or you want to further fine tune, do the following:

13. Reboot with the stock kernel version selected in boot menu, it shall boot up normally.

14. Login as root, remount as read/write:
%remountrw

15. Goto /root/linux-{version}, if your recent kernel built works fine, I suggest making a backup of the ".config" in case the new kernel built doesn't work.
%cp .config config.bak
Run make menuconfig again.

16. Based on the error message (you have to "guess" what blocks the machine bootup!), enable it this time.

Or, if it could boot up but some hardware is not working, just enable that particular hardware. You can choose to build that device driver into kernel core or build as module. I think it doesn't have noticible performance hurt for building the device driver as kernel module but it certainly would be more flexible. (For me, I built the USB keyboard, USB wi-fi driver as kernel modules because I may not always need them.)

17. Save and exit the kernel configuration menu, delete the files created previously.
%rm /boot/*3.10.27*
This will remove those files with the kernel version as part of the file name.
%rm /vmlinuz /vmlinuz.old /initrd.img /initrd.img.old

repeat steps 9-12. Good luck!

Friday, 3 January 2014

Power Off the Display of Your Rasberry Pi

If you are using RaspyFi or similar Linux MPD player, you may further improve the sound by disabling the HDMI display output. Just add the following line to "/etc/init.d/bootmisc.sh"

# Turn off HDMI display output 
/opt/vc/bin/tvservice -o

Tuesday, 10 September 2013

給 LX800 一個殼

之前玩個LX800出到聲, 發覺它唔錯, 正正常常好穩定, 於是就去揾個殼給它...
揾左好耐, 原來要揾做合適的殼給它是十分困難的. 最後揾左個比較高身的殼, 連運費$60HKD.
安好的模樣
前方開左兩個孔放黃LED(network activity) 和綠色LED(power)


  開孔因為全人手, 用手鋸, 手銼, 整左兩個鐘好辛苦...
前前後後做左四個鐘. 煲了一晚都好正常, 只係微暖.

Sunday, 25 August 2013

LX800 上裝 Voyage

經一位網友指點, 我得知原來有些二手的LX800可以買入來安裝 Voyage MPD. 於是上星期便拍了一件回來.
星期一收到的


收到後當然第一時間試試, 我先把 Voyage 安裝在一張4G CF 卡上, 插上, 給它5V供電 (是的, 雖然它有12V和5V, 但其實它只要5V), 通電後 3秒它發出 beep 一聲. 但過了很久, 我還是不能找到它的 IP address.

有可能的原因是:
1. CF 卡不被它認出
2. CF 卡能認出, 但 boot機途中出現錯誤
3. CF 卡能認出, boot 機也沒問題, 只是找不到 eth0...等等可能性

因為沒有 serial cable (RS232), 而且它是沒有VGA的, 我只有靠估...
試了很久, 心想, 沒有顯示, 這樣等也不是辦法, 於是又上去拍了 Serial to USB 和 Serial female-to-female 回來...
到了星期四, 收到這些線


插好, 用 putty 打開 COM7, 給電, beep, 過了3分鐘依然沒有畫面... 問了賣家, 他的回應是, "我也不知".... 我心想, 莫非真是要放棄?

因為有別的忙, 又放它一邊沒理會...

到了星期六(今天), 又拿它出來看看, 給它最後機會吧, 如果都唔得便拿落樓下的電腦回收(剛好今天有流動回收車來), 仔細看看, 原來它是有個 15針的VGA 接口, 但不知何故沒有銲上插座. 我想是不是這板子有不同的版本, 因為大量生產便有些沒有銲這VGA接口, 即是可能就算我加上接口座也不會有訊號... 但唔試過又點知, 於是下午我就出去買左粒 D-sub 座(要成 $6 HKD, 拍回來的話不用 $1 RMB !!! 但我心急)

安了上去,通電, 即時有畫面, 原來是 work 的, 這 $6 也沒有白費哦!
原來這東西只有128M RAM, 是 AMD Geode GX-MMX (LX800), Primary Master 的 hard disk 是一個 mini IDE 的插槽. Primary Slave 才是 CF 卡的插槽.

看看它的開機畫面:

開機到一半出現這句:
ide_dma_sff_timer_expiry: DMA status (0x41)

又攪了三四個鐘, 上網找, 試不同的設定, 終於找到解決方法. 是要叫 Voyage 不要用 DMA.


 最後, 原來有一個 LAN port 是不能用的.

 

Thursday, 15 August 2013

Rabsperry Pi + piCorePlayer

早前見網友用Rabsperry Pi當Squeezebox玩, 攪到我心思思又買嚟玩下. 星期一收到 Rabsperry Pi

一直都只係祼跑,


仲未諗到點安放佢, 直到昨日因為8號風球唔使番工, 所以就做左個盒放Rabsperry Pi同線性牛.










張SD CARD只有piCorePlayer: https://sites.google.com/site/picoreplayer/home

Tuesday, 30 July 2013

開箱 --- Cubieboard A20

上星期買的 Cubieboard A20 昨天收到, 今天才有時間玩玩.
大陸設計, 大陸做! 強!
 
 打開是A20的卡, 下層有線和亞加力膠板
 開了機...

Thursday, 11 July 2013

Cubox 上裝 Voyage

終於都出左, 比起用日本人YO的, 我覺得好處係方便, 睇過它的 installation guide 後, 見只要用一只USB手指行起個 setup program (加一條 usb console cable 出screen / HDMI) 就可以裝, 仲有不同的OS可選. 十分體貼易用.

http://mubox.voyage.hk

Tuesday, 4 June 2013

Cubox 推薦計劃

昨天收到 SolidRun 的"Cubox 推薦計劃"邀請電郵, 今晚看過了內容, 覺得都OK, 於是開了戶:

如果大家打算買Cubox, 可按以下的連結, 咁佢地就會知係我 refer 你俾佢地了:

http://www.solid-run.com?partner_id=894


 

Monday, 27 May 2013

Cubox for CAS #6 : 安裝 Cubox 的 Linux (下)

之前做好了 Yo 的 Linux image, 開了 Cubox, 找到了 Cubox 的 IP 并可透過 SSH 看到登入畫面, 以下會做一些客化, 包括:
1. 刪去日文的設定
2. 設定 mpd 的 configure 檔
3. 設定 NAS 的 file sharing mapping (在 rc.local 內)
4. 把系統會寫的file 移至 RAM drive 上 (廷長 micro SD 的壽命)

1. 刪去日文的設定
開了機, SSH 入去後 (username = root, password = cubox), 執行:
apt-get update && apt-get -y upgrade; apt-get -y remove --purge language-pack-*; apt-get -y install lighttpd language-pack-en-base; 




再執行:
dpkg-reconfigure locales; export LANG=en_HK.UTF-8; dpkg-reconfigure tzdata; apt-get update && apt-get -y upgrade; echo "export LANG=en_HK.UTF-8;" >> /root/.profile; apt-get -y autoremove; reboot

它會問你當前的 Locale, 只要選 "Asia", "Hong Kong" 便可.

到了最後它會自己 reboot. Reboot 後又 SSH 登入. 再執行:
echo "alias ls='ls -la --color=auto'" >> /root/.profile;
cd /var; mv /var/log /run
ln -s ../run/log log
cd /var/lib; mv /var/lib/urandom /run
ln -s /run/urandom /var/lib/urandom
mv /var/lib/dhcp /run
ln -s /run/dhcp /var/lib/dhcp
mv /root/.bash_history /run
ln -s /run/.bash_history /root/.bash_history
mkdir -p /run/music
ln -s /run/music /music
ln -s /music /var/www/music
2. 設定 mpd 的 configure 檔
執行:
mv /etc/mpd.conf /etc/mpd.conf.org
nano /etc/mpd.conf
(nano 的簡單教學: [轉] 基本 Nano 指南)

Copy & Paste 以下內容 (可用 mouse highlight 下面藍色的字,再按 ctrl-C, 然後把 滑老放標放在 putty 的 nano 內按 right click)
music_directory         "/music"
playlist_directory      "/music/.mpdConf/playlists"
db_file                 "/music/.mpdConf/cubox/db"
log_file                "/run/mpd/log"
pid_file                "/run/mpd/pid"
state_file              "/music/.mpdConf/cubox/state"
sticker_file            "/music/.mpdConf/cubox/sticker.sql"
audio_buffer_size              "8192"
buffer_before_play             "90%"
user                            "mpd"
group                          "audio"
zeroconf_enabled               "yes"
zeroconf_name                  "Cubox"
mixer_type                      "disabled"
filesystem_charset              "UTF-8"
id3v1_encoding                  "UTF-8"

realtime_option {
        memlock                 "yes"
        stack_reserve           "2048"
        heap_reserve            "10240"
        main_priority           "OTHER:0"
        player_priority         "FIFO:52"
        decoder_priority        "FIFO:51"
        update_priority         "OTHER:0"
}

decoder {
        plugin "dsdiff"
        enabled "yes"           # DSD native
}

decoder {
        plugin "dsdiff_native"
        enabled "yes"
        dsdsampleformat "24"
        tagsupport "id3pref"
}

# An example of an ALSA output:
#
audio_output {
        type            "alsa"
        name            "My ALSA Device"
        device          "hw:0,0"        # optional
        priority        "FIFO:52"
        dsd_usb         "yes"
}
請自行修改粉紅色的內容, 其中,
  • "My ALSA Device" 是你的DAC在MPaD上顯示的名稱
按下 Ctrl+O。再按下 Ctrl+X 離開 nano

離開 nano 之後執行:
chown mpd:audio /etc/mpd.conf

3. 設定 NAS 的 file sharing mapping

nano -w /etc/rc.local
(nano 的簡單教學: [轉] 基本 Nano 指南)

清除原來的內容, 然後 Copy & Paste 以下內容 (可用 mouse highlight 下面藍色的字,再按 ctrl-C, 然後把 滑老放標放在 putty 的 nano 內按 right click)

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
chrt -f -p 53 `pgrep -n cifsd`
chrt -f -p 53 `pgrep -o cifsd`

mount -t cifs -o uid=mpd,file_mode=0666,dir_mode=0766,iocharset=utf8,\
rsize=130048,wsize=4096,\
username=mpduser,password=mpd1234 192.168.0.101:/Music /run/music
service mpd restart
mpc update
find /run/music/USB -type d -empty -delete

exit 0
請自行修改粉紅色的內容, 其中,
  • mpduser 是你打 NAS 上的 music folder 分享的用戶名稱, 
  • mpd1234 是你打 NAS 上的 music folder 分享的用戶密碼,
  • 192.168.0.101:/Music 是你打 NAS 上的 music folder 分享的link,

按下 Ctrl+O。再按下 Ctrl+X 離開 nano


4. 把系統會寫的file 移至 RAM drive 上

執行:
nano /etc/init.d/readonlySetup
(nano 的簡單教學: [轉] 基本 Nano 指南)

貼上以下
#!/bin/sh

### BEGIN INIT INFO
# Provides:          read-only file-system preparation
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: prepare for read-only root FS
# Description:       prepare for read-only root FS
### END INIT INFO

prep_start () {
        echo "Prep for read-only FS"
        echo heartbeat > /sys/class/leds/cubox:red:health/trigger
    /bin/mkdir -p /run/log/lighttpd /run/tmp /run/urandom /run/dhcp /run/music/.mpdConf/cubox /run/music/.mpdConf/playlists
        /bin/touch /run/.bash_history /run/music/.mpdConf/cubox/db /run/music/.mpdConf/cubox/state /run/music/.mpdConf/cubox/sticker.sql
        /bin/chmod -R 777 /run/log /run/tmp /run/urandom /run/dhcp /run/music
    #/bin/mount -o remount,ro /
}

prep_stop () {
        echo "Prep for read-only FS (stop)"
    /bin/mount -o remount,rw /
}

case "$1" in
    start)
        prep_start
        ;;
    stop)
        prep_stop
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 2
        ;;
esac

按下 Ctrl+O。再按下 Ctrl+X 離開 nano

離開 nano 之後執行:
chmod 777 /etc/init.d/readonlySetup
cd /etc/rc2.d
ln -s ../init.d/readonlySetup S10readonlySetup
cd ..
cd /etc/rc3.d
ln -s ../init.d/readonlySetup S10readonlySetup
cd ..
cd /etc/rc4.d
ln -s ../init.d/readonlySetup S10readonlySetup
cd ..
cd /etc/rc5.d
ln -s ../init.d/readonlySetup S10readonlySetup
reboot
Reboot 後, 你可用 MPaD (或任何 mpd controller) 見到 "Cubox".  

設定完成!

Sunday, 26 May 2013

Cubox for CAS #5 : 安裝 Cubox 的 Linux (中)

前文講到如何把日本人Yo的 2012-11-08 Linux for Cubox 版本寫上 Micro SD 卡上, 接住要開了 Cubox, 要先找出你的 Cubox 在你家中被分配了甚麼 IP.

如果你家中的是用 Wifi-Router 連接上網, 基本上你可以 login 這 wifi router 的 web admin page, 它多數會有一版可以列出現在網絡上的 devices, 當中你會找到 "cubox" 的. 如果這個方法不行, 你可以用以下的 software:

Windows 上做 IP scanning 有好多FREEWARE個得到, 例如以下呢個:

Angry IP Scanner


找到了 Cubox 的 IP address 後, 下一步是透過 SSH "remote access" Cubox.

如果你是 Mac 用戶,只需在 "terminal" 打 "ssh root@<server ip>" 即可, 例如你的 Cubox IP address 是 192.168.1.10, 你只需開 terminal, 打 ssh root@192.168.1.10, 它便會問你 login 的 password.


如果你是 Windows 用戶, 可以用呢個叫 Putty 的 freeware

1. 打開 putty, 輸入 Cubox 的 IP Address

2. 選左方 menu 的 "Window -> Translation", 再把右方的 "Remote character set" 改為 "UTF-8", 咁先可在 putty SSH 時看到 cubox 上的中文字


3. 選左方 menu 的 "Connection -> Data", 再把右方的 "Auto-login username" 輸入 "root", 咁每當你用 putty SSH 至 cubox 時它便會默認 "root"
 
4.最後回到首頁 (Session), 在 "Saved Sessions" 下輸入 "cubox", 再按 "Save", Putty 便會把你之前入的所有設定記住, 下次你開 putty 時只要 double-click 個 "cubox" session 便可.

5. Save 好便可 click "open", 首次登入時, putty 會要你接受 Cubox 發出的認証, 這是 SSH的保安一部分,只要 accept 它(按"Y") 便可
 登入的 username 是 "root", password  "cubox"

接下來你需要對 Cubox 做一些客化