Somewhere I Belong

All about geek's life


  • 首頁

  • 開源專案

  • 關於

  • 歸檔

  • 標籤

Windows XP 登入後立刻被登出 (忽然要輸入登入密碼)

發表於 6月 24 2014   |  

這一天老媽忽然把電腦搬到我面前告訴我,不能開機了 …

看了一下,奇怪原本不需要輸入密碼的電腦怎麼忽然要輸入使用者名稱與密碼?心想應該是他們不小心弄到什麼了!於是就開始輸入一些例如:Administrator試圖登入。

顯然事情沒有這麼簡單,所以我又找了一些關於忘記密碼的解法。當然這過程當中可以說是困難重重,因為我的電腦都是 sata 介面,連 光碟機、IDE 什麼的都沒有,也不能用 USB 來製作救援。因為電腦已經十歲了,還無法支援 USB 開機。原本想說拿一台外接光碟機來用,但是發現我的快接線壞掉了…真是一波三折。

總結一下,最後就是拿了 伽利略 旗艦版 SATA&IDE TO USB3.0 光速線 這個好物來接到我電腦上,並搭配 VirtualBox 來使用。

  1. ERD Commander 2005
  2. 快接線

就這樣,把使用者密碼給改了。原本以為故事到此結束!但是我發現根本無法登入!就算密碼對了,登入後也會立刻被登出

於是找到了這篇 Windows Log on and Log off immediately.

關鍵在於這個 HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon 新增這兩個鍵

Shell = explorer.exe
Userinit = X:\windows\system32\userinit.exe

ps. HKLM = HKEY_LOCAL_MACHINE

以上,終於達成修理電腦的任務。

想不到十年的電腦到現在還是一尾活龍阿…

在 Samba 分享資料夾上編輯檔案變成可執行權限

發表於 6月 12 2014   |  

因為工作關係桌機使用 Windows 然後檔案透過 Samba 分享在 Linux 環境當中…

但是說也奇怪,每次我使用 Sublime Text 3 編輯完一個檔案存檔後都會變成可執行的權限 Permission 755

起初我一直懷疑是 Sublime Text 3 是不是給我動什麼手腳,後來才看到原來有人跟我有一樣的問題!!!

居然是不起眼的 Samba 在作祟

問題就在於 smb.conf 中的參數設定

map archive = false

要設定成 false 才行,預設是 true。來看看官方文件怎麼說…

This controls whether the DOS archive attribute should be mapped to the UNIX owner execute bit. The DOS archive bit is set when a file has been modified since its last backup. One motivation for this option is to keep Samba/your PC from making any file it touches from becoming executable under UNIX. This can be quite annoying for shared source code, documents, etc…

原來就是這個好意的設定讓我困擾這麼久…

將 Debian/Ubuntu 套件清單輸出備份與還原

發表於 6月 12 2014   |  

要打包系統所以要把目前裝過的套件全部記錄起來

簡單的拜了一下 Google 大神

dpkg --get-selections | grep -v deinstall

輸出已安裝清單

tasksel                                         install
tasksel-data install
tcpd install
tcpdump install
tmux install
traceroute install
ttf-dejavu-core install
tzdata install
ubuntu-keyring install
ubuntu-minimal install
ucf install
udev install
unattended-upgrades install
........................skip...........................
vnstat install
vsftpd install
w3m install
webalizer install
wget install
whiptail install
whois install
wireless-regdb install
x11-common install
xauth install
xfonts-encodings install
xfonts-utils install
xkb-data install
xml-core install
xz-lzma install
xz-utils install
zlib1g install
zlib1g-dev install
zsh install

所以說你想要備份目前機器上所有 package 清單就可以輸入下列指令

備份已安裝清單

dpkg --get-selections > pkglist.txt

還原已安裝套件

dpkg --clear-selections
sudo dpkg --set-selections < list.txt

source: How to list all installed packages?

Node.js npm 安裝 node-sqlite3 套件在不同平台

