Re: Copying a disk containing a btrfs filesystem

2014-04-10 Thread Jan Kouba
Dne Čt 10. dubna 2014 15:21:01, Michael Schuerig napsal(a):
 SMART indicates that my notebook disk may soon be failing (an
 unreadable/uncorrectable sector), therefore I intend to exchange it. The
 disk contains a single btrfs filesystem with several nested(!)
 subvolumes, each with several read-only snapshots in a .snapshots
 subdirectory.
 
 As far as I can tell, btrfs currently does not offer a sensible way to
 duplicate the entire contents of the old disk onto a new one. 

Yes it does

You can make the old disk a seeding device and use it to seed the new one like 
this:


btrfstune -S 1 old_device

mount old_device /mnt
# this will be mounted read-only

btrfs dev add new_device /mnt

mount -o remount,rw /mnt

btrfs dev delete old_device

According to my experiments, the filesystem on the new device will have 
different UUID, so if you are mounting using UUIDs, you must change it 
everywhere, but other than that the new filesystem should have the same content 
as the old one (including subvolumes).


 I can use
 cp, rsync, or send/receive to copy the main subvolumes. But unless I'm
 missing something obvious, the snapshots are effectively lost. btrfs
 send optionally takes multiple clone sources, but I've never seen an
 example of its usage.
 
 If that's what experimental means, I'm willing to accept it. However,
 I'd like to emphasize that there's still something missing. Of course,
 most of all I'd like to be proved wrong.
 
 Michael

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Copying a disk containing a btrfs filesystem

2014-04-10 Thread Jan Kouba
Dne Čt 10. dubna 2014 20:36:32, Michael Schuerig napsal(a):
 On Thursday 10 April 2014 19:17:13 Jan Kouba wrote:
  Dne Čt 10. dubna 2014 15:21:01, Michael Schuerig napsal(a):
   SMART indicates that my notebook disk may soon be failing (an
   unreadable/uncorrectable sector), therefore I intend to exchange it.
   The disk contains a single btrfs filesystem with several nested(!)
   subvolumes, each with several read-only snapshots in a .snapshots
   subdirectory.
   
   As far as I can tell, btrfs currently does not offer a sensible way
   to duplicate the entire contents of the old disk onto a new one.
  
  Yes it does
  
  You can make the old disk a seeding device and use it to seed the new
 
  one like this:
 Intriguing. I didn't find much on the topic, but these pages seem
 pertinent
 
 http://en.wikipedia.org/wiki/Btrfs#Seed_devices
 https://btrfs.wiki.kernel.org/index.php/Seed-device
 http://unix.stackexchange.com/a/97819/64935
 
  btrfstune -S 1 old_device
 
 Does the 1 mean true or is this indeed an integer-value arg? I've
 only seen the 1 in examples, are there other possible values?
Yes, 1 means true, 0 false. If you run it twice with the same argument, 
it says something like Seeding flag already set/unset..
 
  mount old_device /mnt
  # this will be mounted read-only
  
  btrfs dev add new_device /mnt
  
  mount -o remount,rw /mnt
  
  btrfs dev delete old_device
 
 Is the last one the step where data is copied from the seed device to
 the second device? No balance required before deleting the device?
Yes, everything is copied, no balance needed.


Well actually if you don't need to preserve the filesystem on the old device, 
you can just add the new device into the filesystem and remove the old one like 
this:

mount old_device /mnt
btrfs dev add new_device /mnt
btrfs dev delete old_device /mnt

The last command will copy everything from old_device to the new_device 
and somehow wipe the old_device so it can't be mounted anymore.
 
This method will also preserve the UUID of the filesystem so there is no need 
to change any config files.


Jan Kouba
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Unable to remove read-only seeding device from a filesystem.

2014-04-09 Thread Jan Kouba
When running this script:

dd if=/dev/zero of=seed-disk.img bs=1M seek=1k count=0
dd if=/dev/zero of=test-disk.img bs=1M seek=1k count=0

# Make image of seed device
mkfs.btrfs seed-disk.img
seed_dev=`losetup -f --show seed-disk.img`
mount $seed_dev /mnt/tmp
touch /mnt/tmp/a
umount /mnt/tmp
losetup -d $seed_dev
btrfstune -S 1 seed-disk.img

# Make read-only seed device
seed_dev=`losetup -f -r --show seed-disk.img`

test_dev=`losetup -f --show test-disk.img`

mount $seed_dev /mnt/tmp
btrfs dev add $test_dev /mnt/tmp
mount -o remount,rw /mnt/tmp

# This fails
btrfs dev delete $seed_dev /mnt/tmp

# cleanup
umount /mnt/tmp
losetup -d $seed_dev
losetup -d $test_dev

rm seed-disk.img
rm test-disk.img




the command 
btrfs dev delete $seed_dev /mnt/tmp fails with 
ERROR: error removing the device '/dev/loop0' - Permission denied message.

If /dev/loop0 is not read-only everything works. 

I tested this on ubuntu 13.10, 14.04 with stock kernel and btrfs-progs and on 
ubuntu 14.04 with latest PPA kernel (3.14.0-031400-generic) and v3.14 btrfs-
progs.

Is this behaviour expected or is it a bug? 

I thougt that btrfs never changes seeding devices, so I don't understand, why 
it needs to be writeable in order to remove it from a filesystem.


Jan Kouba





--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html