Using Spare Disk Space as One Large Disk

This is a neat trick in Linux for when you have a bit (some GB) in different disks and want to use it to save large files. I use this for mining XCH (Chia Cryptocoin).

  1. First check the available space on each disk using df -h:
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdg        4.6T  4.5T   84G  99% /media/omar/SEA_5T_B
/dev/sdp2        30T   30T   68G 100% /media/omar/seagate1

Here we have 2 disks, one with 84G and another with 68G. The size of the file we want to store is more than 100GB. To do that, we will first create "image" files using the remaining space in each disk:

truncate -s67G /media/omar/seagate1/67G.img
truncate -s83G /media/omar/SEA_5T_B/83G.img

Then, we create a loopback device with losetup for each disk:

losetup --show --find /media/omar/seagate1/67G.img
losetup --show --find /media/omar/SEA_5T_B/83G.img

We must pay attention to the data returned by those two previous commands, as they will tell us the name of the loopback device (e.g. /dev/loop1).

As a next step, we are going to use btrfs to create a single filesystem from those 2 devices:

sudo mkfs.btrfs -d single /dev/loop1 /dev/loop2
(Replace /dev/loop1 and /dev/loop2 with whatever you got from the losetup step)

Finally, we can mount our btrfs filesystem in some directory like:

sudo mount -t btrfs -o ssd,nodatacow,nodatasum,discard,nodiratime,discard=async,noatime /dev/loop1 loops/

In my case I added all those options to make access faster. With btrfs you can mount a several-disk filesystem by referring to one of the devices (like /dev/loop1 in this case)

After mounting this device, we do a df -h again and should see our new disk mounted in the specified directory with the summed amount of space:

Filesystem      Size  Used Avail Use% Mounted on
/dev/loop1      150G  3.8M  148G   1% /media/omar/loops

And that's it! we've got 150G to use for large files!

Some references: