# lvm2 fragmentation

## nordic bro

Is there some way w/o having to reboot that I can see what an lvm2 logical volume's fragmentation level is (ext3)?   If I have to reboot to see this is there some way to save its output since it's usually scrolling too fast to read them all?  And is the only way to unfragment by moving the data, recreating the filesystem then putting the data back?  

When I was booting and fsck (I guess) was checking partitions, I didn't notice until it was nearly off the screen but I'm almost positive a 15G lvm partition being checked said "62% fragmentation" (it's about 80% full and I rarely move/copy/delete anything there).

----------

## frostschutz

You should be able to see all the boot messages in dmesg. If your dmesg buffer is too small you can increase its size in your kernel config (CONFIG_LOG_BUF_SHIFT, Kernel log buffer size in General options). There may also be a /var/log/dmesg that keeps the full output in a file.

Do you mean file system fragmentation, or LVM fragmentation? You get LVM fragmentation only when resizing partitions, or when there is not enough continuous space to create a single new partition in. Even so it should not be a problem because the fragmented pieces should be a lot larger than what you usually get with file based fragmentation.

If you're concerened about fragmentation on a file system level (since you mentioned ext3), that is an issue completely unrelated to LVM. Unfortunately the only way to defragment an ext3 filesystem is to copy files and hope that the copy will be less fragmented than the original. Other filesystems, like XFS, offer user land tools to defrag their filesystem properly and transparently even while it's mounted and in use. It actually only copies the files that are fragmented and only if the copy will be better than the original, and it will only do that when and if you want it to (you can put it in a cron job, let it run for an hour, and resume the next day).

----------

## nordic bro

Thanks.  They're lvm2 volume groups but individual partitions within, created with mkfs.ext3.  I only mentioned lvm in case that had something to do w/the high level of ext3 fragmentation.  

So as far as you know w/ext3 there's no cmd prompt way I can check fragmentation level w/o forcing fsck upon reboot (then hoping fsck's output is captured in dmesg; it def isn't currently but will try the kernel cfg you mention)?

Could a high level of fragmentation on ext3 have anything do w/the fact that this is about 11G of video files, each 60M-130M apiece?  That's all that's on this partition and IIRC it's pretty new so I was surprised fragmentation was so high.

----------

## x22

You can run fsck manually but only if the partition is unmounted or mounted read-only. -f option will be necessary to force check of clean filesystem.

On ext2/3 large files are always fragmented.

Fragmentation of large files usually does not matter.

Dmesg only shows kernel messages not messages from fsck.

----------

