delete from hateblo.jp where 1=1;

タイトルに意味はありません。

zfsonlinuxをdebianで使ってみる

前提条件

  • zfsonlinuxのインストールが完了している
  • hddがあまっている
    • うらやましい
  • 注意!!HDDセクタサイズが512Bであること!!
  • 4kセクタの場合
    • この手順のfdiskだと、パフォーマンス劣化がすごいです。(100MBi/s→20MBi/s)
    • partedを使うようにし、ashift=12を指定しましょう see: ZFS on Linux

現状確認

現状、何もプールがない状態。

user@host64-1:~$ sudo zpool status
no pools available
user@host64-1:~$ sudo zpool list
no pools available

対象のHDDが認識されていることを確認する。
dmesgもしくは以下のコマンドで確認する。

user@host64-1:~$ ls /dev/vd*
vda

仮想マシンのvirtio経由の物理HDDなのでvd*になる

初期化作業

HDDのパーティションテーブルを作成する

一気に全部割り当てるなら、これで決まり。
fdisk で Sun disklabel を作成する。

user@host64-1:~$ sudo fdisk /dev/vda 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xbeef2929.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
# 上記メッセージは基本的に出ないはず。
# 前回、fdisk後に電源断が発生したためテーブルへ正常にデータが書き込まれていなかった模様。

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/vda: 300.1 GB, 300090728448 bytes
16 heads, 63 sectors/track, 581463 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xbeef2929

   Device Boot      Start         End      Blocks   Id  System

# 対象のHDDにはMBRがないため、一覧が出てこなかった。
# 実際にリストされている場合は削除する必要がある。
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): s
Building a new sun disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

# 上記コマンドでHDD全体をSun形式で区画整備してくれる
Command (m for help): p

Disk /dev/vda (Sun disk label): 16 heads, 63 sectors, 57175 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Flag    Start       End    Blocks   Id  System
/dev/vda1             0    581362 293006448   83  Linux native
/dev/vda2  u     581362    581463     50904   82  Linux swap
/dev/vda3             0    581463 293057352    5  Whole disk

# Linux nativeのパス/dev/vda1を覚えておきます。
# 書き込み!ここでデータ紛失が発生しますので、HDDが本当にあっているか確認してください
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
パーティション作成されたか確認する
user@host64-1:~$ ls /dev/vd*
vda   vda1  vda2  vda3 

zpoolに追加する(create)

作成したLinux Nativeパーティション(vda1)をmypoolへ登録し、状態を確認する。

user@host64-1:~$ sudo zpool create mypool vda1
user@host64-1:~$ sudo zpool status
  pool: mypool
 state: ONLINE
 scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        mypool      ONLINE       0     0     0
          vda1      ONLINE       0     0     0

errors: No known data errors
user@host64-1:~$ sudo zpool list
NAME     SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
mypool   278G    90K   278G     0%  1.00x  ONLINE  -

マウントポイントを作成する

user@host64-1:~$ sudo zfs create mypool/storage
user@host64-1:~$ sudo zfs create mypool/storage/samba
user@host64-1:~$ sudo zfs create mypool/storage/datastore
user@host64-1:~$ sudo zfs list
NAME                       USED  AVAIL  REFER  MOUNTPOINT
mypool                     206K   274G    31K  /mypool
mypool/storage              92K   274G    32K  /mypool/storage
mypool/storage/datastore    30K   274G    30K  /mypool/storage/datastore
mypool/storage/samba        30K   274G    30K  /mypool/storage/samba

参考文献