Skip to contentSkip to conversation

Overwrite mounted filesystem

DISCUSSION Wolter Kamphuis 2 participants 3 messages Sep 22, 2003 – Oct 7, 2003 VFS

lore
Share & tools
lore
#0 lore raw

Hi all,

Does anyone know if it's possible to overwrite a mounted filesystem with another filesystem (both ext2) without having to umount or reboot?

I've build a static daemon which kill's all other processes, remounts root read-only and overwrites it with a new filesystem image, received over the network, stored in memory. After overwriting the currect filesystem I use ioctl BLKFLSBUF and BLKRRPART to flush all buffers and re-read the partition table. Remounting the root-fs read-write works and I can list the new filesystem. Accessing and creating files however results in fs-corruption.

I need to place a few files on this new filesystem before rebooting, for example the passwd file.

I think the problem is some kind of filesystem cache, maybe a cache in the VFS layer. Does anybody here know what could be wrong or give me some pointers where to look?

thanks in advance,
Wolter Kamphuis

btw, I'm building this tool for a embedded system, a motorola mpc850 cpu, 4-16mb ram and 4-16mb flash. The root-fs is placed on the flash. We use a modified 2.2.5 linux kernel.

#1 lore raw
Quoted 4 lines

Does anyone know if it's possible to overwrite a mounted filesystem with another filesystem (both ext2) without having to umount or reboot?
...
I think the problem is some kind of filesystem cache

Yes, at least the superblock and inodes are cached.

Quoted 7 lines

I've build a static daemon which kill's all other processes, remounts root read-only and overwrites it with a new filesystem image, received over the network, stored in memory. After overwriting the currect filesystem I use ioctl BLKFLSBUF and BLKRRPART to flush all buffers and re-read the partition table. Remounting the root-fs read-write works and I can list the new filesystem. Accessing and creating files however results in fs-corruption.

This suggests a much narrower question than the original, in that the filesystem image is read-only at the time you blow away the underlying filesystem. But you still have the problem of the stale metadata cache.

Note that contrary to what the composition of the word suggests, "remounting" is not mounting again. It is just modifying the attributes of the existing filesystem image.

Quoted 2 lines

I need to place a few files on this new filesystem before rebooting, for example the passwd file.

This sounds like a job for pivot_root(). Make a temporary root filesystem in a ramdisk, pivot to that as your root, then unmount the original root disk and have your way with it. I have only a passing acquaintance with pivot_root(), so if I'm oversimplifying, someone please correct me.

--
Bryan Henderson IBM Almaden Research Center
San Jose CA Filesystems

#2 lore raw

hi all,

Two weeks ago I asked on this list how I could unmount a root filesystem, overwrite it with new content and remount it again, all without rebooting. Bryan Henderson pointed me at the pivot_root function which indeed does what I need. I've been very busy trying but I can't get it to work. I've made the next program to test the pivot_root function and show you my problem:
http://wkamphuis.student.utwente.nl/coding-temp/

The problem is the umounting of the old root filesystem, line 342. Even if I close all filedescriptors I still can't unmount it.

I looked in the kernel to force a unmount even if the filesystem is busy but that didn't really work. I don't know where to start.

does anyone here know what I do wrong or what I should do?

thanks in advance,
Wolter Kamphuis