星期二, 9月 08, 2009

轉貼:『雲端』與『姆指電』-自行製作 OpenSolaris 開機姆指碟

找天來實作一下 ^___^


原文網址 http://blog.xuite.net/evereasy/solarpower/26486208




  • 前言


  • 一個可能在 Run PC 出現的問答-PC Run OpenSolaris:

    問:請問 OpenSolaris 在 PC 上也可以 Run 嗎?

    答:其實在 PC 上可以 Run 的作業系統有很多。大家都熟知的 Windows 當然是一種, Linux 當然也是一種,另外像 Solaris/OpenSolaris 其實也可以在 PC 上 RUN。 OpenSolaris 是一個像 Linux 一樣開放原始碼的作業系統。它也和 Linux 一樣提供有 LiveCD 或 LiveUSB 可以用光碟或 USB 開機。如果在姆指碟有開機的作業系統及儲存資料的空間,找到一台支援 USB 開機的 PC,您馬上可以有台比『小筆電』還炫的『姆指電』。配合未來的『雲端』環境,以後網咖只要提供『姆指電』的插槽,每個使用者都可以有個人開機的環境及『本地』和『雲端』的儲存空間。

    說到『雲端』與『姆指電』,今天是記者節,很幸運有機會訪問到 Chao-Chin Hung 大大。 Chao-Chin Hung 大大對『姆指電』可是研究了一段時間。不過因為我不是記者,因此您會看到的是我整理後的筆記而不是一問一答實況報導的訪問記錄。有那麼一點點抱歉...

    以下是採訪 Chao-Chin Hung 大大的記實:

  • 空間規劃使用


  • 我們的計劃是在姆指碟上有一個區域是用來存放開機用的 Live USB 影像,另外有兩個區域是 ZFS 及 FAT32 用來存放資料。基於一些可能的限制,我們將 FAT32 放在第一個分割。在姆指碟上分成兩個分割(Partition),分別是 FAT32 及 Soalris 2。在 Solaris2 中再分為兩個切片(Slice),分別為 UFS 及 ZFS 的檔案系統。其中切片 0 使用 UFS 檔案系統,而切片 1 使用 ZFS 檔案系統。

    MBR
    P1: FAT32
    P2: Solaris 2
    S0: UFS, Live USB
    S1: ZFS, Home

    對於空間大小的規劃則為:Live USB 1.5GB,ZFS 0.5GB,其餘的則保留給 FAT32。

  • 取得適當的 USB 影像檔
    1. 直接下載,目前 OpenSolaris 的安裝下載網址通常都提供了 ISO 及 USB 兩種格式的選擇。
    2. 自行製作,這個部份也許下次有機會採訪 Chao-Chin Hung 大大時再報導。


  • 可以使用以下幾種方式取得姆指碟的影像檔:


  • 安裝複製 USB 影像檔的工具


  • 參考以下的程序安裝 Distribution Constructor,以便使用 usbcopy 工具:
    root@X-Wing:~ # pkg install SUNWdistro-const
    DOWNLOAD                                  PKGS       FILES    XFER (MB)
    Completed                                  1/1       75/75      0.2/0.2
    
    PHASE                                        ACTIONS
    Install Phase                                106/106
    root@X-Wing:~ # pkg list SUNWdistro-const
    NAME (PUBLISHER)                              VERSION         STATE      UFIX
    SUNWdistro-const                              0.5.11-0.118    installed  u---
                
  • 確認姆指碟運作正常


  • 在將 USB 姆指碟插入電腦之後檢查是否偵測到設備:
    root@X-Wing:~ # rmformat
    正在尋找裝置...
         1. Logical Node: /dev/rdsk/c3t0d0p0
            Physical Node: /pci@0,0/pci1179,1@1a,7/storage@1/disk@0,0
            Connected Device: USB      Flash Disk       5.00
            Device Type: Removable
    Bus: USB
    Size: 4.0 GB
    Label: 
    Access permissions: 媒體沒有寫入保護。
                
  • 檢查目前的磁碟分割方式


  • 使用 fdisk 指令可檢視目前姆指碟的現況:
    root@X-Wing:~ # fdisk /dev/rdsk/c3t0d0p0
                 Total disk size is 509 cylinders
                 Cylinder size is 16065 (512 byte) blocks
    
                                                   Cylinders
          Partition   Status    Type          Start   End   Length    %
          =========   ======    ============  =====   ===   ======   ===
              1                 Ext Win95         0   379     380     75
              2       Active    Solaris2        380   508     129     25
    
    
    
    
    SELECT ONE OF THE FOLLOWING:
       1. Create a partition
       2. Specify the active partition
       3. Delete a partition
       4. Change between Solaris and Solaris2 Partition IDs
       5. Exit (update disk configuration and exit)
       6. Cancel (exit without updating disk configuration)
    Enter Selection: 6
                
    記錄下來一個磁柱的大小(有多少個區塊)。

  • 檢查是否掛載此一姆指碟


  • 確認目前並無掛載此一姆指碟上的分割或切片,若有則進行卸載:
    root@X-Wing:~ # mount -p | grep c3t0d0
    /dev/dsk/c3t0d0s0 - /media/Flash Disk ufs - no rw,nosuid,intr,largefiles,logging,xattr,onerror=panic
    /dev/dsk/c3t0d0p0:1 - /media/EVEREASY pcfs - no nosuid,hidden,nofoldcase,clamptime,noatime,timezone=-28800
    root@X-Wing:~ # umount /dev/dsk/c3t0d0s0
    root@X-Wing:~ # umount /dev/dsk/c3t0d0p0:1
                
  • 清除姆指碟


  • 清除姆指碟的第一個磁柱:
    root@X-Wing:~ # dd if=/dev/zero of=/dev/rdsk/c3t0d0p0 bs=512 count=16065
    進來 16065+0 個記錄
    出去 16065+0 個記錄
                
  • 劃分磁區分割


  • 參考以下程序劃出 FAT32 及 SOLARIS2 的分割:
    root@X-Wing:~ # fdisk /dev/rdsk/c3t0d0p0
    No fdisk table exists. The default partition for the disk is:
    
      a 100% "SOLARIS System" partition
    
    Type "y" to accept the default partition,  otherwise type "n" to edit the
     partition table. n
    
                 Total disk size is 1998 cylinders
                 Cylinder size is 4096 (512 byte) blocks
    
                                                   Cylinders
          Partition   Status    Type          Start   End   Length    %
          =========   ======    ============  =====   ===   ======   ===
    
    
    
    
    WARNING: no partitions are defined!
    
    SELECT ONE OF THE FOLLOWING:
       1. Create a partition
       2. Specify the active partition
       3. Delete a partition
       4. Change between Solaris and Solaris2 Partition IDs
       5. Exit (update disk configuration and exit)
       6. Cancel (exit without updating disk configuration)
    Enter Selection: 1
    
    Select the partition type to create:
       1=SOLARIS2  2=UNIX        3=PCIXOS     4=Other
       5=DOS12     6=DOS16       7=DOSEXT     8=DOSBIG
       9=DOS16LBA  A=x86 Boot    B=Diagnostic C=FAT32
       D=FAT32LBA  E=DOSEXTLBA   F=EFI        0=Exit? C
    
    Specify the percentage of disk to use for this partition
    (or type "c" to specify the size in cylinders). 50
    
    Should this become the active partition? If yes, it  will be activated
    each time the computer is reset or turned on.
    Please type "y" or "n". n
    
    Select the partition type to create:
       1=SOLARIS2  2=UNIX        3=PCIXOS     4=Other
       5=DOS12     6=DOS16       7=DOSEXT     8=DOSBIG
       9=DOS16LBA  A=x86 Boot    B=Diagnostic C=FAT32
       D=FAT32LBA  E=DOSEXTLBA   F=EFI        0=Exit? 1
    
    Specify the percentage of disk to use for this partition
    (or type "c" to specify the size in cylinders). 49
    
    Should this become the active partition? If yes, it  will be activated
    each time the computer is reset or turned on.
    Please type "y" or "n". y
    
    Partition 2 is now the active partition.
    
                 Total disk size is 1998 cylinders
                 Cylinder size is 4096 (512 byte) blocks
    
                                                   Cylinders
          Partition   Status    Type          Start   End   Length    %
          =========   ======    ============  =====   ===   ======   ===
              1                 Win95 FAT32       1   999     999     50
              2       Active    Solaris2       1000  1978     979     49
    
    
    
    
    SELECT ONE OF THE FOLLOWING:
       1. Create a partition
       2. Specify the active partition
       3. Delete a partition
       4. Change between Solaris and Solaris2 Partition IDs
       5. Exit (update disk configuration and exit)
       6. Cancel (exit without updating disk configuration)
    Enter Selection: 5
                
  • 劃分磁區切片


  • 參考以下程序劃出切片(slice) 0 及 切片(slice) 1:
    root@X-Wing:~ # format -e
    Searching for disks...done
    
    
    AVAILABLE DISK SELECTIONS:
           0. c3t0d0 
              /pci@0,0/pci1179,1@1a,7/storage@1/disk@0,0
           1. c4t0d0   HD-0160G
              /pci@0,0/pci1179,1@1f,2/disk@0,0
           2. c4t1d0   HD-0250G
              /pci@0,0/pci1179,1@1f,2/disk@1,0
    Specify disk (enter its number): 0
    selecting c3t0d0
    [disk formatted]
    
    
    FORMAT MENU:
            disk       - select a disk
            type       - select (define) a disk type
            partition  - select (define) a partition table
            current    - describe the current disk
            format     - format and analyze the disk
            fdisk      - run the fdisk program
            repair     - repair a defective sector
            label      - write label to the disk
            analyze    - surface analysis
            defect     - defect list management
            backup     - search for backup labels
            verify     - read and display labels
            save       - save new disk/partition definitions
            inquiry    - show vendor, product and revision
            scsi       - independent SCSI mode selects
            cache      - enable, disable or query SCSI disk cache
            volname    - set 8-character volume name
            !     - execute , then return
            quit
    format> partition
    
    
    PARTITION MENU:
            0      - change `0' partition
            1      - change `1' partition
            2      - change `2' partition
            3      - change `3' partition
            4      - change `4' partition
            5      - change `5' partition
            6      - change `6' partition
            7      - change `7' partition
            9      - change `9' partition
            select - select a predefined table
            modify - modify a predefined partition table
            name   - name the current table
            print  - display the current table
            label  - write partition map and label to the disk
            ! - execute , then return
            quit
    partition> print
    Current partition table (original):
    Total disk cylinders available: 977 + 2 (reserved cylinders)
    
    Part      Tag    Flag     Cylinders       Size            Blocks
      0 unassigned    wm       0              0         (0/0/0)         0
      1 unassigned    wm       0              0         (0/0/0)         0
      2     backup    wu       0 - 976        1.91GB    (977/0/0) 4001792
      3 unassigned    wm       0              0         (0/0/0)         0
      4 unassigned    wm       0              0         (0/0/0)         0
      5 unassigned    wm       0              0         (0/0/0)         0
      6 unassigned    wm       0              0         (0/0/0)         0
      7 unassigned    wm       0              0         (0/0/0)         0
      8       boot    wu       0 -   0        2.00MB    (1/0/0)      4096
      9 unassigned    wm       0              0         (0/0/0)         0
    
    partition> 0
    Part      Tag    Flag     Cylinders       Size            Blocks
      0 unassigned    wm       0              0         (0/0/0)         0
    
    Enter partition id tag[unassigned]: root
    Enter partition permission flags[wm]: wm
    Enter new starting cyl[1]: 1
    Enter partition size[0b, 0c, 1e, 0.00mb, 0.00gb]: 1.5gb
    partition> print
    Current partition table (unnamed):
    Total disk cylinders available: 977 + 2 (reserved cylinders)
    
    Part      Tag    Flag     Cylinders       Size            Blocks
      0       root    wm       1 - 768        1.50GB    (768/0/0) 3145728
      1 unassigned    wm       0              0         (0/0/0)         0
      2     backup    wu       0 - 976        1.91GB    (977/0/0) 4001792
      3 unassigned    wm       0              0         (0/0/0)         0
      4 unassigned    wm       0              0         (0/0/0)         0
      5 unassigned    wm       0              0         (0/0/0)         0
      6 unassigned    wm       0              0         (0/0/0)         0
      7 unassigned    wm       0              0         (0/0/0)         0
      8       boot    wu       0 -   0        2.00MB    (1/0/0)      4096
      9 unassigned    wm       0              0         (0/0/0)         0
    
    partition> 1
    Part      Tag    Flag     Cylinders       Size            Blocks
      1 unassigned    wm       0              0         (0/0/0)         0
    
    Enter partition id tag[unassigned]: home
    Enter partition permission flags[wm]: wm
    Enter new starting cyl[1]: 769
    Enter partition size[4096b, 1c, 769e, 2.00mb, 0.00gb]: 976e
    partition> print
    Current partition table (unnamed):
    Total disk cylinders available: 977 + 2 (reserved cylinders)
    
    Part      Tag    Flag     Cylinders       Size            Blocks
      0       root    wm       1 - 768        1.50GB    (768/0/0) 3145728
      1       home    wm     769 - 976      416.00MB    (208/0/0)  851968
      2     backup    wu       0 - 976        1.91GB    (977/0/0) 4001792
      3 unassigned    wm       0              0         (0/0/0)         0
      4 unassigned    wm       0              0         (0/0/0)         0
      5 unassigned    wm       0              0         (0/0/0)         0
      6 unassigned    wm       0              0         (0/0/0)         0
      7 unassigned    wm       0              0         (0/0/0)         0
      8       boot    wu       0 -   0        2.00MB    (1/0/0)      4096
      9 unassigned    wm       0              0         (0/0/0)         0
    
    partition> label
    [0] SMI Label
    [1] EFI Label
    Specify Label type[0]: 0
    Ready to label disk, continue? y
    
    partition> quit
    
    
    FORMAT MENU:
            disk       - select a disk
            type       - select (define) a disk type
            partition  - select (define) a partition table
            current    - describe the current disk
            format     - format and analyze the disk
            fdisk      - run the fdisk program
            repair     - repair a defective sector
            label      - write label to the disk
            analyze    - surface analysis
            defect     - defect list management
            backup     - search for backup labels 
            verify     - read and display labels
            save       - save new disk/partition definitions
            inquiry    - show vendor, product and revision
            scsi       - independent SCSI mode selects
            cache      - enable, disable or query SCSI disk cache
            volname    - set 8-character volume name
            !     - execute , then return
            quit
    format> quit
                
  • 格式化 FAT32 的分割


  • 格式化並且將 OpenSoarlis 的 ISO 檔案複製進來,這樣可以隨時將它分享給別人:
    root@X-Wing:~ # mkfs -F pcfs -o fat=32,b=Data /dev/rdsk/c3t0d0p0:c
    在 /dev/rdsk/c3t0d0p0:c 上建構新的 FAT 檔案系統:(y/n)?y
    root@X-Wing:~ # mount -F pcfs /dev/dsk/c3t0d0p1 /mnt
    root@X-Wing:~ # df -h /mnt
    檔案系統               大小   用過   可用 容量      裝載至
    /dev/dsk/c3t0d0p1      1.9G     0K   1.9G     1%    /mnt
    root@X-Wing:~ # cp -p /moon/ISOs/osol-1002-121-x86.iso /mnt
    root@X-Wing:~ # df -h /mnt
    檔案系統               大小   用過   可用 容量      裝載至
    /dev/dsk/c3t0d0p1      1.9G   741M   1.2G    38%    /mnt
    root@X-Wing:~ # umount /mnt
                
  • 建立 ZFS 的儲存池


  • 使用 ZFS 的指令建立一個名叫 venus 的儲存池:
    root@X-Wing:~ # zpool create -f venus c3t0d0s1
    root@X-Wing:~ # zpool list venus 
    NAME    SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
    venus   408M  76.5K   408M     0%  ONLINE  -
    root@X-Wing:~ # zpool export venus
                
  • 修改 /usr/bin/usbcopy 檔案


  • 針對原版的 usbcopy 做了以下幾個修改:
    - 由於 usbcopy 在 zh_TW.UTF-8 的 locale 無法正常執行(在複製影像檔的程式段會有問題),因此加入語言環境變數的設定。
    - 說明會將姆指碟的 Solaris 分割中的切片0覆寫
    - 不執行劃分磁區分割
    - 不執行劃分磁區切片
    - 增加擴大 UFS 檔案系統的動作

    以下為原始版本(/usr/bin/usbcopy)及修改版本(/usr/bin/usbcopy.s0)的差異:
    root@X-Wing:~ # diff /usr/bin/usbcopy /usr/bin/usbcopy.s0;
    25a26,29
    > # Make sure we get the right locale environment
    > LANG=C; export LANG
    > LC_ALL=C; export LC_ALL
    >
    122c126
    <        echo WARNING: All data on your USB storage will be lost.
    ---
    >        echo WARNING: All data on your USB storage\'s Solaris partition slice 0 will be lost.
    151,152c155,156
    < # Install fdisk table with Solaris using entire disk, default VTOC
    < fdisk -B $dev
    ---
    > # # Install fdisk table with Solaris using entire disk, default VTOC
    > # fdisk -B $dev
    154,169c158,173
    < # Now create root partition.  We want to find number of cylinders in backup
    < # partition from label created by fdisk -B and then generate root partition
    < # using whole disk minus cylinder 1
    < acyls=$(prtvtoc $dev | awk '/accessible/{print $2}')
    < cyls=$((acyls - 1))
    < format -e $dev >/dev/null << partition
    < 0
    < root
    < wm
    < 1
    < ${cyls}c
    < label
    < 0
    < y
    < EOF
    ---
    > # # Now create root partition.  We want to find number of cylinders in backup
    > # # partition from label created by fdisk -B and then generate root partition
    > # # using whole disk minus cylinder 1
    > # acyls=$(prtvtoc $dev | awk '/accessible/{print $2}')
    > # cyls=$((acyls - 1))
    > # format -e $dev >/dev/null < # partition
    > # 0
    > # root
    > # wm
    > # 1
    > # ${cyls}c
    > # label
    > # 0
    > # y
    > # EOF
    223a228,230
    > # Resize the UFS filesystem to the allocated slice size
    > /usr/sbin/growfs $s0cdev
    >
                
  • 複製 USB 影像檔到姆指碟


  • 利用以下指令將 USB 影像檔複製到姆指碟:
    root@X-Wing:~ # usbcopy.s0 /moon/ISOs/osol-1002-121-x86.usb
    Found the following USB devices:
    0: /dev/rdsk/c3t0d0p0 4.0 GB USB      Flash Disk       5.00
    Enter the number of your choice: 0
    
    WARNING: All data on your USB storage's Solaris partition slice 0 will be lost.
    Are you sure you want to install to
    USB Flash Disk 5.00, 4000 MB at /dev/dsk/c3t0d0p0 ?  (y/n) y
    Copying and verifying image to USB device
    Finished 889 MB in 182 seconds (4.8MB/s)
    0 block(s) re-written due to verification failure
    Warning: 72 sector(s) in last cylinder unallocated
    /dev/rdsk/c3t0d0s0: 3145728 sectors in 5243 cylinders of 1 tracks, 600 sectors
    1536.0MB in 328 cyl groups (16 c/g, 4.69MB/g, 2240 i/g)
    super-block backups (for fsck -F ufs -o b=#) at:
     32, 9632, 19232, 28832, 38432, 48032, 57632, 67232, 76832, 86432,
    Initializing cylinder groups:
    ......
    super-block backups for last 10 cylinder groups at:
     3052832, 3062432, 3072032, 3081632, 3091232, 3100832, 3110432, 3120032,
     3129632, 3139232
    Installing grub to USB device /dev/rdsk/c3t0d0s0
    Completed copy to USB
                
  • 結語


  • 終於製作好了!那?就用它來開機咯。當然您也可以發揮更多的創意..

    星期二, 9月 01, 2009

    SLES 11 First Class 上課小記

    當初 SLES 11 First Class 的一些小記

    Cluster 名稱  = iscsi  的 LUN  名稱
    上課練習的 主機是 SLED11 , 所以要開 IP_Forward
    另外有關於xen guest 主機不能連接
    • #brctl  addbr  br0
    • #brctl  addif  bro  eth0
    • #yast  network    restart
    • #yast  network    restart
    • #brctl  showstp  bro
    • 檢查 state forwarding

    iscsi 與 NFS 差異
    • NFS Server 決定讀寫
    • iscsi TARGET 不能決定讀寫
    • 由 iscsi connect 來決定及讀寫