Giter Site home page Giter Site logo

nixpart's Introduction

nixpart's People

Contributors

aszlig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nixpart's Issues

Could you add a README.md?

Just so we don't need to dive in the repo to know what it can do, what it uses and whether it is obsolete.

Can't reformat machine when using LVM on RAID1

I'm using this on a Hetzner server with nixops:

        deployment.hetzner.partitions = ''
          clearpart --all --initlabel --drives=sda,sdb

          part raid.1 --grow --ondisk=sda
          part raid.2 --grow --ondisk=sdb

          raid pv.01 --level=1 --device=root --fstype=ext4 --label=root raid.1 raid.2

          volgroup vg0 pv.01
          logvol swap           --vgname=vg0 --recommended      --fstype swap --name=swap
          logvol /              --vgname=vg0 --size=400000      --fstype ext4 --name=root
          logvol /data --vgname=vg0 --size=1000 --grow --fstype xfs  --name=gluster-brick1
        '';

I get:

test-node-1> installing machine...
test-node-1> rebooting machine ‘test-node-1’ (1.2.3.4) into rescue system
test-node-1> sending reboot command... 
test-node-1> bash: warning: setlocale: LC_TIME: cannot change locale ()
test-node-1> done.
test-node-1> waiting for rescue system...Connection to 1.2.3.4 closed by remote host.
[down]..........................................................[up]
test-node-1> building Nix bootstrap installer... done. (/nix/store/4v16dw4gvm9ih3ki55gh8j1d6q6g7iaw-hetzner-nixops-installer/bin/hetzner-bootstrap)
test-node-1> creating nixbld group in rescue system... 
test-node-1> bash: warning: setlocale: LC_TIME: cannot change locale ()
test-node-1> done.
test-node-1> checking if tmpfs in rescue system is large enough... 
test-node-1> bash: warning: setlocale: LC_TIME: cannot change locale ()
test-node-1> yes: 15956 MB
test-node-1> copying bootstrap files to rescue system... 
test-node-1> bash: warning: setlocale: LC_TIME: cannot change locale ()
test-node-1> done.
test-node-1> partitioning disks... 
test-node-1> bash: warning: setlocale: LC_TIME: cannot change locale ()
test-node-1> Traceback (most recent call last):
test-node-1>   File "/nix/store/ni2js4lwp1w6l14azfcjlgwn2im38m1b-nixpart-0.4.1/bin/.nixpart-wrapped", line 166, in <module>
test-node-1>     main()
test-node-1>   File "/nix/store/ni2js4lwp1w6l14azfcjlgwn2im38m1b-nixpart-0.4.1/bin/.nixpart-wrapped", line 126, in main
test-node-1>     ks.initialize()
test-node-1>   File "/nix/store/ni2js4lwp1w6l14azfcjlgwn2im38m1b-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 978, in initialize
test-node-1>     self.handler.clearpart.execute(self.storage, self.handler)
test-node-1>   File "/nix/store/ni2js4lwp1w6l14azfcjlgwn2im38m1b-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 246, in execute
test-node-1>     storage.clearPartitions()
test-node-1>   File "/nix/store/fl2pafsa1c4y6z4hnqv8235jpbj6wja1-blivet-0.17-1/lib/python2.7/site-packages/blivet/__init__.py", line 773, in clearPartitions
test-node-1>     self.recursiveRemove(part)
test-node-1>   File "/nix/store/fl2pafsa1c4y6z4hnqv8235jpbj6wja1-blivet-0.17-1/lib/python2.7/site-packages/blivet/__init__.py", line 741, in recursiveRemove
test-node-1>     self.destroyDevice(leaf)
test-node-1>   File "/nix/store/fl2pafsa1c4y6z4hnqv8235jpbj6wja1-blivet-0.17-1/lib/python2.7/site-packages/blivet/__init__.py", line 1178, in destroyDevice
test-node-1>     action = ActionDestroyDevice(device)
test-node-1>   File "/nix/store/fl2pafsa1c4y6z4hnqv8235jpbj6wja1-blivet-0.17-1/lib/python2.7/site-packages/blivet/deviceaction.py", line 315, in __init__
test-node-1>     device.teardown()
test-node-1>   File "/nix/store/fl2pafsa1c4y6z4hnqv8235jpbj6wja1-blivet-0.17-1/lib/python2.7/site-packages/blivet/devices.py", line 3193, in teardown
test-node-1>     mdraid.mddeactivate(self.path)
test-node-1>   File "/nix/store/fl2pafsa1c4y6z4hnqv8235jpbj6wja1-blivet-0.17-1/lib/python2.7/site-packages/blivet/devicelibs/mdraid.py", line 225, in mddeactivate
test-node-1>     raise MDRaidError("mddeactivate failed for %s: %s" % (device, msg))
test-node-1> blivet.errors.MDRaidError: mddeactivate failed for /dev/md/0: running mdadm --stop /dev/md/0 failed

Going into rescue mode manually and running it myself hints at the problem:

# mdadm --stop /dev/md/0
mdadm: Cannot get exclusive access to /dev/md/0:Perhaps a running process, mounted filesystem or active volume group?
 # lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sdb                         8:16   0   3.7T  0 disk  
|-sdb2                      8:18   0   3.7T  0 part  
| `-md0                     9:0    0   3.7T  0 raid1 
|   |-vg0-root            253:1    0 390.6G  0 lvm   
|   |-vg0-swap            253:2    0  15.7G  0 lvm   
|   `-vg0-gluster--brick1 253:0    0   3.2T  0 lvm   
`-sdb1                      8:17   0     1M  0 part  
loop0                       7:0    0   2.5G  1 loop  
sda                         8:0    0   3.7T  0 disk  
|-sda2                      8:2    0   3.7T  0 part  
| `-md0                     9:0    0   3.7T  0 raid1 
|   |-vg0-root            253:1    0 390.6G  0 lvm   
|   |-vg0-swap            253:2    0  15.7G  0 lvm   
|   `-vg0-gluster--brick1 253:0    0   3.2T  0 lvm   
`-sda1                      8:1    0     1M  0 part  

Indeed, the problem is that the volume group is active:

root@rescue ~ # vgchange -a n vg0
  0 logical volume(s) in volume group "vg0" now active

After this I can stop:

root@rescue ~ # mdadm --stop /dev/md/0
mdadm: stopped /dev/md/0

I think there's something wrong in blivet or nixpart or nixops, it doesn't know that it should stop all VGs on the device before trying to --stop it.

I think this is because of some failed (or rather, successful?) deployment before that created the current state as shown in lsblk; I suspect that when the rescue mode boots, it immediately starts the mdadm array and the LVM volume group.

I could work around it by wiping that LVM setup manually:

root@rescue ~ # mdadm --zero-superblock /dev/sda2 
root@rescue ~ # mdadm --zero-superblock /dev/sdb2 

But I think that nixops should be able to provision Hetzner machines, no matter what's on the disk.

Status of the repository?

Hi,

As part of NixOS/teams-collaboration#1, I am trying to clarify the status of the repositories under the NixOS organisation.

This repository seems to be unmaintained or obsolete, so it will be archived in a month.

If you think it warrants staying here or should be moved to another organization instead, please answer this issue.

Update to a newer blivet (or pin an older anaconda)

