Sha256: 47f9db033f1235eb409a9db24247fd4c0521dc2a809568e87c0426ce160b9a89

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

require 'tempfile'

class SystemBuilder::IsoSquashfsImage

  attr_accessor :boot
  attr_reader :file

  def initialize(file)
    @file = file
  end

  def create
    boot.configurators << SystemBuilder::InitRamFsConfigurator.new
    boot.create

    compress_root_fs
    install_isolinux_files
    make_iso_fs

    self
  end

  def compress_root_fs
    unless File.exists?("build/filesystem.squashfs")
      FileUtils::sudo "mksquashfs #{boot.root}/ build/filesystem.squashfs -noappend -e /boot"
      FileUtils::sudo "chown #{ENV['USER']} build/filesystem.squashfs && chmod +r build/filesystem.squashfs"
    end
  end

  def install_isolinux_files(options = {})
    version = (options[:version] or Time.now.strftime("%Y%m%d%H%M"))

    boot.image do |image|
      image.mkdir "/boot/isolinux"

      image.open("/boot/isolinux/isolinux.cfg") do |f|
        f.puts "default linux"
        f.puts "label linux"
        f.puts "kernel /vmlinuz"
        f.puts "append ro initrd=/initrd.img boot=local root=/boot/filesystem.squashfs rootflags=loop rootfstype=squashfs"
      end

      image.install "/boot/isolinux", "/usr/lib/syslinux/isolinux.bin"
    end
  end

  def readlink_boot_file(boot_file)
    File.basename(%x{readlink #{boot.root}/#{boot_file}}.strip)
  end

  def make_iso_fs
    FileUtils::sudo "mkisofs -quiet -R -o #{file} -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -graft-points vmlinuz=#{boot.root}/boot/#{readlink_boot_file('vmlinuz')} initrd.img=#{boot.root}/boot/#{readlink_boot_file('initrd.img')} filesystem.squashfs=build/filesystem.squashfs #{boot.root}/boot"
    FileUtils::sudo "chown $USER #{file}"
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
system-builder-0.0.21 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.20 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.19 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.18 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.17 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.16 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.15 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.14 lib/system_builder/iso_squashfs_image.rb
system-builder-0.0.13 lib/system_builder/iso_squashfs_image.rb