發表於 6月 10 2014   |  

今天在公司要跨平台編譯 node-sqlite3,結果編出來的東西一直有問題…
搞半天原來是因為少下了一個指令,囧

在 node 在 0.8 版本之後使用了 node-gyp,可以讓工程師比較輕鬆地將一些 native code 編譯到不同平台上。

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js, which takes away the pain of dealing with the various differences in build platforms. It is the replacement to the node-waf program which is removed for node v0.8. If you have a native addon for node that still has a wscript file, then you should definitely add a binding.gyp file to support the latest versions of node.

由於小弟我知識淺薄,說到 cross-compile 大概只想到置換環境變數 $(CC) 或是改改 header 檔案,結果遇到 npm install 一時之間還真的不知道要怎麼指定 toolchain 囧!後來翻到了 node-sqlite3 說明中有教你怎麼樣編譯到別的平台上。

我自己的做法

首先要具備 node-gyp 並安裝到全域 npm install node-gyp -g

再來就是 npm install sqlite3 --build-from-source --target_arch=arm

注意
這個 --build-from-source 非常重要,如果你的 toolchain 是自備的一定要加上這個 flag 要不然他會很好心的幫你直接下載 arm 版本的 binary,而達不到你要的效果(cross-compile)

另外,node-sqlite3是有套件相依性的…apt-get install libsqlite3 可以輕鬆解決

如果想查看他有相依那些 lib 的話不妨來一下 ldd 唄!

npm install 錯誤在虛擬機共享資料夾

發表於 6月 7 2014   |  

今天更新 Blog 產生器 HEXO 時發現我要安裝 NPM 套件時會發生很詭異的錯誤…

TL;DR

使用虛擬機分享資料夾,例如我是用 VirtualBox 分享 windows 資料夾給 Debian。系統在建立 Symlink 的時候會有問題。

以下是錯誤訊息

