0

I have an embedded linux on arm7.

I have a rootfs mounted on MTD partition 10 (for example), i.e. /dev/mtd10, which is a flash device. The volume is UBIFS device UBI0 (/dev/ubi0).

I have setup a pivot_root (similar to a chroot) tmpfs roughly following the instructions from here: resize-a-live-root-fs-a-howto.

I want to erase/re-format mtd10 (UBI0) The problem that I have is that I can't detach/format UBI0 until I have because it tells me its busy. So, I use the command:

fuser -vm /dev/mtd10 and this gives me a list of processes that I can kill, so I do all that and then umount (or umount -l) all the partitions that are mounted on UBI0.

So my system no longer has any dependency on UBI0... except the shell I am running. I have tried combinations of many things, but the only thing that seems to work (once I have tidied up) is to logout (using exit command) and then log back in (for me I just have to type in the username root).

As soon as I logout/run telinit u at this point then I see the UBI0 go away and I can detatch it.

update: killing rc_mxc.S has a similar effect to loging out (i.e. it ends my shell and I have to login again. But this also ends my script :(

The problem here is that I don't know how I can script that up. Running exit in a script just ends the script.

  • Have you ensured the current directory for your shell is not on the device? Or the file holding the shell binary (say /bin/sh), or the file holding the shell script is on the device? You can do something like exec /tmp/.../bin/sh /tmp/.../myscript to swap over to a new shell script, releasing some of these. – meuh Oct 3 '18 at 11:50
  • @meuh hmm... I think it is somthing to do with that. As I say if I kill my shell or logout (both have a similar effect) then I can free the device. I was actually just messing around with running a script exec myscript.sh to kill of everything including the sh that was running on the device and that seemed to work (but after the script I still need to login again) - however I think because my sh that I start in is on the device then the exec may also be on it so I had to not terminate the sh that I spawned ...complicated! - in short, I will try your recommendation as it seems sound :) – code_fodder Oct 3 '18 at 12:13
  • 1
    What about using initramfs that never "pivots" to a "physical" file system? – jc__ Oct 3 '18 at 13:58
  • @jc__ that looks really like what I want to do!...but I can't find a simple/basic example of this. It seems like you build up a tmp-rootfs similar to creating a chroot/pivot_root folder (in RAM/tmpfs) - but then I am not sure what happens... Do you need to have a specific init script... bit confused as how exactly initramfs work - if you have any good links or want to layout an answer I'll happily mark them up :) – code_fodder Oct 4 '18 at 6:52
  • Are you just needing to do maintenance on your system (partition,format)? If yes boot to a live distro (via USB). If you want to create a custom 'distro', that will consist of building a kernel from source and using something like busybox for a simple init. Buildroot for a custom 'distro' that is more advanced. What boot loader are you using? uboot? uboot contains tools to partition and format too. I said all that to ask: What is your ultimate goal? What do you need to accomplish? – jc__ Oct 4 '18 at 13:54
0

Run find /proc/$$ -type l -ls in the shell that's holding the FS open. For each one of those links that points to that FS, take appropriate action:

  • In the fd subdirectory: run exec n>replacement, where n is the file descriptor number and replacement is the file it should point at, or &- to close that descriptor.
  • As exe or in the map_files subdirectory: run exec /bin/sh, replacing /bin/sh with the path to any shell you want in your tmpfs root.
  • As cwd: cd to some other directory.
  • As root: go to the tmpfs root, and chroot ..
  • hm... sorry, I really don't get what this is trying to do + did not work : ( – code_fodder Oct 4 '18 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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