unbrick/re-flash from command line

147 views
Skip to first unread message

Tomáš Klouda

unread,
May 26, 2022, 4:04:46 AM5/26/22
to Alt-F
I am trying to find a way how to re-flash my DNS-320-A1 from command line and preferably backup settings first.

I am not sure how this happened, but I did 'cd /mnt/SOME_PATH/' and than 'rm -rf $OF/' as I wanted to delete everything in the '$OF' folder (created by windows file history) and it started spitting errors about being unable to remove files from root '/' !!! 😱
Seems like Linux is unable to handle folder name with '$' in name and it somehow evaluated '$OF/' as '/' . Most probably it thought '$OF' is a variable, which it haven't found.

So I am still logged in to ssh, but apparently can't even open new ssh connections as some parts of the root filesystem were erased. 

Samba still works though, so I have uploaded the firmware binary there, but I don't know how to flash it to fix the box.
Any advice?

João Cardoso

unread,
May 26, 2022, 1:21:51 PM5/26/22
to Alt-F
You don't need to reflash, just reboot. You have probably removed files from the Alt-F folder, where packages are installed, not the linux kernel or the root filesystem; you can't easily change those using 'rm'.
You don't say if the webui is still working. Is it? You don't say what your box model is nor...
Before doing the reboot you want to disable the Alt-F folder, or the problem will reappear after reboot. You can do that using the webUI, Packages->Alt-F, check "Boot Disable". Alternatively, from the command line "touch /mnt/where-the-alt-f-folder-is/Alt-F/NOAUFS". If you don't know where the Alt-F folder is, try using the command "aufs.sh -l" and you can see where it is. In my case, on a DNS-323:

aufs on / type aufs (rw,relatime,si=b0335380)
/mnt/sda3/Alt-F=rw
/rootmnt/rw=rw
/rootmnt/ro=rr

To be sure, you can reboot without disks, just to be certain that Alt-F is still working and you don't need reflash.

In the future to manipulate folders, use the webUI, Setup->Folders


Tomáš Klouda

unread,
May 26, 2022, 2:18:49 PM5/26/22
to Alt-F
Thanks for fast response!

I forgot you are using aufs on root, that might save me.

Trouble is, that the UI is not working as well, that's why I am asking for CLI way. 
My box is DNS-320-A1.

Mount is saying this:
tmpfs on /rootmnt type tmpfs (rw,relatime)
/dev/root on /rootmnt/ro type squashfs (ro,relatime)
aufs on / type aufs (rw,relatime,si=bfea8d2a)
...

No mention about Alt-F mount on any of my /dev/sdx disks though.
I have tried to find it, but that shell script was probably deleted as well:
```
 aufs.sh -l
-sh: aufs.sh: not found
```
Then I realized it must be on my first drive and found it, so I created that NOAUFS there.

Do I understand it correctly, that the flash in the box is used in read-only mode by OS, so when I remove disks it will boot clean system?
So the only thing I really could have damaged by rm are data on my disks (which includes additional packages installed by me)?
But settings are written in the flash, right?

Sorry for so many questions ;-)
Dne čtvrtek 26. května 2022 v 19:21:51 UTC+2 uživatel João Cardoso napsal:

João Cardoso

unread,
May 26, 2022, 8:56:43 PM5/26/22
to Alt-F
On Thursday, May 26, 2022 at 7:18:49 PM UTC+1 klou...@gmail.com wrote:
Thanks for fast response!

I forgot you are using aufs on root, that might save me.

Trouble is, that the UI is not working as well, that's why I am asking for CLI way. 
My box is DNS-320-A1.

Mount is saying this:
tmpfs on /rootmnt type tmpfs (rw,relatime)
/dev/root on /rootmnt/ro type squashfs (ro,relatime)
aufs on / type aufs (rw,relatime,si=bfea8d2a)
...

No mention about Alt-F mount on any of my /dev/sdx disks though.
I have tried to find it, but that shell script was probably deleted as well:
```
 aufs.sh -l
-sh: aufs.sh: not found
```
Then I realized it must be on my first drive and found it, so I created that NOAUFS there.

Do I understand it correctly, that the flash in the box is used in read-only mode by OS, so when I remove disks it will boot clean system?

Yes.
Any modifications will be made to memory or to the Alt-F folder, if it is aufs mounted. The presence of the NOAUFS file under the Alt-F folder avoids the aufs mounting, so it behaves as like booting without disks

 
So the only thing I really could have damaged by rm are data on my disks (which includes additional packages installed by me)?

Yes. Your data is under /mnt/<device or label> :-(
 
But settings are written in the flash, right?

yes, but... when the Alt-F folder is aufs mounted, any files on it will take precedence. Notice the following code comments in 'loadsave_settings':

# Copy current box settings to /Alt-F dir.
# Used after mounting Alt-F dir but before adding it to the union.
to_AltF() {
...
# Copy current box settings in /Alt-F to RAM root dir
# Used after removing Alt-F from the union but before unmounting it
from_AltF() {
 

Sorry for so many questions ;-)

That's OK.

> Seems like Linux is unable to handle folder name with '$' in name and it somehow evaluated '$OF/' as '/' . Most probably it thought '$OF' is a variable, which it haven't found.

That is the expected behaviour. In unix shells, the '$' is used to expand variables. so you are right, if variable 'OF' does not exists or is empty, 'rm $OF/' becomes 'rm /'. It is possible to use '$', if carefully quoted or escaped.

João Cardoso

unread,
May 26, 2022, 9:03:13 PM5/26/22
to Alt-F
ah, and to reboot or power off from the command line, use the 'reboot' or 'poweroff' commands. They will unmount fs, stop raids, etc. But as the commands they might have been damaged, use 'umount' first for sure. if some umount fails, stop (or kill) all services and retry ('rcall stop', if not deleted, will do that)

Tomáš Klouda

unread,
May 27, 2022, 8:02:56 AM5/27/22
to Alt-F
So, I was able to start it with the NOAUFS file, but I don't know how to continue now.
I tried to activate Alf-F, which immediately rendered the system broken so I had to remove the disk with Alf-F to be able to boot again.
And connecting the disk into a running system also immediately render it broken as it seems to automount it immediately.

My assumption is, that unless I delete the Alt-F folder I can't fix it. Or is there a manual way to trigger reinstall of Alt-F into the current location?

Dne pátek 27. května 2022 v 3:03:13 UTC+2 uživatel João Cardoso napsal:
Reply all
Reply to author
Forward
0 new messages