I was looking at the filesystem module today, hoping to use it to resize a filesystem that is living in a logical volume. However, I am not sure how to use it safely so it doesn’t create a filesystem. Has anyone used the filesystem module to resize an LV? If so, how did you do it?
If you are growing the fs, you first need to increase the LV size with the lvol size option then increase the fs using filesystem resizefs option.
However, shrinking the fs opens up a can of worms…
You’d have do it the opposite way around: first reduce the filesystem, then reduce the LV. But, looking at the code for filesystem.py it doesn’t look like you can reduce the filesystem - it prints out the message saying it’s doing it, but exits. It looks like it can onlygrow the filesystem, and only when it sees that the underlying device is larger.
So, you’d need to run a command rather than using the filesystem module. Also, you’d need to make sure the shrink worked before resizing the underlying LV, otherwise you are asking for big trouble with your data !
To make things even more complicated, you can only shrink the filesystem if there is sufficient free space. Even then it might not work depending on how much meta data or fragmentation there is.
The bottom line is that I’m not entirely sure how well suited CM tools (Ansible, Puppet, etc) are to filesystem management on an on-going basis. Possibly use CM for initial deployment or subsequent checking/reporting. But the idea of using CM tools to perhaps shrink a filesystem strikes me as very questionable in the first place.
For example, not too long ago I dealt with a couple of systems that wouldn’t boot because they both had a filesystem where fsck failed because the filesystem was larger than the underlying device. I’m quite sure the problem was caused by some buggy Puppet manifest code which had left a data corruption problem waiting to happen.
Thanks! Yes, I was growing filesystems on an initial deployment from a small backup to a larger working volume. I had figured out the lvol module - that is handy! I had to do a shell command to pvresize first, though.
Thanks for the pointers. I got it working like so:
`
name: resize the pv
shell: pvresize /dev/xvdz
name: extend logical volumes
lvol:
vg: VGMagneticBU
lv: “{{ item }}”
size: 45%VG #Note this fails if that percentage space isn’t available
shrink: no
with_items: