Class: Mkfs::Zfs

Inherits:
Root
  • Object
show all
Defined in:
lib/mkfs/zfs.rb

Instance Method Summary collapse

Constructor Details

#initialize(devs, options) ⇒ Zfs

Returns a new instance of Zfs.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mkfs/zfs.rb', line 5

def initialize(devs, options)
  @mountpoint = options[:mountpoint]
  @zfs = options[:zfs_name] ||= 'pool'
  @os = options[:os]
  @encrypt = options[:encrypt]
  @zlog = devs[:zlog] ||= nil
  @zcache = devs[:zcache] ||= nil
  @rpool = "r#{@zfs}"
  @bpool = "b#{@zfs}"
  @hpool = "h#{@zfs}"
  @log = Getch::Log.new
  super
end

Instance Method Details

#add_datasetObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/mkfs/zfs.rb', line 100

def add_dataset
  zfs_create "-o canmount=off -o mountpoint=none #{@rpool}/ROOT"
  zfs_create "-o canmount=noauto -o mountpoint=/ #{@rpool}/ROOT/#{@os}"
  Getch::Command.new("zfs mount #{@rpool}/ROOT/#{@os}")

  zfs_create "-o canmount=off #{@rpool}/ROOT/#{@os}/usr"
  zfs_create "#{@rpool}/ROOT/#{@os}/usr/src"

  zfs_create "-o canmount=off #{@rpool}/ROOT/#{@os}/var"
  zfs_create "#{@rpool}/ROOT/#{@os}/var/log"
  zfs_create "#{@rpool}/ROOT/#{@os}/var/db"
  zfs_create "#{@rpool}/ROOT/#{@os}/var/tmp"
  zfs_create "#{@rpool}/ROOT/#{@os}/var/lib"
  zfs_create "#{@rpool}/ROOT/#{@os}/var/lib/docker"

  boot_dataset
  user_dataset
end

#add_zcacheObject



67
68
69
70
71
72
# File 'lib/mkfs/zfs.rb', line 67

def add_zcache
  @zcache || return

  id = Getch::Helpers.get_id(@zcache)
  sh 'zpool', 'add', @rpool, 'cache', id
end

#add_zlogObject



60
61
62
63
64
65
# File 'lib/mkfs/zfs.rb', line 60

def add_zlog
  @zlog || return

  id = Getch::Helpers.get_id(@zlog)
  sh 'zpool', 'add', @rpool, 'log', id
end

#boot_datasetObject



119
120
121
122
123
124
# File 'lib/mkfs/zfs.rb', line 119

def boot_dataset
  @boot || return

  zfs_create "-o canmount=off -o mountpoint=none #{@bpool}/BOOT"
  zfs_create "-o canmount=noauto -o mountpoint=/boot #{@bpool}/BOOT/#{@os}"
end

#format_bootObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mkfs/zfs.rb', line 30

def format_boot
  @boot || return

  id = Getch::Helpers.get_id(@boot)
  ashift = get_ashift @boot
  args = "-f -o ashift=#{ashift} -o autotrim=on"
  args << ' -o feature@async_destroy=enabled'
  args << ' -o feature@bookmarks=enabled'
  args << ' -o feature@embedded_data=enabled'
  args << ' -o feature@empty_bpobj=enabled'
  args << ' -o feature@enabled_txg=enabled'
  args << ' -o feature@extensible_dataset=enabled'
  args << ' -o feature@filesystem_limits=enabled'
  args << ' -o feature@hole_birth=enabled'
  args << ' -o feature@large_blocks=enabled'
  args << ' -o feature@lz4_compress=enabled'
  args << ' -o feature@spacemap_histogram=enabled'
  args << ' -O acltype=posixacl -O canmount=off -O compression=lz4'
  args << ' -O devices=off -O normalization=formD -O atime=off -O xattr=sa'
  args << ' -O mountpoint=/boot'
  args << " -R #{@mountpoint} #{@bpool} #{id}"
  sh 'zpool', 'create', args
end

#format_homeObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/mkfs/zfs.rb', line 86

def format_home
  @home || return

  id = Getch::Helpers.get_id(@home)
  ashift = get_ashift @home
  args = "-f -o ashift=#{ashift} -o autotrim=on"
  @encrypt && args << ' -O encryption=aes-256-gcm'
  @encrypt && args << ' -O keylocation=prompt -O keyformat=passphrase'
  args << ' -O acltype=posixacl -O canmount=off -O compression=lz4'
  args << ' -O xattr=sa -O mountpoint=/home'
  args << " -R #{@mountpoint} #{@hpool} #{id}"
  sh 'zpool', 'create', args
end

#format_rootObject



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mkfs/zfs.rb', line 74

def format_root
  id = Getch::Helpers.get_id(@root)
  ashift = get_ashift @root
  args = "-f -o ashift=#{ashift} -o autotrim=on"
  @encrypt && args << ' -O encryption=aes-256-gcm'
  @encrypt && args << ' -O keylocation=prompt -O keyformat=passphrase'
  args << ' -O acltype=posixacl -O canmount=off -O compression=lz4'
  args << ' -O xattr=sa -O mountpoint=/'
  args << " -R #{@mountpoint} #{@rpool} #{id}"
  sh 'zpool', 'create', args
end

#format_swapObject



54
55
56
57
58
# File 'lib/mkfs/zfs.rb', line 54

def format_swap
  mk_swap "/dev/#{@swap}"
  add_zlog
  add_zcache
end

#user_datasetObject



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/mkfs/zfs.rb', line 126

def user_dataset
  if @home
    zfs_create "-o canmount=off -o mountpoint=/ #{@hpool}/USERDATA"
    zfs_create "-o canmount=on -o mountpoint=/root #{@hpool}/USERDATA/root"
    zfs_create "-o canmount=on -o mountpoint=/home #{@hpool}/USERDATA/home"
  else
    zfs_create "-o canmount=off -o mountpoint=/ #{@rpool}/USERDATA"
    zfs_create "-o canmount=on -o mountpoint=/root #{@rpool}/USERDATA/root"
    zfs_create "-o canmount=on -o mountpoint=/home #{@rpool}/USERDATA/home"
  end
end

#xObject

reorder process, root should be formatted first



20
21
22
23
24
25
26
27
# File 'lib/mkfs/zfs.rb', line 20

def x
  format_efi
  format_root
  format_boot
  format_swap
  format_home
  add_dataset
end