prettyprint

2022年5月31日 星期二

ZFS介紹--在FreeBSD與ubuntu環境下實作(ZFS file system introduction and experiment in FreeBSD and ubuntu)

本篇文章著重在FreeBSD與ubuntu下實作ZFS 檔案系統,ZFS理論與優缺點部分不再贅述。

ZFS (Zettabyte file system):

實作上以兩個指令(zpool與zfs)來運作 

  1. zpool: 設定ZFS storage pools
  2. zfs --設定 ZFS datasets

zpool指令: 管理實體儲存設備,形成storage pool

  1. Device: 一個實體儲存設備,例如硬碟等.
  2. Virtual Device(vdev): 一個虛擬設備(vdev)可以是單一個device組成,也可以是多的devices組成mirror, raidz, raidz2, raidz3等主要儲存虛擬設備,也可以當成是hot spare,log等虛擬設備。 
  3. zfs pool: 一個storage pool是由多個vdevs組成,若主要儲存是由多個vdevs組成,則這幾個vdevs在storage pool中是以stripe方式組成。因此若vdev是由單一個device構成,則損換一個device則整個storage pool就會損壞。因此構成storage pool的vdevs一般會採用mirror 或raidz[1-3]較為適合。

zfs指令:管理在storage pool內的dataset

dataset分為:

  1. File system: 能直接掛載在檔案系統中,就像一般檔案系統一樣。
  2. Volume: 是一種block device,可視為是一顆邏輯硬碟,若要掛載在檔案系統中使用,需partition與format後才可mount在檔案系統下。一般直接用來當作iSCSI target的device。
  3. Snapshot: file system或volume特定時間點的快照,一般以 filesystem@name 或 volume@name形式表示。
  4. Bookmark: 像snapshot,但沒有實際保留資料空間。

實機測試:

實際在FreeBSD與ubuntu下,使用12個 20GB虛擬硬碟測試。
包含:
  • ZFS pool硬碟設備故障,如何手動與自動更換故障的設備。
  • ZFS pool在不同作業系統中實體移轉。
  • zfs dataset 的snapshot, rollback, clone
  • zfs dataset在同機器或跨機器間備份與回存(zfs send/zfs receive)
實作過程請參閱以下影片




2022年5月9日 星期一

Raspberry Pi 3 + FreeBSD + ZFS + iSCSI (Part 1)

實驗在Raspberry pi 3 B+上安裝FreeBSD作業系統,啟用ZFS檔案系統,比較ZFS dataset有使用壓縮(Compression)與副本(copies)屬性使用磁碟空間比較。另外建立一個ZFS Volume(Block device)作為iSCSI Target使用。以Windows系統連線iSCSI Target並格式化為NTFS。測試ZFS snapshot, rollback 等功能。 

一、下載Raspberry Pi的FreeBSD OS Image:

從FreeBSD官網下載作業系統映像檔,如下圖所示:

下載檔案:FreeBSD-13.0-RELEASE-arm64-aarch64-RPI.img.xz


二、使用Raspberry Pi Imager安裝作業系統到SD Card上:
  1. 從https://www.raspberrypi.com/software/下載Raspberry Pi Imager:
  2. 安裝FreeBSD Image:
    選用use custom選項,安裝剛剛下載的OS映像檔。

三、設定FreeBSD Static IP, nameserver, 與sshd允許遠端連線:

  1. static IP: 查看網路面卡名稱(ue0),編輯/etc/rc.conf加入
    ipconfig_ue0="inet x.x.x.x netmask x.x.x.x"
    defaultrouter="x.x.x.x"

  2. nameserver:編輯/etc/resolv.conf加入nameserver ip:

  3. sshd:編輯/etc/ssh/sshd_config更改permitRootLogin成yes

四、把外接USB硬碟加入ZFS pool:

啟用ZFS服務:
  1. 編輯/etc/rc.conf加入zfs_enable="YES"

  2. 執行service zfs start啟用zfs service
  3. 查看外接USB硬碟設備代號(da0),
    執行zpool create storage da0建立名稱為storage的zfs pool。

五、比較zfs dataset具有compression與copies屬性儲存空間的差異

  1. 分別建立storage/normal, storage/compress與storage/data三個filesystem,

  2. 設定storage/compress具有compression屬性
  3. 設定storage/data具有copies=2屬性,可把資料儲存兩份,增加可靠性
  4. 複製相同的資料到這三個檔案系統,查看使用硬碟空間的差異。



    六、建立iSCSI Target,使用Windows iSCSI Initiator 連線成為自己的硬碟

  1. 建立zfs volume(block device)作為iSCSI Target設備 zfs create -V 25G storage/iscsi01
  2. 編輯/etc/ctl.conf
    更改etc.conf權限,chmod 644 /etc/ctl.conf
    編輯/etc/rc.conf加入ctld_enable="YES"
    啟用service ctld start

  3. 啟用Windows iSCSI Initiator 連線iSCSI Target

  4. 使用Windoes disk managment格式化iSCSI 硬碟

七、zfs snapshot與rollback展示: