4

I use Ubuntu 20.04, on a machine that has a limited system drive.

I came across a build script that checks for available size in /tmp, and it refuses to run if it doesn't see 12 GB available, which I do not have on system drive.

However, I do have another NTFS drive on this machine; since its NTFS, I cannot really use it directly, but I can create a disk image.

So, I thought of creating a 16 GB ext3 image on the NTFS partition, then mount this as /tmp.

So, I tried:

dd if=/dev/zero of=tmp16.img bs=16M count=0 seek=1024
mkfs.ext3 ./tmp16.img
fdisk -l ./tmp16.img
e2label ./tmp16.img tmp16

So far, so good - all of that worked; but then I try to mount:

$ sudo mount -o remount /path/to/ntfs/tmp16.img /tmp
mount: /tmp: mount point not mounted or bad option.

Ups, must be an old memory of mine from somewhere, that /tmp is a separate mount - it turns out, on this machine, /tmp is not a separate mount:

$ mount | grep tmp
udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=3970256k,nr_inodes=992564,mode=755)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=802768k,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
tmpfs on /run/snapd/ns type tmpfs (rw,nosuid,nodev,noexec,relatime,size=802768k,mode=755)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=802764k,mode=700,uid=1000,gid=1000)
tmpfs on /run/netns type tmpfs (rw,nosuid,nodev,noexec,relatime,size=802768k,mode=755)

Well ... is there any way that I can use this disk image as /tmp on this machine - and is there a way to do that, without having to reboot the machine (which would be needed, I think, if something has to be done int /etc/fstab?)

If not, is there any other way I could make use of the available NTFS space and use it as /tmp - preferably, without having to reboot the machine?

6
  • 2
    why not edit the script so that it uses /var/tmp/ or some other directory with enough space available (whether it's a mount-point or not)? It's not a great idea to mount another fs over /tmp unless you do it very early in the boot process (before anything really starts using it) - files that were already in /tmp won't be available when a new fs is mounted on top of it (even overlayfs doesn't really solve that problem if you need RW access to the older files in /tmp) Commented Apr 8, 2023 at 11:10
  • Existing open files will be available/usable and nothing will break. The issue might arise with directories but those could simply be copied/recreated. Commented Apr 8, 2023 at 13:29
  • 1
    @cas You really should not need to edit a well-written script but just set TMPDIR prior to running it. Unfortunately I don’t see a lot of scripts that are this well written. Commented Apr 8, 2023 at 20:58
  • @ArtemS.Tashkinov when you mount a filesystem, you can no longer see, or open, the files & dirs that were in the mount-point before the mount. Any already open file handles are still valid until they're closed. Try making directory /tmp/junk, copy a bunch of files & dirs into it. run ls on it. then truncate -s 1G /tmp/1gb.img; mkfs.ext4 /tmp/1gb.img; sudo mount -o loop /tmp/1gb.img /tmp/junk. run ls /tmp/junk again, all you'll see is the lost+found dir. Commented Apr 8, 2023 at 23:13
  • Any already open file handles are still valid until they're closed. - exactly what I was talking about. Mounting something on top of /tmp is relatively safe. Commented Apr 9, 2023 at 9:53

1 Answer 1

8
sudo mount -o loop /path/to/ntfs/tmp16.img /tmp

should work. No idea why you're using remount.

TBO sudo mount -o bind /path/to/ntfs/empty_dir /tmp could work as well. NTFS has all the features required to store Linux files https://linux.die.net/man/8/ntfs-3g : "it can handle special files like symbolic links, devices, and FIFOs; moreover it provides standard management of file ownership and permissions, including POSIX ACLs". NTFS-3g might be quite slower when working with thousands of small files but otherwise it's OK.

2
  • Many thanks, @ArtemS.Tashkinov - that does, indeed, work! I thought I had to have remount because I though /tmp was mounted (which it wasn't); given it was a directory, though, it can be used as a mount point - I was a bit afraid that might cause a conflict, but no; simply the content of the mounted image shadows what else existed in /tmp previously. Commented Apr 8, 2023 at 11:17
  • -o remount,new_option1,new_option2 is used to change the mount point options. You simply want to mount something on top of the existing mount. Commented Apr 8, 2023 at 11:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.