Class: BoxGrinder::LinuxHelper
- Inherits:
-
Object
- Object
- BoxGrinder::LinuxHelper
- Defined in:
- lib/boxgrinder-build/helpers/linux-helper.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ LinuxHelper
constructor
A new instance of LinuxHelper.
- #kernel_image_name(guestfs) ⇒ Object
- #kernel_version(guestfs) ⇒ Object
-
#partition_mount_points(partitions) ⇒ Object
Returns valid array of sorted mount points.
- #recreate_kernel_image(guestfs, modules = []) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ LinuxHelper
Returns a new instance of LinuxHelper.
56 57 58 |
# File 'lib/boxgrinder-build/helpers/linux-helper.rb', line 56 def initialize( = {}) @log = [:log] || LogHelper.new end |
Instance Method Details
#kernel_image_name(guestfs) ⇒ Object
113 114 115 |
# File 'lib/boxgrinder-build/helpers/linux-helper.rb', line 113 def kernel_image_name(guestfs) guestfs.sh("ls -1 /boot | grep initramfs | wc -l").chomp.strip.to_i > 0 ? "initramfs" : "initrd" end |
#kernel_version(guestfs) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/boxgrinder-build/helpers/linux-helper.rb', line 94 def kernel_version(guestfs) kernel_versions = guestfs.ls("/lib/modules") # By default use the latest available kernel... version = RPMVersion.new.newest(kernel_versions) # ...but prefer xen or PAE kernel over others if kernel_versions.size > 1 kernel_versions.each do |v| if v.match(/xen$/) or v.match(/PAE$/) version = v break end end end version end |
#partition_mount_points(partitions) ⇒ Object
Returns valid array of sorted mount points
['/', '/home'] => ['/', '/home'] ['swap', '/', '/home'] => ['/', '/home', 'swap'] ['swap', '/', '/home', '/boot'] => ['/', '/boot', '/home', 'swap'] ['/tmp-eventlog', '/', '/ubrc', '/tmp-config'] => ['/', '/ubrc', '/tmp-config', '/tmp-eventlog']
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/boxgrinder-build/helpers/linux-helper.rb', line 67 def partition_mount_points(partitions) partitions.keys.sort do |a, b| a_count = a.count('/') b_count = b.count('/') if a_count > b_count v = 1 else if a_count < b_count v = -1 else if a.length == b.length v = a <=> b else v = a.length <=> b.length end end end # This forces having swap partition at the end of the disk v = 1 if a_count == 0 v = -1 if b_count == 0 v end end |
#recreate_kernel_image(guestfs, modules = []) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/boxgrinder-build/helpers/linux-helper.rb', line 117 def recreate_kernel_image(guestfs, modules = []) kernel_version = kernel_version(guestfs) raise "Cannot find valid kernel installs in the appliance. Make sure you have your kernel installed in '/lib/modules'." if kernel_version.nil? kernel_image_name = kernel_image_name(guestfs) if guestfs.exists("/sbin/dracut") != 0 command = "/sbin/dracut -f -v --add-drivers #{modules.join(' ')}" else drivers_argument = "" modules.each { |mod| drivers_argument << " --preload=#{mod}" } command = "/sbin/mkinitrd -f -v#{drivers_argument}" end @log.trace "Additional modules to preload in kernel: #{modules.join(', ')}" @log.debug "Recreating kernel image for #{kernel_version} kernel..." guestfs.sh("#{command} /boot/#{kernel_image_name}-#{kernel_version}.img #{kernel_version}") @log.debug "Kernel image recreated." end |