Dear Internet, does anyone know of a reliable way to unmount and remount a file-system with a script, without rebooting the server? Because I'm struggling to find one. RTs gratefully received!

For anyone interested in the resolution, I ended up doing this:

Thanks @mansr for pointing me in the right direction. This seems to work well, ideally I'd prefer not to have to reload services, but this is a solid solution. 🙂

@mansr For now I'm trying to run umount followed by mount, but sometimes the volume is busy so umount fails. `umount -l` works consistently for unmounting, but then I can't remount because I get told /dev/loop0 is busy and only a reboot seems to fix that. I tried `mount -t remount` as well, but that only *attempts* to remount and I'm not seeing the changes in the .sqsh image reflected in the mounted volume, so it seems that's failing silently. 🤔

@greg_harvey Busy means some process has a file on it open. You could find them and kill them (fuser can help here), but that might not be desirable.

@mansr It's worth a look, I suspect it's Nginx because the context here is mounting a SquashFS volume with some PHP code on (to save untarring 15,000 files on autoscaling events!) ... it all works well, except replacing the volume after a code release. I think it would be acceptable to kill Nginx for a few seconds to get the volume updated.

@greg_harvey If you know nginx/php is using the volume, the cleanest is probably to shut that down properly, do the remount, then restart the service.

@mansr True! And this is only happening in infra where there are multiple web heads, so it should be fine. I'll check it definitely is what I suspect first, and if it is then stopping the service, unmountin, remounting and starting the service again is probably as good as it'll get.

@mansr Stupidly, I tried stopping Nginx and it didn't help, so I kind of abandoned the idea. But I've just realised now that it's not Apache and mod_php so stopping Nginx is the wrong service. I should've stopped PHP-FPM. 🙄

@mansr Anyway, thanks for the idea, appreciate it! I'll give it a try in the morning. 🙂

Sign in to participate in the conversation

Instance générique de Mastodon hébergée par l'association FairSocialNet Generic Mastodon instance hosted by the FairSocialNet association.