> partitioning disks...
> Traceback (most recent call last):
>   File "/nix/store/2dzkd1lr1bpici9y93ibicj063k9jb7i-python2.7-nixpart-0.4.1/bin/.nixpart-wrapped", line 166, in <module>
>     main()
>   File "/nix/store/2dzkd1lr1bpici9y93ibicj063k9jb7i-python2.7-nixpart-0.4.1/bin/.nixpart-wrapped", line 152, in main
>     storage = ks.run(init=False)
>   File "/nix/store/2dzkd1lr1bpici9y93ibicj063k9jb7i-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 1040, in run
>     self.partition()
>   File "/nix/store/2dzkd1lr1bpici9y93ibicj063k9jb7i-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 990, in partition
>     errors, warnings = self.storage.sanityCheck()
>   File "/nix/store/z8qd1ic8chnhl0d1pwx9x5d69215aagj-python2.7-blivet-0.17-1/lib/python2.7/site-packages/blivet/__init__.py", line 1556, in sanityCheck
>     required = Size(spec="%s kb" % isys.EARLY_SWAP_RAM)
> AttributeError: 'NoneType' object has no attribute 'EARLY_SWAP_RAM'

See storaged-project/blivet#4

Generate grub configuration.

Currently, we're writing a NixOS configuration to stdout, containing fileSystem and swapDevices attributes.
But clearly, we should also add boot.loader.grub.devices (and maybe boot.loader.grub.version) to the generated attribute set.

Show list of known devices, when failing

I'm doing deploy with NixOps, but because of misconfigured partition script, I'm continuously seeing errors like this:

hetznerIron> checking if tmpfs in rescue system is large enough... yes: 32085 MB
hetznerIron> copying bootstrap files to rescue system... done.
hetznerIron> partitioning disks...
hetznerIron> Traceback (most recent call last):
hetznerIron>   File "/nix/store/k1vjvdjqrg5f6mwpzfjv8biyaq89x6c5-python2.7-nixpart-0.4.1/bin/.nixpart-wrapped", line 166, in <module>
hetznerIron>     main()
hetznerIron>   File "/nix/store/k1vjvdjqrg5f6mwpzfjv8biyaq89x6c5-python2.7-nixpart-0.4.1/bin/.nixpart-wrapped", line 126, in main
hetznerIron>     ks.initialize()
hetznerIron>   File "/nix/store/k1vjvdjqrg5f6mwpzfjv8biyaq89x6c5-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 983, in initialize
hetznerIron>     self.handler.partition.execute(self.storage, self.handler)
hetznerIron>   File "/nix/store/k1vjvdjqrg5f6mwpzfjv8biyaq89x6c5-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 452, in execute
hetznerIron>     p.execute(storage, ksdata)
hetznerIron>   File "/nix/store/k1vjvdjqrg5f6mwpzfjv8biyaq89x6c5-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 595, in execute
hetznerIron>     raise KickstartValueError, formatErrorMsg(self.lineno, msg="Specified nonexistent disk %s in partition command" % n)
hetznerIron> pykickstart.errors.KickstartValueError: The following problem occurred on line 3 of the kickstart file:
hetznerIron>
hetznerIron> Specified nonexistent disk md2 in partition command
hetznerIron>

Maybe show list of available disks when exception occured?

nixpart -p generates invalid syntax for my kickstart file

Trying to format a Hetzner server:

root@rescue ~ # cat kickstartfile
clearpart --all --initlabel --drives=sda,sdb,sdc,sdd

part raid.1 --grow --ondisk=sda
part raid.2 --grow --ondisk=sdb

#raid "" --level=1 --device=md0 --label=ssdjournal raid.1 raid.2

part raid.3 --grow --ondisk=sdc
part raid.4 --grow --ondisk=sdd

#raid "" --level=1 --device=md1 --label=root raid.3 raid.4

%post
# --run makes mdadm not promt the user for confirmation
mdadm --create --run --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm --create --run --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sdc1 /dev/sdd1

mke2fs -O journal_dev /dev/md0
mkfs.ext4 -J device=/dev/md0 /dev/md1
echo "/dev/md1   /   ext4   data=journal,errors=remount-ro 0 1" >> /etc/fstab
%end

root@rescue ~ # nixpart -p kickstartfile 
{
  swapDevices = [
  ];
  boot.loader.grub.devices = [
    "/dev/sda"
    "/dev/sdb"
    "/dev/sdc"
    "/dev/sdd"
  ];
  fileSystems = {}{};
}

