• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

KVM host image creator.Jessica Lockwood


コミットメタ情報

リビジョンdc529c373ce1b032966b80bdc8daf38b5891c4e0 (tree)
日時2019-09-11 10:00:05
作者Tatsuki Sugiura <sugi@nemu...>
コミッターTatsuki Sugiura

ログメッセージ

Support for lxc host without kernel & grub.

変更サマリ

差分

--- a/create-image
+++ b/create-image
@@ -96,7 +96,7 @@ class ImageCreator
9696 begin
9797 system("mount", dev, mount_point) or raise "Failed to mount file system #{dev} on #{mount_point}"
9898 puts "Copying #{src_host}:#{di.srcpath} to #{dev}..."
99- system("rsync", "-azHSAX", "--numeric-ids", "--info=progress2", "#{src_host}:#{di.srcpath}/", "#{mount_point}/", *((["--exclude"] * di.exclude.size).zip(di.exclude).flatten))
99+ system("rsync", "-azHSAX", "--numeric-ids", "--info=progress2", "#{src_host}:#{di.srcpath}/", "#{mount_point}/", *((["--exclude"] * di.exclude.size).zip(di.exclude).flatten)) or raise "rsync fails"
100100 ensure
101101 system("umount", mount_point)
102102 File.directory?(mount_point) and
@@ -113,23 +113,45 @@ class ImageCreator
113113 coreimg = "#{dir}/core.img"
114114 system("grub-mkimage", "-o", coreimg, "-O", "i386-pc", "-p", "(hd0,gpt2)/boot/grub", "biosdisk", "part_gpt", "ext2", "gzio", "xzio", "lzopio") or raise "Failed to create grub core image."
115115 with_loopdev do |devices, root|
116- puts "Override grub..."
116+ puts "Override grub with host version..."
117117 system("grub-bios-setup", "-d", dir, root) or raise "Failed to run grub-bios-setup"
118118 rootfs_uuid=`blkid -o value -s UUID #{devices[1]}`.chomp("\n")
119119 puts "New rootfs UUID=#{rootfs_uuid}"
120120 begin
121121 system("mount", devices[1], dir)
122- system("cp -a /usr/lib/grub/i386-pc/*.mod #{dir}/boot/grub/i386-pc/") or raise "Failed to copy grub modules"
123- grubconf = File.read "#{dir}/boot/grub/grub.cfg"
124- if old_uuid = grubconf[/root=UUID=(\S+)/, 1]
125- File.write "#{dir}/boot/grub/grub.cfg", grubconf.gsub(/#{old_uuid}/, rootfs_uuid)
126- end
127122
128123 puts "Rewrite fstab..."
129124 fstab = File.read "#{dir}/etc/fstab"
130125 fstab.gsub!(%r{^(UUID=|/)\S+(\s+/\s+)}, "UUID=#{rootfs_uuid}\\2")
131126 fstab.gsub!(%r{^(\S+\s+\S+\s+\S+\s+sw(?=\b))}, '#\1')
132127 File.write "#{dir}/etc/fstab", fstab
128+
129+ unless File.exists? "#{dir}/vmlinuz"
130+ system("chroot", dir, "apt-get", "-qy", "update")
131+ system("chroot", dir, "apt-get", "-y", "install", "linux-image-amd64")
132+ end
133+
134+ puts "Update grub.cfg..."
135+ system("mkdir", "-p", "#{dir}/boot/grub/i386-pc") or raise "Failed to create grub dir"
136+ system("cp -a /usr/lib/grub/i386-pc/*.mod #{dir}/boot/grub/i386-pc/") or raise "Failed to copy grub modules"
137+ if File.exists? "#{dir}/boot/grub/grub.cfg"
138+ grubconf = File.read "#{dir}/boot/grub/grub.cfg"
139+ if old_uuid = grubconf[/root=UUID=(\S+)/, 1]
140+ File.write "#{dir}/boot/grub/grub.cfg", grubconf.gsub(/#{old_uuid}/, rootfs_uuid)
141+ end
142+ else
143+ File.write "#{dir}/boot/grub/grub.cfg", <<-EOC
144+ set timeout=5
145+ insmod part_gpt
146+ insmod ext2
147+ insmod linux
148+ search --no-floppy --fs-uuid --set=root #{rootfs_uuid}
149+ menuentry 'Linux' {
150+ linux /vmlinuz root=UUID=#{rootfs_uuid} ro
151+ initrd /initrd.img
152+ }
153+ EOC
154+ end
133155 ensure
134156 system("umount", dir)
135157 end