-   Linux - Software (
-   -   Question: Unmounting /boot after reboot (

haertig 05-03-2017 09:17 PM

Question: Unmounting /boot after reboot
I have a question on mounting /boot, or rather, unmounting it (or better, preventing it from being mounted) after control is transferred to the root filesystem.

This is on a Raspberry Pi 3 ("RPi") running Raspbian (a Debian Jessie derivative), but it is not specific to the RPi, it's more of a general Linux question.

My RPi has the minimal files needed for booting on it's MicroSD card (RPi's normally boot and run from Flash). I have an external USB HDD that holds the root filesystem and user data. After booting, /boot is no longer needed and I want it unmounted to protect the flash card from corruption (this corruption frequently happens on a RPi if it looses power). Currently, I am unmounting it manually.

The RPi can boot directly from USB without using the flash card normally, but not in my circumstance, otherwise that is the way I would have done this. My external drive is 4Tb, thus is requires GPT. But the RPi only understands MBR during boot, so it can't recognize my GPT drive. The RPi can deal with GPT, but ONLY after it has successfully booted from MBR.

Below is what the RPi looks like after booting (I use "df" to show the mounts because I like the layout of the display better than "mount"). Note that /dev/mmcblk0p1 is mounted on /media/pi/boot. That's what I want to prevent. It is not needed after booting (except during upgrades or config changes, but I understand that).


root@raspberrypi:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root      9.5G  5.4G  3.7G  60% /
devtmpfs        459M    0  459M  0% /dev
tmpfs          463M  36K  463M  1% /dev/shm
tmpfs          463M  6.4M  457M  2% /run
tmpfs          5.0M  4.0K  5.0M  1% /run/lock
tmpfs          463M    0  463M  0% /sys/fs/cgroup
tmpfs          463M    0  463M  0% /var/tmp
tmpfs          463M  4.0K  463M  1% /tmp
/dev/sda2      3.6T  68M  3.4T  1% /user_data
tmpfs            93M  4.0K  93M  1% /run/user/1000
/dev/mmcblk0p1  66M  21M  46M  31% /media/pi/boot

I assume this is udev, systemd or something similar that is mounting this after boot. How do I prevent that from happening? If I can't prevent it in the first place, my other option is to have a script unmount it after the fact. I must ashamedly admit that my brain still works back in the old sysvinit days as far as startup scripts go, and I'm not sure where the best place to run an unmount script after boot would be these days. Any pointers on where/how to invoke a startup script to do this would be appreciated.

Note: The root filesystem above is mounted from "/dev/root". For some reason unknown to me, that is what the RPi calls it. I think that's a poor choice, because you don't know where it is coming from. Most other systems would call it "/dev/sda1", since it's coming from my external HDD.

Thanks in advance!

syg00 05-03-2017 09:48 PM

Couple of options:
- if you can bust that user_data so it mounts on 2 mount-points you can probably use MBR on the 4T. Just make both partitions less than 2T - strictly speaking the last partition needs to start before the 2T mark, and be less than 2T in size. Works on my 3T anyway .... :p
- otherwise use a systemd timer pop to run the umount - say 2 minutes after boot. See "man systemd.timer".
- fix udev. I don't use Raspian, but on Arch the rules are in the normal place(s).

mrmazda 05-05-2017 03:50 AM

Have you tried creating an fstab entry for it using ro and/or noauto options?

haertig 05-05-2017 09:32 AM

There currently is NO fstab entry for this device at all. Do you think ADDING a new entry can be used to stop it's mounting? That seems unlikely to me. Especially since it's being mounted in /media/<username>

mrmazda 05-05-2017 12:42 PM


Originally Posted by haertig (Post 5706590)
Do you think ADDING a new entry can be used to stop it's mounting?

That's precisely why I wrote what I wrote. It's important to use option noauto, and preferable to use volume label to mount by.

haertig 05-05-2017 03:24 PM


Originally Posted by mrmazda (Post 5706665)
That's precisely why I wrote what I wrote.

Well, you were certainly right! Worked perfectly. I should not have doubted. Thank you very much for the suggestion. Trivially easy to implement.

mrmazda 05-05-2017 05:56 PM


Revisiting your original goal, you might want to consider mounting it elsewhere than /boot/ (e.g. /mnt/boot/), and leaving /boot/ as a mountpoint empty. That way, when updates need to write to /boot/, they can proceed normally, without you having to think ahead and take appropriate action. Then when updates are done, you can sync the changes manually at your leisure, needing first only to remount the MicroSD card rw.

All times are GMT -5. The time now is 09:40 PM.