fileSystems = {}{}; isn't valid syntax, and nixops trips over this output.

nix expression for btrfs subvolumes is not correct

On Hetzner I want to deploy a machine with the following partitioning scheme:

clearpart --all --initlabel --drives=sda,sdb,sdc

part raid.0 --size=512 --ondisk=sda
part raid.1 --size=512 --ondisk=sdb
part raid.2 --size=512 --ondisk=sdc

raid /boot --level=1 --device=LABEL=host_boot_md --fstype=ext3 --label=host_boot raid.0 raid.1 raid.2

part swap0 --size=8192 --label=swap0 --fstype=swap --ondisk=sda
part swap1 --size=8192 --label=swap1 --fstype=swap --ondisk=sdb
part swap2 --size=8192 --label=swap2 --fstype=swap --ondisk=sdc

part btrfs.0 --grow --ondisk=sda
part btrfs.1 --grow --ondisk=sdb
part btrfs.2 --grow --ondisk=sdc

btrfs none --data=1 --metadata=1 --label=btrfs_pool btrfs.0 btrfs.1 btrfs.2
btrfs /            --subvol --name=host_root LABEL=btrfs_pool
btrfs /run       --subvol --name=host_run  LABEL=btrfs_pool
btrfs /nix/store --subvol --name=nix_store LABEL=btrfs_pool

The btrfs part can be found on pykickstart. Anyways, this results in the following physical spec:

          ({
            swapDevices = [
              { label = "swap0"; }
              { label = "swap1"; }
              { label = "swap2"; }
            ];
            boot.loader.grub.devices = [
              "/dev/sda"
              "/dev/sdb"
              "/dev/sdc"
            ];
            fileSystems = {
              "/nix/store" = {
                device = "/dev/sda3";
                fsType = "btrfs";
              };
              "/boot" = {
                fsType = "ext3";
                label = "host_boot";
              };
              "/run" = {
                device = "/dev/sda3";
                fsType = "btrfs";
              };
              "/" = {
                device = "/dev/sda3";
                fsType = "btrfs";
              };
            };
          })

which is not quite right. It should rather be something like the following:

          ({
            swapDevices = [
              { label = "swap0"; }
              { label = "swap1"; }
              { label = "swap2"; }
            ];
            boot.loader.grub.devices = [
              "/dev/sda"
              "/dev/sdb"
              "/dev/sdc"
            ];
            fileSystems = {
              "/nix/store" = {
                fsType = "btrfs";
                options = "subvol=nix_store";
                label = "btrfs_pool";
              };
              "/boot" = {
                fsType = "ext3";
                label = "host_boot";
              };
              "/run" = {
                fsType = "btrfs";
                options = "subvol=host_run";
                label = "btrfs_pool";
              };
              "/" = {
                fsType = "btrfs";
                options = "subvol=host_root";
                label = "btrfs_pool";
              };
            };
          })

I achieved the latter with the following patch:

diff --git a/nixpart b/nixpart
index 036967b..8a8997c 100644
--- a/nixpart
+++ b/nixpart
@@ -67,6 +67,9 @@ def get_nixos_config(storage):
             fs = {}
             if label is not None:
                 fs['label'] = label
+            elif device.type == 'btrfs subvolume':
+                fs['label'] = device.volume.name
+                fs['options'] = device.format.mountopts
             else:
                 fs['device'] = path
             fs['fsType'] = device.format.type

DISCLAIMER: Currently I am not entirely done with the deployment so I am not sure if the patch above really works. I will provide further information when everything worked out allright.

deploy to hetzner fails with `invalid device specification`

