0

I am trying to move the /var folder to another (bigger) partition but I get stuck on the error message

device or resource busy

I have done every step such as creating a new mount for the new folder and copying the contents of the /var folder to it as well as setting up runlevel to 1 (through init 1).

I don't know what else to do, I even killed the process that is making it busy but when I kill them I am unable to type on terminal again to finish the operation.

6
  • 1
    Please elaborate on "every step". Which steps did you do exactly? Apart from that: Can you bring the system down and do the changes while it is offline (accessing its drive from another system i.e. live boot)?
    – Hermann
    Oct 10, 2019 at 2:09
  • 1
    I'm afraid that the simplest way is to prep the new partition, including changing fstab, and rebooting. Oct 10, 2019 at 2:11
  • Use lsof to see open files, but since /var is used for lots of state stuff like pidfiles you're going to have to shut down a lot to do all of /var. Consider moving only the big parts of var ( you haven't told us what that is, but say /var/log or docker files) . Easier to stay up that way. Be careful with this, there might be some boot time deps on /var being there
    – erik258
    Oct 10, 2019 at 3:00
  • Boot from a live distro to delete your old /var and change /etc/fstab to mount your new partition to /var. That should do the trick.
    – markgraf
    Oct 10, 2019 at 8:10
  • I'm not at all certain that modern Linux distributions support having / and /var on different filesystems...
    – AlexP
    Oct 10, 2019 at 8:22

1 Answer 1

1

In contrary to your belief, it is possible for System V runlevel 1 (a la init 1) to have some running services, which may hog your /var directory.

Since you neither elaborate on which kind of system/distribution you are using, nor give ps auxfww output; I'm going give a generic, sure-fire— but also dirty and dodgy advice...


To boot a GNU/Linux system without any program but your shell, boot your machine with init=/bin/sh parameter appended to the end of kernel command line.

Without any other program running, this is an ideal environment to commence your /var relocation operation.

But there are few things you need to take note of...

  • Beware that this is a dodgy thing to do, only resort to this if it cannot be done in other ways.
  • The shell will be a root shell, and likely to have neither command history nor line editing.
  • Only one console will be available; no pressing Ctrl+Alt+F2 if you got stuck.
  • Job control will not work; no pressing Ctrl+C to stop runaway program.
  • $HOME directory location will be set to / (rather than the usual /root); so avoid doing things that write to your home directory.
  • Do not exit from your main shell. (Doing so will halt your system with kernel panic)

And don't forget these operational safety procedure...

  • Once booted in this environment, before doing anything, run mount -o rw,remount / to make sure that that root filesystem is writable.
  • Once you are done with your business...

    1. Make sure to un-mount any extra filesystems you mounted.
    2. Make sure you re-mount root filesystem read-only: mount -o ro,remount /
    3. Make sure you flush all disk cache: sync
    4. Then force-reset the system: reboot -f (pressing Ctrl+Alt+Del also works)

A less-dodgy alternative is booting your system with a GNU/Linux boot disk, and do your moving operations from there of course.

2
  • I think booting into a initrd "hook" is also a possibility. Then you have busybox instead of pid 1 shell. In a situation like this, a small second installation can also be useful - if you have it already. Insetad of remounting root from "inside", you just mount that partition from "outside". Same idea as markgraf's live distro.
    – user373503
    Oct 10, 2019 at 8:21
  • "GNU/Linux boot disk": disk? like floppy disk? ;) You mean live distro? Oh sorry you mean "compact disk" = "Live CD". Today: USB.
    – user373503
    Oct 10, 2019 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .