Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.sh
  • It remount /system as rw, and creates an image file in /system/swap/swap.img

After 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.

share|improve this question
    
What kernel version are these phones running? –  Gilles Jun 5 '13 at 21:28
    
@Gilles it 3.0.78, from CM10.1 –  davidshen84 Jun 7 '13 at 9:11
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
That's the general knowledge I learned about Linux, and since the /system is mounted as ro after that script, I guess Android should implemented the same way. But I just cannot remount it as ro... –  davidshen84 Jun 9 '13 at 11:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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