Resize a zpool on a FreeBSD geli partition

09/20/15

Tagged with freebsd

This took quite some time and the interweb was not that helpful, so here it is:

As this particular freebsd machine is running within a qemu backed kvm virtual machine we first need to resize the image

$ qemu-img resize freebsd.img +20g
Image resized.

I booted the freebsd guest with the install cd and startet a rescue shell. To access the rescue system via the serial port, start a getty on ttyu0

# /usr/libexec/getty std.115200 ttyu0

and login as root without a password

$ virsh console freebsd
Connected to domain freebsd
Escape character is
FreeBSD/amd64 (Amnesiac) (ttyu0)

login: root
Last login: Sat Sep 19 09:55:26 on ttyv3
<lots of output skipped>

root@:~ #

First i checked the gpt partition table

root@:~ # gpart show
=>      34  20971453  vtbd0  GPT  (30G) [CORRUPT]
        34      1024      1  freebsd-boot  (512K)
      1058   4194304      2  freebsd-zfs  (2.0G)
   4195362   4194304      3  freebsd-swap  (2.0G)
   8389666  12581821      4  freebsd-zfs  (6.0G)

Note that it tells you that the gpt is corrupt, this needs to be fixed with

root@:~ # gpart recover vtbd0
vtbd0 recovered
root@:~ # gpart show
=>      34  62914493  vtbd0  GPT  (30G)
        34      1024      1  freebsd-boot  (512K)
      1058   4194304      2  freebsd-zfs  (2.0G)
   4195362   4194304      3  freebsd-swap  (2.0G)
   8389666  12581821      4  freebsd-zfs  (6.0G)
  20971487  41943040         - free -  (20G)

As the encryption key is located on the bootpool we first need to import the zpool:

root@:~ # zpool import -fR /tmp bootpool
root@:~ #

next we open the geli device (gpt partition 4), this needs to be done before resizing the gpt partition

root@:~ # geli attach -k /tmp/bootpool/boot/encryption.key vtbd0p4
Enter passphrase:
root@:~ #

List the geli device and make sure to write down the consumer media size

root@:~ # geli list
Geom name: vtbd0p4.eli
State: ACTIVE
EncryptionAlgorithm: AES-XTS
KeyLength: 256
Crypto: software
Version: 7
UsedKey: 0
Flags: BOOT
KeysAllocated: 2
KeysTotal: 2
Providers:
1. Name: vtbd0p4.eli
   Mediasize: 6441889792 (6.0G)
   Sectorsize: 4096
   Mode: r0w0e0
Consumers:
1. Name: vtbd0p4
   Mediasize: 6441892352 (6.0G)
   Sectorsize: 512
   Stripesize: 0
   Stripeoffset: 541696
   Mode: r1w1e1

in our case 6441892352.

now resize the gpt partition

root@:~ # gpart resize -i 4 vtbd0
vtbd0p4 resized
root@:~ #

resizing the geli device right now failed in my case with

root@:~ # geli resize -s 6441892352 vtbd0p4
geli: Cannot open vtbd0p4: Operation not permitted.

so i rebooted the system and tried the resize operation again.

once again make sure you know the mediasize of the geli consumer before rebooting!

it is not possible to open the geli device after the gpt partition resize operation.

# geli load
# geli resize -s 6441892352 vtbd0p4
#

After rebooting the system expand the zroot pool with

zpool set autoexpand=on zroot
zpool online -e zroot vtbd0p4.eli

Setting up a CentOS 7 host with virt-install

12/18/14

Tagged with centos, libvirt, kickstart

Setting up a new CentOS 7 host with the help of virt-install(1) is quite easy. I’m using the following command line options:

virt-install --name=infra \
             --ram=4096 \
             --vcpu=2 \
             --os-variant=rhel6 \
             --disk path=/var/lib/libvirt/images/infra.img \
             --nographics \
             --network network=default \
             --location 'http://mirror.centos.org/centos/7/os/x86_64/' \
             --initrd-inject=/root/infra.ks \
             --extra-args='console=ttyS0,115200n8 ks=file:/infra.ks serial'

The most important option is –initrd-inject to inject your kickstart config into the initial ramdisk that virt-install is going to download when installing the host. This only works when you are using the –location option as well.

and here is the kickstart file

#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512

# Use network installation
url --url="http://mirror.centos.org/centos/7/os/x86_64/"

cmdline

ignoredisk --only-use=vda
clearpart --drives=vda --all
part pv.01 --size 1 --grow --ondisk=vda
part /boot --fstype=ext4 --asprimary --size=512 --asprimary --ondisk=vda
volgroup rootvg pv.01
logvol /    --vgname=rootvg --size=5000 --name=rootlv
logvol /tmp --vgname=rootvg --size=512  --name=tmplv
logvol swap --vgname=rootvg --size=2048 --name=swaplv

# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'

# System language
lang en_US.UTF-8
timezone --utc Europe/Vienna

# Network information
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network  --hostname=localhost.localdomain

rootpw --iscrypted <your salted password hash here>

reboot

%packages --nobase
@core --nodefaults
-aic94xx-firmware*
-alsa-*
-iwl*firmware
-NetworkManager*
-iprutils
%end

How to remove unneeded files from a git repo

10/04/14

Tagged with git, puppet

This is the distilled information from these two excellent blog posts:

First list all the files with the repository with

git rev-list --objects --all | sort -k 2 > allfiles.txt

or if you would like to list unique files

git rev-list --objects --all | sort -k 2 | cut -f 2 -d\  | uniq

Found a file/directory you would like to completely wipe from the repository?

Execute

git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch directory/' -- --all

but be careful, this might eat your beloved cat!

Install puppetdb-terminus > 1.0 as a gem

09/22/14

Tagged with ruby, puppet

On our puppet master we are not able to use the puppetlabs provided rpm’s, instead we are installing puppet via ruby gems. Reason being that we run the puppet master under passenger with ruby 1.9.3 (installed via RedHat SCL).

Today I’ve updated our master to 3.6.2 / puppetdb 1.6.3 and hit a major road block:

You need the package/gem puppetdb-terminus, which matches the version of puppetdb. So if you would like to run puppetdb 1.6.3, you also need puppetdb-terminus 1.6.3. But there’s only a rpm package available, the ruby gem is still at version 1.0.0.

This is what i did to manually create the puppetdb-terminus gem in the right version:

$ curl -O http://downloads.puppetlabs.com/puppetdb/puppetdb-1.6.3.tar.gz
$ tar zxvf puppetdb-1.6.3
$ cd puppetdb-1.6.3/ext/master

Drop the following gemspec file into the folder (puppetdb-terminus.gem):

Gem::Specification.new do |s|
  s.name        = 'puppetdb-terminus'
  s.version     = '1.6.3'
  s.summary     = 'PuppetDB is a Puppet data warehouse; it manages storage and retrieval of all platform-generated data, such as catalogs, facts, reports'
  s.description = 'Centralized Puppet Storage'
  s.authors     = ['Puppetlabs']
  s.email       = 'puppet@puppetlabs.com'
  s.files       = Dir['lib/**/*']
  s.license     = 'Apache-2.0'
  s.homepage    = 'https://github.com/puppetlabs/puppetdb'
end

and finally create the gem:

$ gem build puppetdb-terminus.gem

you are now able to install the gem via

$ gem install puppetdb-terminus-1.6.3.gem