When am playing with my Android phone (CyanogenMod 10.1 with kernel 3.0.78), I found this:A script in /etc/init.d/99system.swap.shIt remount /system as rw, and creates an image file in /system/swap/swap.imgAfter the phone is started, I can find this swap.img file, and it is in use, by checking /proc/swaps. But the /system is mounted as ro.I tried to do the same thing, by manual, on another phone. But when I try to remount /system as ro, I got error message saying there are resources in use. If I swapoff the image on swap.img file, I can immediately remount /system as ro.I was wrong, I cannot remoutn /system as ro after I remount it as rw. lsof shows tons of process are using /system.
Can I remount as readonly if there's a swap image in use?
linux;mount;swap;readonly
It should be possible in theory, as the swapon manpage states:[...] the swap file implementation in the kernel expecting to be able to write to the file directly, without the assistance of the file system [...]So when you have a swap file, the kernel likes to treat it more like a partition, i.e. it determines where the swap file is physically located on disk and then uses that region directly as it would with a partition region. This is a trick to make swapping to a file just as fast as to a regular partition.At that point the filesystem is out of the loop and it should be okay to make the filesystem itself readonly. Whether you're actually allowed to do this is another matter; I haven't tested it myself and Android in particular may behave differently from regular Linux environment.