Ask Your Question

pull a whole partition intact out of LVM2?

asked 2014-03-23 18:03:27 -0500

shanemikel gravatar image

updated 2014-09-30 21:51:03 -0500

mether gravatar image

I recently spent a lot of time setting up a new F20 installation, and out of my haste (not to mention the GUI could be a little more intuitive) during installation, I have accidentally installed Fedora's / to ext4 inside of LVM2..

Because of my current setup (tri-boot). and the fact that I like using gparted, It is not going to work for me to use an LVM.

I can't boot fedora, because I've reinstalled my Grub2 setup with ubuntu and Grub won't recognize the LVM2 filesystem

I have my fedora install intact (i hope), but I'm having trouble copying the files out and into a manually setup ext4 partition.. I can mount fedora's / and browse it, but when I copy even using cp -dR --preserve=all I get tons of errors regarding the preservation of links and stuff like that..

What is the best way to do what I'm asking (other than reinstalling from scratch)

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2014-03-25 05:20:22 -0500

joshuar gravatar image

As long as the new partition you have created is the same size or bigger than the existing F20 root partition, you can use dd to copy the partitions. Boot from either a live CD (any distribution will do) or boot into your Ubuntu install and make sure both the old and new partitions are not mounted. Then run a command like the following:

dd if=/dev/mapper/f20-lvm-root of=/dev/sdxn bs=4096 conv=notrunc,noerror,sync

Where /dev/mapper/f20-lvm-root is your Fedora 20 root partition and /dev/sdxn is the new partition you created. This will take a long time to run. Once it is finished, you should be able to mount the new partition and you should change the fstab file to reflect your new disk layout and also update the F20 entry in your grub configuration.

edit flag offensive delete link more


That's an elegant alternative to the rsync command I wrote up. Nice.

bitwiseoperator gravatar imagebitwiseoperator ( 2014-03-25 09:29:32 -0500 )edit

answered 2014-03-25 19:01:41 -0500

shanemikel gravatar image

I decided to just wing it and try using cp.. Well who'd have thunk?? it works! I learn more about linux every day. They really weren't kidding when they said:

EVERYTHING is a file

First, I had to mount my exisiting lvm Fedora install partition.

Create EXT4 partition large enough to hold the files and mount it

use the copy command to copy the files over

$ sudo cp -a /media/old-partition-mount-point/* /media/new-partition-mount-point

and edit my fstab to mount the new partition as /

edit flag offensive delete link more


Nice work! Just remember though when using cp:

  • If cp encounters an error, it'll bail out and you'll have to start the entire copy again. The rsync and dd methods outlined in the other answers do not have this limitation.
  • Make sure the old and new partitions have the same mount options (especially for the user_xattr and acl mount options, see man mount) to ensure that all acls and extended attributes each file may have are copied over.
joshuar gravatar imagejoshuar ( 2014-03-27 02:14:17 -0500 )edit

answered 2014-03-24 22:14:06 -0500

Can you make yourself a bootable USB (or other media) of Fedora 20 so you can enter rescue mode and rebuild GRUB? provides instructions on how to do that.

Now, let me preface this as such: I wouldn't do this unless I REALLY had to. I'd rather have a cleanly-installed OS. But, if you must, this may work:

After you've booted into your current system, you can add a simple ext4 volume to the disk you intend to use for your new root filesystem using whatever interface is familiar to you and boot into your OS. Once in, and this is important, get the UUID for your disks and be ready to map them to your mount locations. Print your fstab file if you need to.

Once that's done,

Mount the disk with the target filesystem somewhere in your directory tree:

# mkdir /mnt/newOS/
# mount /dev/mapper/diskname /mnt/newOS/

Copy everything from root into that directory, excluding the virtual filesystems /dev, /proc, and /sys, and the mount filesystem /mnt:

# rsync -aPEHv --exclude=/dev --exclude=/proc --exclude=/sys --exclude=/mnt --exclude=/var/cache/apt/archives/ / /mnt/newOS/

The -a option puts rsync in archive mode, which is just shorthand for the following options: The -r option, instructing the rsync operation to recurse directories. The -l option, instructing rsync to copy symbolic links as symbolic links The -p option, instructing rsync to preserve permissions The -t option, instructing rsync to preserve modification timestamps on the files The -o option, instructing rsync to preserve the owners of the files The -g option, instructing rsync to preserve the group owners of the files And the -D option, which is short hand for: The --devices option, instructing rsync to preserve device files The --specials option, instructing rsync to preserve special files

The -P option shows progress during the transfer operation.
The -H option tells rsync to look for hard-linked files in the source and link together the corresponding files on the destination. The -v option enables verbose logging.

Then make mountpoints in your filesystem for those virtual directories and /mnt, which you didn't copy:

# mkdir /mnt/newOS/dev
# mkdir /mnt/newOS/proc
# mkdir /mnt/newOS/sys
# mkdir /mnt/newOS/mnt

Finally, copy over some important and missed locations:

# cp -avp /dev/console /mnt/newOS/dev
# cp -avp /dev/urandom /mnt/newOS/dev
# cp -avp /dev/zero /mnt/newOS/dev/
# cp -avp /dev/random /mnt/newOS/dev/

Take the fstab information you gathered prior to this process and edit the newOS/etc/fstab file to change the device names to point to the devices you will be using with the new system.

Finally, power down the system, and install the disk to which you just copied your operating system. Uninstall the disk with your old OS (or clone it to back up and blow it away or whatever you need to do, as far as disk management is concerned). Boot into your rescue disk ... (more)

edit flag offensive delete link more

Question Tools



Asked: 2014-03-23 18:03:27 -0500

Seen: 540 times

Last updated: Mar 25 '14