• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

KVM host image creator.Jessica Lockwood


Commit MetaInfo

修訂0b71cee5ebe70b855ad785897d1526f5f0ef1923 (tree)
時間2019-09-30 12:58:55
作者Tatsuki Sugiura <sugi@nemu...>
CommiterTatsuki Sugiura

Log Message

Change grub install method, run gru-install.

Change Summary

差異

--- a/create-image
+++ b/create-image
@@ -52,8 +52,7 @@ class ImageCreator
5252 if !use_gpt
5353 system("parted", "-s", path, "set", "1", "boot", "on") or raise "Failed to set bios boot partition"
5454 end
55- puts "Image partition created."
56- #system "sfdisk", "-l", path
55+ puts "Image partition has been created."
5756 end
5857
5958 def with_loopdev &block
@@ -113,17 +112,16 @@ class ImageCreator
113112 def fix_boot
114113 puts "Fixing boot environments..."
115114 Dir.mktmpdir("ci-#{$$}-#{name}") do |dir|
116- system("cp", "-a", "/usr/lib/grub/i386-pc/boot.img", dir) or raise "Failed to copy boot.img"
117- coreimg = "#{dir}/core.img"
118- system("grub-mkimage", "-o", coreimg, "-O", "i386-pc", "-p", "(hd0,msdos1)/boot/grub", "biosdisk", "part_msdos", "ext2", "gzio", "xzio", "lzopio") or raise "Failed to create grub core image."
119115 with_loopdev do |devices|
120116 puts "Override grub with host version..."
121117 root_dev = "/dev/#{devices.first[/loop\d+/]}"
122- system("grub-bios-setup", "-d", dir, root_dev) or raise "Failed to run grub-bios-setup"
123118 rootfs_uuid = dirs.find { |d| d.path == '/'}.fs_uuid
124119 puts "New rootfs UUID=#{rootfs_uuid}"
125120 begin
126121 system("mount", devices.first, dir) or raise "Failed to mount #{devices.first} to #{dir}"
122+ system("mount", "--bind", "/dev", "#{dir}/dev") or raise "Failed to mount /dev to #{dir}/dev"
123+ system("mount", "--bind", "/proc", "#{dir}/proc") or raise "Failed to mount /proc to #{dir}/proc"
124+
127125 dirs[1..-1].each_with_index do |di, idx|
128126 system "mkdir", "-p", "#{dir}#{di.path}"
129127 system("mount", di.device, "#{dir}#{di.path}") or raise "Failed to mount #{di.device} to #{dir}#{path}"
@@ -144,30 +142,19 @@ class ImageCreator
144142 system("chroot", dir, "apt-get", "-y", "install", "linux-image-amd64")
145143 end
146144
147- puts "Update grub.cfg..."
148- system("mkdir", "-p", "#{dir}/boot/grub/i386-pc") or raise "Failed to create grub dir"
149- system("cp -a /usr/lib/grub/i386-pc/*.mod #{dir}/boot/grub/i386-pc/") or raise "Failed to copy grub modules"
150- if File.exists? "#{dir}/boot/grub/grub.cfg"
151- grubconf = File.read "#{dir}/boot/grub/grub.cfg"
152- if old_uuid = grubconf[/root=UUID=(\S+)/, 1]
153- File.write "#{dir}/boot/grub/grub.cfg", grubconf.gsub(/#{old_uuid}/, rootfs_uuid)
154- end
155- else
156- system("chroot", dir, "apt-get", "-qy", "update")
145+ puts "Update grub..."
146+ unless File.exists? "#{dir}/boot/grub/grub.cfg"
147+ system("chroot", dir, "apt-get", "-qy", "update") or raise "Failed to install grub-pc"
157148 system({'DEBIAN_FRONTEND' => 'noninteractive'}, "chroot", dir, "apt-get", "-y", "install", "grub-pc")
158- File.write "#{dir}/boot/grub/grub.cfg", <<-EOC
159- set timeout=5
160- insmod part_msdos
161- insmod ext2
162- insmod linux
163- search --no-floppy --fs-uuid --set=root #{rootfs_uuid}
164- menuentry 'Linux' {
165- linux /vmlinuz root=UUID=#{rootfs_uuid} ro
166- initrd /initrd.img
167- }
168- EOC
169149 end
150+ File.open "#{dir}/boot/grub/device.map", "w" do |f|
151+ f.puts "(hd0)\t#{root_dev}"
152+ end
153+ system("chroot", dir, "grub-mkconfig", "-o", "/boot/grub/grub.cfg") or raise "grub-mkconfig fails."
154+ system(*%W(grub-install --no-floppy --grub-mkdevicemap=#{dir}/boot/grub/device.map --root-directory=#{dir} #{root_dev})) or raise "grub-install failed."
170155 ensure
156+ system("umount", "#{dir}/dev")
157+ system("umount", "#{dir}/proc")
171158 dirs.reverse[0..-2].each do |di, idx|
172159 system("umount", "#{dir}#{di.path}")
173160 end