LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I have a LVM2 need and am confused. (http://www.linuxquestions.org/questions/linux-newbie-8/i-have-a-lvm2-need-and-am-confused-911941/)

gcmartin 11-04-2011 07:54 PM

I have a LVM2 need and am confused.
 
I have just completed building a test system. It has a boot area (kernel) and a LVM2 volume.

I would like to reduce the size of the LVM2 volume to add a swap partition to the system. I have found lots of information of growing but the info on reduction is very confusing. I am lost and am appealing. I saw this, but found that the problem being addressed does not match mine.

Here's my single drive system info. And, I would like to have a 16GB Swap partition.
Code:

# mount
/dev/mapper/pve-root on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
procbususb on /proc/bus/usb type usbfs (rw)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/mapper/pve-data on /var/lib/vz type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)

# df -l
dev/mapper/pve-root ... /
tmpfs ... /lib/ini/rw
udev ... /dev
tmpfs ... /dev/shm   
/dev/mapper/pve-data ... /var/lib/vz
/dev/sda1 ... /boot

# fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          66      524288  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              66      60801  487859712  8e  Linux LVM

Disk /dev/dm-0: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000


Disk /dev/dm-1: 103.0 GB, 103079215104 bytes
255 heads, 63 sectors/track, 12532 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000


Disk /dev/dm-2: 387.9 GB, 387901816832 bytes
255 heads, 63 sectors/track, 47159 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000


# lvdisplay
  --- Logical volume ---
 LV Name                /dev/pve/swap
 VG Name                pve
 LV UUID                fSULxh-H69J-3iu6-6fGv-zyUf-vux4-KUMMp9
 LV Write Access        read/write
 LV Status              available
 # open                1
 LV Size                4.00 GB
 Current LE            1024
 Segments              1
 Allocation            inherit
 Read ahead sectors    auto
 - currently set to    256
 Block device          254:0
 
 --- Logical volume ---
 LV Name                /dev/pve/root
 VG Name                pve
 LV UUID                64Zfbj-BOdy-Icqm-93wW-Hv6V-eChf-c3ROyL
 LV Write Access        read/write
 LV Status              available
 # open                1
 LV Size                96.00 GB
 Current LE            24576
 Segments              1
 Allocation            inherit
 Read ahead sectors    auto
 - currently set to    256
 Block device          254:1
 
 --- Logical volume ---
 LV Name                /dev/pve/data
 VG Name                pve
 LV UUID                jSTxnG-kpLx-eyac-SWwy-hgoY-Wy9N-lPgf0l
 LV Write Access        read/write
 LV Status              available
 # open                1
 LV Size                361.26 GB
 Current LE            92483
 Segments              1
 Allocation            inherit
 Read ahead sectors    auto
 - currently set to    256
 Block device          254:2

# vgdisplay
 --- Volume group ---
 VG Name              pve
 System ID           
 Format                lvm2
 Metadata Areas        1
 Metadata Sequence No  4
 VG Access            read/write
 VG Status            resizable
 MAX LV                0
 Cur LV                3
 Open LV              3
 Max PV                0
 Cur PV                1
 Act PV                1
 VG Size              465.26 GB
 PE Size              4.00 MB
 Total PE              119106
 Alloc PE / Size      118083 / 461.26 GB
 Free  PE / Size      1023 / 4.00 GB
 VG UUID              EPCWMl-xc1n-3xUB-V5TD-YQ1l-6pZY-4NZ464
 
# pvdisplay -m
 --- Physical volume ---
 PV Name              /dev/sda2
 VG Name              pve
 PV Size              465.26 GB / not usable 1.50 MB
 Allocatable          yes
 PE Size (KByte)      4096
 Total PE              119106
 Free PE              1023
 Allocated PE          118083
 PV UUID              JogU1D-cKPA-dQNL-2EwU-YTZT-4kV2-iGkHk6
 
 --- Physical Segments ---
 Physical extent 0 to 1023:
  Logical volume    /dev/pve/swap
  Logical extents    0 to 1023
 Physical extent 1024 to 25599:
  Logical volume    /dev/pve/root
  Logical extents    0 to 24575
 Physical extent 25600 to 118082:
  Logical volume    /dev/pve/data
  Logical extents    0 to 92482
 Physical extent 118083 to 119105:
  FREE

