2013年10月29日 星期二

Centos 開機磁區重建

以往可能在一台電腦上安裝多個作業系統(例如CentOS+CentOS , CentOS+Windows)於不同硬碟上, 但開機的設定只能預設在一處, 當開機磁區移走時通常會遇到不能開機,以下Centos解法:
1. 找到安裝光碟
2. 以rescue mode開機, 並把原本Centos硬碟mount在/mnt/sysimage
    chroot /mnt/sysimage
    順便查一下kernel跟initrd的參數(版本)怎麼下, 可以參考原本/boot/grub/grub.conf的設定
    順便簡化它, 例如,如果指定kernel參數中root=指定/磁區, 可以把UUID改成識別符(/dev/sda3)
    如果/boot是獨立磁區, 要注意手動用grub開機的參數(見第4點說明)

3. 確定這顆Centos的硬碟的識別符是什麼(例如/dev/sda),重新安裝grub
    #grub-install /dev/sda
      Installation finished. No error reported.
      This is the contents of the device map /boot/grub/device.map.
      Check if this is correct or not. If any of the lines is incorrect,
      fix it and re-run the script `grub-install'.

      # this device map was generated by anaconda
      (hd0)     /dev/sda
 4. 此時重開機應該仍會找不到對應的開機磁區, 因為原本的grub.conf有問題,
     重開機後,會出現grub>的提示符, 假設原CentOS的磁區分配如下
     /dev/sda1    /boot
     /dev/sda2    swap
     /dev/sda3    /
    手動開機方式如下:
    grub>find //boot/grub/stage1    #尋找開機stage1的位置, 有時會不準, 尤其是/boot是獨立磁區
             (hd0,2)                           #在上面的磁區分配, 其實應該在(hd0,0)
    grub>root (hd0,0)                    #指定/boot分割區的位置
              Filesystem type is ext2fs, partition type 0x83
    grub>setup (hd0)                     #安裝開機程式(注意/boot分割區指定, 不然下次無法自動開機)
接下來如果要手動到把CentOS完全開機,就要載入kernel跟initramfs, 若不要重開機看看reboot
    grub>kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/sda3
    grub>initrd /initramfs-2.6.32-220.el6.x86_64.img
如果到這裡就沒反應,表示initrd的img檔不對, 回頭確認再試一次,(注意, 有些是initrd-2.6...)
    grub>boot
如果此時能開機成功, 回頭看一下/boot/grub/grub.conf的設定跟上面的一不一樣, 有錯的就改過來

2013年10月8日 星期二

nc - netcat TCP/UDP network testing tool

Client(10.108.2.2) ---- Server(10.108.1.1)

1. Listen as a TCP Server (IPv4)
    Server> nc -4 -l 1234

2. connect to a TCP Server (as TCP Client, IPv4)
    Client> nc -4 10.108.1.1 1234


3. Listen as a UDP Server (IPv4)
    Server> nc -4 -l -u 12345

4. connect to a UDP Server (as UDP Client, IPv4)
    Client> nc -4 -u 10.108.1.1 12345


<[outbound server] 172.16.43.100:1111>
                    +
                    |
                    +-Client(10.108.2.2) ---- Server(10.108.1.1)

5. Recieve and Listen as a TCP Server (IPv4, tcp to tcp)
    Server> nc -4 -l 1234

6. connect to a TCP Server (as TCP Client, IPv4)
    Client> nc -4 72.16.43.100 1111 | nc -4 10.108.1.1 1234


7. Recieve and Listen as a UDP Server (IPv4, tcp to udp)
    Server> nc -4 -l -u 12345

8. connect to a TCP Server (as TCP Client, IPv4)
    Client> nc -4 72.16.43.100 1111 | nc -4 -u 10.108.1.1 12345

udp to tcp
udp to udp
also fine

reference:http://blog.miniasp.com/post/2008/07/A-magic-command-netcat.aspx
                         http://www.thegeekstuff.com/2012/04/nc-command-examples/


文章分類