LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-15-2015, 02:18 PM   #1
funtoos
Member
 
Registered: Jun 2003
Location: US
Distribution: Gentoo x86/AMD64, KDE 4.13
Posts: 38

Rep: Reputation: 25
Replace a mounted squashfs image file


Is there a way to atomically replace a squashfs image file that is already mounted?

In my case, /mnt/cdrom/squashfs.img is mounted on /mnt/livecd and /usr is a symlink to /mnt/livecd/usr. So, all commands and binaries are coming /mnt/livecd, which all the daemons which are running, have their executable pages coming from /mnt/livecd.

I want to replace /mnt/cdrom/squashfs.img without killing those daemons. I can not unmount (won't even be allowed because FS is in use) because even the 'mount' program and its dependent libs can get paged out, and I can not remount after overwriting squashfs.img because between 'cp' and 'mount -o remount...', some daemon may have asked for a file block which may not even be a valid block number in the new image.

I need something like:

freeze FS
copy new_squashfs.img squashfs.img
remount /mnt/livecd
discard or rebuild all in-memory block references
unfreeze FS

Its pretty much like pulling the disk from underneath the FS. The only saving grace is that FS is read only in this case, so it should be doable.

Last edited by funtoos; 02-15-2015 at 02:22 PM.
 
Old 02-18-2015, 12:47 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Unmounting a filesystem while programs are using is not possible. Removing a mounted filesystem is also not possible.

Perhaps you can use ram (tmpfs, zram, ramdisk) to store/setup your commands and their libraries and then try what you want to do.
 
Old 02-18-2015, 09:06 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by funtoos View Post
Is there a way to atomically replace a squashfs image file that is already mounted?
In my case, /mnt/cdrom/squashfs.img is mounted on /mnt/livecd and /usr is a symlink to /mnt/livecd/usr. So, all commands and binaries are coming /mnt/livecd, which all the daemons which are running, have their executable pages coming from /mnt/livecd.

I want to replace /mnt/cdrom/squashfs.img without killing those daemons. I can not unmount (won't even be allowed because FS is in use) because even the 'mount' program and its dependent libs can get paged out, and I can not remount after overwriting squashfs.img because between 'cp' and 'mount -o remount...', some daemon may have asked for a file block which may not even be a valid block number in the new image.

I need something like:

freeze FS
copy new_squashfs.img squashfs.img
remount /mnt/livecd
discard or rebuild all in-memory block references
unfreeze FS

Its pretty much like pulling the disk from underneath the FS. The only saving grace is that FS is read only in this case, so it should be doable.
Have you checked out the man page on the umount command? Specifically, the "-l" option, which performs a 'lazy' unmount? This will detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. So the /mnt/livecd filesystem will detach and let you re-mount it to a different image...the programs that are running should still continue to run in memory, until they complete. After the unmount, you should be able to remove links to that 'mounted' file system, since it will DISmounted at that point.

I have *NEVER* attempted anything like this, though, and it's not really a good thing to do, in my opinion. Personally, I'd schedule downtime and do things cleanly.

---------- Post added 02-18-15 at 09:07 AM ----------

Quote:
Originally Posted by veerain View Post
Unmounting a filesystem while programs are using is not possible. Removing a mounted filesystem is also not possible.
Wrong on both counts. Read the man pages on umount.
Quote:
Perhaps you can use ram (tmpfs, zram, ramdisk) to store/setup your commands and their libraries and then try what you want to do.
So then why don't you show us how??? You post things like this frequently, saying "perhaps you can do xxxx", but don't ever seem to offer any advice past that.
 
Old 02-18-2015, 09:43 AM   #4
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Maybe mount over the original image?
As I understand (and just tested), existing calls to files would continue uninteruppted. However new calls would be sent to the new mounted squash image.

The obvious flaw here is that you cannot umount the orginal mounted squash image until you umount the second one.

So while /mnt/livecd has /mnt/cdrom/squashfs.img, mount /mnt/cdrom/newsquashfs.img onto /mnt/livecd

I have not tested this in production though, so it may or may not be safe.
You're asking to pull a mounted fs from underneath while daemons are using it though, if possible I would say a clean reboot would be the better choice. (Which sometimes isn't possible)
 
1 members found this post helpful.
Old 02-18-2015, 10:15 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by Miati View Post
Maybe mount over the original image?
As I understand (and just tested), existing calls to files would continue uninteruppted. However new calls would be sent to the new mounted squash image.

The obvious flaw here is that you cannot umount the orginal mounted squash image until you umount the second one.

So while /mnt/livecd has /mnt/cdrom/squashfs.img, mount /mnt/cdrom/newsquashfs.img onto /mnt/livecd

I have not tested this in production though, so it may or may not be safe.
You're asking to pull a mounted fs from underneath while daemons are using it though, if possible I would say a clean reboot would be the better choice. (Which sometimes isn't possible)
Agreed...while this CAN be done...I'd not want to do it in production.
 
