8

My PC has a SSD for the root filesystem and the home directory and a large HDD for other data. From time to time I sync the SSD content to the HDD in case the SSD fails. The HDD has a separate backup.

Now I consider if I can use the BTRFS RAID modes to achieve the same. So can I use subvolumes with RAID mode, such that the SSD is mostly used for reads/writes and the data is synced to the HDD?
In addition, I would like to have snapshots of the volume on the HDD.

It would be great, when this would work without manual work, even when the HDD was disconnected for some time.

Another option would probably be btrfs send/receive, but a RAID mode which writes the HDD when the IO is idle would allow for always having a recent copy of the data.

Edit: This is not a duplicate of these 1, 2, and 3 because I am explicitly asking for BTRFS, that has a storage pool concept instead of just using a block-level RAID.

allo
  • 1,026
  • 1
  • 10
  • 27
  • Possible duplicate of [Use the speed of an SSD + two HDDs in RAID 1](https://superuser.com/questions/663509/use-the-speed-of-an-ssd-two-hdds-in-raid-1) – phuclv Apr 14 '19 at 12:13
  • [combining SSD and hard disk in software RAID1?](https://superuser.com/q/293144/241386), [One SSD + two HDD in RAID 1: SSD performance hit?](https://superuser.com/q/457707/241386) – phuclv Apr 14 '19 at 12:14

1 Answers1

1

How to use BTRFS for RAID between a SSD and a larger HDD?

You simply create a BTRFS volume using the two disks:

mkfs.btrfs -m raid1 -d raid1 /path/to/ssd /path/to/hdd

More examples at https://btrfs.wiki.kernel.org/index.php/UseCases

However, please note that RAID1 is not a backup mechanism.

So can I use subvolumes with RAID mode, such that the SSD is mostly used for reads/writes and the data is synced to the HDD?

No.

  1. BTRFS doesn't do RAID at the subvolume level;
  2. RAID1 I/O will read and write to both drives at the same time;

a RAID mode which writes the HDD when the IO is idle would allow for always having a recent copy of the data.

That is not how RAID works. See 1. above.

BTRFS does allow you to mix drives of different sizes and types so you can use your existing SSD + HDD to create a RAID1 array where your data will sit on both drives. However,

  1. You will be limited by the size of the smaller drive. You can use a calculator to find out what your available storage will be.
  2. Setting this up will be rather complex as you'll have to rebuild the entire system;

I would like to have snapshots of the volume on the HDD.

You can achieve this by creating a BTRFS volume on that HDD and enabling period snapshots. btrbk is a tool I use and can recommend.

Good luck! :)

  • 3
    This is unfortunate, because I really hoped to be able to just mirror a subvolume, so I have increased reading speed (I think RAID1 should be able to read in parallel) and hoped that writing may sync the slower disk lazy, because it happens on filesystem level in BTRFS. Without this, it is rather useless for me. When the system drive fails, I just restore it from a backup, so the speedup is the primary factor why I wanted the RAID setup. – allo Apr 14 '19 at 11:02
  • @allo Reading from a BTRFS RAID1 volume does not currently benefit from having the data in 2 places. I actually use a setup similar to yours, `/` and `/home` on solid state drives and a bunch of HDDs running BTRFS RAID1 and I back up `/home` to them HDDs and they get backed up to an external HDD. Not all of the data on my HDDs is precious (e.g. Steam library). – Alexandru Ungureanu Apr 14 '19 at 11:07
  • 2
    it's actually possible. See [Use the speed of an SSD + two HDDs in RAID 1](https://superuser.com/q/663509/241386) – phuclv Apr 14 '19 at 12:13
  • 1
    @phuclv Thanks for the link. You are right, there are ways to use the speed of SSDs with the capacity of HDDs in a transparent way such as RAID arrays. However, the question was in the context of BTRFS which is not something currently supported. See https://btrfs.wiki.kernel.org/index.php/Project_ideas#dm_cache_or_bcache_like_cache_e.g._on_a_SSD – Alexandru Ungureanu Apr 14 '19 at 12:31
  • 1
    @AlexandruUngureanu I am not sure, if a RAID1 solution and ``dm_cache`` are equivalent. On the other hand, ``dm_cache`` might be what you would use when you want to achieve this on block-level. In addition I do not know if ``dm_cache`` allows to use the data on the SSD in case of a HDD failure. – allo Apr 15 '19 at 08:12
  • 2
    @allo `limited by the size of the smaller drive` -- A remedy to this is to create a single partition on the SSD and a partition of the same size on the HDD; then let btrfs use them. Use the rest of the HDD for other partition(s) with separate filesystem(s). – Kamil Maciorowski Apr 15 '19 at 08:17
  • @allo You're right. RAID1 and dm_cache are not equivalent. However, if/when that feature would be implemented in BTRFS one could use RAID1 on a bunch of HDDs and add an SSD for fast reads which is where most of the performance gains are obtained from. – Alexandru Ungureanu Apr 15 '19 at 10:36