is there a way to get to them while mounted?
Not that I know of. You could mount the existing storage somewhere else (another mountpoint) if you need to transfer anything to or from that. Or use a Live session.
To umount the external drive:
$ sudo umount /mnt
Check to make sure the external drive has been unmounted from /mnt
$ df -h
Now change directory to /mnt
$ cd /mnt
Run this to make sure you are now in the /mnt directory
$ pwd
It should show this now:
/mnt
Warning! Make VERY sure you are in /mnt before issuing the next command, it will remove every file from your current location and traverse every directory removing those files too.
$ rm -fr *
If you are in / when you run that command, it will remove every file on your SD.
And finally, remount the external drive or reboot.
If you know what processes are running that access the drive, you will need to stop them. Hopefully you know, hunting those down can be difficult.
There is a command “lsof” which can tell you which files are open on a filesystem and the process that is accessing those files.
$ sudo lsof /mnt
It is far better to properly stop the processes. Also, if you changed directory to /mnt (ie. cd /mnt) this too counts as a process and will prevent the umount, and tell you the target is busy.
mount --bind / /mnt
seemingly unmounted /mnt and the drive is no longer showing up in df -h
Got it! I found the old backup data that was taking up space - back down to 3.7G now!
setting boot partition as read-only can prevent this - do you know any easy way to do that? i’d need to disable it only to update system/server packages
Have you checked man fstab
?
There’s an example in this forum: Howto mount drive as read-only with fstab - Ask Ubuntu
There’s also this, which is more raspberry pi relevant:
yeah I found a guide for Raspbian. Looking at my fstab:
LABEL=BOOT_MNJRO /boot vfat defaults 0 0
thats obviously main filesystem partition, and I would change that to:
LABEL=BOOT_MNJRO /boot vfat ro,suid,dev,exec,auto,nouser,async 0 0
this is great so far but it would just affect mount point /boot
:
/dev/mmcblk2p1 214M 53M 161M 25% /boot
the partition that had the hidden data is: /dev/mmcblk2p2 15G 3.7G 9.8G 28% /
but there is no mount point, so this wont be affected by the config above right?
Yes, but you said you wanted to make the boot partition Read-Only:
so changing the entry to: LABEL=BOOT_MNJRO /boot vfat ro,suid,dev,exec,auto,nouser,async 0 0
would do the trick then?
I don’t know about the others, but the ro
one should be there atleast.
i just replaced default
with all the default settings individually and changed rw
to ro
would I still be able to update using sudo/root or will I have to change fstab
back to rw
before updating system?
No, no… setting /boot as read only will only serve to mess up your updates when you forget to remount it R/W. What I think you are wanting is to set the root filesystem / to be read only (to protect /mnt from being written to)… it can be done I suppose, but you will be greatly limited in the software you can run. Both /etc and /var are a real issue for having a R/O / filesystem.
I suppose you could make 2 extra partitions and mount them on /etc and /var but this will be headache, as partition size will matter and /var can grow unexpectedly. And with a MBR SD (limited to 4 primary partitions), you will have to make extended partitions.
So you will end up with a complex and fragile setup that is not easily “fixed” by simply making a new SD card from an image. You might be better off waiting for the UEFI firmware to be production ready for more complex filesystem configurations. But I do not know a timeframe of when this will happen.
There is something to be said for the simplicity of the RPi4 and SD cards, given the current immature status. I enjoy these types of complex configuration challenges myself, but not everyone else will.
yes, the root filesystem.
the main reason for wanting read-only is to prevent corruption in case of improper shutdown - the writing to /mnt
was a one-off mistake and not an issue in future.
I got the idea from this thread: Raspbian with Read-only Root - Raspberry Pi Forums
im using a RockPi4 booting from eMMC, is there a way I can benefit from what they are doing in the thread above?
I am working on network booting a good number of RPi4 and I would very much like a R/O root filesystem, so they could all share a single root filesystem. So this is a work in progress for me as well. If I am successful in making a R/O filesystem that works for a general use desktop, I will for sure post it in my thread on network booting the RPi4.
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.