deployer@deploy:~/slipstream$ nixops deploy -d production
tokyo> creating an exclusive robot admin account for ‘tokyo’... done. 
tokyo> installing machine...
tokyo> rebooting machine ‘tokyo’ (x.x.x.x) into rescue system
tokyo> sending hard reset to robot... done.
tokyo> waiting for rescue system...[down].......................................................................................................[up]
tokyo> building Nix bootstrap installer... done. (/nix/store/6c47hh0f40yf40hln4sla314ihbd0xjn-hetzner-nixops-installer/bin/hetzner-bootstrap)
tokyo> creating nixbld group in rescue system... done.
tokyo> checking if tmpfs in rescue system is large enough... yes: 32078 MB
tokyo> copying bootstrap files to rescue system... done.
tokyo> partitioning disks... 
tokyo> Traceback (most recent call last):
tokyo>   File "/nix/store/bdbybjhccgdp2rqwsbs83ildilss7drm-python2.7-nixpart-0.4.1/bin/.nixpart-wrapped", line 166, in <module>
tokyo>     main()
tokyo>   File "/nix/store/bdbybjhccgdp2rqwsbs83ildilss7drm-python2.7-nixpart-0.4.1/bin/.nixpart-wrapped", line 152, in main
tokyo>     storage = ks.run(init=False)
tokyo>   File "/nix/store/bdbybjhccgdp2rqwsbs83ildilss7drm-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 1040, in run
tokyo>     self.partition()
tokyo>   File "/nix/store/bdbybjhccgdp2rqwsbs83ildilss7drm-python2.7-nixpart-0.4.1/lib/python2.7/site-packages/nixkickstart.py", line 993, in partition
tokyo>     self.storage.doIt()
tokyo>   File "/nix/store/cfb9msg4r518ihgxiyg8h2f7d9k7mwfv-python2.7-blivet-0.17-1/lib/python2.7/site-packages/blivet/__init__.py", line 310, in doIt
tokyo>     self.devicetree.processActions()
tokyo>   File "/nix/store/cfb9msg4r518ihgxiyg8h2f7d9k7mwfv-python2.7-blivet-0.17-1/lib/python2.7/site-packages/blivet/devicetree.py", line 237, in processActions
tokyo>     action.execute()
tokyo>   File "/nix/store/cfb9msg4r518ihgxiyg8h2f7d9k7mwfv-python2.7-blivet-0.17-1/lib/python2.7/site-packages/blivet/deviceaction.py", line 471, in execute
tokyo>     options=self.device.formatArgs)
tokyo>   File "/nix/store/cfb9msg4r518ihgxiyg8h2f7d9k7mwfv-python2.7-blivet-0.17-1/lib/python2.7/site-packages/blivet/formats/__init__.py", line 311, in create
tokyo>     raise FormatCreateError("invalid device specification", self.device)
tokyo> blivet.errors.FormatCreateError: ('invalid device specification', u'/dev/sdb2')
error: command ‘['ssh', '-oControlPath=/tmp/nixops-ssh-tmpwYD0U2/master-socket', '-p', '22', '-o', 'LogLevel=quiet', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'GlobalKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-p', '22', '-o', 'LogLevel=quiet', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'GlobalKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-x', '[email protected]', '--', 'export LANG= LC_ALL= LC_TIME=; nixpart -p -']’ failed on machine ‘tokyo’ (exit code 1)

I tried two configurations:

clearpart --all --initlabel --drives=sda,sdb

part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb

part raid.1 --grow --ondisk=sda
part raid.2 --grow --ondisk=sdb

raid / --level=1 --device=md0 --fstype=ext4 \
       --label=root raid.1 raid.2

and

clearpart --all --initlabel --drives=sda,sdb

part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb

part btrfs.1 --grow --ondisk=sda
part btrfs.2 --grow --ondisk=sdb

btrfs / --data=1 --metadata=1 --label=root btrfs.1 btrfs.2

The harddisks are two "ATA Crucial_CT500MX2 (scsi)" with 500GB each. Installing another Linux distro like Ubuntu seems to work fine.

Any ideas how this could be fixed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.