npm ERR! error rolling back Error: ETXTBSY, unlink '/media/sf_project/imZack.github.io/node_modul
es/hexo-renderer-marked/node_modules/lodash/lodash.js'
npm ERR! error rolling back hexo-renderer-marked@0.1.0 { [Error: ETXTBSY, unlink '/media/sf_proj
ect/imZack.github.io/node_modules/hexo-renderer-marked/node_modules/lodash/lodash.js']
npm ERR! error rolling back errno: 62,
npm ERR! error rolling back code: 'ETXTBSY',
npm ERR! error rolling back path: '/media/sf_project/imZack.github.io/node_modules/hexo-rendere
r-marked/node_modules/lodash/lodash.js' }
npm ERR! Error: EROFS, symlink '../marked/bin/marked'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>

npm ERR! System Linux 3.2.0-4-amd64
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /media/sf_project/imZack.github.io
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! path ../marked/bin/marked
npm ERR! code EROFS
npm ERR! errno 56

丟上去 google,嗯!我不是孤單的…簡單的抓了一個答案來看得到的結果是:npm install 後面加入參數 --no-bin-link

依據 npm 官方文件表示:

The –no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.

也就是說避免 npm 去幫你產生 symlinks,這時我才忽然想起我的環境是 windows 資料夾透過 virtualbox 的 shared folder 分享到 debian 難怪不能用 symlinks…

這裡似乎有一篇解法,將 virtual box 跑在 administrator 下然後在 VM 內設定下面參數

VBoxManage setextradata YOURVMNAME VBoxInternal2/
SharedFoldersEnableSymlinksCreate/YOURSHAREFOLDERNAME 1

不過我後來還是將這部分回到 windows 上面完成…哈

參考資料

Nodejs + npm, installing modules on ntfs partition

“Error: ETXTBSY” when installing the package with npm (gruntjs, gulp) at VirtualBox

NPM, Vagrant and Symlinks on Windows

利用 sshpass 幫你輸入 ssh 密碼

發表於 5月 29 2014   |  

最近公司在測產品的時候常常要使用 scp 傳檔案到機器(target)上

每次都要輸入密碼,實在是很惱人阿~ 好險有 sshpass 讓你沒煩惱

只要輸入

sshpass -p your_password scp file root@xxx.xxx.xxx:/home

就可以不用輸入密碼把檔案傳到遠端啦!

如何安裝?

Ubuntu & Debian

apt-get install sshpass

sshpass: http://www.cyberciti.biz/faq/noninteractive-shell-script-ssh-password-provider/
install: https://gist.github.com/arunoda/7790979

Linux Find 指令找出前幾大的檔案或資料夾

發表於 5月 29 2014   |  

找前 10 大的檔案

find node_modules -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
265K    node_modules/hexo-generator-minify/node_modules/css-condense/extras/trello.css
271K node_modules/hexo-generator-minify/node_modules/css-condense/extras/diff.txt
283K node_modules/hexo-generator-minify/node_modules/css-condense/extras/soundcloud.condensed3b_yui.css
284K node_modules/hexo-generator-minify/node_modules/css-condense/extras/soundcloud.condensed3b.css
297K node_modules/hexo-generator-minify/node_modules/css-condense/extras/soundcloud.yui.css
317K node_modules/hexo-generator-minify/node_modules/css-condense/extras/github.diff
325K node_modules/hexo-generator-minify/node_modules/css-condense/extras/soundcloud.css
339K node_modules/hexo-generator-minify/node_modules/css-condense/extras/yahoo.diff
457K node_modules/hexo-generator-minify/node_modules/css-condense/extras/trello.diff
499K node_modules/hexo-generator-minify/node_modules/css-condense/extras/soundcloud.diff

找前 10 大的資料夾

find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
1.9M    ./.deploy
3.8M ./node_modules/hexo-migrator-wordpress/node_modules
3.8M ./node_modules/hexo-migrator-wordpress
4.4M ./themes
8.2M ./node_modules/hexo-generator-minify/node_modules/css-condense/extras
8.7M ./node_modules/hexo-generator-minify/node_modules/css-condense
9.5M ./node_modules/hexo-generator-minify/node_modules
9.5M ./node_modules/hexo-generator-minify
15M ./node_modules
22M .

差異就在 find 的 -type d 跟 -type f 分別代表 directory 與 file

如果要變成前 20 大,只要改 tail -10 變成 tail -20

source: Linux utility for finding the largest files/directories

mount -o remount,rw /

發表於 5月 27 2014   |  

隨手記一下, 有些機器預設掛載不能寫入

mount -o remount,rw /

MQTT Mosquitto 移植 arm9 平台

發表於 5月 16 2014   |  

今天在公司弄一些 RD Award 的東西,就順手把 mosquitto 移植到公司產品上

不囉嗦先準備好 ARM9 32-bit RISC CPU toolchain 然後把一些環境變數設定好

建立一個 build.sh 內容物如下…

#!/bin/sh

MACH=arm9 #xscale

if [[ "${MACH}" = xscale ]]; then
trueTOOLCHAIN="/usr/local/arm-linux-4.4.2-v4"
trueHOST="arm-none-linux-gnueabi"
else
trueTOOLCHAIN="/usr/local/arm-linux"
trueHOST="arm-linux"
fi

# export shell environment variables
export PATH="${PATH}:${TOOLCHAIN}/bin"
export CPP="${HOST}-gcc -E"
export STRIP="${HOST}-strip"
export OBJCOPY="${HOST}-objcopy"
export AR="${HOST}-ar"
export RANLIB="${HOST}-ranlib"
# This is due to linker doesn't take the 'rpath' parameter
#export LD="${HOST}-ld"
export LD="${HOST}-g++"
export OBJDUMP="${HOST}-objdump"
export CC="${HOST}-gcc"
export CXX="${HOST}-g++"
export NM="${HOST}-nm"
export AS="${HOST}-as"

make clean
make

上面這些參數設定基本上就依照不同情況去做一些調整,網路上有些 crosscompile 的文章可以參考看看 (裡面的 MACH 改成 xscal 是我要移植到另一台用的)

Compile 過程當中會遇到兩個錯誤,分別是…

net_mosq.c: In function `_mosquitto_try_connect':
net_mosq.c:235: error: `AI_ADDRCONFIG' undeclared (first use in this function)
net_mosq.c:235: error: (Each undeclared identifier is reported only once
net_mosq.c:235: error: for each function it appears in.)
make[1]: *** [net_mosq.o] Error 1

上面這個 AI_ADDRCONFIG 可參考 RFC 2553 裡面的描述…

The AI_ADDRCONFIG flag specifies that a query for AAAA records
should occur only if the node has at least one IPv6 source
address configured and a query for A records should occur only
if the node has at least one IPv4 source address configured.

For example, if the node has no IPv6 source addresses
configured, and af equals AF_INET6, and the node name being
looked up has both AAAA and A records, then:

(a) if only AI_ADDRCONFIG is specified, the function
returns a NULL pointer;
(b) if AI_ADDRCONFIG | AI_V4MAPPED is specified, the A
records are returned as IPv4-mapped IPv6 addresses;

總之就是 IPv6 的東東,於是我們可以在檔案 mosquitto/src/lib/net_mosq.h 69行附近加入

#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0x0000
#endif

大功告成讓我們繼續看下去…

嗯,很好又遇到錯誤了

net.c:342: error: `IPV6_V6ONLY' undeclared (first use in this function)
net.c:342: error: (Each undeclared identifier is reported only once
net.c:342: error: for each function it appears in.)
make[1]: *** [net.o] Error 1

原來是 IPV6_V6ONLY 沒有定義阿…依據 google 所以我們簡單把他設定為一個 nonzero 就可以了

IPV6_V6ONLY (since Linux 2.4.21 and 2.6)
If this flag is set to true (nonzero), then the socket is re‐
stricted to sending and receiving IPv6 packets only. In this
case, an IPv4 and an IPv6 application can bind to a single
port at the same time.

If this flag is set to false (zero), then the socket can be
used to send and receive packets to and from an IPv6 address
or an IPv4-mapped IPv6 address.

The argument is a pointer to a boolean value in an integer.

The default value for this flag is defined by the contents of
the file /proc/sys/net/ipv6/bindv6only. The default value for
that file is 0 (false).

在檔案的 mosquitto/src/net.c 第 75 行左右加入

#ifndef IPV6_V6ONLY
#define IPV6_V6ONLY 1
#endif

大功告成啦~ Hooooooray~

快快樂樂享受 Mosquitto 吧~ 我們下次見~

後記:其實過程當中一度編譯成功但是 mosquitto_sub, mosquitto_pub 這兩隻一直不能正常運作,mosquitto 可以動(但是 bridge mode 不行),還想說到底是哪裡有病阿…結果原來是我網路上抄來的 AI_ADDRCONFIG 這個數值害慘了…因為有些定義成 0x0020 我直接拿來用顯然是錯誤的 0x0000 在我們的 case 中才是正解,所以鄉親啊!!!要注意。

一本創業電子書

發表於 5月 11 2014   |  

這兩天在網路上看到人家在轉貼一個電子書是有關於創業的,感覺滿有意思的就下載來看看…

他的網站是 Startup 2.0 工程師創業手冊 – 高科技創業經驗分享

電子書下載的 頁面

從事資訊相關對創業有興趣但是沒有概念與想法可以當作小說參考看看,提早認知一些過來人的經驗感覺挺不錯的!感謝原作者願意分享他一路上的寶貴經驗 :)

(我還沒看完,看完有心得再補上。)

1…567
YuLun Shih

YuLun Shih

66 文章
6 分類
122 標籤
RSS
Creative Commons
© 2016 YuLun Shih
由 Hexo 強力驅動
主題 - NexT.Mist