system-builder 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/system_builder/boot.rb +17 -0
- data/lib/system_builder/image.rb +79 -59
- data/lib/system_builder/task.rb +2 -2
- data/lib/system_builder.rb +1 -1
- metadata +3 -3
data/lib/system_builder/boot.rb
CHANGED
@@ -27,6 +27,7 @@ class SystemBuilder::DebianBoot
|
|
27
27
|
kernel_configurator,
|
28
28
|
fstab_configurator,
|
29
29
|
timezone_configurator,
|
30
|
+
resolvconf_configurator,
|
30
31
|
policyrc_configurator
|
31
32
|
]
|
32
33
|
@cleaners = [ apt_cleaner, policyrc_cleaner ]
|
@@ -80,6 +81,7 @@ class SystemBuilder::DebianBoot
|
|
80
81
|
SystemBuilder::ProcConfigurator.new do |chroot|
|
81
82
|
puts "* create fstab"
|
82
83
|
chroot.image.open("/etc/fstab") do |f|
|
84
|
+
f.puts "LABEL=boot /boot vfat defaults,noatime 0 1"
|
83
85
|
%w{/tmp /var/run /var/log /var/lock /var/tmp}.each do |directory|
|
84
86
|
f.puts "tmpfs #{directory} tmpfs defaults,noatime 0 0"
|
85
87
|
end
|
@@ -95,6 +97,16 @@ class SystemBuilder::DebianBoot
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
100
|
+
def resolvconf_configurator
|
101
|
+
SystemBuilder::ProcConfigurator.new do |chroot|
|
102
|
+
unless chroot.image.exists?("/etc/resolv.conf")
|
103
|
+
puts "* define resolv.conf"
|
104
|
+
# Use the same resolv.conf than build machine
|
105
|
+
chroot.image.install "/etc/", "/etc/resolv.conf"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
98
110
|
def apt_configurator
|
99
111
|
# TODO see if this step is really needed
|
100
112
|
SystemBuilder::ProcConfigurator.new do |chroot|
|
@@ -197,6 +209,11 @@ class SystemBuilder::DebianBoot
|
|
197
209
|
File.join(@root,path)
|
198
210
|
end
|
199
211
|
|
212
|
+
def exists?(path)
|
213
|
+
path = expand_path(path)
|
214
|
+
File.exists?(path) or File.symlink?(path)
|
215
|
+
end
|
216
|
+
|
200
217
|
end
|
201
218
|
|
202
219
|
class Chroot
|
data/lib/system_builder/image.rb
CHANGED
@@ -18,13 +18,17 @@ class SystemBuilder::DiskImage
|
|
18
18
|
if file_creation
|
19
19
|
create_file
|
20
20
|
create_partition_table
|
21
|
+
|
22
|
+
format_boot_fs
|
21
23
|
format_root_fs
|
22
24
|
end
|
23
25
|
|
24
|
-
|
26
|
+
install_syslinux_files
|
25
27
|
|
28
|
+
sync_boot_fs
|
26
29
|
sync_root_fs
|
27
|
-
|
30
|
+
|
31
|
+
install_syslinux
|
28
32
|
|
29
33
|
self
|
30
34
|
end
|
@@ -35,14 +39,24 @@ class SystemBuilder::DiskImage
|
|
35
39
|
|
36
40
|
def create_partition_table
|
37
41
|
# Partition must be bootable for syslinux
|
38
|
-
FileUtils::sh "echo '
|
42
|
+
FileUtils::sh "echo -e '#{free_sectors},#{boot_fs_sector_count},b,*\n#{boot_fs_sector_count+free_sectors},,L,' | /sbin/sfdisk --no-reread -uS -H16 -S63 #{file}"
|
39
43
|
end
|
40
|
-
|
44
|
+
|
41
45
|
def format_root_fs
|
42
46
|
loop_device = "/dev/loop0"
|
43
47
|
begin
|
44
|
-
FileUtils::sudo "losetup -o #{
|
45
|
-
FileUtils::sudo "mke2fs -L #{
|
48
|
+
FileUtils::sudo "losetup -o #{root_fs_offset} #{loop_device} #{file}"
|
49
|
+
FileUtils::sudo "mke2fs -L #{root_fs_label} -jqF #{loop_device} #{root_fs_block_size}"
|
50
|
+
ensure
|
51
|
+
FileUtils::sudo "losetup -d #{loop_device}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def format_boot_fs
|
56
|
+
loop_device = "/dev/loop0"
|
57
|
+
begin
|
58
|
+
FileUtils::sudo "losetup -o #{boot_fs_offset} #{loop_device} #{file}"
|
59
|
+
FileUtils::sudo "mkdosfs -v -F 32 -n #{boot_fs_label} #{loop_device} #{boot_fs_block_size}"
|
46
60
|
ensure
|
47
61
|
FileUtils::sudo "losetup -d #{loop_device}"
|
48
62
|
end
|
@@ -54,7 +68,20 @@ class SystemBuilder::DiskImage
|
|
54
68
|
FileUtils::mkdir_p mount_dir
|
55
69
|
|
56
70
|
begin
|
57
|
-
FileUtils::sudo "mount -o loop,offset=#{
|
71
|
+
FileUtils::sudo "mount -o loop,offset=#{root_fs_offset} #{file} #{mount_dir}"
|
72
|
+
yield mount_dir
|
73
|
+
ensure
|
74
|
+
FileUtils::sudo "umount #{mount_dir}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def mount_boot_fs(&block)
|
79
|
+
# TODO use a smarter mount_dir
|
80
|
+
mount_dir = "/tmp/mount_boot_fs"
|
81
|
+
FileUtils::mkdir_p mount_dir
|
82
|
+
|
83
|
+
begin
|
84
|
+
FileUtils::sudo "mount -o loop,offset=#{boot_fs_offset} #{file} #{mount_dir}"
|
58
85
|
yield mount_dir
|
59
86
|
ensure
|
60
87
|
FileUtils::sudo "umount #{mount_dir}"
|
@@ -63,69 +90,41 @@ class SystemBuilder::DiskImage
|
|
63
90
|
|
64
91
|
def sync_root_fs
|
65
92
|
mount_root_fs do |mount_dir|
|
66
|
-
FileUtils::sudo "rsync -a --delete #{boot.root}/ #{mount_dir}"
|
93
|
+
FileUtils::sudo "rsync -a --delete --exclude='boot/**' #{boot.root}/ #{mount_dir}"
|
67
94
|
end
|
68
95
|
FileUtils.touch file
|
69
96
|
end
|
70
97
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
boot.image do |image|
|
76
|
-
image.mkdir "/boot/extlinux"
|
77
|
-
|
78
|
-
boot.image.open("/boot/extlinux/extlinux.conf") do |f|
|
79
|
-
f.puts "DEFAULT linux"
|
80
|
-
f.puts "LABEL linux"
|
81
|
-
f.puts "SAY Now booting #{version} from syslinux ..."
|
82
|
-
f.puts "KERNEL /vmlinuz"
|
83
|
-
f.puts "APPEND ro root=#{root} initrd=/initrd.img"
|
84
|
-
end
|
98
|
+
def sync_boot_fs
|
99
|
+
mount_boot_fs do |mount_dir|
|
100
|
+
FileUtils::sudo "rsync -a --delete #{boot.root}/boot/ #{mount_dir}"
|
85
101
|
end
|
102
|
+
FileUtils.touch file
|
86
103
|
end
|
87
104
|
|
88
|
-
def
|
89
|
-
|
105
|
+
def install_syslinux_files(options = {})
|
106
|
+
root = (options[:root] or "LABEL=#{root_fs_label}")
|
107
|
+
version = (options[:version] or Time.now.strftime("%Y%m%d%H%M"))
|
90
108
|
|
91
109
|
boot.image do |image|
|
92
|
-
image.mkdir "/boot/
|
93
|
-
|
94
|
-
install_grub_menu options
|
95
|
-
image.install "boot/grub", stage_files.collect { |f| '/usr/lib/grub/**/' + f }
|
96
|
-
end
|
97
|
-
end
|
110
|
+
image.mkdir "/boot/"
|
98
111
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
112
|
+
image.open("/boot/syslinux.cfg") do |f|
|
113
|
+
f.puts "default linux"
|
114
|
+
f.puts "label linux"
|
115
|
+
f.puts "kernel #{readlink_boot_file('vmlinuz')}"
|
116
|
+
f.puts "append ro root=#{root} initrd=#{readlink_boot_file('initrd.img')}"
|
117
|
+
end
|
103
118
|
end
|
104
|
-
# TODO install mbr only when needed
|
105
|
-
# install MBR
|
106
|
-
FileUtils::sh "dd if=/usr/lib/syslinux/mbr.bin of=#{file} conv=notrunc"
|
107
119
|
end
|
108
120
|
|
109
|
-
def
|
110
|
-
|
111
|
-
grub.puts "device (hd0) #{file}"
|
112
|
-
grub.puts "root (hd0,0)"
|
113
|
-
grub.puts "setup (hd0)"
|
114
|
-
grub.puts "quit"
|
115
|
-
}
|
121
|
+
def readlink_boot_file(boot_file)
|
122
|
+
File.basename(%x{readlink #{boot.root}/#{boot_file}}.strip)
|
116
123
|
end
|
117
124
|
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
boot.image.open("/boot/grub/menu.lst") do |f|
|
123
|
-
f.puts "default 0"
|
124
|
-
f.puts "timeout 2"
|
125
|
-
f.puts "title #{version} Debian GNU/Linux"
|
126
|
-
f.puts "kernel /vmlinuz root=#{root} ro"
|
127
|
-
f.puts "initrd /initrd.img"
|
128
|
-
end
|
125
|
+
def install_syslinux
|
126
|
+
FileUtils::sh "syslinux -o #{boot_fs_offset} #{file}"
|
127
|
+
FileUtils::sh "dd if=/usr/lib/syslinux/mbr.bin of=#{file} conv=notrunc"
|
129
128
|
end
|
130
129
|
|
131
130
|
def convert(export_file, options = {})
|
@@ -136,17 +135,38 @@ class SystemBuilder::DiskImage
|
|
136
135
|
end
|
137
136
|
end
|
138
137
|
|
139
|
-
def
|
138
|
+
def root_fs_block_size
|
140
139
|
linux_partition_info = `/sbin/sfdisk -l #{file}`.scan(%r{#{file}.*Linux}).first
|
140
|
+
linux_partition_info.split[4].to_i
|
141
|
+
end
|
142
|
+
|
143
|
+
def free_sectors
|
144
|
+
64
|
145
|
+
end
|
146
|
+
|
147
|
+
def boot_fs_offset
|
148
|
+
free_sectors * 512
|
149
|
+
end
|
150
|
+
|
151
|
+
def boot_fs_block_size
|
152
|
+
linux_partition_info = `/sbin/sfdisk -l #{file}`.scan(%r{#{file}.*W95 FAT32}).first
|
141
153
|
linux_partition_info.split[5].to_i
|
142
154
|
end
|
143
155
|
|
144
|
-
def
|
145
|
-
|
156
|
+
def boot_fs_sector_count
|
157
|
+
(120 * 1008) - free_sectors # end of partition on a multiple of 1008 (cylinder size)
|
158
|
+
end
|
159
|
+
|
160
|
+
def root_fs_offset
|
161
|
+
(free_sectors + boot_fs_sector_count) * 512
|
146
162
|
end
|
147
163
|
|
148
|
-
def
|
164
|
+
def root_fs_label
|
149
165
|
"root"
|
150
166
|
end
|
151
167
|
|
168
|
+
def boot_fs_label
|
169
|
+
"boot"
|
170
|
+
end
|
171
|
+
|
152
172
|
end
|
data/lib/system_builder/task.rb
CHANGED
@@ -38,8 +38,8 @@ class SystemBuilder::Task < Rake::TaskLib
|
|
38
38
|
required_packages << "sudo"
|
39
39
|
required_packages << "debootstrap"
|
40
40
|
required_packages << "rsync"
|
41
|
-
required_packages << "
|
42
|
-
required_packages << "syslinux
|
41
|
+
required_packages << "dosfstools"
|
42
|
+
required_packages << "syslinux"
|
43
43
|
|
44
44
|
FileUtils.sudo "apt-get install #{required_packages.join(' ')}"
|
45
45
|
end
|
data/lib/system_builder.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: system-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alban Peignier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-28 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.4.1
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: hoe
|