Any guidance would be appreciated.

syg00 11-04-2011 08:21 PM

What does "swapon -s" show ?. I suspect you'll find no (technical) need to allocate swap outside of LVM.

gcmartin 11-04-2011 08:56 PM

Request if backup in place
 
BACKUP is not a problem. I OK on this. But, maybe a recommendation on how I should proceed. What should I designate to reduce? And which toolset? I venturing into a new world of reduction. GParted is not a help.

tollingalong 11-04-2011 09:28 PM

Are you ok with a swap file? You need to be root to do this.

Create a 16GB file:
dd if=/dev/zero of=/swapfile_01 bs=1M count=16000
mkswap /swapfile_01
swapon /swapfile_01

Add the following line at the bottom of your /etc/fstab so the file will load as a swapfile when you reboot.
/swapfile_01 swap swap defaults 0 0

Reducing the size of ext3 file systems didn't always go well for me in the past. It's doable but do you REALLLY need it?

Why do you need the added swap? If you do a free and look at the cached, buffers and free that's what your processes will use (ie apps). The used memory is a cache of your disk so if you need to read from it, the reads will be faster.


free -m
total used free shared buffers cached
Mem: 3763 3612 150 0 0 3422
-/+ buffers/cache: 189 3573
Swap: 0 0 0


If you still want to try resizing here's a page that's a nice read:
http://www.howtoforge.com/linux_resi...xt3_partitions

tollingalong 11-04-2011 09:29 PM

Oh one more thing. It took me 7.5 minutes to create a 16GB file on a 2nd gen 40GB SSD. I'm assuming it'll take you a lot longer.

syg00 11-04-2011 10:26 PM

You didn't answer my question.

gcmartin 11-04-2011 10:32 PM

Thanks but i really want to reduce the LVM2
 
Thanks for the assistance thus far.

But, I really want help reducing the LVM such that it ends with 16GB of free space. Then, I can use GParted to make the free space a SWAP partition.

So the help I need is understanding on how to go about
  1. reducing the LVM partttion (VG first/middle/last steps)
  2. reducing LVM size, itself, to create free space on the drive
if someone can guide me with the above steps, GParted can use that free space to create the SWAP partition.

Thanks.

ptrivino 11-04-2011 10:41 PM

Use the Nancy Reagan method...
 
...just say No!

I just went through a good deal of research on reducing an LVM2 VG/LV, as an exercise (I had installed CentOS with 'defaults' and it does a big LVM on the whole disk). I wanted to gain experience with LVM so I thought I'd try it. I have a fair amount of Linux experience as well as other OS'es and I can tell you it is *possible* to do it but only if you are absolutely desperate.

Long story short, I searched LQ, CentOS.org, and many other sites for LVM info (tldp.org LVM-HOWTO, and Redhat Mag LVM2/resize fs, and some others) and had a plan to do it, until I got to the 'pvresize' step. The PE's were spread out over the whole disk and while they (apparently) can be moved, it's a bear. I did not continue as this was just a learning exercise.

So unless you have no other choice, I'd suggest you make another choice. If you want to do it as a learning tool, on a test system, by all means give it a try!

gcmartin 11-04-2011 10:59 PM

Thanks @Ptrivino.

I have a new system with little to no data that cannot be recreated. I don't think I have any PEs that are scattered about as you have.

Did you find a paper or a solution that led you to try this? I like to use it if you can point me to one.

There's lots of experiences on increasing, but the reductions seemingly are very lacking.

If anyone has any solutions tucked away or any knowledge I'll give it a run. I had hope that I could publish something with Pics for others to use as a guide for how to reduce a single drive system where the LVM has consumed the total drive. And, like me, they would want to reduce it for a good reason.

Thanks for any help.

gcmartin 11-05-2011 01:26 AM

Reduce VG size - Reduce LVM2 size for drive free space
 
Found it! Looks like this will do the trick. but, there appears to be some confusion on the final step for creating the free space.

Does anyone know if the pvreduce (physical volume) will leave an open free space area on the drive?

Thanks in advance, if you know the answer.


All times are GMT -5. The time now is 09:33 PM.