Sunday, 17 January 2016

Resize encrypted lvm partitions in Fedora23

In this article I will describe how to shrink one Logical Volume and extend another one in the same volume group.

My setup

During Fedora23 installation I let the installer to partition my disk automatically. I also checked that I want to encrypt my data.
The installer created Logical Volumes: 50GB root partition, 60GB home and 8GB swap.

After some time of using the system I found out that there is only 15GB left in /home and that there is 40GB of free space in / (root). I've decided that I will extend home and shrink root.

Preparation for the action

I spent some time reading about lvm and also LUKS disk encryption in fedora, and then I found this great page about resizing of lvm encrypted partitions - exactly what I needed, even little bit more.

I will try to describe exactly how it went in my case, so this article should be little bit shorter then the one I linked.

Initialization

When you want to shrink a partition you have to do it in unmounted state. For the root partition it means to boot from a live CD. I used Fedora23 CD for that.

Everybody warns you that you should backup your data before doing this, because you can easily loose them if something goes wrong. As I have all my important data in clouds (Dropbox, Google drive) I just restarted my laptop and booted Fedora live.

Thursday, 14 January 2016

MTP in Fedora23 for Android phone

I've recently installed fresh Fedora23 LXDE spin and when I connected my Android phone with 5.0.2 android version which supports MTP and PTP protocols for transferring files it appeared that it's not supported out of the box.

Luckily the solution is easy. You just need to install one utility.
sudo dnf install gvfs-mtp
After installation I had to restart my notebook (maybe starting some service would be enough, but I wanted to boot with new kernel anyway).

And when I connect the phone by USB cable now it automatically appears in the file manager as LGE Android Phone.

I want to add that at first I was afraid that it doesn't work properly, because when I clicked on the device in the file manager for the fist time, nothing appeared. But it just took some time till the device was scanned and its internal storage appeared.


Saturday, 9 January 2016

Symfony console no colors, symfony console progressbar on many lines

When you install symfony installer and after executing symfony command you don't see colorized help text, you might also experience problem with progress-bar on many lines. Progressbar is used when you're creating new symfony project by command symfony new myproject.

Symfony help text without colors Symfony installer progressbar on many lines, because of not installed php posix module


Both problems are probably caused by a lack of POSIX support in your php environment.

Solution

Just install php posix module.

The package named php-process in current Fedora distribution.

So you just need to do:
sudo dnf install php-process

See the result after the installation of the module:

Symfony help text with colors
Symfony progressbar after installation of php posix module


Wednesday, 6 January 2016

How to fix vagrant hanging when mounting folders on fedora (Fedora firewall configuration for Vagrant NFS synced folders)

Situation

If you use Fedora distribution on your host machine and you configure your vagrant box to use NFS type of synced folders, you might get into trouble with vagrant hanging during mounting of those NFS shared folders.
$ vagrant up
...
...
==> default: Mounting NFS shared folders...

Verify if the firewall configuration is the problem

If you haven't changed default firewall settings, the problem is probably there because Fedora has pretty securely configured firewall by default.

To quickly check if the problem is in the firewall settings you can try to disable it:
sudo systemctl stop firewalld
If you want to double check that firewall is really disabled, you can check iptables rules. Disabled firewall looks like this:
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

But of course disabling the firewall permanently is not a good idea so let's configure it that it allows mounting of NFS folders for the vagrant box.

Don't forget to enable the firewall again:
sudo systemctl start firewalld

Virtualbox network interfaces and fedora firewall

By default Virtualbox uses network interface vboxnet0 but when you reload your vagrant box it might happen that new interface will be created and used by the box (vboxnet1, vboxnet2 etc). So if you see hanged mounting in the future, check if the box uses interface which is allowed in the firewall config.

As I described in my older article about fedora firewall, fedora uses zones into which you assign network interfaces and then you set specific configuration for each zone.

Therefore what we need to do is to assign vboxnet0 (vboxnet1,...) interface into zone "internal" and then allow apropriate ports (services). We can do it via GUI firewall-config or via terminal firewall-cmd.

As clicking into the gui is something what you can probably handle by yourself, I will use the terminal. Another advantage of firewall-cmd is that you can simply copy following commands and paste them intoto your terminal so it's much quicker.

Change the firewall settings to allow NFS mount

sudo su
firewall-cmd --zone internal --add-interface vboxnet0
firewall-cmd --permanent --zone internal --add-service nfs
firewall-cmd --permanent --zone internal --add-service rpc-bind
firewall-cmd --permanent --zone internal --add-service mountd
firewall-cmd --permanent --zone internal --add-port 2049/udp
firewall-cmd --reload

If you do this when nfs directory mounting is hanged you can see that mounting will continue just after you reload the firewall settings.
==> default: Mounting NFS shared folders...
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

If you got troubles to make it work, just leave a comment and I will try to help.

Monday, 4 January 2016

Ansible provisioning fails with fedora/23-cloud-base box

I have been playing with Vagrant and ansible recently and got into trouble to make it work.

At first I want to say that I'm not an experienced user of ansible, but I'm sure that there are many people like me therefore I will try to describe it in a way that even I would understand it ;)

Situation

I have Fedora 23  on the host machine with installed Vagrant, ansible, python3, python2 etc. I have Vagrantfile with fedora/23-cloud-base as config.vm.box and provision by ansible.

When I started vagrant provision comand I got this error:
$ vagrant provision
==> default: Running provisioner: ansible...     default: Running ansible-playbook... PLAY [vagrant] **************************************************************** GATHERING FACTS *************************************************************** failed: [192.168.25.25] => {"failed": true, "parsed": false} BECOME-SUCCESS-afwahqttsdeueajwfcuqsvaulkoxjixf /bin/sh: /usr/bin/python: No such file or directory OpenSSH_7.1p1, OpenSSL 1.0.2e-fips 3 Dec 2015 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug1: auto-mux: Trying existing master debug1: mux_client_request_session: master session id: 2 Shared connection to 192.168.25.25 closed. TASK: [apache | Install Apache] *********************************************** FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************            to retry, use: --limit @/home/tomor/playbook.retry 192.168.25.25              : ok=0    changed=0    unreachable=0    failed=1
Ansible failed to complete successfully. Any error output should be visible above. Please fix these errors and try again.
When I enabled debugging by ansible.verbose="vvv" I saw more output but it didn't help me.

Reason of the fail

The problem is in the fact that 
  • ansible needs python 2.x on the remote system and Fedora23 has only python3 installed by default
  • python3 does not create /usr/bin/python - because it's not compatible with python2
and that's the reason why ansible provisioning fails - see the beginning of the fail:
failed: [192.168.25.25] => {"failed": true, "parsed": false}
BECOME-SUCCESS-afwahqttsdeueajwfcuqsvaulkoxjixf
/bin/sh: /usr/bin/python: No such file or directory
Python is needed for gathering of the facts (setup module).

Solution

To solve this situation you just have to install python 2 on the remote machine.

As I wanted to do the whole installation of the Vagrant box by ansible I solved it by:
  1. disable Gathering Facts
  2. add installation of python2
  3. start gathering facts manually (by setup module)
It means adapting basic playbook like this:
---
- hosts: vagrant
  sudo: true
  gather_facts: false # Fedora23 doesn't have python2 installed by default
  roles:
    - ansible_prepare # install python2, gather facts manually after python is prepared
    - my_another_role
And creation of ansible_prepare role task:
- name: Install python2 on the remote machine
  raw: dnf install -y python2 python2-dnf libselinux-python

- name: Gather facts
  setup:
Yes, there is just setup: which does gathering of the facts ;)
See the setup module docs for more details.


That's it. 

Sources