From 285a0dca4874332d9605a978567622ae31ce15a7 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 9 Apr 2013 13:34:35 +0000 Subject: Create BE --- install | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 4 deletions(-) diff --git a/install b/install index 6587a58..e594bbb 100755 --- a/install +++ b/install @@ -31,6 +31,10 @@ rpool = None # Name of the root slice, where ZFS root pool will be created (e. g. c0t0d0s0) rslice = None +# Created boot environment +bootenv = None + + class Abort(Exception): ''' User clicked "Cancel" ''' pass @@ -136,11 +140,13 @@ def create_rpool(hdd): pool_name = 'rpool{}'.format(pool_no) if not pool_name in zpools: break + else: + pool_name = None; progress = ProgressMessage(screen, title='Please, wait', text='Creating ZFS pool "{rpool}" on slice "{slice}" ...'.format(rpool=pool_name, slice=rslice)) - zpool_cmd = Popen(['zpool', 'create', '-f', pool_name, rslice], + zpool_cmd = Popen(['zpool', 'create', '-R', '/mnt/'+pool_name, '-f', pool_name, rslice], stderr=PIPE, stdout=PIPE) out, err = zpool_cmd.communicate() if 0 != zpool_cmd.returncode: @@ -168,7 +174,7 @@ def configure_rpool(): if not pool_is_imported(rpool): progress = ProgressMessage(screen, title='Please, wait', text='Importing ZFS pool "{}" ...'.format(rpool)) - zpool_cmd = Popen(['zpool', 'import', '-f', rpool], stderr=PIPE, stdout=PIPE) + zpool_cmd = Popen(['zpool', 'import', '-R', '/mnt/'+rpool, '-f', rpool], stderr=PIPE, stdout=PIPE) out, err = zpool_cmd.communicate() if 0 != zpool_cmd.returncode: ButtonChoiceWindow(screen, @@ -176,10 +182,99 @@ def configure_rpool(): text=err, buttons=['Ok'], width=70) rpool = None +def zfs_exists(fs): + fs_exists = call(['zfs', 'list', '-H', fs], stdout=PIPE, stderr=PIPE) + return fs_exists == 0 -def configure_zfs(): - pass +def zfs_create(fs, zvol=None, options={}): + args = ['zfs', 'create'] + if zvol: + args += ['-V', zvol] + + for o in options: + args += ['-o', o + '=' + options[o]] + + args.append(fs) + zfs_cmd = Popen(args, stderr=PIPE, stdout=PIPE) + out, err = zfs_cmd.communicate() + if 0 != zfs_cmd.returncode: + ButtonChoiceWindow(screen, + title='Creating of ZFS dataset failed', + text=err, buttons = ['Ok'], width=70) + return False + return True + + +def configure_zfs(): + global bootenv + progress = ProgressBar(screen, title='Creating ZFS filesystems') + root = rpool + '/ROOT' + if not zfs_exists(root): + progress.text = 'Creating ' + root + zfs_create(root, options={'canmount':'off'}) + progress.progress = 10 + + # Make sure we are creating new boot environment + bootenv = None + for be_no in range(20): + bootenv = root + '/osdy-' + str(be_no) + if not zfs_exists(bootenv): + break + else: + bootenv = None + progress.progress = 20 + + progress.text = 'Creating ' + bootenv + zfs_create(bootenv, options={'canmount':'noauto'}) + progress.progress = 30 + + fs = bootenv + '/usr' + progress.text = 'Creating ' + fs + zfs_create(fs) + progress.progress = 50 + + fs = bootenv + '/usr/local' + progress.text = 'Creating ' + fs + zfs_create(fs, options={'compression':'on'}) + progress.progress = 55 + + fs = bootenv + '/usr/src' + progress.text = 'Creating ' + fs + zfs_create(fs, options={'compression':'on'}) + progress.progress = 60 + + fs = bootenv + '/var' + progress.text = 'Creating ' + fs + zfs_create(fs) + progress.progress = 65 + + fs = bootenv + '/var/log' + progress.text = 'Creating ' + fs + zfs_create(fs) + progress.progress = 70 + + fs = bootenv + '/var/lib' + progress.text = 'Creating ' + fs + zfs_create(fs) + progress.progress = 75 + + fs = bootenv + '/var/cache' + progress.text = 'Creating ' + fs + zfs_create(fs) + progress.progress = 80 + + fs = bootenv + '/var/tmp' + progress.text = 'Creating ' + fs + zfs_create(fs) + progress.progress = 90 + + home = root + '/home' + if not zfs_exists(home): + progress.text = 'Creating ' + home + zfs_create(home, options={'mountpoint':'/home', 'compression':'on', + 'devices':'off', 'setuid':'off'}) + progress.progress = 100 def choose_hdd(number_of_zpools = 0): hdd_items = map(lambda x: '{}: {} {}'.format(x.name, x.capacity, x.description), hdds) -- cgit v1.2.3