how to free up an LVM logic volumn into a physical partition
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?)
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
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.
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/
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:
Create a partition on it for LVM (let's call it /dev/sdb1).
Add /dev/sdb1 as a PV to the existing VG.
Migrate the LVs from the /dev/sda2 PV to the /dev/sdb1 PV.
Remove the existing PV from the VG.
Re-partition /dev/sda as required (including a new, smaller partition for LVM -- let's call it /dev/sda6)
Add /dev/sda6 as a PV to the VG.
Migrate the LVs from the /dev/sdb1 PV to the /dev/sda6 PV.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.