I would like to create virtual volume (partition) on my disk. I use VPS and I cannot shrink root partition and create new one.

So I decided to create a virtual volume on disk, let's say that I want to create virtual volume with size of 12 GB, how can I do it?

Next, is possible to automatically mount it after every reboot? How?

I wonder is there is any performance drop between real partition and virtual volume (like latency, etc..).

I use Debian 9 with ext4 file system.


I cannot shrink parition, because I cannot mount livecd (rescue disk), because my hosting provider has no option for it. So then i cannot boot into livecd to unmount filesystem to make changes to partitions.

i want that "partition", because in that partition users will be able to upload (using web app) some files, and I would like to limit size of that space/partition for example to 12 GB, so it never take more than 12 GB.

Update 2:

After running fallocate -l 7G dummy (to create big dummy file) inside mounted device and df -h:

Filesystem              Size  Used Avail Use% Mounted on
udev                    485M     0  485M   0% /dev
tmpfs                   100M  6.8M   93M   7% /run
/dev/mapper/vg-lv_root   19G  1.2G   17G   7% /
tmpfs                   496M     0  496M   0% /dev/shm
tmpfs                   5.0M     0  5.0M   0% /run/lock
tmpfs                   496M     0  496M   0% /sys/fs/cgroup
/dev/sda1               236M   37M  187M  17% /boot
/dev/loop0               12G  7.1G  3.9G  65% /srv/data
tmpfs                   100M     0  100M   0% /run/user/0

You can see, that it is mounted and it shows used space in /srv/data, but I wonder why it doesn't show used space on root partition (I have 20 GB SSD from provider, but df -h shows that I have 32 GB (20 GB root and 12 GB mounted device). How can I see "real" used space in root partition? Because in root directory I have that data.img which has size of 12 GB, but it doesn't count as used space, df -h showed used space, but after running mkfs.ext4 it doesn't show anymore, do you understand me? :)

Another question: Should I run dd if=/dev/zero of=data.img bs=1M count=12000 command?

closed as unclear what you're asking by Rui F Ribeiro, Christopher, Timothy Martin, G-Man, steve Apr 18 '18 at 21:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You can create a 12G big file and point a loopback device at it, then the inside of the file is something you can format with a file system. But why you would want to do that is beyond me, so maybe I'm misunderstanding what you want. – Ulrich Schwarz Apr 17 '18 at 16:00
  • Because I cannot create new partiton, because I cannot boot livecd, because my hosting provider doesn't support it. I use Debian 9. I don't know why dislike.. I provided all information. – tomsk Apr 17 '18 at 16:33
  • Which filesystem are you using for your root filesystem (partition)? – Emmanuel Rosa Apr 17 '18 at 18:03
  • I am using Ext4, I found this tylerburton.ca/2014/06/… so it looks like that what I want, but I want to make that image persistent --> mount automatically after boot (like hard drive). – tomsk Apr 17 '18 at 18:34
  • 1
    If your web app can designed to write the uploaded files with a Linux user account dedicated to that purpose only, you may be able to take advantage of filesystem quotas. Quotas work by limiting how many files (including directories) and how much data a user can consume on a filesystem. Take a look at wiki.archlinux.org/index.php/Disk_quota and the links at the bottom of the page. – Emmanuel Rosa Apr 17 '18 at 22:00

Here's how to create a 12GB ext4 disk image which you can then mount automatically upon boot:

  1. Create the image file: fallocate -l 12G /path/to/image.img
  2. Create the filesystem in the file: mkfs.ext4 /path/to/image.img
  3. Mount the filesystem automatically: echo "/path/to/image.img /srv/data ext4 defaults,auto,loop 0 0" >>/etc/fstab
  • @tomsk, You have a better option available: LVM. Unfortunately, your question has jumped around too much and is no longer suitable for this forum. Get with me on Google+ so we can chat offline. In hindsight, it makes sense your VPS uses LVM because it "effectively" allows you to create something akin to partitions. plus.google.com/+EmmanuelRosa – Emmanuel Rosa Apr 20 '18 at 2:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.