LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to free up an LVM logic volumn into a physical partition (http://www.linuxquestions.org/questions/linux-general-1/how-to-free-up-an-lvm-logic-volumn-into-a-physical-partition-807640/)

shva 05-13-2010 02:38 PM

how to free up an LVM logic volumn into a physical partition
 
In my computer there is only one hard disk with two partitions. /dev/sda1 is mounted as /boot, while /dev/sda2 is used as LVM. In that LVM partition I have only one logic volumn group with several logic volumns. One of the logic volumns is mounted as /data, and now I want to remove this logic volumn, free up the space and make it another physical partition outside LVM as /dev/sda3. Can someone help me on this, especially the procedure of steps I should go through ? Thanks.

MensaWater 05-13-2010 03:16 PM

You can't really do what you're asking. It is easy enough to get rid of data filesystem and remove the Logical Volume (LV) but the space in the partition is allocated to the Volume Group (VG) and the LV is a subdivision of that. Therefore removing the LV increase free space in the VG but the VG is still taking up the same amount of allocated space in the partition.

However what you CAN do is create a new LV using free space from the VG for whatever purpose you intended to use /dev/sda3 for. This is the main point in LVM - it allows you to reallocate resources more quickly without having to worry about worry about other partitions.

Why do you feel you need a new partition rather than a new LV? (That is to say what is the purpose of /dev/sda3 in this scenario?)

shva 05-13-2010 04:30 PM

After removing a LV, can I use vgreduce to shrink the volumn group in the physical volumn, followed by pvresize? ( I am not sure about these commands though...)

The reason I want to do this is that I want to compile another Linux system in the same hard disk. I am not sure how to boot from a LVM partition, so I just need a new partition /dev/sda3

GazL 05-13-2010 04:44 PM

No vgreduce is for removing PVs not LVs. It's not what you want.

Have a read of the pvresize and pvmove man-pages. Those look like the commands you'll need (along with lvremove which you'll use to get rid of your /data lv).

It's going to be messy and somewhat risky no matter what you do. Make sure you have a good backup.

chrism01 05-14-2010 03:58 AM

I think you're going to have to wipe sda2 and start over. The point is, a disk partition eg sda2 is at the bottom, which is then set to a PV type (fdisk type 8e), then VG goes on top and LV on top of that.
http://tldp.org/HOWTO/LVM-HOWTO/

alli_yas 05-14-2010 04:28 AM

The previous 2 Guru's are correct - your best bet is to back up your data (if any) and restart.

I also suggest you do a bit of reading on LVM in terms of how it works from a logical perspective before your start.

LVM is a great technology; however it can be painful if you misconfigure something and realize afterwards.

If you can explain what/how you want to divide the space you have available I can give you some tips on using LVM to achieve your desired goal

catkin 05-14-2010 04:34 AM

chrism01's advice is normally dependable so I hesitate to suggest it but the pvresize command might do what you want. Depending on the location of LVs within the LVM partition /dev/sda2 this may not be possible.

Regarding "The reason I want to do this is that I want to compile another Linux system in the same hard disk. I am not sure how to boot from a LVM partition, so I just need a new partition /dev/sda3" you would not have to boot the new distro from a LVM partition; you could boot it from /boot after which it would mount / from an LVM volume. This is a common arrangement.

I used to run ubuntu 8.04 with a LVM volume for / but concluded that the advantages of doing so outweighed the disadvantages and switched to an ordinary partition on migrating to Slackware. If you conclude similarly, you may want to bite the bullet and take this opportunity to have an ordinary partition for the new distro's / .

The easiest way, if you can get another HDD, perhaps temporarily, would be:
  1. Create a partition on it for LVM (let's call it /dev/sdb1).
  2. Add /dev/sdb1 as a PV to the existing VG.
  3. Migrate the LVs from the /dev/sda2 PV to the /dev/sdb1 PV.
  4. Remove the existing PV from the VG.
  5. Re-partition /dev/sda as required (including a new, smaller partition for LVM -- let's call it /dev/sda6)
  6. Add /dev/sda6 as a PV to the VG.
  7. Migrate the LVs from the /dev/sdb1 PV to the /dev/sda6 PV.
  8. Remove the /dev/sda6 PV from the VG.
  9. Win!
Backups would be a valuable insurance!

shva 05-14-2010 10:27 AM

Thanks all guys. The reason I considered creating a new partition /dev/sda3/ is that I wanted to try out Linux From Scratch. If LFS's root system is a logic volumn in LVM partition, I remember I had to compile something (initramfs) that supports LVM and put it into /boot (which is /dev/sda1). I am currently not sure how to do it. That's why I need a new /dev/sda3.


All times are GMT -5. The time now is 08:50 PM.