linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Ray Morris <support@bettercgi.com>
To: LVM general discussion and development <linux-lvm@redhat.com>
Subject: Re: [linux-lvm] "Condensing" Physical Volumes
Date: Sat, 04 Dec 2010 13:40:27 -0600	[thread overview]
Message-ID: <1291491627.8066.13@raydesk1.bettercgi.com> (raw)
In-Reply-To: <201012042006.46803.d_baron@012.net.il> (from d_baron@012.net.il on Sat Dec  4 12:06:46 2010)

   A followup for the case where it's the filesystems that
have free space.  This is an example of reclaiming space where
the file  system has free space.  That filesystem is on a partition,
which is part of a logical volume.  We shrink from the inside
out - first the filesystem, then the partition, then the logical
volume.  If you don't have partitions within your LVs, skip that part.


#!/bin/sh


PATH="$PATH:/sbin:/root/bin"
export PATH

VG=bob

if [ -z "$2" ]
then
     echo "usage: $0 name size_in_gb (dh -h, NOT df -H)"
     exit
fi

name=$1
fssize=$2

echo "called clone_shrink $name $fssize"

kpartx -p '' -a /dev/mapper/${VG}-${name}
mount /dev/mapper/${VG}-${name}1 && sleep 2 &&
used=`df -P -BG | grep "$name" | awk '{ print \$3 }' | sed 's@G@@'` &&

if [ $used -gt $fssize ]
then
     echo "$name is using $used G, which is more than $fssize G" 1>&2
     exit 1
fi

/dev/mapper/${VG}-${name}1 &&
kpartx -dv -p '' /dev/mapper/${VG}-${name} && sleep 2 &&

# filesystem overhead
partsize=`perl -e "print int($fssize * 1.04)"` &&
vgsize=`expr $partsize + 1` &&


lvchange -ay $VG/$name &&
kpartx -p '' -a /dev/mapper/$VG-${name} &&
e2fsck -fp /dev/mapper/$VG-${name}1 2>/dev/null &&
resize2fs /dev/mapper/$VG-${name}1 ${fssize}G &&
e2fsck -fp /dev/mapper/$VG-${name}1 2>/dev/null
kpartx -p '' -d /dev/mapper/$VG-${name} &&
kpartx -p 'p' -d /dev/mapper/$VG-${name} &&

# If changing to parted or other, these are 1024 GB, not 1000 GB
lvchange -an $VG/$name &&
lvchange -ay $VG/$name &&
echo -e "d\nn\np\n1\n63\n+${partsize}GB\na\n1\np\nw\n | fdisk -u -S 63  
/dev/mapper/$VG-${name}"
echo -e "d\nn\np\n1\n63\n+${partsize}GB\na\n1\np\nw\n" | fdisk -u -S 63  
/dev/mapper/$VG-${name}
kpartx -p '' -d /dev/mapper/$VG-${name} &&
kpartx -p 'p' -d /dev/mapper/$VG-${name}


lvchange -an $VG/${name} &&
lvreduce -L ${vgsize}G $VG/${name} &&
lvchange -ay $VG/${name}

   The above commands are slightly adjusted from a script we use.
They may not be right for your situation.  They may not be right at all.
You should read and fully understand all commands before running them.

   Note particularly that due to overhead, 1000 vs. 1024, or other
reasons, the size of each container may need to be specified as being
a little larger than what it is supposed to contain.  Be very careful
when reducing the size of things - you could cut the end off of your
filesystems.  Also be sure you are familiar with vgcfgbackup,  
vgcfgrestore,
and other tools for undoing what you've done in case of problems.
--
Ray Morris
support@bettercgi.com

Strongbox - The next generation in site security:
http://www.bettercgi.com/strongbox/

Throttlebox - Intelligent Bandwidth Control
http://www.bettercgi.com/throttlebox/

Strongbox / Throttlebox affiliate program:
http://www.bettercgi.com/affiliates/user/register.php


On 12/04/2010 12:06:46 PM, David Baron wrote:
> I need more extents to move stuff off older, possibly failing IDE  
> disks to my
> new SATA terrabyter. However, not enough extents are available. The  
> disk is
> very sparsely populated.
> 
> Is there any way to "condense" physical volumes to recover/expose  
> empty
> extents in order to make use of them?
> 
> _______________________________________________
> linux-lvm mailing list
> linux-lvm@redhat.com
> https://www.redhat.com/mailman/listinfo/linux-lvm
> read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/
> 
> 

  parent reply	other threads:[~2010-12-04 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-04 18:06 [linux-lvm] "Condensing" Physical Volumes David Baron
2010-12-04 19:28 ` Ray Morris
2010-12-04 19:38 ` Lars Ellenberg
2010-12-04 19:40 ` Ray Morris [this message]
     [not found] <mailman.7913.1291608602.9820.linux-lvm@redhat.com>
2010-12-06 12:34 ` David Baron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291491627.8066.13@raydesk1.bettercgi.com \
    --to=support@bettercgi.com \
    --cc=linux-lvm@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).