mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
fix raw image creation
This commit is contained in:
parent
0854f7920e
commit
ed76870ec9
4 changed files with 23 additions and 13 deletions
|
@ -10,8 +10,10 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"mount_dir": { "type": "string" },
|
"mount_dir": { "type": "string" },
|
||||||
|
"image_file": { "type": "string" },
|
||||||
"tarball": { "type": "boolean" },
|
"tarball": { "type": "boolean" },
|
||||||
"tarball_dir": { "type": "string" }
|
"tarball_dir": { "type": "string" },
|
||||||
|
"device" : { "type" : "string" }
|
||||||
},
|
},
|
||||||
"required": ["mount_dir"]
|
"required": ["mount_dir"]
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"bootstrapper": {
|
"bootstrapper": {
|
||||||
"mount_dir": "/tmp/target",
|
"mount_dir": "/mnt/target",
|
||||||
|
"image_file": "/tmp/target",
|
||||||
"tarball": true,
|
"tarball": true,
|
||||||
"device": "/dev/sda"
|
"device": "/dev/sda"
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,18 +3,22 @@ from common import phases
|
||||||
from common.exceptions import TaskError
|
from common.exceptions import TaskError
|
||||||
from common.tools import log_check_call
|
from common.tools import log_check_call
|
||||||
from bootstrap import Bootstrap
|
from bootstrap import Bootstrap
|
||||||
|
import os
|
||||||
|
|
||||||
class FormatVolume(Task):
|
class FormatVolume(Task):
|
||||||
description = 'Formatting the volume'
|
description = 'Formatting the volume'
|
||||||
phase = phases.volume_preparation
|
phase = phases.volume_preparation
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
mkmount = 'create -f raw "'+info.manifest.bootstrapper['mount_dir']+'" "'+str(info.manifest.volume['size'])+'"'
|
mkmount = ['/usr/bin/qemu-img', 'create', '-f', 'raw', info.manifest.bootstrapper['image_file'], str(info.manifest.volume['size'])+'M']
|
||||||
log_check_call(['/usr/bin/qemu-img',mkmount])
|
log_check_call(mkmount)
|
||||||
dev_path = info.manifest.bootstrapper['mount_dir']
|
ddcmd = ['/bin/dd', 'if=/dev/zero', 'bs=1024', 'conv=notrunc', 'count='+str(info.manifest.volume['size']), 'of='+info.manifest.bootstrapper['image_file']]
|
||||||
mkfs = '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem'])
|
log_check_call(ddcmd)
|
||||||
log_check_call([mkfs, dev_path])
|
loopcmd = ['/sbin/losetup', '/dev/loop0', info.manifest.bootstrapper['image_file']]
|
||||||
|
log_check_call(loopcmd)
|
||||||
|
mkfs = [ '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem']), '-m', '1', '-v', '/dev/loop0']
|
||||||
|
log_check_call(mkfs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TuneVolumeFS(Task):
|
class TuneVolumeFS(Task):
|
||||||
|
@ -23,7 +27,8 @@ class TuneVolumeFS(Task):
|
||||||
after = [FormatVolume]
|
after = [FormatVolume]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
dev_path = info.bootstrap_device['path']
|
#dev_path = info.bootstrap_device['path']
|
||||||
|
dev_path = info.manifest.bootstrapper['image_file']
|
||||||
# Disable the time based filesystem check
|
# Disable the time based filesystem check
|
||||||
log_check_call(['/sbin/tune2fs', '-i', '0', dev_path])
|
log_check_call(['/sbin/tune2fs', '-i', '0', dev_path])
|
||||||
|
|
||||||
|
@ -44,9 +49,9 @@ class CreateMountDir(Task):
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
import os
|
import os
|
||||||
mount_dir = info.manifest.bootstrapper['mount_dir']
|
mount_dir = info.manifest.bootstrapper['mount_dir']
|
||||||
info.root = '{mount_dir}/{vol_id}'.format(mount_dir=mount_dir, vol_id=info.volume.id)
|
info.root = mount_dir
|
||||||
# Works recursively, fails if last part exists, which is exaclty what we want.
|
# Works recursively, fails if last part exists, which is exaclty what we want.
|
||||||
os.makedirs(info.root)
|
os.makedirs(mount_dir)
|
||||||
|
|
||||||
|
|
||||||
class MountVolume(Task):
|
class MountVolume(Task):
|
||||||
|
@ -61,7 +66,7 @@ class MountVolume(Task):
|
||||||
msg = 'Something is already mounted at {root}'.format(root=info.root)
|
msg = 'Something is already mounted at {root}'.format(root=info.root)
|
||||||
raise TaskError(msg)
|
raise TaskError(msg)
|
||||||
|
|
||||||
log_check_call(['/bin/mount', info.bootstrap_device['path'], info.root])
|
log_check_call(['/bin/mount', '-t', info.manifest.volume['filesystem'], '/dev/loop0', info.root])
|
||||||
|
|
||||||
|
|
||||||
class MountSpecials(Task):
|
class MountSpecials(Task):
|
||||||
|
@ -94,6 +99,8 @@ class UnmountVolume(Task):
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
log_check_call(['/bin/umount', info.root])
|
log_check_call(['/bin/umount', info.root])
|
||||||
|
log_check_call(['/sbin/losetup', '-d', '/dev/loop0'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DeleteMountDir(Task):
|
class DeleteMountDir(Task):
|
||||||
|
|
|
@ -7,7 +7,7 @@ class HostPackages(Task):
|
||||||
phase = phases.preparation
|
phase = phases.preparation
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
packages = set(['debootstrap'])
|
packages = set(['debootstrap', 'qemu-utils'])
|
||||||
if info.manifest.volume['filesystem'] == 'xfs':
|
if info.manifest.volume['filesystem'] == 'xfs':
|
||||||
packages.add('xfsprogs')
|
packages.add('xfsprogs')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue