summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2015-03-05 11:53:14 +0000
committerTiago Gomes <tiago.gomes@codethink.co.uk>2015-03-06 16:17:59 +0000
commit42b1f0b0d55cf34055e683b8352e9e9d18874c19 (patch)
tree1db08e81a1fb8f353a7ad32cbdc357b72195c4a8
parentaa2c42511e26b6e9b1a2063df40a7c5f0504add7 (diff)
downloadinstaller-scripts-baserock/tiago-ed/m2-moonshot-deployment.tar.gz
Support creating ext4 boot partitionsbaserock/tiago-ed/m2-moonshot-deployment
Some bootloaders are unable to read from a btrfs system.
-rwxr-xr-xbaserock-installer81
1 files changed, 75 insertions, 6 deletions
diff --git a/baserock-installer b/baserock-installer
index e98ef1a..897b984 100755
--- a/baserock-installer
+++ b/baserock-installer
@@ -31,6 +31,9 @@ import errno
import time
import stat
import traceback
+import contextlib
+import tempfile
+import shutil
config_file = '/etc/install.conf'
@@ -50,6 +53,24 @@ class FileNotExistsError(Exception):
class NotBaserockRootfsError(Exception):
pass
+@contextlib.contextmanager
+def _tempdir():
+ td = tempfile.mkdtemp()
+ try:
+ yield td
+ finally:
+ subprocess.check_call(['rmdir', td])
+
+@contextlib.contextmanager
+def _mount(device, mount_type):
+ with _tempdir() as mount_dir:
+ try:
+ subprocess.check_call(['mount', '-t', mount_type, device,
+ mount_dir])
+ yield mount_dir
+ finally:
+ subprocess.check_call(['umount', mount_dir])
+
def validate_install_values(disk_dest, rootfs):
if not os.path.exists(disk_dest):
print "ERROR: The device %s doesn't exist." % disk_dest
@@ -64,10 +85,55 @@ def validate_install_values(disk_dest, rootfs):
def is_baserock_rootfs(rootfs):
return os.path.isdir(os.path.join(rootfs, 'baserock'))
-def run_install(writeext_path, deployment_config, rootfs, disk_dest):
+
+def run_install(writeext_path, deployment_config, rootfs,
+ disk_dest, create_boot_partition):
env = dict(os.environ)
env.update(deployment_config)
- subprocess.check_call([writeext_path, rootfs, disk_dest], env=env)
+ if create_boot_partition in ('yes', 'True'):
+ subprocess.check_call([writeext_path, rootfs, disk_dest + '2'],
+ env=env)
+ print "Creating a boot partition"
+ p = subprocess.Popen(['/sbin/sfdisk', '-uM', disk_dest],
+ stdin=subprocess.PIPE)
+ p.stdin.write(',250,83,*\n')
+ p.stdin.write(',,83,\n')
+ p.communicate()
+ subprocess.check_call(['/usr/sbin/mkfs.ext4', '-L', 'boot', '-F',
+ disk_dest + '1'])
+
+ with _mount(disk_dest + '1', 'ext4') as boot_mount, \
+ _mount(disk_dest + '2', 'btrfs') as root_mount:
+
+ boot_factory = os.path.join(boot_mount, 'systems', 'factory')
+ root_factory = os.path.join(root_mount, 'systems', 'factory')
+ os.makedirs(boot_factory)
+
+ shutil.copy(os.path.join(root_factory, 'kernel'),
+ os.path.join(boot_factory))
+
+ dtb_path = os.path.join(root_factory, 'dtb')
+ if os.path.exists(dtb_path):
+ shutil.copy(dtb_path, boot_factory)
+
+ initramfs_path = os.path.join(root_factory, 'initramfs')
+ if os.path.exists(initramfs_path):
+ shutil.copy(initramfs_path, boot_factory)
+
+ extlinuxconf_path = os.path.join(root_mount, 'extlinux.conf')
+ if os.path.exists(extlinuxconf_path):
+ shutil.copy(extlinuxconf_path, boot_mount)
+
+ bootscr_path = os.path.join(root_factory, 'orig', 'boot',
+ 'boot.scr')
+ if os.path.exists(bootscr_path):
+ shutil.copy(bootscr_path, boot_mount)
+
+ os.symlink('factory',
+ os.path.join(boot_mount, 'systems', 'default'))
+ else:
+ subprocess.check_call([writeext_path, rootfs, disk_dest], env=env)
+
def finish_installation(postinstallcmd):
os.system("sync")
@@ -110,10 +176,12 @@ def check_and_read_config(config_file):
device, rootfs = (read_option(config, key)
for key in keys)
+ create_boot_partition = read_option(config,
+ 'INSTALLER_CREATE_BOOT_PARTITION')
postinstallcmd = read_option(config,
'INSTALLER_POST_INSTALL_COMMAND',
'reboot -f')
- return device, rootfs, postinstallcmd
+ return device, rootfs, create_boot_partition, postinstallcmd
def read_option(config, option, default_value=None):
try:
@@ -166,13 +234,14 @@ try:
writeext_path = morphlib.extensions._get_morph_extension_filename(
'rawdisk', '.write')
- disk_dest, rootfs, postinstallcmd = check_and_read_config(
- config_file)
+ disk_dest, rootfs, create_boot_partition, postinstallcmd = \
+ check_and_read_config(config_file)
validate_install_values(disk_dest, rootfs)
deployment_config=get_deployment_config(rootfs)
- run_install(writeext_path, deployment_config, rootfs, disk_dest)
+ run_install(writeext_path, deployment_config, rootfs,
+ disk_dest, create_boot_partition)
do_unmounts(mounted)
finish_installation(postinstallcmd)