顯示具有 FreeBSD 標籤的文章。 顯示所有文章
顯示具有 FreeBSD 標籤的文章。 顯示所有文章

2012-12-01

FreeBSD Disk Label

FreeBSD 中習慣用 label 來幫硬碟加上標籤,好處是方便硬碟移來移去,尤其是系統碟換到不同主機或 sata port 時不需要再改 fstab (ad、da、ada)。另外會貼標籤在硬碟上註明 label (實體化),硬碟壞掉時要換也比較好找。

在已安裝好的系統中記下要 label 的 partition,此例中 root 為 /dev/ada1p2,swap 為 /dev/ada1p3 (註: 現在都很懶,直接整顆硬碟切一個 partition 安裝)
# gpart show ada1
=>       34  625142381  ada1  GPT  (298G)
         34        128     1  freebsd-boot  (64k)
        162  616562560     2  freebsd-ufs  (294G)
  616562722    8388608     3  freebsd-swap  (4.0G)
  624951330     191085        - free -  (93M)
要 label root 與 swap 需重開機進入單人模式
#glabel label system /dev/ada1p2
#glabel label swap /dev/ada1p3
用 glabel 命名的會在 /dev/label 底下。修改 fstab
# Device        Mountpoint      FStype  Options Dump    Pass#
/dev/label/system       /               ufs     rw      1       1
/dev/label/swap         none            swap    sw      0       0
新硬碟的話習慣用 gpart -l 來加上 label,命名後會在 /dev/gpt 底下
#dd if=/dev/zero of=/dev/ada5 bs=1m count=1
#gpart create -s gpt ada5
ada5 created
#gpart add -b 2048 -l h10x01 -t freebsd-ufs ada5
ada5p1 added
#glabel status|grep gpt
gpt/h10x01     N/A  ada5p1

ZFS send/receive & rsync

用 rsync 在兩組六顆硬碟的 raidz2 複製資料時發現速度很慢,根據之前的經驗 cpu 夠力的話不該這麼慢。觀察 cpu 與 disk 狀態:
  PID USERNAME  THR PRI NICE   SIZE    RES STATE   C   TIME   WCPU COMMAND
   11 root        4 155 ki31     0K    64K RUN     3  98:09 321.09% idle
 1430 root        1  43    0 70468K  5136K CPU3    3   0:15 31.40% rsync
 1428 root        1  42    0 66372K  5084K select  1   0:16 31.30% rsync
    0 root      308  -8    0     0K  4928K -       1   0:20 15.04% kernel
               capacity     operations    bandwidth
pool        alloc   free   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank1       6.96G  10.9T      2      0  12.0K      0
tank2       10.7T   183G    695      0  85.7M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.96G  10.9T      0      0      0      0
tank2       10.7T   183G    769      0  95.6M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.96G  10.9T      0      0      0      0
tank2       10.7T   183G    776      0  96.2M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.96G  10.9T      0     70      0  8.61M
tank2       10.7T   183G    712      0  88.4M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.96G  10.9T      0  3.39K      0   424M
tank2       10.7T   183G    781      0  96.9M      0
不知道為什麼沒有邊讀邊寫,且讀的速度實在是有點慢... 改用 zfs send/receive 看看
  PID USERNAME  THR PRI NICE   SIZE    RES STATE   C   TIME   WCPU COMMAND
   11 root        4 155 ki31     0K    64K RUN     3  34.1H 270.70% idle
    0 root      307  -8    0     0K  4912K -       0 378:49 79.44% kernel
 2937 root        1  27    0 33548K  2820K CPU3    0   0:09 12.89% zfs
 2936 root        1  25    0 33548K  2740K pipelk  3   0:06  8.59% zfs
               capacity     operations    bandwidth
pool        alloc   free   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank1       5.58G  10.9T     18  1.64K   127K   197M
tank2       10.3T   582G  1.56K      0   197M  3.27K
----------  -----  -----  -----  -----  -----  -----
tank1       6.19G  10.9T      0  3.15K      0   391M
tank2       10.3T   582G  2.34K      0   297M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.19G  10.9T      0  2.44K      0   304M
tank2       10.3T   582G  2.17K      0   276M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.81G  10.9T      0  1.05K      0   116M
tank2       10.3T   582G  1.95K      0   247M      0
----------  -----  -----  -----  -----  -----  -----
tank1       6.81G  10.9T      0  3.47K      0   427M
tank2       10.3T   582G  2.63K      0   334M      0
速度快了不少,最後 7TB 的資料花了九小時才複製完 @@
receiving full stream of tank2/data@2012-11-22 into tank1/data@2012-11-22
                received 6.88TB stream in 32266 seconds (224MB/sec)

ZFS with Advanced Format (4k sector) Drives

一組六顆 1.5T 硬碟的 raidz2 掛了兩顆 WD 1.5T,現在 1.5T 不好買且不划算,乾脆全都換成 2T。之前看人討論有沒有對齊 4k 似乎是沒什麼影響,反正新入手的硬碟都是 4k sector,那就用 4k 的做法吧。

依序建 disk0~5
#gpart create -s gpt da0
#gpart add -t freebsd-zfs -l disk0 -b 2048 -a 4k da0
對其中一顆建 4k nop 後再建 pool,zfs 會以 disk 中 sector 最大值建立 pool
#gnop create -S 4096 /dev/gpt/disk0
#zpool create tank raidz2 /dev/gpt/disk0.nop /dev/gpt/disk[1-5]
export pool 後刪掉 nop 再 import
# zpool export tank
# gnop destroy /dev/gpt/disk0.nop
# zpool import -d /dev/gpt tank 
查看 ashift 是否為 12 (2^12 = 4096)
#zdb tank|grep ashift
         ashift: 12

2012-10-19

ZFS import labeled disk

把某台主機的 ZFS Raidz2 export 後到別台 import 時發現原本已 label 命名的 disk 都變回代號。
# zpool import tank1
# zpool status tank1
  pool: tank1
 state: ONLINE
 scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        tank1       ONLINE       0     0     0
          raidz2-0  ONLINE       0     0     0
            da2p1   ONLINE       0     0     0
            da3p1   ONLINE       0     0     0
            da1p1   ONLINE       0     0     0
            da0p1   ONLINE       0     0     0
            ada0p1  ONLINE       0     0     0
            ada1p1  ONLINE       0     0     0

errors: No known data errors

查了手冊發現可以加上 -d 指定要尋找的目錄。
# zpool import -d /dev/label tank1 
# zpool status tank1
  pool: tank1
 state: ONLINE
 scan: none requested

config:

        NAME              STATE     READ WRITE CKSUM
        tank1             ONLINE       0     0     0
          raidz2-0        ONLINE       0     0     0
            label/s15x01  ONLINE       0     0     0
            label/s15x02  ONLINE       0     0     0
            label/s15x03  ONLINE       0     0     0
            label/s15x04  ONLINE       0     0     0
            label/s20x05  ONLINE       0     0     0
            label/h15x01  ONLINE       0     0     0

errors: No known data errors
這樣 label 就都回來了。

2010-07-15

Dell Perc 6/i on FreeBSD

要跑 zfs 的主機還得等上一段時間才會到,先買了張便宜又大碗的 Dell Perc 6i 來用。

環境
CPU:Intel P4 3.0GHz
RAM:512MB DDR2 x 2
MB:Supermicro PDSLA
HDD:Hitach 1TB (7K1000.B) x 4
OS:FreeBSD 8.0R i386

安裝 megacli
#cd /usr/ports/sysutils/linux-megacli/ && make  install clean
會出現須自行至 LSI 下載檔案到 /usr/ports/distfiles,下載完後若沒 load linux kernel module 記得先 kldload linux 後再 make (忘記沒 load 的話編到哪裡會出錯)。編完後照著說明編輯 loader.conf、sysctl.conf、fstab 等檔案。megacli 指令可參考 Managing PERC 6 with MegaCli under Solaris 10 或是 MegaCLI cheat sheet

Raid 5 效能測試
# diskinfo -t /dev/mfid0
/dev/mfid0
        512             # sectorsize
        2998960914432   # mediasize in bytes (2.7T)
        5857345536      # mediasize in sectors
        364602          # Cylinders according to firmware.
        255             # Heads according to firmware.
        63              # Sectors according to firmware.

Seek times:
        Full stroke:      250 iter in   1.556091 sec =    6.224 msec
        Half stroke:      250 iter in   2.696059 sec =   10.784 msec
        Quarter stroke:   500 iter in   4.767586 sec =    9.535 msec
        Short forward:    400 iter in   2.793659 sec =    6.984 msec
        Short backward:   400 iter in   2.692022 sec =    6.730 msec
        Seq outer:       2048 iter in   0.417360 sec =    0.204 msec
        Seq inner:       2048 iter in   0.404697 sec =    0.198 msec
Transfer rates:
        outside:       102400 kbytes in   0.682351 sec =   150069 kbytes/sec
        middle:        102400 kbytes in   0.669891 sec =   152861 kbytes/sec
        inside:        102400 kbytes in   0.694164 sec =   147516 kbytes/sec
# bonnie -d /mnt -s 128
-------Sequential Output-------- ---Sequential Input-- --Random--
 -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
   MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
128 103562 99.9 221013 62.2 278379 85.6 101971 100.0 772229 100.0 35227.1 103.7
# bonnie -d /mnt -s 4096
-------Sequential Output-------- ---Sequential Input-- --Random--
 -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
   MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
  4096 97948 98.9 225527 69.2 70188 24.7 87023 95.1 191095 31.3 263.1  1.3
因為卡上有 256MB 的 cache 加上有裝電池可以開啟 write back,所以 128MB 的測試根本是爆表的快,不過 4GB 的測試結果也不錯。從 win7 上的 SSD 透過 samba (Gb網路) 寫入 2GB 檔案速度大都維持在 90~100MB/s。本來還想測 rebuild 時間,但剛裝好後的 background initialization 大約 10 分鐘才跑 1%,看到要這麼久就放棄了。後來查到可以透過 megacli –adpsetprop 來設定 RebuildRate 和 BgiRate,馬上將它設定成 100% (預設是 30%),反正遇到硬碟壞掉一定是停止檔案服務全速重建 raid。

2010-06-09

FreeBSD zfs performance

昨天用五年前主機測出的數據實在是很失望,調整 zfs 參數後寫入最多也只能跑到 35MB/s,今天換台主機測看看。

測試環境:
CPU:Intel Core 2 Duo E8400
RAM:2GB DDR2 x 3
MB:Gigabyte GA-EP45-UD3P
HDD:Hitach 1TB (7K1000.B) x 4
OS:FreeBSD 8.0R amd64

/boot/loader.conf
ahci_load="YES"
vm.kmem_size_max="1024M"
vm.kmem_size="1024M"
vfs.zfs.arc_max="100M" 
直接將昨天在別台主機建的 pool 裝上
# zpool import -f tank
測試
# dd if=/dev/zero of=/home/dslab/data/test bs=1m count=4000
4000+0 records in
4000+0 records out
4194304000 bytes transferred in 30.429420 secs (137837133 bytes/sec)

# dd if=/home/dslab/data/test of=/dev/null bs=1m
4000+0 records in
4000+0 records out
4194304000 bytes transferred in 22.393339 secs (187301412 bytes/sec)

# bonnie -d /home/dslab/data -s 4096 -m zfs
              -------Sequential Output-------- ---Sequential Input-- --Random--
              -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
Machine    MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
zfs      4096 79500 44.1 106960 20.8 60252 12.9 155730 70.2 170719 13.6 121.5  0.5
zfs      4096 78294 42.9 108320 20.8 58735 13.0 145792 64.4 167522 13.2 118.4  0.5
應該不用多說什麼了... 準備買新主機!!

FreeBSD zfs raidz

環境:P4 3.0GHz、2GB Ram、FreeBSD 8.0R i386、Hitachi 1TB x4

開機啟動 zfs
#echo 'zfs_enable="YES"' >> /etc/rc.conf 
設定參數 (參考 ZFSTuningGuide)
#ee /boot/loader.conf
vm.kmem_size="330M"
vm.kmem_size_max="330M"
vfs.zfs.arc_max="40M"
vfs.zfs.vdev.cache.size="5M"
初始化硬碟 (ad4、ad6、ad8、ad10)
#dd if=/dev/zero of=/dev/ad4 bs=1m count=1 
#fdisk -I /dev/ad4
#glabel label radz11 /dev/ad4s1
建立 raidz pool 並察看
#zpool create tank raidz /dev/label/raidz11 /dev/label/raidz12 /dev/label/raidz13 /dev/label/raidz14 
#zpool status tank
pool: tank
state: ONLINE
scrub: none requested
config:
        NAME               STATE     READ WRITE CKSUM
        tank               ONLINE       0     0     0
         raidz1           ONLINE       0     0     0
            label/raidz11  ONLINE       0     0     0
            label/raidz12  ONLINE       0     0     0
            label/raidz13  ONLINE       0     0     0
            label/raidz14  ONLINE       0     0     0

errors: No known data errors

#df -H
Filesystem     Size    Used   Avail Capacity  Mounted on
tank           2.9T    0B      2.9T  0%           /tank

