Sha256: 0642678c2812c4238611e6079e8f8cf906dd5f0b310011f20634f491e5005b4e

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

class SystemBuilder::InitRamFsConfigurator 

  def configure(chroot, options = {})
    debian_release = (options.delete(:debian_release) or :lenny)

    puts "* install initramfs-tools"

    packages = %w{initramfs-tools syslinux}
    packages << "extlinux" unless debian_release == :lenny
    chroot.apt_install packages

    install_script(chroot, "local-top/mount_boot") do |f|
      f.puts "modprobe loop"
      f.puts "/lib/initrd/mount_boot"
      # f.puts "PS1='(initramfs) ' /bin/sh -i </dev/console >/dev/console 2>&1"
    end

    install_script(chroot, "local-bottom/move_boot") do |f|
      f.puts "mount -n -o move /boot /root/boot"
    end

    install_hook(chroot, "mount_boot") do |f|
      f.puts "mkdir -p $DESTDIR/lib/initrd/"
      f.puts "install -m 755 /usr/local/share/initramfs-tools/mount_boot $DESTDIR/lib/initrd/"
    end

    chroot.image.open("/etc/initramfs-tools/modules") do |f|
      f.puts "squashfs"
    end

    chroot.image.mkdir "/usr/local/share/initramfs-tools"
    chroot.image.open("/usr/local/share/initramfs-tools/mount_boot") do |f|
      f.puts File.read("#{File.dirname(__FILE__)}/mount_boot.sh")
    end

    chroot.sudo "/usr/sbin/update-initramfs -u"
  end

  @@script_header = <<EOF
#!/bin/sh -x
if [ "$1" = "prereqs" ]; then
  echo ""; exit 0;
fi
EOF

  def install_script(chroot, name, &block)
    install_file(chroot, :script, name, &block)
  end

  def install_hook(chroot, name, &block)
    install_file(chroot, :hook, name) do |f|
      f.puts ". /usr/share/initramfs-tools/hook-functions"
      yield f
    end
  end

  def install_file(chroot, type, name, &block)
    file = "/usr/share/initramfs-tools/#{type}s/#{name}"
    chroot.image.mkdir File.dirname(file)
    chroot.image.open(file) do |f|
      f.puts @@script_header
      yield f
      f.puts "exit 0"
    end
    chroot.sudo "chmod +x #{file}"
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
system-builder-0.0.26 lib/system_builder/init_ram_fs_configurator.rb