Old 02-18-2015, 12:25 PM   #6
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by TB0ne View Post
After the unmount, you should be able to remove links to that 'mounted' file system, since it will DISmounted at that point.
So how does he knows umount happened. By using a regular poll.

Quote:
Originally Posted by TB0ne View Post
So then why don't you show us how??? You post things like this frequently, saying "perhaps you can do xxxx", but don't ever seem to offer any advice past that.
So you want me to be his machines system administrator. I can only give a lead or a way of process.
 
Old 02-18-2015, 12:57 PM   #7
funtoos
Member
 
Registered: Jun 2003
Location: US
Distribution: Gentoo x86/AMD64, KDE 4.13
Posts: 38

Original Poster
Rep: Reputation: 25
I don't think mounting new squashfs image over the existing mount point is an issue. That's pretty much same as doing a live yum update of a library like glibc which is used by pretty much every program on the system.

But the problem is my use case is not served well by that. I want to switch between two squashfs installs, keeping the last one handy in case an update breaks an app I use. If my original mount point gets buried underneath, I can't unmount it and make the next update point to it.

What I am thinking now is to use a symlink because symlink is smallest atomic operation that has few chances of failing.

In this install /usr is a symlink to /mnt/livecd-sym/usr instead of standard /mnt/livecd/usr

Then, I make /mnt/livecd-sym a symlink to /mnt/livecd

I mount the new squashfs to /mnt/livecd2 and point the /mnt/livecd-sym to /mnt/livecd2 if its pointing to /mnt/livecd and vice versa. /mnt/livecd (or /mnt/livecd2) can be unmounted (only lazy umount will work here) at this time. The old programs will continue to get stuff from caches and new programs will read from new squashfs image.

I tried this on a fully booted system with desktop running and things work fine. But the two squashfs images I used do not differ that much from each other. I will need to make a glibc switch to actually be sure that this will work.

Last edited by funtoos; 02-18-2015 at 01:28 PM.
 
Old 02-18-2015, 01:27 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by veerain View Post
So how does he knows umount happened. By using a regular poll.
No, you know unmount happens by the return status of the command. And a well-documented one at that.
Quote:
So you want me to be his machines system administrator. I can only give a lead or a way of process.
Not asking you to be HIS administrator, but to STOP GIVING MISLEADING, INCORRECT, OR USELESS ADVICE. You said "Perhaps you can use ram (tmpfs, zram, ramdisk) to store/setup your commands and their libraries and then try what you want to do."

Great...since you said that, why don't you 'lead' or 'give way of process', by actually showing us examples of what you're talking about. "Perhaps" by giving an actual command, process, documentation, or SOMETHING to support what you're saying. Just telling people "perhaps you can do xxx" is useless; telling people they can't do something which is easily done is incorrect.

So...support what you said by giving us examples of how to do exactly what you stated.
 
Old 02-18-2015, 06:32 PM   #9
funtoos
Member
 
Registered: Jun 2003
Location: US
Distribution: Gentoo x86/AMD64, KDE 4.13
Posts: 38

Original Poster
Rep: Reputation: 25
I had to patch genkernel package to use create the /mnt/livecd-sym symlink and refer /mnt/livecd-sym instead of /mnt/livecd when creating symlinks for /usr, /bin, /lib64 etc.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help editing livecd image.squashfs file fdisk13 Linux - Software 1 04-24-2012 01:16 PM
Can mounted directory be synchronous with image file? zhsishi Linux - Embedded & Single-board computer 1 01-27-2010 04:37 PM
Live CD not proceeding to second stage of boot after squashfs image editing cyber_apostle Programming 0 11-13-2009 02:34 AM
Invalid loop location: /image.squashfs crontab Linux - Software 2 09-18-2008 08:54 AM
How to modify squashfs file ? kkpal Linux - Newbie 0 01-16-2008 12:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration