We are using a network Samba drive for Backup on our Linux Server. In order to store permissions (Samba does not support this), we have created a loop device to a large file (50GB) on the network drive. This works fine most of the time, but every few weeks the loop device goes into readonly mode.

Here is the fstab snippet for network drive and loop drive:

//xyxyxy.your-backup.de/backup /backup cifs credentials=/root/backup-credentials,iocharset=utf8 0 0
/backup/backup.lp /backup-loop ext3 loop,sync,defaults,_netdev 0 0

I aldo tried standard loop configuration, but the problem maintains:

/backup/backup.lp /backup-loop ext3 loop,sync 0 0

Our assumption: As far as I know the mounted drive goes into readonly mode when the connection to the physical device is lost. Thus when the network drive loses connection, the loop file is gone and the loop mount goes into readonly mode. The cifs handles reconnecting of its own mount, but loop knows nothing about it.

Our current solution is to force remount of both samba and loop device shortly before our cronjob would start the backup process. This works, but doesn't feel right.

Is there a possibility to trigger remount of loop device when the target loop file gets back online?

  • Running mount -o rw,remount /backup-loop doesn't help once it's broken? You could run that before starting the backup job just in case. – fuero Feb 2 '15 at 8:01
  • @fuero That is our current solution but it doesn't work always (device is busy), and sometimes the loop drive goes into readonly mode in the middle of a backup. I need a way for loop device to reconnect by itself (without a remount) in rw mode if the connection is shortly gone. – Bojan Hrnkas Feb 2 '15 at 8:11

I think your assumption about things going into read only mode when the connection to the network drive is lost is correct. I made a simple test with a just a small file on a Samba share and the same thing happens if I yank the network cable.

As for a solution to the problem, I would go about it like this:

  • Depending on how you actually do the backup, I would mount the loop file rw as part of the backup process and unmount it once done. This also helps safeguarding the backup against accidental pilfering.

  • If you need access to the backup at other times, mount it read-only. You can keep the file mounted this way at all times, excepting when you actually want to do a backup

  • That way, no one gets hurt and you are able to do what you want when you want. I would go so far as to say it is even a little bit better than keeping the loop file mounted rw all the time - given safety concerns.

If you use rsync to do your backup, you can check on the rsync exit status to figure out if you have been unlucky enough to lose the connection while doing the backup (true for other tools too - just my preference). You may then act accordingly.

This does not get you exactly what you asked for - I would say it gets you something a little better - but I don't think you can expect the loop device to work as you want wo. some trickery anyway.

I hope this helps :-)

  • I will try this later during the day and let you know if it worked. The answer is worth the bounty nevertheless. – Bojan Hrnkas Feb 2 '15 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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