Sha256: 2292ef7e3f1b5ca814c586ecaafe1faa1eee8eb5f1fa67c8e832119e8fe004ab

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require 'fileutils'

module Getch
  module FileSystem
    module Zfs
      class Mount < Getch::FileSystem::Zfs::Device
        def initialize
          super
          @root_dir = MOUNTPOINT
          @boot_dir = "#{@root_dir}/boot"
          @boot_efi_dir = "#{@root_dir}/boot/efi"
          @state = Getch::States.new()
          @log = Getch::Log.new
        end

        def run
          return if STATES[:mount]
          exec("zpool export -a")
          exec("rm -rf #{MOUNTPOINT}/*")
          exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
          exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
          mount_swap
          mount_root
          mount_boot
          mount_boot_efi
          exec("zfs mount -a")
          @state.mount
        end

        private

        def mount_swap
          if Helpers::grep?('/proc/swaps', /^\/dev/)
            exec("swapoff #{@dev_swap}")
          end

          exec("swapon #{@dev_swap}")
        end

        def mount_root
          Helpers::mkdir(@root_dir)
          exec("zfs mount #{@pool_name}/ROOT/gentoo")
        end

        def mount_boot_efi
          return if ! @dev_boot_efi
          Helpers::mkdir(@boot_efi_dir)
          exec("mount #{@dev_boot_efi} #{@boot_efi_dir}")
        end

        def mount_boot
          return if ! @dev_boot
          Helpers::mkdir(@boot_dir)
          exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
        end

        def exec(cmd)
          @log.info("==> #{cmd}")
          system(cmd)
          unless $?.success?
            raise "Error with #{cmd}"
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
getch-0.1.0 lib/getch/filesystem/zfs/mount.rb