Is it possible to convert a Linux box to LVM after the fact?
Yes, this can be done.
Yes, you can use it for a dual-boot windows system, provided you make Windows the first partition, and it's a primary partition (not an extended inside a logical). My instructions here do not cover this situation, which requires you have some experience dealing with dual booting. If you're after a dual-boot windows/linux setup, don't follow any advice below this point.
I'll go one better: with only a few exceptions, you should be able to migrate your entire laptop live, provided you use an external drive with enough capacity.
Warning! This proceedure is EXTREMELY DANGEROUS! It assumes you have intimate knowledge of the partitioning process, you have a separate /boot partition, and you know a botched attempt can leave you with a brain-damaged installation THAT WON'T BOOT! YOU HAVE BEEN WARNED!
You'll need:
- /boot located on a separate partition. If you have a combined root filesystem (everyting is stuffed into / ) then this won't work.
- The ability to boot from a USB hard drive.
- an external drive large enough to hold all of the data and programs on your existing system. Be sure to run a "du /" and wait for the end result, to get a real feel for the kind of space you'll need.
General Procedure (forgive me for lack of a few commands, I'm writing this very quickly):
- Attach the external drive and locate its device name. Let's pretend that you see it as /dev/sdb.
-
Create a two partitions on your external drive. In our example, this will show up as /dev/sdb1 and /dev/sdb2.
parted /dev/sdb
Format the first partition as ext2 or ext3, and labeled "boot". Format the second partition on the external drive as type "Linux LVM".
-
Get the newly minted LVM volume recognized by the system using
pvscan ; vgscan
Carve off a large-enough chunk of the external LVM volume to hold the entire laptop's hard drive. If in doubt, just use all of the space available.
-
Format your LVM-based volume as ext3 or whatever filesystem tickles your fancy.
mke3fs /dev/ExternalUSBVolume/ExternalRoot
For each non-special file system mount, create a directory on your external disk and copy (with attributes) all of your files in each mount to that disk. Ignore copies of mountpoints like /proc, etc. as these are "special".
- create the special mountpoints by hand, so that they exist on your external drive. Do not populate them, just make sure the names and permissions match.
- (Very carefully) use your bootloader to install a boot image on your external drive, into the /boot partition. This process is a bit complex so I'll leave it to you to find the info elsewhere. It's also dangerous if you botch it - you could end up trying to overwrite your bootloader on your laptop drive. Be careful.
- Reboot your laptop. When it is going through the POST, be sure to specify the external drive as your boot drive. At this point in time, you should have a (more-or-less) near-replica of your laptop's drive. (to the other admins out there: yes, I know, the log files and others are not in a 100% copied state, but that's not the emphasis here...it's on getting the data and tools moved over...)
- Once you can boot from the external drive, you can then use it to wipe your laptop drive. At this point, you're "living out of" your external drive. Keep this in mind.
- Then use a partition editor - gparted or whatever - to delete the original laptop partitions (bye-bye data...), then mark your newly-minted area as "LVM". Go through the process of getting your LVM volume recognized, partitioned, formatted, etc.
- Using LVM's mirroring process, mirror your live system (which is currently on the external drive) back to the laptop drive. Take a lunch break (or two) for this as it will take time.
- Remount the live filesystem, moving the / filesystem from the external drive to your laptop LVM volume.
- Re-run your bootloader installation process. This is critical as the current ramdisk will not have the right settings and will not know you've moved things around. Failing to do this will result in an unbootable system and a visit to a rescue disk. If all else fails, you can boot from your external drive again (nothing lost...)
- Reboot the laptop without the external drive attached, and specifying the laptop's internal drive instead. It should boot fine. Note anything that feels or looks hurt or broken (there shouldn't be anything), and fix it.
- Sit back and enjoy a beverage for a job well done.
I recently wrote blocks (née lvmify) which does this conversion in-place. It takes a single partition, shrinks the filesystem if necessary, moves the start of the filesystem to the end of the partition, and copies an LVM superblock (preconfigured with the right PV/LV/VG) in its place. If you have multiple partitions, merging the newly created volume groups is done with vgmerge
. It can't work on mounted filesystems.
The easiest way to move a linux system to LVM is to use a external disk (USB, eSATA) and a CD-ROM based system like grml to move away all data from the PC to the external disk, then re-partition the PC with LVM. Finally copy everything back and configure and re-install grub to the MBR.
This procedure is slightly involved, but you always have the data on the external drive and the CD-ROM to boot your system.
As you correctly expect, Windows is not able to access any LVM volumes.
http://serialized.net/2006/04/migrating-live-filesystems-to-lvm/ has an interesting way of migrating a live fs. Add it as part of a RAID-1 group, which the OS will then mirror to the other device (which could be an LVM logical volume). It's a bit dated, so I don't know if that would still work.
Starting from the bottom: no, windows cannot read LVM logical volumes (partitions).
If you have a spare disk that can be used as temporary storage the it's just a matter of booting from a live CD, copying the data to the temporary location, creating one or more LVs and putting the data back. It's impractical (but possible) to do an in-place conversion to LVM; you basically have to shrink the old partition and resize the the LV multiple times (and the final LV would be fragmented)