LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-23-2010, 04:17 AM   #1
CoderMan
Member
 
Registered: Jan 2009
Location: Gemini Capsule 25164
Distribution: Gentoo
Posts: 375
Blog Entries: 24

Rep: Reputation: 43
Question LVM Physical Volume -- Not Shrinking?


Hi. I was running through a fairly routine Gentoo install on a 160G hard disk. My intention was to have two partitions on the disks: one for boot, and one to be an LVM physical volume. In a stroke of absent-mindedness, however, I forgot to create the boot partition and only created the LVM physical volume, and didn't realize it until the end of the installation.

Anyway, I just want to shrink the physical volume partition and add in another partition with fdisk. However, this doesn't seem to be working the way I intend. I ran

Code:
livecd dev # pvresize --setphysicalvolumesize 159G /dev/hda1
  WARNING: /dev/hda1: Overriding real size. You could lose data.
  Physical volume "/dev/hda1" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
But then when I went to fdisk to add the new partition, fdisk just told me that there are no free sectors on the disk. I tried the same command as above, but with 155G instead of 159G, just to see what would happen, but fdisk still acts like there is no extra space.

So, I'm not sure then how to actually resize the partition to get the free space to add another partition.

Here's other terminal output that might be helpful:

Code:
livecd dev # fdisk /dev/hda

The number of cylinders for this disk is set to 19457.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x1549f232

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1       19457   156288321   83  Linux
Code:
livecd dev # pvscan 
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  PV /dev/hda1   VG vg0   lvm2 [155.00 GB / 10.00 GB free]
  Total: 1 [155.00 GB] / in use: 1 [155.00 GB] / in no VG: 0 [0   ]
livecd dev # lvscan 
  ACTIVE            '/dev/vg0/system' [10.00 GB] inherit
  ACTIVE            '/dev/vg0/home' [5.00 GB] inherit
  ACTIVE            '/dev/vg0/scratch' [100.00 GB] inherit
  ACTIVE            '/dev/vg0/archive' [30.00 GB] inherit
 
Old 02-23-2010, 04:52 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
You can't just shrink the physical partition without reducing the size of the LVM volume first.
You also have to resize the filesystem before resizing the LVM volume or physical partition.
And reducing the LVM volume does not free up any extents you have assigned to the LVM volume in the first place. AFAIK the only way to free up extents is to migrate them to another drive in the volume.

This is quite old but has some details
http://www.tldp.org/HOWTO/LVM-HOWTO/index.html
 
Old 02-23-2010, 02:29 PM   #3
CoderMan
Member
 
Registered: Jan 2009
Location: Gemini Capsule 25164
Distribution: Gentoo
Posts: 375
Blog Entries: 24

Original Poster
Rep: Reputation: 43
Quote:
Originally Posted by smoker View Post
You can't just shrink the physical partition without reducing the size of the LVM volume first.
You also have to resize the filesystem before resizing the LVM volume or physical partition.
And reducing the LVM volume does not free up any extents you have assigned to the LVM volume in the first place. AFAIK the only way to free up extents is to migrate them to another drive in the volume.

This is quite old but has some details
http://www.tldp.org/HOWTO/LVM-HOWTO/index.html
I'm a little confused: I have four lvm volumes in one volume group on one physical volume. The sum of space needed by the four lvm volumes (145G) is already less than the space of the partition that became the physical volume (160G). So I should have 15G of wiggle room. I want to resize the physical volume partition to get some of the wiggle room back and turn it into another (non-lvm) partition.

Is this not possible? I suppose I could copy all data off disk, reformat, and copy everything back... but I would prefer a more convenient solution.
 
Old 02-23-2010, 03:05 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,350

Rep: Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041Reputation: 1041
I'm not a LVM user, however ...
The pvresize manpage suggests only the LVM metadata is adjusted - the real physical partition is your responsibility. That means deleting the partition (containing all your data), and resizing it appropriately with fdisk. Then you'll have some space available for the boot partition.
This is the same process as manually resizing a filesystem - like we had to with NTFS before the ntfsprogs tools were as good as they are now.

Some caveats:
- when reallocating the partition smaller, it has to be at least as big as the pv - I always allow a "fudge factor". You'd better hope the pv is i) contiguous, and ii) at the beginning of the partition. Both are likely to be true.
- don't change the start location of the partition. This will be where all the metadata is. That means your boot partition will be (logically) at the "end" of the disk.

Sounds simple enough. Read my sigline.
 
Old 02-23-2010, 06:09 PM   #5
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
LVM is a cow.

You specify the number of extents when you create a logical volume, but the only way I've found to reduce the number of extents is to add another larger (or equal size) drive, allocate less extents than the drive can hold (but enough to equal the drive you want to remove) then copy your data across.
Then you have free space on your drive. Then you can remove the old drive. Once you have allocated the whole of a drive to LVM, you need another larger drive to retire the first drive, even if the LVM volume is half full.

If you know of a way around this please hit the green button now, as I have 2TB of data and nowhere to go. Even though I know for a fact that most of the data is on a failing drive in the LVM volume, and I have 50% spare space in the logical volume.

I can't afford another drive right now.

LVM is for life, not just for convenience ...

(actually there is a way to avoid this, build the LVM volume on raid 5. Then just take the drive out !)

Last edited by smoker; 02-23-2010 at 06:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems With LVM i cant create physical Volume msanguino Linux - Software 4 03-23-2009 05:12 PM
Fedora LVM volume group & Physical Volume resize problem gabeyg Fedora 1 05-14-2008 11:26 AM
Shrinking a Logical Volume With LVM jimmyjiang Red Hat 1 02-28-2008 04:45 PM
LVM -creating physical volume satimis Linux - General 2 08-10-2006 01:44 AM
LVM Physical Volume Lucky_Sevin Linux - Software 2 01-10-2006 10:44 AM


All times are GMT -5. The time now is 04:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration