Class: SystemBuilder::DiskSquashfsImage
- Defined in:
- lib/system_builder/disk_squashfs_image.rb
Instance Attribute Summary collapse
-
#boot ⇒ Object
Returns the value of attribute boot.
-
#build_dir ⇒ Object
Returns the value of attribute build_dir.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #boot_fs_block_size ⇒ Object
- #boot_fs_offset ⇒ Object
- #compress_root_fs ⇒ Object
- #compute_checksums ⇒ Object
- #create ⇒ Object
- #create_file ⇒ Object
- #create_partition_table ⇒ Object
- #format_boot_fs ⇒ Object
- #free_sectors ⇒ Object
- #fs_label ⇒ Object
-
#initialize(file) ⇒ DiskSquashfsImage
constructor
A new instance of DiskSquashfsImage.
- #install_extlinux ⇒ Object
- #install_extlinux_files(options = {}) ⇒ Object
- #mount_boot_fs(mount_dir = "/tmp/mount_boot_fs", &block) ⇒ Object
- #readlink_boot_file(boot_file) ⇒ Object
- #squashfs_file ⇒ Object
- #sync_boot_fs ⇒ Object
Constructor Details
#initialize(file) ⇒ DiskSquashfsImage
Returns a new instance of DiskSquashfsImage.
8 9 10 11 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 8 def initialize(file) @file = file @size = 512.megabytes end |
Instance Attribute Details
#boot ⇒ Object
Returns the value of attribute boot.
5 6 7 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 5 def boot @boot end |
#build_dir ⇒ Object
Returns the value of attribute build_dir.
66 67 68 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 66 def build_dir @build_dir end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 6 def file @file end |
#size ⇒ Object
Returns the value of attribute size.
5 6 7 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 5 def size @size end |
Instance Method Details
#boot_fs_block_size ⇒ Object
145 146 147 148 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 145 def boot_fs_block_size linux_partition_info = `/sbin/sfdisk -l #{file}`.scan(%r{#{file}.*Linux}).first linux_partition_info.split[5].to_i end |
#boot_fs_offset ⇒ Object
141 142 143 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 141 def boot_fs_offset free_sectors * 512 end |
#compress_root_fs ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 76 def compress_root_fs FileUtils::sudo "mksquashfs #{boot.root}/ #{squashfs_file} -noappend -e #{boot.root}/boot" FileUtils::sudo "chown #{ENV['USER']} #{squashfs_file} && chmod +r #{squashfs_file}" mount_boot_fs do |mount_dir| FileUtils::sudo "cp #{squashfs_file} #{mount_dir}/filesystem.squashfs" end FileUtils.touch file end |
#compute_checksums ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 121 def compute_checksums mount_boot_fs do |mount_dir| FileUtils::cd("#{mount_dir}") do FileUtils::sh"md5sum * |sudo tee MD5SUM" end end end |
#create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 13 def create boot.configurators << SystemBuilder::InitRamFsConfigurator.new boot.create file_creation = (not File.exists?(file)) if file_creation create_file create_partition_table format_boot_fs end sync_boot_fs install_extlinux_files compress_root_fs install_extlinux compute_checksums self end |
#create_file ⇒ Object
35 36 37 38 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 35 def create_file FileUtils::mkdir_p File.dirname(file) FileUtils::sh "dd if=/dev/zero of=#{file} count=#{size.in_megabytes.to_i} bs=1M" end |
#create_partition_table ⇒ Object
40 41 42 43 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 40 def create_partition_table # Partition must be bootable for syslinux FileUtils::sh "echo '#{free_sectors},,L,*' | /sbin/sfdisk --force --no-reread -uS -H16 -S63 #{file}" end |
#format_boot_fs ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 45 def format_boot_fs loop_device = "/dev/loop0" begin FileUtils::sudo "losetup -o #{boot_fs_offset} #{loop_device} #{file}" FileUtils::sudo "mke2fs -L #{fs_label} -jqF #{loop_device} #{boot_fs_block_size}" ensure FileUtils::sudo "losetup -d #{loop_device}" end end |
#free_sectors ⇒ Object
137 138 139 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 137 def free_sectors 64 end |
#fs_label ⇒ Object
129 130 131 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 129 def fs_label "boot" end |
#install_extlinux ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 112 def install_extlinux mount_boot_fs("#{boot.root}/boot") do boot.chroot do |chroot| chroot.sudo "extlinux --install -H16 -S63 /boot" end end FileUtils::sh "dd if=#{boot.root}/usr/lib/syslinux/mbr.bin of=#{file} conv=notrunc" end |
#install_extlinux_files(options = {}) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 95 def install_extlinux_files( = {}) root = ([:root] or "LABEL=#{fs_label}") version = ([:version] or Time.now.strftime("%Y%m%d%H%M")) mount_boot_fs do |mount_dir| SystemBuilder::DebianBoot::Image.new(mount_dir).tap do |image| image.open("extlinux.conf") do |f| f.puts "DEFAULT linux" f.puts "LABEL linux" f.puts "SAY Now booting #{version} from syslinux ..." f.puts "KERNEL /vmlinuz" f.puts "APPEND ro initrd=/initrd.img boot=local root=/boot/filesystem.squashfs rootflags=loop rootfstype=squashfs rootdelay=6" end end end end |
#mount_boot_fs(mount_dir = "/tmp/mount_boot_fs", &block) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 55 def mount_boot_fs(mount_dir = "/tmp/mount_boot_fs", &block) FileUtils::mkdir_p mount_dir begin FileUtils::sudo "mount -o loop,offset=#{boot_fs_offset} #{file} #{mount_dir}" yield mount_dir ensure FileUtils::sudo "umount #{mount_dir}" end end |
#readlink_boot_file(boot_file) ⇒ Object
133 134 135 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 133 def readlink_boot_file(boot_file) File.basename(%x{readlink #{boot.root}/#{boot_file}}.strip) end |
#squashfs_file ⇒ Object
72 73 74 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 72 def squashfs_file "#{build_dir}/filesystem.squashfs" end |
#sync_boot_fs ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/system_builder/disk_squashfs_image.rb', line 86 def sync_boot_fs mount_boot_fs do |mount_dir| FileUtils::sudo "rsync -a --delete #{boot.root}/boot/ #{mount_dir}/" FileUtils::sudo "ln -s #{readlink_boot_file('initrd.img')} #{mount_dir}/initrd.img" FileUtils::sudo "ln -s #{readlink_boot_file('vmlinuz')} #{mount_dir}/vmlinuz" end FileUtils.touch file end |