Fedora Linux Support Community & Resources Center
  #1  
Old 4th January 2017, 04:19 AM
stratacast1 Offline
Registered User
 
Join Date: Apr 2014
Location: Washington
Posts: 266
linuxfirefox
Move btrfs subvolume to new drive help

My entire /home directory is on a btrfs subvolume, and I'm trying to move it from a 1TB HDD to a 2TB HDD. I have done stuff like this before on EXT4, but I know btrfs works differently with its subvolumes. So here's my thought, and please correct my errors:

1. Plug in the new drive (assume from here current /home is on /dev/sdc and new drive is /dev/sdd)
2. mkfs.btrfs /dev/sdd (new btrfs filesystem on new drive)
3. mv /home /old_home (and make that edit to /etc/fstab)
4. mount /dev/sdd1 /home (I'm not sure if this is technically how btrfs would work)
5. Here there should be some btrfs send ... | btrfs receive ...

Then somewhere in there I just change the UUID in /etc/fstab to my new drive on /home and my new drive should have /home and my old drive be unused, so I can shut down my computer and unplug my old drive. I'm part way there, but I'm missing some detail in how to do this job
Reply With Quote
  #2  
Old 7th January 2017, 12:36 AM
stratacast1 Offline
Registered User
 
Join Date: Apr 2014
Location: Washington
Posts: 266
linuxfirefox
Re: Move btrfs subvolume to new drive help

How about this....

Add the HDD, do a mirror and then remove the old HDD from the mirror once the new drive has everything written to it?
Reply With Quote
  #3  
Old 9th January 2017, 05:33 AM
stratacast1 Offline
Registered User
 
Join Date: Apr 2014
Location: Washington
Posts: 266
linuxfirefox
Re: Move btrfs subvolume to new drive help

Nothing huh? Seems most people know little about filesystems (including myself here)..I'll risk my computer and report back then. Hopefully it'll help people later.
Reply With Quote
  #4  
Old 9th January 2017, 09:49 AM
Dutchy Offline
Registered User
 
Join Date: Aug 2011
Location: ~
Posts: 1,878
linuxfedorafirefox
Re: Move btrfs subvolume to new drive help

There are multiple ways to do it. Send/receive seems to be the btrfs way, btrfs mirroring is also an option but seems a bit convoluted and disk cloning would take quite a bit of extra time. Besides that you could also just keep it simple and cp or rsync your home to the new drive after you create the btrfs file system and subvolume (you would need to use the right flags and there are some caveats). However you do it you should probably do this as root (user logged out) and then just make the changes in fstab if the fs handle changes.
Reply With Quote
  #5  
Old 9th January 2017, 06:31 PM
ndc333 Offline
Registered User
 
Join Date: Dec 2016
Location: United Kingdom
Posts: 10
linuxchrome
Re: Move btrfs subvolume to new drive help

thinking aloud. why not just use the btrfs pool ie -> btrfs device add ; btrfs balance ; btrfs delete the old drive! then add the new uuid to fstab ; mount -a (btrfs is like the terminator 2 -> it just speads the fs over any storage media you tell it to) look up the add and delete commands.
Reply With Quote
  #6  
Old 17th January 2017, 05:47 PM
stratacast1 Offline
Registered User
 
Join Date: Apr 2014
Location: Washington
Posts: 266
linuxfirefox
Re: Move btrfs subvolume to new drive help

Sorry for getting to this late, but the bug going around got the best of me! I just finished my process last night and it works very well. My old btrfs volume was /dev/sdc1 and my new disk was /dev/sda:

btrfs replace start /dev/sdc1 /dev/sda /home
*Wait for the job to complete and reboot when finished
*Resize the btrfs pool to fill the entire device
btrfs filesystem resize max /dev/sda

Then it's done! What's cool is btrfs replace also edits the /etc/fstab file with the new, proper drive
Reply With Quote
  #7  
Old 17th January 2017, 09:54 PM
ndc333 Offline
Registered User
 
Join Date: Dec 2016
Location: United Kingdom
Posts: 10
linuxchrome
Re: Move btrfs subvolume to new drive help

im impressed! (added to my recipes)
Reply With Quote
  #8  
Old 18th January 2017, 10:33 AM
Dutchy Offline
Registered User
 
Join Date: Aug 2011
Location: ~
Posts: 1,878
linuxfedorafirefox
Re: Move btrfs subvolume to new drive help

Btrfs replace is interesting. However, I would not us it on a raw disk but first create a GPT partition. Also, I think the documentation of btrfs replace is lacking. What's the RAID used for in this method? Is it considered stable? Why does it need the mount point? Does it remove the btrfs file system on the source drive?

I expect btrfs replace to be some automation of btrfs device add and btrfs device remove. Btrfs device remove deletes the data on the source drive [1] so when moving your data to a new drive I would not recommend it because you might screw up during the process and end up with all your data gone.

[1] http://dabase.com/blog/Do_not_btrfs_device_remove/
Reply With Quote
  #9  
Old 18th January 2017, 11:58 PM
stratacast1 Offline
Registered User
 
Join Date: Apr 2014
Location: Washington
Posts: 266
linuxfirefox
Re: Move btrfs subvolume to new drive help

Dutchy, I'll have to double check my drive but I recall it creating a GPT partition for me. The documentation is absolutely lacking, I ended up seeing that what it does though is similar to the related ZFS tool. I'll try to answer your questions:

What's the RAID used for in this method: I didn't have any RAID going on in my system when I did this. From my reading though, if there is an active, functioning device it's replacing, it does an exact replica of the drive. If the drive isn't present, then it builds the drive on the RAID array. So if this is a RAID1 setup and /dev/sdb is dead, then do the replace but you may have to change your command arround and add arguments.

Is it considered stable: I believe it is a stable feature now. As far as I'm aware, the only unstable features that currently exist in btrfs are their RAID56 implementations. I can only anecdotally call it stable

Does it remove the btrfs file system on the source drive: when the job finished for me, it appeared my old drive was still mounted to the system and all my data was there, so to make the full change doing reboot or mount -a should mount the new drive and umount the old one? Either way, it didn't remove any data from my old drive.

I think btrfs replace is its own thing. If btrfs remove actually deletes the data, then I would say that these commands appear to be mutually exclusive
Reply With Quote
  #10  
Old 20th January 2017, 01:54 AM
stratacast1 Offline
Registered User
 
Join Date: Apr 2014
Location: Washington
Posts: 266
linuxfirefox
Re: Move btrfs subvolume to new drive help

I looked at my drive and it turns out it doesn't have a GPT partitioning table...and this strikes me as odd, but I looked at an Oracle page and it turns out btrfs can also work as a partitioning scheme? I'd have to know more about how btrfs works to see how it's not necessary to need to have to format the drive with a GPT or MBR partition table.

I looked at ArchWiki and here's what they have to say about btrfs replacing partition schemes:

Btrfs can occupy an entire data storage device, replacing the MBR or GPT partitioning schemes, using subvolumes to simulate partitions. However, using a partitionless setup is not required to simply create a Btrfs filesystem on an existing partition that was created using another method. There are some limitations to partitionless single disk setups:

Cannot use different file systems for different mount points.
Cannot use swap area as Btrfs does not support swap files and there is no place to create swap partition. This also limits the use of hibernation/resume, which needs a swap area to store the hibernation image.
Cannot use UEFI to boot.

My guess is the first point only applies to btrfs being your root filesystem. I only use my drive for /home (same with btrfs on this system) and I haven't encountered any errors. I would say though if you're concerned, to perhaps make the disk a GPT partition table ahead of doing the replace
Reply With Quote
  #11  
Old 20th January 2017, 11:44 AM
Dutchy Offline
Registered User
 
Join Date: Aug 2011
Location: ~
Posts: 1,878
linuxfedorafirefox
Re: Move btrfs subvolume to new drive help

There is usually little reason to not use mbr or gpt. Also, I think on Linux any file system can work on a raw drive but there might be inconveniences and other OS's do not handle it well, but with btrfs that is not really an issue.
Reply With Quote
  #12  
Old 22nd February 2017, 04:27 PM
Dutchy Offline
Registered User
 
Join Date: Aug 2011
Location: ~
Posts: 1,878
linuxfedorafirefox
Re: Move btrfs subvolume to new drive help

I looked into this some more and have just successfully replaced one of my drives with a bigger one using `btrfs replace` and it worked great (live duplication of ~2 TB of data).

The data on the original drive is left alone but the superblock magic strings are removed. Simply echoing them in again via dd (see the btrfs wiki on manually wiping) will turn it back into a valid btrfs filesystem (be sure not to also have the new drive in the machine because you will get UUID clashes and possibly corrupt both drives).
After adding the magic strings again the old drive cannot be mounted normally yet because it will still be in the replace state. Simply mount it in degraded mode, cancel the replace action and then remount it. Now the old drive works just like it was never replaced (can be handy in case the new drive crashes shortly after the replacement).

Be aware that `btrfs replace` mainly seems to be used with and tested for multi-device setups (I read about one case of corruption in a single device setup on the mailing list).
Reply With Quote
Reply

Tags
btrfs, drive, subvolume

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does a BTRFS Drive Need a BTRFS Backup Drive? joncr Using Fedora 5 15th February 2014 08:32 PM
F19: Can't mount btrfs file system - dmsg='btrfs: superblock checksum mismatch' mmmmm Guides & Solutions (Not For Questions) 2 18th September 2013 10:29 PM
Best way to install to subvolume of already existing BTRFS filesystem? Azendale Installation, Upgrades and Live Media 0 8th November 2011 06:06 PM
BTRFS Subvolume of Home? Timberbrook Using Fedora 5 6th November 2011 01:20 PM
btrfs - add RAID1 partition to existing encrypted btrfs parition techmum Using Fedora 0 4th July 2011 01:21 AM


Current GMT-time: 04:41 (Friday, 21-07-2017)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat