顯示具有 tiny server core 標籤的文章。 顯示所有文章
顯示具有 tiny server core 標籤的文章。 顯示所有文章

2013年1月3日 星期四

Linux KVM 魔法石 - Tiny Server Core 安裝與啟動


Tiny Server Core (TSC) 此微型 Linux 系統, 是由 Tiny Core Linux 發行套件重製而來. 它可直接透過 Linux 核心參數, 設定它的 IP, Default Gateway 及 DNS Server, 並還可決定是否啟動 NAT 功能, 如有雙網卡還會自動啟用靜態路由功能

在 Linux KVM 裸機系統中 (安裝 qemu-kvm 套件), 使用 Tiny Server Core 的操作步驟如下

1. 下載 Tiny Server Core 系統檔
在終端機模式下, 執行以下命令 :

$ wget http://tobala.net/download/kvmtsc.zip
--2013-01-03 11:15:23--  http://tobala.net/download/kvmtsc.zip
正在查找主機 tobala.net (tobala.net)... 69.89.27.215
正在連接 tobala.net (tobala.net)|69.89.27.215|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 16607224 (16M) [application/zip]
Saving to: `kvmtsc.zip'

100%[======================================>] 16,607,224  87.4K/s   in 2m 36s

2013-01-03 11:18:03 (104 KB/s) - `kvmtsc.zip' saved [16607224/16607224]

2. 解壓縮 kvmtsc.zip 至目前使用者的家目錄

$ unzip kvmtsc.zip
Archive:  kvmtsc.zip
  inflating: kvmtsc/tsc32.gz       
  inflating: kvmtsc/tsc64.gz       
  inflating: kvmtsc/vmlinuz32      
  inflating: kvmtsc/vmlinuz64

3. Tiny Server Core目錄 - kvmtsc

切換到 kvmtsc 目錄

$ cd kvmtsc   

在 kvmtsc 目錄中存放以下四個檔案

$ ls -alh
總計 16M
drwxrwxr-x  2 student student 4.0K  1月  3 11:18 .
drwxr-xr-x 35 student student 4.0K  1月  3 11:18 ..
-rw-rw-r--  1 student student 5.4M 11月 13 10:48 tsc32.gz
-rw-rw-r--  1 student student 5.5M 11月 13 10:48 tsc64.gz
-rw-rw-r--  1 student student 2.4M  7月  7 21:19 vmlinuz32
-rw-rw-r--  1 student student 2.7M  7月  7 21:43 vmlinuz64

32 位元系統 = vmlinuz32+tsc32.gz
64 位元系統 = vmlinuz64+tsc64.gz

4. 啟動 Tiny Server Core 系統
透過核心參數直接設定 IP, Default Gateway 及 DNS, 命令如下 :

$ kvm -m 128 -kernel vmlinuz32 -initrd tsc32.gz -append 'ipv4=172.16.100.19:255.255.255.0:172.16.100.254:168.95.1.1'

-append 這個參數的內容格式如下 :


"ipv4=IP:Subnet Mask:default Gateway:DNS IP"

TSC 系統啟動後畫面如下 :


在系統啟動畫面可以得知 TSC 系統的 IP 設為 172.16.100.19, default gateway 設為 172.16.100.254,  DNS Server 設為 168.95.1.1

2012年6月29日 星期五

重製 Tiny Core Linux 光碟


Tiny Core Linux 從 4.0 版開始, 共推出三個版本, 分別是 TinyCore, CorePlusCore. Core 這個版本並沒有提供桌面系統, 只提供文字命令模式, 因它具有系統擴充功能的能力, 可以輕易換裝扮演 網路設備(NAT, Router,..)應用伺服器 (Samba, Apache,...), 為了換裝方便, 必須重製 Core 的光碟檔, 使它具有儲存 "系統設定檔" 及 "應用伺服器套件檔" 的功能. 重製後的光碟檔, 為了與原發行套件做區別, 所以給它命名為 Tiny Server Core, 簡稱為 TSC.

重製 Core 光碟檔, 主要是針對 isolinux 這個 boot loader 的核心參數, 加入 tce=sda1 及 restore=sda1 這二個參數. 重製後的光碟檔, 一旦啟動如偵測到有一顆硬碟(必須有格式化), 它會自動將此硬碟設為 "系統設定檔 (bootlocal.sh,..)" 及 "應用伺服器套件檔 (*.tcz)" 的儲存裝置

重製操作步驟如下 :

1. 下載 Tiny Core Linux 的 Core 光碟檔 (32 位元)

http://distro.ibiblio.org/tinycorelinux/4.x/x86/release/Core-current.iso

2. 使用本文後面提供的 fromiso.sh 程式, 將 Core 光碟檔解開

$ sudo ./fromiso.sh ISO/Core-current.iso
[sudo] password for student:
/tmp/core
└── boot
    ├── core.gz
    ├── isolinux
    │   ├── boot.cat
    │   ├── boot.msg
    │   ├── f2
    │   ├── f3
    │   ├── f4
    │   ├── isolinux.bin
    │   └── isolinux.cfg
    └── vmlinuz

2 directories, 9 files

光碟解開的內容, 會存放在 /tmp/core 目錄中

3. 修改 isolinux 系統啟動設定檔 (isolinux.cfg), 命令如下 :

$ sudo nano /tmp/core/boot/isolinux/isolinux.cfg

display boot.msg
default microcore
label microcore
        kernel /boot/vmlinuz
        append initrd=/boot/core.gz quiet tce=sda1 restore=sda1

label mc
        kernel /boot/vmlinuz
        append initrd=/boot/core.gz quiet
implicit 0
prompt 1
timeout 300
F1 boot.msg
F2 f2
F3 f3
F4 f4

在 isolinux.cfg 設定檔中加入 "tce=sda1 restore=sda1" 這二個 Linux 系統核心參數, 這二個參數用來指定 "擴充套件" 及 "系統設定檔" 的儲存裝置 (/dev/sda1)

4. 使用本文後面提供toiso.sh 程式, 產生 Tiny Server Core 光碟檔

$ sudo ./toiso.sh
I: -input-charset not specified, using utf-8 (detected in locale settings)
Size of boot image is 4 sectors -> No emulation
Total translation table size: 2048
Total rockridge attributes bytes: 1301
Total directory bytes: 4096
Path table size(bytes): 38
Max brk space used 22000
4048 extents written (7 MB)

重製的光碟檔存放在 /tmp 目錄, 檔名為  tsc32.iso


fromiso.sh 程式內容如下 :

# 執行前檢查
[ "$USER" != "root" ] && echo "需要 root 權限" && exit 1

if [ -f "$1" ]; then
   mkdir /tmp/isotmp
   mount $1 /tmp/isotmp -o loop,ro &>/dev/null

   [ -d /tmp/core ] && rm -r /tmp/core

   mkdir /tmp/core
   cp -a /tmp/isotmp/boot /tmp/core &>/dev/null

   umount /tmp/isotmp &>/dev/null
   rm -r /tmp/isotmp

   # 顯示重製目錄內容
   tree /tmp/core
fi

toiso.sh 程式內容如下 :

# 執行前檢查
[ "$USER" != "root" ] && echo "需要 root 權限" && exit 1

if [ -d /tmp/core ]; then
   cd /tmp/
   mkisofs -o tsc32.iso -l -J -R -V Core-custom -no-emul-boot -boot-load-size 4 -b boot/isolinux/isolinux.bin -boot-info-table -c boot/isolinux/boot.cat core
fi