2012年7月9日 星期一

重建Ubuntu MBR

Ubuntu的MBR不見了,只剩下windows的MBR
1. 準備Ubuntu LiveCD
2. 利用Ubuntu LiveCD開機
3. 進入terminal
    # cd /
    # sudo -s -H
    # mount -t ext4 /dev/sda6 /mnt      ->sda6為Ubuntu所在的磁區
    # mount -t proc proc /mnt/proc
    # mount -t sysfs /sys /mnt/sys
    # mount -o bind /dev /mnt/dev
    # chroot /mnt /bin/bash         ->切換 root到硬碟上的Ubuntu

如果不知道Ubuntu在那一個磁區,查詢硬碟上的partition資訊    
    # ls -l /dev/disk/by-label
    # fdisk -l

安裝grub2
    # aptitude install grub2 grub-pc

如果已經安裝了grub,先移除
    # apt-get pruge grub

更新grub
   # update-grub
   # grub-install /dev/sda
   # reboot
恢復原先Ubuntu的grub

如果開機後,沒有任何開機選單,只出現
  grub >  -> 這代表沒有grub menu
  grub > find /boot/grub/core.img
  grub > root (hd0, 5)    -> root (hdx, y) previous command will tell you the x, y in this case is (hd0, 5)
  grub > kernel /boot/grub/core.img
  grub > boot
  現在可以進入Ubuntu 系統

如果開機會直接進入Ubuntu,沒有menu可以選擇要那個OS
   # update-grub
  讓 grub自動建立menu.list, 檔案位置在/boot/grub/menu.list
  grub2沒有menu.list,是grub.cfg, 檔案位置在/boot/grub/grub/cfg

2012年7月6日 星期五

git 相關

git error
fatal: unable to create 'abc/.git/index.lock' File exist.
If no other git process is currently running, this probably means a git process crashed in this repository earlier, Make sure no other git process is running and remove the file manual to continue.

Solution:
remove ../.git/index.lock
ex: rm -r ./.git/index.lock

git command
1. repo sync
2. repo start new_branch . (新增 branch)
3. git branch (確認branch狀態)
4. git branch -d branch_name( 刪除branch)
5. git diff > diff.txt ( 將有修改的檔名的不同處存下來)
6. git status (顯示所有有動變的檔案)
7. git commit -a
8. git show HEAD( show上一個commit 資訊)
9. repo upload . (實際上傳到server)

如果還要修改但還沒merge
1 git add .
2. git commit --amend
3. repo upload .

切換到別的branch
git checkout branch_name

將存下的 patch加入source code 之中(打 patch)
patch -R p1 < xxx.patch --dry-run

將檔案回歸到原始(server)狀態
git checkout -- filename

新增一個檔案
git add -p file_name(只加這一個檔案,有時路徑下有很多檔案修改,但只想上傳這一個)

新增 folder
git add folder_name(先新增folder, 才會出現此folder下的檔案)
PS. 如果新增一個空資料夾,必須在此資料夾加一個隱藏檔

取得git log並格式化
git log --pretty=format:"%h%x09%an%x09%ad%x09%s"



MSVCR100D.dll missing

MSVCR100D.dll missing
MS: Miscrosoft
V: visual
C: C++
R: Redistributable

Solution
Release:
1. in VS, project properity
2. configuration > C++ Generation
3. change to Multi-thread (/MT)

Debut:
1. same with release
2. change to Multi-thread Debug (/MTd)

Windows 8 相關

metro app execute directly(直接執行metro app)
1. VS2011 tool bar :
    Project > store > create app package > Build a package to use local only
2. There is added a folder "Packages" in Project, find file "Add-AppxDevPackage.bat",
    press mouse right key then select "Run as administrator".

Trun on or off windows features ( enable .net framework 3.5)
control panel >Programs > Programs Features > Turn windows Features on or off > check or uncheck Feature.

if Enable .Net Framework 3.5, but result is fail, then.

1. mount windows 8 image (XXX.iso)
2. find file inside \sources\sxs
3. copy *.* from \sources\sxs\*.* to a temp folder, ex: c:\net35\*.*
4. execute cmd.exe as administrator. (cmd.exe in c:\windows\system32\cmd.exe,  按右鍵,run as administrator)
5. type command in cmd.exe
    c:\windows\system32> Dism.exe /online /enable-feature /featurename:NetFX3 /All /Source:c:\net35 /LimitAccess
6. The result : The operation completed successfully.

Search files
搜尋含有特定文字的檔案.
ex: 'ABC' in *.txt

Ubuntu好用command

1. 將grep出來的文字replace
grep -rl matchstring somedir | xargs sed -i 's/string1/string2/g'
ex: grep -rl 'ABCD' * |xargs sed -i 's/ABCD/HEF/g'

2.將^M的換行符號拿掉
(1) sed  "s/\r//" dos_file  > dos_file_linux
(2) sed -i 's/\x0D$//' filename.txt

3. mount iso
sudo mount -t auto -o loop xxx.iso /mnt/iso

4. 安裝deb
 dpkg -i abc.deb

5. 轉換PNG到PPM
 (1) apt-get install netpnm
 (2) pngtopnm sample.png > linuxlogo.pnm
 (3) pnmquant 224 linuxlogo.pnm > linuxlogo224.pnm
 (4) pnmtoplainpnm linuxlogo224.pnm > linuxlogo_clut224.ppm

PS. 如果要取代原linux logo, replace driver/vide/logo下的原圖檔.

5. copy folder to server
scp -r folder_name user@10.109.109.109:/home/user_name/folder_name
ex: scp -r TVBox favoritepili@10.109.109.109:/home/favoritepili/

6. Download file from server
scp -r user@10.109.109.109:/home/user/folder /home/user
ex: scp -r favoritepili@10.109.109.109:/home/favoritepili/TVBox /home/favoritepili

7. unload driver
sduo modprobe -r vboxpci

8. list module
(1) lsmod | grep vbox
(2) modprobe -l | grep vbox

9. load module
modprobe vboxdrv