LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do I clone /tmp into a different filesystem? (https://www.linuxquestions.org/questions/linux-general-1/how-do-i-clone-tmp-into-a-different-filesystem-4175516214/)

PreguntoYo 08-24-2014 01:58 PM

How do I clone /tmp into a different filesystem?
 
Hello:

I have my / and /tmp using the same filesystem, into a logical volume (which itself is inside an encrypted container).

I'd like to separate /tmp into a different logical volume. I want to keep it's size more controlled, and add some security options in /etc/fstab for mounting it.

I know how to resize my logical volumes, its filesystems, create new logical volumes, and I have some idea about /etc/fstab.

But... I don't know exactly how to "clone" the existing /tmp into the new logical volume.

I mean, there are files inside my /tmp which I know for sure why they are there (like packages built by slackpkg), but there are others whose function is unknown to me; and I'm afraid I'll break something if I just copy them clumsyly and then access node times (or something else I don't know of) will be different on next reboot.

BTW, I'm going to do this job in my HD from a "rescue" environment; Slackware's installation CD.

OOT?: Most of these "unknown files" are named like: "virtuoso_n17983.ini" or "YvAiHe_H.part" (I guess these are from kde and a failed Firefox download, respectively).

Well, what could the magical command be? :confused:

ondoho 08-24-2014 03:41 PM

isn't the whole point of /tmp that it's temporary?

in other words, do your fstab stuff, don't copy anything, because it'll be gone anyway once you reboot.

https://en.wikipedia.org/wiki/Tmpfs

syg00 08-24-2014 07:01 PM

Wrong.
IF /tmp were mounted as a tmpfs, it would disappear at re-boot. The OP states it is a real filesystem.

But I agree with the sentiment - anything left in /tmp shouldn't be missed. And if it is, it will still be (unseen) under the root once it is mounted elsewhere. Personally I'd not copy anything over - and put a regime in place to clear it regularly. Or better, use a tmpfs ... :p

PreguntoYo 08-27-2014 02:12 PM

Some help needed, still
 
Understood, mounting /tmp as a tmpfs would be faster and no files would be created in the HD. Still...

I have yet tmpfs (should be half of my memory, if I understand man mount well) mounted as shared memory in /dev/shm; my fstab:
Code:

.
.
.
tmpfs  /dev/shm  tmpfs  defaults  0  0
.
.
.

Can I mount parts of tmpfs in two different places?. How?. Which sizes would you advice?.

Thanks for the help.

TobiSGD 08-27-2014 06:33 PM

You can mount as many tmpfs as you want (well, not really, but the limits are beyond reasonable use). Just use the default sizes, tmpfs only takes RAM that it actually uses.

syg00 08-27-2014 10:07 PM

Further to that, for a tmpfs, the "size" you see in df (for example) is the maximum size it can grow to (in RAM) - half of your RAM size by default. This is not like a normal filesystem where the size actually is the size of the formatted filesystem itself.
The system will manage it - see here for all the gory details.

PreguntoYo 08-31-2014 01:27 PM

Could you check my list?
 
Well, it looks like I have a lot of admin. work ahead...
  1. Shrink the /home filesystem and then reduce the size of the logical volume in order to make more space for /var
  2. Create a new /var logical volume, because /var was inside the /
  3. Copy /var inside the new logical volume
  4. Copy needed files from /tmp to /var (this is because sbopkg uses /tmp for working and saving finished packages, and I'm interested in keeping these) (I think)
  5. Modify /etc/sbopkg/sbopkg.conf so now it points to /var
  6. Modify fstab so the new logical volume will be /var and mount /tmp as a tmpfs
  7. Restart and pray to "Bob" that everything will work well
  8. If so, clean rubbish left in /tmp and /var, which will increase the size of / a lot
  9. Resize the / filesystem and reduce the logical volume, in order to use the left space for something better
Pheeew... please, could you check that I didn't forget anything (well, besides marking the thread as solved, afterwards)

Thanks to all of you for your help.

syg00 08-31-2014 06:44 PM

I would have thought the days of messing wtih filesystems to scrimp back disk space were long gone.
Personally I'd leave /var under the root, and just adjust the root filesystem in need - maybe not required as you'll get the current /tmp allocation back as you say.
Note that 8 will have to be done (safest) from a liveCD - other than that looks ok. Hardly the end of the world if it fails, it's all easily recoverable from a liveCD.

EmaRsk 09-04-2014 07:17 AM

Quote:

Originally Posted by PreguntoYo (Post 5230271)
clean rubbish left in /tmp and /var

You won't be able to do that from the running system, because /tmp and /var will show the content of the mounted filesystem, and you can't unmount them with the system running.
Do that from a live distro.

EDIT: Damn, I realized a second too late that syg00 already told you that.

rknichols 09-04-2014 10:12 AM

Quote:

Originally Posted by EmaRsk (Post 5232260)
You won't be able to do that from the running system, because /tmp and /var will show the content of the mounted filesystem, and you can't unmount them with the system running.

By making use of a bind mount, you indeed can clear the old /tmp and /var while the new filesystems are mounted there.
Code:

mkdir /mnt/tmproot
mount --bind / /mnt/tmproot

Now you can clean out /mnt/tmproot/tmp amd /mnt/tmproot/var however you like
Code:

find /mnt/tmproot/tmp /mnt/tmproot/var -mindepth 1 -delete
and clean up
Code:

umount /mnt/tmproot
rmdir /mnt/tmproot


EmaRsk 09-04-2014 10:40 AM

Nice! I didn't think of that.


All times are GMT -5. The time now is 03:01 PM.