In Ubuntu (and probably other OSes) you can create an empty file, resize it to a couple GBs, create a filesystem on it, and then mount it at any location. You can treat this as a virtual drive to, for example, limit the size of a directory:
$ touch myfile
$ truncate -s 2G myfile
$ mke2fs -t ext4 -F myfile
$ sudo mount myfile /path/to/virtualdrive
$ df -h /path/to/virtualdrive
$ truncate -s 2G myfile
$ mke2fs -t ext4 -F myfile
$ sudo mount myfile /path/to/virtualdrive
$ df -h /path/to/virtualdrive
Note that /path/to/virtualdrive
needs to exist as a directory, otherwise, you'll get an error on the mount
command.