* [linux-lvm] Bringing an existing filesystem under LVM2 control
@ 2006-06-01 13:40 Alasdair G Kergon
2006-06-02 2:05 ` Harik A'ttar
2006-06-02 17:43 ` Dieter Stüken
0 siblings, 2 replies; 4+ messages in thread
From: Alasdair G Kergon @ 2006-06-01 13:40 UTC (permalink / raw)
To: LVM general discussion and development
A question which came up again on irc last night was whether an existing
filesystem on a non-LVM partition can be turned into an LVM logical volume
without having to wipe the disk.
With LVM2, I think the answer is often 'Yes'.
N.B. These instructions are untested.
Perhaps someone would be interested in trying them out and turning them
into a script?
LVM2 needs to use for itself just one sector on the device (for a label).
By default this is the second sector - ext2 and ext3, for example, don't
use this sector. But some bootloaders might - check first.
You'll also need at least one other normal physical volume in your volume
group to hold the LVM2 metadata. Not a problem if the reason for the
exercise is to expand the filesystem! But it could be quite small.
Say the existing filesystem is on /dev/sda1.
1. Run: pvcreate -M2 --metadatacopies 0 -Zn /dev/sda1
Do *not* miss the '-Zn' or you will wipe some of your data!
-M2 is unnecessary if it's the default.
This command generates an LVM2 label and writes it into the second sector.
2. If you're using an existing volume group, skip this step.
Otherwise create the second PV in the normal way. Say it's /dev/sdb (not
partitioned).
Run: pvcreate -M2 --metadatacopies 1 /dev/sdb
-M2 is unnecessary if it's the default.
--metadatacopies 1 is unnecessary if it's the default.
(You can also use 2 but not 0.)
3. Determine the actual size of your existing filesystem, the actual size of
the disk or partition holding your filesystem and choose a suitable physical
extent size for the volume group.
The size of your new LV will be an exact multiple of this physical extent
size and needs to be at least as large as the filesystem.
The size of your new LV needs to be no larger than the actual size of the
disk or partition that holds the filesystem.
Disk/partition size >= New LV size >= filesystem size
In the example here, I'm going to use 4k, but normally you'll be able to use
a much larger size and you should do so.
You can use 'pvs -o+dev_size' to display the device size and use --units to
do divisions for you (see man page).
If you're using an existing volume group, use vgchange -s to reduce the
physical extent size if necessary and then run vgextend to add /dev/sda1 to
it.
Otherwise create a new volume group.
Let's say the volume group is called vg0.
vgcreate -M2 -s 4k vg0 /dev/sdb /dev/sda1
-M2 is unnecessary if it's the default.
Let's say you've calculated that the number of PEs in your new LV will be
2000.
4. Now the part we don't yet have a tool option for. [This should be
handled with a new vgcreate/vgextend parameter that sets pe_start to 0 and
does the necessary calculations.]
Edit /etc/lvm/backup/vg0 (generated by the vgcreate or the vgextend).
Find the physical volume section for /dev/sda1 and reduce pe_start to 0 and
increase pe_count to the number of physical extents you decided you needed
for your new LV in step 3, 2000 in this example. (Typically you'll need to
add the original value of pe_start divided by pe_size expressed in 512 byte
sectors).
Apply your revised backup file with 'vgcfgrestore vg0'.
5. Create your new logical volume.
Important: don't forget -Zn or you'll wipe the start of your filesystem!
lvcreate -Zn -l2000 vg0 /dev/sda1
6. Finally run fsck on your new logical volume and check everything worked.
Alasdair
--
agk@redhat.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [linux-lvm] Bringing an existing filesystem under LVM2 control
2006-06-01 13:40 [linux-lvm] Bringing an existing filesystem under LVM2 control Alasdair G Kergon
@ 2006-06-02 2:05 ` Harik A'ttar
2006-06-02 17:43 ` Dieter Stüken
1 sibling, 0 replies; 4+ messages in thread
From: Harik A'ttar @ 2006-06-02 2:05 UTC (permalink / raw)
To: LVM general discussion and development
Alasdair G Kergon wrote:
> A question which came up again on irc last night was whether an existing
> filesystem on a non-LVM partition can be turned into an LVM logical volume
> without having to wipe the disk.
>
> With LVM2, I think the answer is often 'Yes'.
> 6. Finally run fsck on your new logical volume and check everything worked.
Wow, that's a bit scary. The problem I see with it is you have PV data
sitting inside a LV. An errant tool operating on the filesystem would
wipe out your entire volumegroup (until you manually intervened) rather
then just screwing up one filesystem.
What I would do is copy the first (and probably last depending on
alignment) extant out to another PV, then pvcreate. You end up losing
one or extants due to it, but there's always waste when dealing with
large blocksizes.
Something like this:
lvcreate temporary-filesystem-head
copy one extant from raw partition -> vg1/temporary-filesystem-head
pvcreate on raw partition
vgextend vg1 raw partition
edit the config backup to set the pe_start=pe_size
restore the config
lvextend temporary-filesystem-head raw_partition filesystem size
depending on alignment and allocation, you may have to copy the
filesystem tail to another PV.
Wastes a bit more space, but you don't end up with an oddball PV with
it's UUID in the middle of a filesystem.
Now for the tough question: With LVM2 built on device-mapper, why isn't
extant_size = 512 bytes? Is large-chunk allocation just leftover from
LVM1, or is there a deeper technical reason for keeping it large?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [linux-lvm] Bringing an existing filesystem under LVM2 control
2006-06-01 13:40 [linux-lvm] Bringing an existing filesystem under LVM2 control Alasdair G Kergon
2006-06-02 2:05 ` Harik A'ttar
@ 2006-06-02 17:43 ` Dieter Stüken
2006-06-02 18:03 ` Alasdair G Kergon
1 sibling, 1 reply; 4+ messages in thread
From: Dieter Stüken @ 2006-06-02 17:43 UTC (permalink / raw)
To: LVM general discussion and development
Alasdair G Kergon wrote:
> LVM2 needs to use for itself just one sector on the device (for a label).
> By default this is the second sector - ext2 and ext3, for example, don't
> use this sector. But some bootloaders might - check first.
If the FS resides on the first partition it usually starts at some offset
of 63 sectors. So, if you simply erase the partition table and use hda
for the PV, you may use this space for LVM. Don't know, if this is big
enough, as I normally see "pe_start = 384".
Is there any brief description around about how a PV header is organized,
or do I have to analyze the LVM source code for this?
Dieter.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [linux-lvm] Bringing an existing filesystem under LVM2 control
2006-06-02 17:43 ` Dieter Stüken
@ 2006-06-02 18:03 ` Alasdair G Kergon
0 siblings, 0 replies; 4+ messages in thread
From: Alasdair G Kergon @ 2006-06-02 18:03 UTC (permalink / raw)
To: LVM general discussion and development
On Fri, Jun 02, 2006 at 07:43:35PM +0200, Dieter St�ken wrote:
> If the FS resides on the first partition it usually starts at some offset
> of 63 sectors. So, if you simply erase the partition table and use hda
> for the PV, you may use this space for LVM. Don't know, if this is big
> enough, as I normally see "pe_start = 384".
1 sector is all it needs. The second sector is safe with ext2/ext3 unless
you placed a bootloader there. Filesystem tools and utilities shouldn't
interfere. I'm guessing other filesystems will behave similarly, but I
haven't checked.
> Is there any brief description around about how a PV header is organized,
> or do I have to analyze the LVM source code for this?
Start at the 'Metadata' slide here:
http://people.redhat.com/agk/talks/LVM2-LinuxTag2006/
http://people.redhat.com/agk/talks/LVM2-LinuxTag2006/text28.html
Alasdair
--
agk@redhat.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-06-02 18:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-01 13:40 [linux-lvm] Bringing an existing filesystem under LVM2 control Alasdair G Kergon
2006-06-02 2:05 ` Harik A'ttar
2006-06-02 17:43 ` Dieter Stüken
2006-06-02 18:03 ` Alasdair G Kergon
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).