# zpool list
NAME   SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
tank   3.64T   630K  3.64T     0%    ONLINE  -
建立 mount point
#zfs set mountpoint=/home/dslab/data tank/data
#df -H
Filesystem     Size    Used   Avail Capacity  Mounted on
tank/data      2.9T      0B    2.9T     0%         /home/dslab/data
tank           2.9T      0B    2.9T     0%         /tank
測試讀寫效能
#dd if=/dev/zero of=/home/dslab/data/test bs=1m count=4000
4000+0 records in
4000+0 records out
4194304000 bytes transferred in 108.070644 secs (38810762 bytes/sec)

#dd if=/home/dslab/data/test of=/dev/null bs=1m
4000+0 records in
4000+0 records out
4194304000 bytes transferred in 33.516918 secs (125139907 bytes/sec)

#bonnie -d /home/dslab/data -s 4096 -m zfs
              -------Sequential Output-------- ---Sequential Input-- --Random--
              -Per Char- --Block--- -Rewrite-- -Per Char- --Block--- --Seeks---
Machine    MB K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU K/sec %CPU  /sec %CPU
zfs      4096 25813 36.6 33618 17.0 22683 11.5 44180 53.0 81775 15.9 107.6  1.0

結果不是很理想,應該是 cpu 不夠力。

WD15EARS on FreeBSD

看硬碟盒子中附的說明寫著 windows 之外的系統之接插上就可以用,不過還是去找了資料,最簡單的應該是用 gpart 吧。
#gpart create -s GPT ad10
ad10 created
#gpart show ad10
=>   34  2930277101  ad10  GPT  (1.4T)
     34  2930277101        - free -  (1.4T)
4k = 512x8,所以接著由 40 開始
#gpart add -b 40 -s 2930277095 -t freebsd-ufs ad10
ad10p1 added
# gpart show ad10
=>   34  2930277101  ad10  GPT  (1.4T)
     34           6        - free -  (3.0K)
     40  2930277095     1  freebsd-ufs  (1.4T)

#newfs -S 4096 -b 32768 -f 4096 -O 2 -U -m 1 -o space /dev/ad10p1
接著測看看速度
#dd if=/dev/zero of=/dev/ad10p1 bs=1m count=8k
8192+0 records in
8192+0 records out
8589934592 bytes transferred in 90.180949 secs (95252209 bytes/sec)
diskinfo 看到的 sectorsize 還是 512
#diskinfo -t /dev/ad10
/dev/ad10
        512             # sectorsize
        1500301910016   # mediasize in bytes (1.4T)
        2930277168      # mediasize in sectors
        2907021         # Cylinders according to firmware.
        16              # Heads according to firmware.
        63              # Sectors according to firmware.
        WD-WMAVU3127845 # Disk ident.

Seek times:
        Full stroke:      250 iter in   5.759155 sec =   23.037 msec
        Half stroke:      250 iter in   4.177206 sec =   16.709 msec
        Quarter stroke:   500 iter in   7.581140 sec =   15.162 msec
        Short forward:    400 iter in   2.664591 sec =    6.661 msec
        Short backward:   400 iter in   2.181377 sec =    5.453 msec
        Seq outer:       2048 iter in   0.273239 sec =    0.133 msec
        Seq inner:       2048 iter in   0.238800 sec =    0.117 msec
Transfer rates:
        outside:       102400 kbytes in   1.065353 sec =    96118 kbytes/sec
        middle:        102400 kbytes in   1.264815 sec =    80960 kbytes/sec
        inside:        102400 kbytes in   2.177371 sec =    47029 kbytes/sec

2010-01-18

Windtop BBS + FreeBSD 8.0

之前一直龜在 FreeBSD 6.x 很多新硬體新功能不能用,前幾天換硬體時升級到 FreeBSD 8.0 (想玩 zfs)。重編 bbs 時因系統預設的 gcc 是 4.2.1 出現一堆錯誤,google 不到相關的資料只好慢慢試。
安裝 gcc34cd /usr/ports/lang/gcc34/ && make install clean
rehash
修改 ~/bbs/src/lib/Makefile,把 CC 改成gcc34CC = gcc34修改 ~/bbs/src/其他/Makefile,把 freebsd 的 CC 改成 gcc34freebsd: @$(MAKE) CC=gcc34freebsd 在 8.0 後移掉 sgtty.h 只好自己建立 /usr/include/sgtty.h 加入#ifndef USE_OLD_TTY
#define USE_OLD_TTY
#endif
#include <sys/ioctl.h>
接著照原本的編譯方式即可。