2010年4月8日 星期四

重建 GRUB (linux boot loader)

 方法一:

GRUB (GRand Unified Bootloader 縮寫) 是 linux 系統中常用的系統啟動軟體,另一個同功能的是 LILO (LInux LOader 縮寫),它的作用是接管 BIOS 交付控制權給作業系統時的第一個工作–把作業系統正確地從硬碟載入。通常一般使用者在用光碟裝完 linux 後,例如 ubuntu,系統就會自動裝好 GRUB,就像 Windows 系統一樣。然而如果有某種原因被毀損了,最常見的是在同個硬碟想有 dual system,先裝好 linux 再裝 Windows,Windows 會很不客氣毫不猶豫地直接蓋掉 GRUB,你的 linux 就此無法開機,這時就需要重建 GRUB 了…

如何重建 GRUB 的步驟如下:
  • 使用原來的 linux 安裝光碟開機。現代的系統都是 live-cd,即開機光碟 boot 完就是可操作的系統。
  • 開一個終端機程式,可以輸入命令。
  • 執行 sudo grub,回答密碼。
  • grub> find /boot/grub/stage1,它會找原來裝 GRUB 的硬碟分區,例如 (hd1,0),即第二個硬碟的第一個分區。
  • grub> root (hd1,0),告訴它 linux root 在哪裡。
  • grub> setup (hd0),安裝 GRUB 在第一個硬碟的 MBR (Master Boot Record)。把 Windows 的 bootloader 蓋掉… 之後可以在 GRUB menu 中加入進 Windows 系統的選項,本文不討論這個。
  • grub> quit,結束,這樣就完成 GRUB rebuild,可以 reboot 了。
另一作法是把 GRUB 安裝在硬碟分區裡,例如 grub> setup (hd1,0),安裝 GRUB 在第二個硬碟的第一個分區,而不是 MBR。這種方法可以使用 Windows 的 boot loader 來作 dual system 啟動.

Reference from  http://ying.homedns.org/wp/2007/11/283/

------------------------------------------------------------------------------------------------------------------------------------
 方法二:

用Ubuntu 9.10的Live CD試用Ubuntu啟動後,打開終端
sudo -i
sudo fdisk -l (查看你的分區信息)
# mount /dev/sdaX /mnt
sdaX,此處填寫 / 的位置

         # grub-install --root-directory=/mnt/ /dev/sda

最後
   
       # update-grub2

使用 Windows bootloader 來 load Linux

用 Windows 本身的 bootloader 來建立多系統的電腦


使用 Windows NT/2000/2003/XP 本身的 bootloader 來 dual boot 需要一個叫 bootpart 的程式,在這裡下載。另外要注意安裝 linux 時要把 GRUB 裝在 linux 的分區,而不是裝在 MBR。

bootpart 執行後可以看到類似下面的資料,是所有硬碟的 partition 列表,
C:\>bootpart
Boot Partition 2.60 for WinNT/2K/XP (c)1995-2005 G. Vollant (info@winimage.com)
WEB : http://www.winimage.com and http://www.winimage.com/bootpart.htm
Add partition in the Windows NT/2000/XP Multi-boot loader
Run "bootpart /?" for more information

Physical number of disk 0 : 96e096d
0 : C:* type=7  (HPFS/NTFS), size= 15358108 KB, Lba Pos=63
1 : C:  type=5  (Extended), size= 145476607 KB, Lba Pos=30716280
2 : C:  type=7   (HPFS/NTFS), size= 145476576 KB, Lba Pos=30716343
Physical number of disk 1 : f6568938
3 : D:* type=83  (Linux native), size= 19535008 KB, Lba Pos=63
4 : D:  type=5  (Extended), size= 2000092 KB, Lba Pos=39070080
5 : D:  type=82   (Linux swap), size= 2000061 KB, Lba Pos=39070143
找到裝有 linux 的 partition,如上面的 3,執行下面的命令:
C:\>bootpart 3 bootlnx.sec ubuntu
意思是建立一個叫 bootlnx.sec 檔名的檔案,用第三個 partition boot,並用 “ubuntu” 的名字加入 Windows bootloader 的選單。執行完了之後,產生一個 bootlnx.sec 檔案,並在 boot.ini 中加了最後一行:
[boot loader]
timeout=5
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows XP Media Center Edition" /noexecute=optin /fastdetect
C:\bootlnx.sec="ubuntu"
這樣就 ok 了,重開機會看到上面的兩個選項 “Windows XP Media Center Edition” 及 “ubuntu”。

Reference from http://ying.homedns.org/wp/2007/12/286/

Ubuntu 9.10 右邊數字鍵區失效

不知為何數字鍵區完全失效而無法輸入任何數字符號,相當不方便.

因此google一下網路上解決的方法

只要按 "shift + alt + NumLock"

就可恢復正常了.

UBUNTU 上安裝 SSH Server

Step 1: 安裝openssh-server

sudo apt-get install openssh-server

Step 2: 設定ssh_config內容

sudo vim /etc/ssh/sshd_config

Step 3:重新啟動SSH Server

sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start

UBUNTU 上安裝TFTP SERVER

Step 1: 安裝 tftpd package

    sudo apt-get install tftpd

Step 2: 視需要修改 /etc/inetd.conf中與 tftpd 有關的預設值

    tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp

Step 3:建立 /srv/tftp

    mkdir -p /srv/tftp
    chmod 777 /srv/tftp


Step 4:重新啟動 inetd

    /etc/init.d/openbsd-inetd restart

How to use simple speedtest in RaspberryPi CLI

  pi@ChunchaiRPI2:/tmp $  wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py --2023-06-26 10:4...