summaryrefslogtreecommitdiff
path: root/vmdebootstrap
diff options
context:
space:
mode:
authorNeil Williams <codehelp@debian.org>2015-08-16 12:21:26 +0200
committerNeil Williams <codehelp@debian.org>2015-08-16 17:02:12 +0200
commit34252150c3ca24e1dc88712406f73f0a78d9ea55 (patch)
treead9168d67c4593d73e2758df793bb1b653a3bcf2 /vmdebootstrap
parent9d776bb74654b80815fe08d87b5237e577ef1099 (diff)
downloadvmdebootstrap-34252150c3ca24e1dc88712406f73f0a78d9ea55.tar.gz
use a constants handler
Add support for using squashfs as an alternative to creating a tarball of a directory tree.
Diffstat (limited to 'vmdebootstrap')
-rw-r--r--vmdebootstrap/constants.py52
-rw-r--r--vmdebootstrap/filesystem.py32
-rw-r--r--vmdebootstrap/grub.py8
-rw-r--r--vmdebootstrap/uefi.py49
4 files changed, 97 insertions, 44 deletions
diff --git a/vmdebootstrap/constants.py b/vmdebootstrap/constants.py
new file mode 100644
index 0000000..9f39415
--- /dev/null
+++ b/vmdebootstrap/constants.py
@@ -0,0 +1,52 @@
+"""
+ Constants which can be used by any handler
+"""
+# -*- coding: utf-8 -*-
+#
+# constants.py
+#
+# Copyright 2015 Neil Williams <codehelp@debian.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+arch_table = { # pylint: disable=invalid-name
+ 'amd64': {
+ 'removable': '/EFI/boot/bootx64.efi', # destination location
+ 'install': '/EFI/debian/grubx64.efi', # package location
+ 'package': 'grub-efi-amd64', # bootstrap package
+ 'bin_package': 'grub-efi-amd64-bin', # binary only
+ 'extra': 'i386', # architecture to add binary package
+ 'exclusive': False, # only EFI supported for this arch.
+ 'target': 'x86_64-efi', # grub target name
+ },
+ 'i386': {
+ 'removable': '/EFI/boot/bootia32.efi',
+ 'install': '/EFI/debian/grubia32.efi',
+ 'package': 'grub-efi-ia32',
+ 'bin_package': 'grub-efi-ia32-bin',
+ 'extra': None,
+ 'exclusive': False,
+ 'target': 'i386-efi',
+ },
+ 'arm64': {
+ 'removable': '/EFI/boot/bootaa64.efi',
+ 'install': '/EFI/debian/grubaa64.efi',
+ 'package': 'grub-efi-arm64',
+ 'bin_package': 'grub-efi-arm64-bin',
+ 'extra': None,
+ 'exclusive': True,
+ 'target': 'arm64-efi',
+ }
+}
diff --git a/vmdebootstrap/filesystem.py b/vmdebootstrap/filesystem.py
index 07ec9ca..ccc95a4 100644
--- a/vmdebootstrap/filesystem.py
+++ b/vmdebootstrap/filesystem.py
@@ -160,7 +160,37 @@ class Filesystem(Base):
elif self.settings['swap'] > 0:
fstab.write("/dev/sda2 swap swap defaults 0 0\n")
- def squash(self):
+ def squash_filesystem(self):
+ """
+ Run squashfs on the temporary directory
+ """
+ if not self.settings['squash']:
+ return
+ if self.settings['image']:
+ return
+ if not os.path.exists('/usr/bin/mksquashfs'):
+ logging.warning("Squash selected but mksquashfs not found!")
+ return
+ logging.debug(
+ "%s usage: %s", self.settings['image'],
+ runcmd(['du', self.settings['image']]))
+ self.message("Running mksquashfs")
+ output = self.settings['squash-file']
+ if os.path.exists(output):
+ os.unlink(output)
+ msg = runcmd(
+ ['mksquashfs', self.devices['rootdir'],
+ output, '-no-progress', '-comp', 'xz'], ignore_fail=False)
+ logging.debug(msg)
+ check_size = os.path.getsize(output)
+ if check_size < (1024 * 1024):
+ logging.warning(
+ "%s appears to be too small! %s bytes",
+ output, check_size)
+ else:
+ logging.debug("squashed size: %s", check_size)
+
+ def squash_image(self):
"""
Run squashfs on the image.
"""
diff --git a/vmdebootstrap/grub.py b/vmdebootstrap/grub.py
index 22d7658..e511462 100644
--- a/vmdebootstrap/grub.py
+++ b/vmdebootstrap/grub.py
@@ -20,6 +20,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# pylint: disable=missing-docstring,duplicate-code
+
+
import os
import cliapp
import logging
@@ -29,9 +32,7 @@ from vmdebootstrap.base import (
mount_wrapper,
umount_wrapper
)
-from vmdebootstrap.uefi import Uefi, arch_table
-
-# pylint: disable=missing-docstring
+from vmdebootstrap.uefi import arch_table
def grub_serial_console(rootdir):
@@ -53,7 +54,6 @@ class GrubHandler(Base):
def __init__(self):
super(GrubHandler, self).__init__()
- self.uefi = Uefi()
def install_grub2(self, rootdev, rootdir):
self.message("Configuring grub2")
diff --git a/vmdebootstrap/uefi.py b/vmdebootstrap/uefi.py
index 1acae14..215e97e 100644
--- a/vmdebootstrap/uefi.py
+++ b/vmdebootstrap/uefi.py
@@ -21,6 +21,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# pylint: disable=missing-docstring,duplicate-code
+
+
import os
import cliapp
import logging
@@ -30,39 +33,7 @@ from vmdebootstrap.base import (
mount_wrapper,
umount_wrapper,
)
-
-# pylint: disable=missing-docstring
-
-
-arch_table = { # pylint: disable=invalid-name
- 'amd64': {
- 'removable': '/EFI/boot/bootx64.efi', # destination location
- 'install': '/EFI/debian/grubx64.efi', # package location
- 'package': 'grub-efi-amd64', # bootstrap package
- 'bin_package': 'grub-efi-amd64-bin', # binary only
- 'extra': 'i386', # architecture to add binary package
- 'exclusive': False, # only EFI supported for this arch.
- 'target': 'x86_64-efi', # grub target name
- },
- 'i386': {
- 'removable': '/EFI/boot/bootia32.efi',
- 'install': '/EFI/debian/grubia32.efi',
- 'package': 'grub-efi-ia32',
- 'bin_package': 'grub-efi-ia32-bin',
- 'extra': None,
- 'exclusive': False,
- 'target': 'i386-efi',
- },
- 'arm64': {
- 'removable': '/EFI/boot/bootaa64.efi',
- 'install': '/EFI/debian/grubaa64.efi',
- 'package': 'grub-efi-arm64',
- 'bin_package': 'grub-efi-arm64-bin',
- 'extra': None,
- 'exclusive': True,
- 'target': 'arm64-efi',
- }
-}
+from vmdebootstrap.constants import arch_table
class Uefi(Base):
@@ -105,28 +76,28 @@ class Uefi(Base):
os.unlink(efi_output)
os.rename(efi_input, efi_output)
- def configure_efi(self):
+ def configure_efi(self, rootdir):
"""
Copy the bootloader file from the package into the location
so needs to be after grub and kernel already installed.
"""
self.message('Configuring EFI')
- mount_wrapper()
+ mount_wrapper(rootdir)
efi_removable = str(arch_table[self.settings['arch']]['removable'])
efi_install = str(arch_table[self.settings['arch']]['install'])
self.message('Installing UEFI support binary')
self.copy_efi_binary(efi_removable, efi_install)
- umount_wrapper()
+ umount_wrapper(rootdir)
- def configure_extra_efi(self):
+ def configure_extra_efi(self, rootdir):
extra = str(arch_table[self.settings['arch']]['extra'])
if extra:
- mount_wrapper()
+ mount_wrapper(rootdir)
efi_removable = str(arch_table[extra]['removable'])
efi_install = str(arch_table[extra]['install'])
self.message('Copying UEFI support binary for %s' % extra)
self.copy_efi_binary(efi_removable, efi_install)
- umount_wrapper()
+ umount_wrapper(rootdir)
def partition_esp(self):
espsize = self.settings['esp-size'] / (1024 * 1024)