| Class | BoxGrinder::LinuxHelper |
| In: |
lib/boxgrinder-build/helpers/linux-helper.rb
lib/boxgrinder-build/helpers/linux-helper.rb |
| Parent: | Object |
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 23
23: def initialize(options = {})
24: @log = options[:log] || LogHelper.new
25: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 23
23: def initialize(options = {})
24: @log = options[:log] || LogHelper.new
25: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 77
77: def kernel_image_name(guestfs)
78: guestfs.sh("ls -1 /boot | grep initramfs | wc -l").chomp.strip.to_i > 0 ? "initramfs" : "initrd"
79: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 77
77: def kernel_image_name(guestfs)
78: guestfs.sh("ls -1 /boot | grep initramfs | wc -l").chomp.strip.to_i > 0 ? "initramfs" : "initrd"
79: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 61
61: def kernel_version(guestfs)
62: kernel_versions = guestfs.ls("/lib/modules")
63: version = kernel_versions.last
64:
65: if kernel_versions.size > 1
66: kernel_versions.each do |v|
67: if v.match(/PAE$/)
68: version = v
69: break
70: end
71: end
72: end
73:
74: version
75: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 61
61: def kernel_version(guestfs)
62: kernel_versions = guestfs.ls("/lib/modules")
63: version = kernel_versions.last
64:
65: if kernel_versions.size > 1
66: kernel_versions.each do |v|
67: if v.match(/PAE$/)
68: version = v
69: break
70: end
71: end
72: end
73:
74: version
75: end
Returns valid array of sorted mount points
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 34
34: def partition_mount_points(partitions)
35: partitions.keys.sort do |a, b|
36: a_count = a.count('/')
37: b_count = b.count('/')
38:
39: if a_count > b_count
40: v = 1
41: else
42: if a_count < b_count
43: v = -1
44: else
45: if a.length == b.length
46: v = a <=> b
47: else
48: v = a.length <=> b.length
49: end
50: end
51: end
52:
53: # This forces having swap partition at the end of the disk
54: v = 1 if a_count == 0
55: v = -1 if b_count == 0
56:
57: v
58: end
59: end
Returns valid array of sorted mount points
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 34
34: def partition_mount_points(partitions)
35: partitions.keys.sort do |a, b|
36: a_count = a.count('/')
37: b_count = b.count('/')
38:
39: if a_count > b_count
40: v = 1
41: else
42: if a_count < b_count
43: v = -1
44: else
45: if a.length == b.length
46: v = a <=> b
47: else
48: v = a.length <=> b.length
49: end
50: end
51: end
52:
53: # This forces having swap partition at the end of the disk
54: v = 1 if a_count == 0
55: v = -1 if b_count == 0
56:
57: v
58: end
59: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 81
81: def recreate_kernel_image(guestfs, modules = [])
82: kernel_version = kernel_version(guestfs)
83: kernel_image_name = kernel_image_name(guestfs)
84:
85: if guestfs.exists("/sbin/dracut") != 0
86: command = "/sbin/dracut -f -v --add-drivers #{modules.join(' ')}"
87: else
88: drivers_argument = ""
89: modules.each { |mod| drivers_argument << " --preload=#{mod}" }
90:
91: command = "/sbin/mkinitrd -f -v#{drivers_argument}"
92: end
93:
94: @log.trace "Additional modules to preload in kernel: #{modules.join(', ')}"
95:
96: @log.debug "Recreating kernel image for #{kernel_version} kernel..."
97: guestfs.sh("#{command} /boot/#{kernel_image_name}-#{kernel_version}.img #{kernel_version}")
98: @log.debug "Kernel image recreated."
99: end
# File lib/boxgrinder-build/helpers/linux-helper.rb, line 81
81: def recreate_kernel_image(guestfs, modules = [])
82: kernel_version = kernel_version(guestfs)
83: kernel_image_name = kernel_image_name(guestfs)
84:
85: if guestfs.exists("/sbin/dracut") != 0
86: command = "/sbin/dracut -f -v --add-drivers #{modules.join(' ')}"
87: else
88: drivers_argument = ""
89: modules.each { |mod| drivers_argument << " --preload=#{mod}" }
90:
91: command = "/sbin/mkinitrd -f -v#{drivers_argument}"
92: end
93:
94: @log.trace "Additional modules to preload in kernel: #{modules.join(', ')}"
95:
96: @log.debug "Recreating kernel image for #{kernel_version} kernel..."
97: guestfs.sh("#{command} /boot/#{kernel_image_name}-#{kernel_version}.img #{kernel_version}")
98: @log.debug "Kernel image recreated."
99: end