summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/vmdebootstrap20
-rw-r--r--vmdebootstrap/base.py9
-rw-r--r--vmdebootstrap/filesystem.py17
3 files changed, 25 insertions, 21 deletions
diff --git a/bin/vmdebootstrap b/bin/vmdebootstrap
index 1880701..876ec5f 100755
--- a/bin/vmdebootstrap
+++ b/bin/vmdebootstrap
@@ -238,9 +238,10 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
uefi = self.handlers[Uefi.name]
base = self.handlers[Base.name]
filesystem = self.handlers[Filesystem.name]
+ extlinux = self.handlers[ExtLinux.name]
base.create_empty_image()
self.partition_image()
- filesystem.install_mbr()
+ extlinux.install_mbr()
filesystem.setup_kpartx()
rootdev = filesystem.devices['rootdev']
roottype = filesystem.devices['roottype']
@@ -263,6 +264,7 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
def _image_operations(self, rootdir, rootdev):
if not self.settings['image']:
return
+ logging.debug("rootdir=%s rootdev=%s", rootdir, rootdev)
grub = self.handlers[GrubHandler.name]
extlinux = self.handlers[ExtLinux.name]
base = self.handlers[Base.name]
@@ -278,19 +280,20 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
elif self.settings['extlinux']:
extlinux.install_extlinux(rootdev, rootdir)
base.append_serial_console(rootdir)
- base.optimize_image(rootdir)
+ self.optimize_image(rootdir)
filesystem.squash()
def start_ops(self):
base = self.handlers[Base.name]
filesystem = self.handlers[Filesystem.name]
- rootdir = filesystem.devices['rootdir']
- rootdev = filesystem.devices['rootdev']
try:
if self.settings['image']:
self._image_preparations()
+ rootdir = filesystem.devices['rootdir']
+ rootdev = filesystem.devices['rootdev']
else:
rootdir = self.mkdtemp()
+ logging.debug("rootdir=%s rootdev=%s", rootdir, rootdev)
self.debootstrap(rootdir)
filesystem.set_hostname()
filesystem.create_fstab()
@@ -520,6 +523,15 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth
logging.debug('stdout:\n%s', out)
shutil.rmtree(tmp)
+ def optimize_image(self, rootdir):
+ """
+ Filing up the image with zeros will increase its compression rate
+ """
+ if not self.settings['sparse']:
+ zeros = os.path.join(rootdir, 'ZEROS')
+ self.runcmd_unchecked(['dd', 'if=/dev/zero', 'of=' + zeros, 'bs=1M'])
+ runcmd(['rm', '-f', zeros])
+
def setup_networking(self, rootdir):
self.message('Setting up networking')
distro = self.handlers[Codenames.name]
diff --git a/vmdebootstrap/base.py b/vmdebootstrap/base.py
index 1843d56..e840855 100644
--- a/vmdebootstrap/base.py
+++ b/vmdebootstrap/base.py
@@ -157,15 +157,6 @@ class Base(object):
"%s usage: %s", self.settings['image'],
runcmd(['du', self.settings['image']]))
- def optimize_image(self, rootdir):
- """
- Filing up the image with zeros will increase its compression rate
- """
- if not self.settings['sparse']:
- zeros = os.path.join(rootdir, 'ZEROS')
- self.runcmd_unchecked(['dd', 'if=/dev/zero', 'of=' + zeros, 'bs=1M'])
- runcmd(['rm', '-f', zeros])
-
def append_serial_console(self, rootdir):
if self.settings['serial-console']:
serial_command = self.settings['serial-console-command']
diff --git a/vmdebootstrap/filesystem.py b/vmdebootstrap/filesystem.py
index 1ccaeed..07ec9ca 100644
--- a/vmdebootstrap/filesystem.py
+++ b/vmdebootstrap/filesystem.py
@@ -129,6 +129,7 @@ class Filesystem(Base):
rootdev = self.devices['rootdev']
bootdev = self.devices['bootdev']
boottype = self.devices['boottype']
+ roottype = self.devices['roottype']
def fsuuid(device):
out = runcmd(['blkid', '-c', '/dev/null', '-o', 'value',
@@ -233,8 +234,8 @@ class Filesystem(Base):
if not rootdir:
raise cliapp.AppException("rootdir not set")
self.message('Removing udev persistent cd and net rules')
- for x in ['70-persistent-cd.rules', '70-persistent-net.rules']:
- pathname = os.path.join(str(rootdir), 'etc', 'udev', 'rules.d', x)
+ for xrule in ['70-persistent-cd.rules', '70-persistent-net.rules']:
+ pathname = os.path.join(str(rootdir), 'etc', 'udev', 'rules.d', xrule)
if os.path.exists(pathname):
logging.debug('rm %s', pathname)
os.remove(pathname)
@@ -246,17 +247,17 @@ class Filesystem(Base):
hostname = self.settings['hostname']
if not rootdir:
raise cliapp.AppException("rootdir not set")
- with open(os.path.join(str(rootdir), 'etc', 'hostname'), 'w') as f:
- f.write('%s\n' % hostname)
+ with open(os.path.join(str(rootdir), 'etc', 'hostname'), 'w') as fhost:
+ fhost.write('%s\n' % hostname)
etc_hosts = os.path.join(str(rootdir), 'etc', 'hosts')
try:
- with open(etc_hosts, 'r') as f:
- data = f.read()
- with open(etc_hosts, 'w') as f:
+ with open(etc_hosts, 'r') as fhost:
+ data = fhost.read()
+ with open(etc_hosts, 'w') as fhosts:
for line in data.splitlines():
if line.startswith('127.0.0.1'):
line += ' %s' % hostname
- f.write('%s\n' % line)
+ fhosts.write('%s\n' % line)
except IOError:
pass