Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Create file-based VM snapshots with reflink

Featured Replies

Many people use BTRFS (or ZFS) snapshots of complete volumes, but with "reflink" this works on per-file basis, too. And the best thing about this: It even works with XFS! As my single SSD cache is XFS formatted, this is a good solution to create space-saving backups/snapshots of a VM, but if you use BTRFS you can use the same method.

 

Note: If you formatted your XFS disk before Unraid 6.9 (?) your partition hasn't enabled this feature and needs to be re-formatted first.

 

Note: This works only if the copy is stored on the same partition!

 

Let's create a reflink copy as follows:

cp -a --reflink --sparse=auto "/mnt/cache/domains/Windows 10/vdisk1.img" "/mnt/cache/domains/Windows 10/vdisk1-backup.img"

 

If we repeat this, we get multiple files which suppose to use 61G disk space:

ls -sh
total 61G
15G vdisk1-backup.img*  15G vdisk1-backup2.img*  15G vdisk1-backup3.img*  16G vdisk1.img*

 

But this is false and we can easily verify this by checking the disk usage before and after creating multiple reflink copies:

# df -h | grep cache
/dev/nvme0n1p1  1.9T  976G  887G  53% /mnt/cache
# cp -a --reflink --sparse=auto "/mnt/cache/domains/Windows 10/vdisk1-backup.img" "/mnt/cache/domains/Windows 10/vdisk1-backup4.img"
# cp -a --reflink --sparse=auto "/mnt/cache/domains/Windows 10/vdisk1-backup.img" "/mnt/cache/domains/Windows 10/vdisk1-backup5.img"
# cp -a --reflink --sparse=auto "/mnt/cache/domains/Windows 10/vdisk1-backup.img" "/mnt/cache/domains/Windows 10/vdisk1-backup6.img"
# df -h | grep cache
/dev/nvme0n1p1  1.9T  977G  886G  53% /mnt/cache

 

Sadly there is no easy method to check the real size of a reflink-file, so I wrote this script:

 

file="/mnt/cache/domains/Windows 10/vdisk1-backup.img"

du -h "$file"

mapfile -t fragments < <( filefrag -ek "$file" | tail -n +4 | cut -d ":" -f 4 | grep -oP "[0-9]+" )
sum=$(IFS=+; echo "$((${fragments[*]}))")
sum=$((sum * 1024))
sum=$(echo "$sum" | numfmt --to=iec)
echo "$sum total"

mapfile -t fragments < <( filefrag -ek "$file" | tail -n +4 | grep "shared" | cut -d ":" -f 4 | grep -oP "[0-9]+" )
sum=$(IFS=+; echo "$((${fragments[*]}))")
sum=$((sum * 1024))
sum=$(echo "$sum" | numfmt --to=iec)
echo "$sum shared"

mapfile -t fragments < <( filefrag -ek "$file" | tail -n +4 | grep -v "shared" | cut -d ":" -f 4 | grep -oP "[0-9]+" )
sum=$(IFS=+; echo "$((${fragments[*]}))")
sum=$((sum * 1024))
sum=$(echo "$sum" | numfmt --to=iec)
echo "$sum unique"

 

I started the VM, installed some updates and shut it down again. After that I checked the size of the backup file:

15G     /mnt/cache/domains/Windows 10/vdisk1-backup.img
15G total
8.3G shared
6.8G unique

 

And the size of the productive vdisk file:

18G     /mnt/cache/domains/Windows 10/vdisk1.img
18G total
8.3G shared
9.3G unique

 

As both use "8.3G" of data which is shared, we can conclude that both files share the same parts of data.

 

After creating an additional reflink copy while the VM is stopped, it returns the following:

18G     /mnt/cache/domains/Windows 10/vdisk1-backup2.img
18G total
18G shared
0 unique

 

After boot and shutdown:

18G     /mnt/cache/domains/Windows 10/vdisk1-backup2.img
18G total
18G shared
101M unique

 

After deleting all backups:

18G     /mnt/cache/domains/Windows 10/vdisk1.img
18G total
0 shared
18G unique

 

Sadly we have no influence how big the parts of the files are, which could be shared, because I think 9.3G of data which went to "unique" after installing a (small) windows update, is really much, but finally it saves ~50% disk space, so why not creating reflink copies instead of 1:1 copies.

  • 1 year later...

From what I've read so far, the xfs file system is the most balanced and performing file system for home labs. Also, it is mature and safe.

 

What I understand the main reason that everyone wants to use zfs to take snapshot.

 

As you mentioned, snapshot/backup can be taken with reflink, so why do many unraid users still wants to use zfs?

 

is there any other major reason choosing zfs over xfs? 

  • Author
On 2/13/2023 at 9:06 AM, emrepolat7 said:

As you mentioned, snapshot/backup can be taken with reflink, so why do many unraid users still wants to use zfs?

With ZFS you could create a subvolume for a complete partition. But I don't think there is really a use case for such a feature in unRAID. I would say ZFS is only a good replacement for BTRFS in RAID Pools. Maybe this will reduce the amount of broken pools if the server or a VM crashes (I read relatively often about this).

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.