This can be a painful and slow experience so I wanted to share some tips about this topic
First of all, using tools that automatically convert your filesystem is dangerous and not reliable, you can lose your data! So the best option is always to just transfer the data, this also ensures their consistency and health of your data located in your disks
The only tool that I recommend for that is using rsync, this is the only tool that provides everything needed, secured, fast, integrity, correct copy of file types, reliable, and you can even stop a copy and continue another day
Concept
Let's say that I want to move from reiserfs to btrfs, as:
- My disk uses reiserfs, and even if is good, seems like no more well supported in new kernels (it crash your entire system by using it)
- I want to convert it to the new BTRFS filesystem which supports transparent compression, because I want to keep my files use the less space possible on disk and it also has good performances and features
Since you cannot convert the filesystem on the fly, the best option is to make a backup and copy it back to your disk with the new filesystem
Problem
But now I'm in a difficult situation:
- Computer A uses Elive 3.0, on which the version of BTRFS is too old to consider using it (btrfs was in heavy development with tons of bugs, but now seems like to be pretty usable in newer kernels)
- Computer B uses Elive 3.7.x which is 64 bit and much updated kernel, it supports well btrfs but it doesn't supports well reiserfs, it can crash the system even if looks like to read it more or less correctly (computer feels bottlenecked), so i don't put my confidence on that
So I can't use both disks in the same computer, I'm forced to use 2 different computers. And this is not a problem at all using rsync
Using rsync to transfer data
To replicate the data from dir1 to dir2 you should use this rsync call:
sudo rsync -avn --delete /home/thana/dir1/ /home/thana/dir2/
Notes:
- sudo is needed unless you are sure that all the files are owned by your user (which should be the case for transfer files that belongs to your user / home files)
- always use the "n" option (which is for "dry-run") before to run the real command, just to make sure that you are not going to make a disaster
- always use absolute paths, if you repeat the same command in the future using the history of your terminal you should be located in the same directory, its just a security measure
- always (very important) end the name of the directories with a slash, never run it like /home/thana/dir1 , you need to slash the end, otherwise your entire /home/thana can be overwritten / deleted
- rsync includes many options and features, read the man to know all the options
This is the best and optimal way to transfer files from a directory to another, ensuring consistency, management of links, etc.. in other words, to replicate data from a place to another
But what if the data is from another computer (called zeus)? you just need to call in one of these possible ways:
sudo rsync -avn --delete zeus:/home/thana/dir1/ /home/thana/dir2/
sudo rsync -avn --delete root@zeus:/home/thana/dir1/ /home/thana/dir2/
sudo rsync -avn --delete zeus.local:/home/thana/dir1/ /home/thana/dir2/
sudo rsync -avn --delete root@ipaddress:/home/thana/dir1/ /home/thana/dir2/
Any of them are valid, note that the "zeus.local" one requires that feature provided in the Elive installer, which basically allows you to ping / access to any remote computer in your network by using its name.local value
Verify data
If the disks includes only this data you can run "df" to compare the same sizes, otherwise use "du -hs" to the directories
If you want to make sure-sure that the data has been transfered correctly, run again the same rsync command, if you add the option "c" it will checksum every data to make sure that their contents are the same (this is as slow as a full new transfer)
Reformat disk and Mount it
Now, I wanted to switch to btrfs with transparent compression, I need to do all of this from computer B since is the one that supports it correctly, you can do it from gparted
Unplug / plug the disk. Open your filemanager and mount your new partition
Now run the command "mount" to ensure that all the mount options are the wanted ones (since you did not defined them!), and there's is a problem: our mounted btrfs is not mounted with compression, in fact, you cannot set this parameter when formatting the partition (so bad!), and to use compression you need to always mount the filesystem with this option included (auto if is set in your fstab), but you can remount the partition to add this option:
mount -o remount -o compress=zstd /mnt/something/
Another option is to run this command to recompress the data:
sudo btrfs defragment -r -v -zstd /mnt/something/
Now you are ready to copy back the data to your new mounted disk, and start using it when finishes
Note: by not being able to "always mount by default" the partition with compression, all the new data will be not compressed, you should remount it before to use the disk or to run the defrag command later (much slower)
Conclusion steps:
- transfer data of your disk to a backuped place, using rsync
- verify transfered data
- reformat your original disk
- mount it with the correct options
- transfer data back to your disk