• R/O
  • HTTP
  • SSH
  • HTTPS

image-creator: Commit

KVM host image creator.


Commit MetaInfo

Révision9b4cf3e12f8781ed0f00c94fa734e9f8b7bdc1e6 (tree)
l'heure2019-09-24 20:30:05
AuteurTatsuki Sugiura <sugi@nemu...>
CommiterTatsuki Sugiura

Message de Log

Update.

Change Summary

Modification

--- a/create-image
+++ b/create-image
@@ -6,7 +6,7 @@ require 'yaml'
66
77 class SyncDirDef
88 DEFAULT_EXCLUDE = %w[/proc/* /sys/* /dev/mqueue /dev/hugepages /run/* /var/lib/os-prober/mount /swap /dev/shm/* /var/lib/lxcfs/*]
9- attr_accessor :path, :size, :exclude, :size, :srcpath, :fs_features, :device
9+ attr_accessor :path, :size, :exclude, :size, :srcpath, :fs_features, :device, :fs_uuid
1010 def initialize(path: '/', size: 8, exclude: DEFAULT_EXCLUDE, srcpath: nil, fs_features: nil)
1111 @path = path
1212 @size = size.to_f
@@ -14,6 +14,7 @@ class SyncDirDef
1414 @srcpath = srcpath || path
1515 @fs_features = fs_features
1616 @device = nil
17+ @fs_uuid = nil
1718 end
1819 end
1920
@@ -48,9 +49,7 @@ class ImageCreator
4849 end
4950 system("parted", "-s", path, "mklabel", use_gpt ? 'gpt' : 'msdos') or raise "Failed to create partition label"
5051 system("parted", "-s", path, "mkpart", "primary", "1MiB", "#{size_gb * 1024 - 1}MiB") or raise "Failed to create partition"
51- if use_gpt
52- system("parted", "-s", path, "name", "1", di.path) or raise "Failed to set part label"
53- else
52+ if !use_gpt
5453 system("parted", "-s", path, "set", "1", "boot", "on") or raise "Failed to set bios boot partition"
5554 end
5655 puts "Image partition created."
@@ -76,7 +75,8 @@ class ImageCreator
7675
7776 def create_fs
7877 with_loopdev do |devices|
79- devices.each_with_index do |dev, index|
78+ dirs.each_with_index do |di, index|
79+ dev = di.device
8080 puts "Creating filesystem on #{dev}..."
8181 cmd = %w(mkfs.ext4 -q)
8282 di = dirs[index]
@@ -85,6 +85,8 @@ class ImageCreator
8585 end
8686 cmd << dev
8787 system(*cmd) or raise "Failed to create file system on #{dev}"
88+ system "e2label", dev, di.path == '/' ? 'ROOT' : di.path[1..-1].tr('/', '-')
89+ di.fs_uuid = `blkid -o value -s UUID #{di.device}`.chomp("\n")
8890 end
8991 end
9092 end
@@ -115,11 +117,10 @@ class ImageCreator
115117 coreimg = "#{dir}/core.img"
116118 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."
117119 with_loopdev do |devices|
118- root_dev = "/dev/#{devices.first[/loop\d+/]}"
119120 puts "Override grub with host version..."
121+ root_dev = "/dev/#{devices.first[/loop\d+/]}"
120122 system("grub-bios-setup", "-d", dir, root_dev) or raise "Failed to run grub-bios-setup"
121- fs_uuids = devices.map { |d| `blkid -o value -s UUID #{d}`.chomp("\n") }
122- rootfs_uuid = fs_uuids.first
123+ rootfs_uuid = dirs.find { |d| d.path == '/'}.fs_uuid
123124 puts "New rootfs UUID=#{rootfs_uuid}"
124125 begin
125126 system("mount", devices.first, dir) or raise "Failed to mount #{devices.first} to #{dir}"
@@ -132,10 +133,10 @@ class ImageCreator
132133
133134 puts "Rewrite fstab..."
134135 File.open "#{dir}/etc/fstab", "w" do |f|
135- devices.map.with_index { |d, idx|
136- f << %W(UUID=#{fs_uuids[idx]} #{dirs[idx].path} ext4 defaults,noatime 0 #{dirs[idx].path == '/' ? 1 : 2}).join("\t")
136+ dirs.each_with_index do |di, idx|
137+ f << %W(UUID=#{di.fs_uuid} #{di.path} ext4 defaults,noatime 0 #{di.path == '/' ? 1 : 2}).join("\t")
137138 f << "\n"
138- }
139+ end
139140 end
140141
141142 unless File.exists? "#{dir}/vmlinuz"
Afficher sur ancien navigateur de dépôt.