UFS UFS to ZFS

Hi!
During the setup I selected UFS and been "living" with it until today.
But I would like to try ZFS again.
I would like to know if there's a way to convert from UFS to ZFS in place, without data loss?
What is the best way to turn my UFS filesystem into ZFS, if there's a way at all?

Thank you.
 
As far as I know you can use a file stored on UFS as a device to create a ZFS pool.
It may be useful if you want to try ZFS.
 
Hi!
During the setup I selected UFS and been "living" with it until today.
But I would like to try ZFS again.
I would like to know if there's a way to convert from UFS to ZFS in place, without data loss?
What is the best way to turn my UFS filesystem into ZFS, if there's a way at all?

Thank you.
dump(8)/restore(8)?
 
Hi!
During the setup I selected UFS and been "living" with it until today.
But I would like to try ZFS again.
I would like to know if there's a way to convert from UFS to ZFS in place, without data loss?
What is the best way to turn my UFS filesystem into ZFS, if there's a way at all?

Thank you.

After you backup all your data, /etc and /usr/local/etc (and other configs) you can use REROOT to do that on the fly.

Details are here: https://people.freebsd.org/~lidl/blog/re-root.html

The idea is to create RAMDISK that will hold your system (4-12 GB of RAM) - copy file there - create new ZFS layout - copy files from RAM to ZFS on disk.
 
Just copying all the files only will not do,
since you need to make the system capable to boot and work with zfs (load the kernel module zfs.ko).

The script vermaden linked respects this in the two lines:
Code:
# Fixup the system to be able to boot via zfs.
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
Those entries are missing in your UFS' installation /boot/loader.conf and /etc/rc.conf, but needed to be added.
Otherwise the system will not reboot properly anymore.

And of course as Alain De Vos pointed out, the fstab needs to be adapted, too.

btw. I recommend using labels for the partitions getting into the zpool(s).
 
You can only restore(8) to UFS.


You can't 'convert' UFS to ZFS, you're going to need to reinstall.
That's the answer I was afraid of.

What if I get another disk, reinstall FreeBSD in a new ZFS and use the original disk as an external drive (USB adapter) then just sync data from one to another, will it work?
In this process I have to make sure to keep ZFS drivers getting loaded at boot, etc.
 
if it's only /boot/loader.conf & /etc/... /usr/local/etc/... & /home/... , then you can .tar.gz the files/directories and store them in a tmpfs (in-memory) or on a usb-stick.
 
Migrated two ufs systems to zfs so far, totally shooty-iny with the guidance contained here, rc.conf, loader.conf and fstab, migrate other files from /etc and /usr/local/etc plus /var/db to make pkg-static upgrade drag in all pkg's again....stare a logs are a couple of boots to fix any lingering perms issues, job done...
 
I presume you already got though the task one way or the other but if not (and for other future readers): You cannot go from UFS to ZFS in place either while running live or from a separately booted disk. Depending on the size of the drive, layout of partitions, and used space, there might be things you can do. 1st party software allows UFS and ZFS partitions/pools to grow in size. 3rd parrty software can move and resize (grow only?) UFS. Converting partitions in place, though theoritally possible, is not something I have seen with either UFS or ZFS support. Might be able to move ZFS but I haven't seen anything offering to shrink it which is what is needed to do this in place easily (assuming <50% disk consumed).

In addition to an external drive and ramdisk, consider if you have enough space in separate partitions & unallocated space to hold the data. If you have a swap partition but nothing swapped then you could use swapoff and then repartition it to temporarily/permanently hold data. If you have multiple UFS partitions, think about if you have enough space in them to temporarily hold data. Any partition you can empty is now usable to reformat to be a ZFS pool. It would be best to not resize a ZFS pool and if you need to do it then minimizing the amount it is resized by is best but you could grow a ZFS partition and its containing pool by extending its end (don't think start can be moved/resized).

If you need <50% of the drive for the data, make sure you don't make a partition bigger than that and then if it is at the back you can make a new one in the front to copy data to 1 last time and resize it to full size (or keep it in 2 halves for easy internal data shuffling in the future). ZFS dedupe is likely not too beneficial to get a good savings but is another consideration to "temporarily" make the migration happen. You will need to recreate any deduped ZFS data to remove the dedupe. ZFS block cloning would be an alternative to save disk space if you have duplicates but will require manual intervention (enabling the feature, then manually ordering a copy of data to create the 2nd copy appropriately).

Think about how much of the data you need vs what is just downloaded from the internet. Things that can be readily redownloaded could be deleted/uninstalled to get back space for the temporary task. For programs, most you can put back when you are done (as long as official packages aren't removed before install command). While there, think about if you have unneeded data that you would remove but only when you usually get around to it: .core files from crashed programs, /tmp entries that aren't set/scheduled to autodelete, logs you don't need, etc. Depending on the data, you can consider if ZFS filesystem compression or 3rd party compressors (xz,. zpaqfrans (has its own deduplication capability), etc. could make data fit in a small enough space to successfully wiggle things around. 3rd party comressors can get better results iwth special options passed to them, custom disctionaries, and preprocessing steps. ZFS compression may be improved by altering the record size but depending on the data its not always the biggest for smallest filesize.

Similarly, you could temporarily or permanently reformat some types of data to take less space. Undoable lossless changes can be done to jpeg with jpeg-xl or a lossless (different data but pixel perfect recreation of the jpeg) with jpegtran. audio/wavpack can losslessly store wav files in a compressed format that can be undone or audio/flac can store files at a similar but slightly smaller size with better compression settings, some less compatible settings, and some trial+error. graphics/optipng, graphics/oxipng, graphics/pngquant, and graphics/pngrewrite can help with lossless (were some of these lossy?) png pixel perfect shrinking. There are other lossless reoptimizers for mp3, zip, xz, etc. files though I don't know which tools we have available directly on FreeBSD for it. Windows has fileoptimizer which runs each compatible file through a collection of utilities to optimize the file; manual efforts can still sometimes beat it. If you have a lot of open document format (libreoffice/openoffice/etc.) files, some programs write a (png?) thumbnail to each file, which can make a file significantly larger than otherwise needed; you have to open+resave each file manually after changing a (somewhat hidden) setting in libreoffice to remove them. If you have a lot of zip or other compressed files/archives, they normally compress to take less space if you extract them and compress them all into 1 file; other than manual workflow to do it+undo it you wuold need software like precomp (not yet ported to FreeBSD) to handle it (works for zlib created zip streams+a few other things).

If using a ramdisk, keep in mind that data that is only stored there is at risk of being lost from any computer failure until rewritten to disk. If you increased ZFS filesystem zstd compression, you may need a lot of RAM for it to work and ZFS dedupe definitely needs RAM.

If you do a migration instead of a reinstall (external disk or not), review if you need to make startup changes: fstab vs zfs properties to mount things, does ZFS need to be manually loaded, etc. for legacy/CSM/MBR booting, you need to make sure you use the ZFS compatible loader if you don't keep a small UFS around just for booting.
 
I'm still using UFS but the goal persist.
Well, here's my plan.
This is a laptop, so I will need a new SSD.
1. remove the current disk and insert a clean one
2. install a minimal FreeBSD setup with ZFS
3. put back the UFS in the laptop
4. use the new SSD (ZFS one) and mount it as an external USB disk
5. enable the zpool of external USB to be mounted in the system
6. copy/rsync all files from UFS to the ZFS disk. since zfs is alread enabled in current system in rc.conf and loader.conf I think there will be no problem to copy all the FS to new disk as it is.
7. put the ZFS SSD back in the laptop.

will this work?
 
3. put back the UFS in the laptop
4. use the new SSD (ZFS one) and mount it as an external USB disk
5. enable the zpool of external USB to be mounted in the system
I would suggest the other way around. Attach the 'old' UFS disk as external USB disk. That'll save you the hassle of importing of the pool. UFS is easy to mount. And it saves you another two disk swaps.

Before removing the UFS disk, I suggest making a note of pkg prime-list, then use that list to install the packages on the new ZFS install. Prime-list only shows 'main' packages, not their dependencies, as those will be automatically installed anyway. Then go over the old UFS install and copy only relevant data en specific configuration files.
 
I would suggest the other way around. Attach the 'old' UFS disk as external USB disk. That'll save you the hassle of importing of the pool. UFS is easy to mount. And it saves you another two disk swaps.

Before removing the UFS disk, I suggest making a note of pkg prime-list, then use that list to install the packages on the new ZFS install. Prime-list only shows 'main' packages, not their dependencies, as those will be automatically installed anyway. Then go over the old UFS install and copy only relevant data en specific configuration files.
Wont there be a problem overriding running executables during rsync?
 
You don't rsync the OS or the packages, you only copy/sync the data.
 
Wasn't there some stupid trick of creating a RAMdisk, copying the whole OS to it, then write it back to the disk with a new filesystem?
 
Wasn't there some stupid trick of creating a RAMdisk, copying the whole OS to it, then write it back to the disk with a new filesystem?
*Rolling eyes* Or just buy a laptop with two hard drive SATA slots like me. I have even been considering getting that SATA enclosure thingie that swaps out the DVD-ROM drive with a third internal hard drive housing.
 
*Rolling eyes* Or just buy a laptop with two hard drive SATA slots like me. I have even been considering getting that SATA enclosure thingie that swaps out the DVD-ROM drive with a third internal hard drive housing.
Or just buy a laptop? hehehe yes I'm considering this a nice joke and thank you for the moment.
Wasn't there some stupid trick of creating a RAMdisk, copying the whole OS to it, then write it back to the disk with a new filesystem?
I would need RAM enough for that, right?
and what if something goes wrong and system shuts down unexpectedly? RAMdisk will be gone as well as all my data.
 
Backing up data minimizes any chance of losing data though battery backup or laptop internal battery can ride you through some power outages. A cheap solution that minimizes that risk is buying a cheap slow USB flash drive of large enough size to write the data to and then you could boot separate install media to do the backup to it, recreate the filesystems, and restore the data. Much slower than just using RAM but avoids the main power loss risk 'and' you end up with a data backup (which will need to be replaced in the future once you are using zfs send/recv as dump doesn't support ZFS). A bigger+faster drive will speed up that whole process and be more useful for all future backups and data transfer purposes.

For your latest steps, you could skip doing a full install to the new drive if you just plan to overwrite it with your old install. Connect the new drive externally and create partitions, boot loader, and ZFS pool+datasets. You can then dump+restore to put the data there and may need to review configurations to prepare the new pool to boot properly from ZFS datasets instead of old UFS; if you overwrote a new ZFS install with UFS data then you would be still needing to review boot order stuff just the same. It would minimize the SSD wear by that 1 extra install (irrelevant or else you need a better SSD anyway), save copy/install time by that 1 install + musical chairs you were playing with the drive (could skip that by installing to it while it is an external drive) but you will spend more time learning/finding commands to create partitions, install boot code, and create filesystems. If you take notes of your steps, you have notes that may benefit any future use on this + other systems.

This is a good time to consider any other optional changes like if you want swap partition of a different size, encrypted swap (minimal CPU load but not free), encrypted data partitions (password blocked startup or later mounting). If you do a manual partitioning then you can tweak some ZFS dataset and pool properties before anything gets written with other settings.
 
Back
Top