Useful SSH Commands For MiSTer?

Kernel, Main, Utilities & Applications, Miscellaneous Devices.
Bits n Stuff
Posts: 2
Joined: Sun May 24, 2020 7:31 pm
Has thanked: 57 times
Been thanked: 1 time

Useful SSH Commands For MiSTer?

Unread post by Bits n Stuff »

Useful SSH Commands For MiSTer?

User avatar
PistolsAtDawn
Posts: 359
Joined: Fri Feb 18, 2022 7:29 pm
Has thanked: 307 times
Been thanked: 100 times

Re: Useful SSH Commands For MiSTer?

Unread post by PistolsAtDawn »

SSH is simply a Secure SHell (almost always through a network, but can be done over other mediums like USB), and that shell in our case is BASH, or the Bourne-Again SHell.

Here is the online manual for it: https://www.gnu.org/software/bash/manua ... tures.html

For those who don't use Linux outside of the MiSTer, I would say that the basics of the shell are good to understand, but the shell is also able to be used in very complicated and powerful ways depending on what it is a user needs to accomplish. Those uses are largely going to be beyond the needs of most of the community.
rafael
Posts: 13
Joined: Sun May 24, 2020 10:11 pm
Has thanked: 26 times
Been thanked: 5 times

Re: Useful SSH Commands For MiSTer?

Unread post by rafael »

I think SSH is quite useful in my opinion. I actually feel lazy most of the time to fetch the keyboard when I need to inspect the contents of the SD card or downloading things directly on my MiSTer while I have it plugged in. So what I end up doing is using a terminal emulator on my phone and connecting to MiSTer via SSH to accomplish this.
Malor
Top Contributor
Posts: 860
Joined: Wed Feb 09, 2022 11:50 pm
Has thanked: 64 times
Been thanked: 195 times

Re: Useful SSH Commands For MiSTer?

Unread post by Malor »

I normally leave an SSH session open to the Mister all the time. I use it to run upgrades or occasionally do housekeeping. That's how I set up my SMB3 share, for instance, by downloading and using the official script, and then setting up symlinks so that there is absolutely no confusion about where files go.

The biggest advantage, IMO, is cut/copy and paste. You can drop to the SSH command line from the main Mister menu by hitting F9, but there's no mouse support turned on in Linux, and thus no ability to mark text for copying. Running from a remote terminal is much more convenient.

There's a bunch of official Mister scripts here:

https://github.com/MiSTer-devel/Scripts_MiSTer

They don't seem to be installed by default anymore. You have to click through to the Raw version for it to be downloadable with wget. For instance, clicking on security_fixes.sh will take you here:

https://github.com/MiSTer-devel/Scripts ... y_fixes.sh

... but that won't work as a link to download. The header that says "437 lines" has a Raw button over on the right. Click that, copy that URL, and prepend wget:

Code: Select all

cd /media/fat/Scripts
wget https://raw.githubusercontent.com/MiSTer-devel/Scripts_MiSTer/master/security_fixes.sh
(Wget downloads into the current dir, so I went to Scripts first.)

There's lots of interesting stuff in that repository. The "make_linux_nice" script also needs a bunch of extra files in the "nice-linux" directory, so you'll need to create a local nice-linux directory in Scripts, and download all the files for that script to work. There's probably an easy way to grab all of them at once, but I didn't bother figuring that out.

edit: be careful with the mac_address_change.sh script. It erases any existing u-boot.txt settings, like fast USB polling, by clobbering /media/fat/linux/u-boot.txt.

This is the bad line in question:

Code: Select all

echo "ethaddr=${MAC_ADDRESS^^}" > /media/fat/linux/u-boot.txt
It should be changed to:

Code: Select all

echo "ethaddr=${MAC_ADDRESS^^}" >> /media/fat/linux/u-boot.txt
That's changing from one > to two >>, meaning to append, instead of overwrite.
User avatar
ragnar
Posts: 27
Joined: Thu May 28, 2020 10:16 am
Been thanked: 10 times

Re: Useful SSH Commands For MiSTer?

Unread post by ragnar »

i use scp quite often. it copies files/folders via ssh. For example:

For a single file
scp file_to_copy user@192.168.178.123:/media/fat/location/

for a folder
scp -r folder_to_copy user@192.168.178.123:/media/fat/location/
• FireBee • Falcon030/040/060 • MiSTer • TT • (Mega)STe • Suska III-B • Suska III-C • (Mega)ST •
User avatar
ragnar
Posts: 27
Joined: Thu May 28, 2020 10:16 am
Been thanked: 10 times

Re: Useful SSH Commands For MiSTer?

Unread post by ragnar »

Bits n Stuff wrote: Sun Jul 24, 2022 4:11 pm ssh root@xxx.xxx.x.xxx
cd /media/fat/Scripts; ./update_all.sh
No need to ssh into the box at all, just execute the script via ssh. For example:

ssh root@xxx.xxx.x.xxx "bash /media/fat/Scripts/update_all.sh"
• FireBee • Falcon030/040/060 • MiSTer • TT • (Mega)STe • Suska III-B • Suska III-C • (Mega)ST •
User avatar
pgimeno
Top Contributor
Posts: 710
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: Useful SSH Commands For MiSTer?

Unread post by pgimeno »

Keep in mind that the command line of the MiSTer is a Linux system.

That means you can do many things that can be done with a Linux system. For example, running the converters in my signature (if you first place them in an appropriate directory in the MiSTer where you can invoke them).
User avatar
PistolsAtDawn
Posts: 359
Joined: Fri Feb 18, 2022 7:29 pm
Has thanked: 307 times
Been thanked: 100 times

Re: Useful SSH Commands For MiSTer?

Unread post by PistolsAtDawn »

That message you're getting for gdrive stuff is saying the computer it's running on has too new of a kernel for the script to run properly and that the author hasn't updated it yet for the 5.XX series kernel.
Malor
Top Contributor
Posts: 860
Joined: Wed Feb 09, 2022 11:50 pm
Has thanked: 64 times
Been thanked: 195 times

Re: Useful SSH Commands For MiSTer?

Unread post by Malor »

It's been that way for awhile, and I find it very surprising, because if there's one thing the Linux devs are passionate about, it's never ever breaking userspace programs. And I'm not even sure why a gdrive-sync script would care about the Linux version at all. It should be doing user-level I/O, which pretty much any Linux kernel would support, going way, way back.

I wonder if it's some other binary that got dropped from the distro, and the error message is bad?

edit: it's looking for a binary named 'gdrive', that somehow seems to have been dropped.
User avatar
Newsdee
Top Contributor
Posts: 873
Joined: Mon May 25, 2020 1:07 am
Has thanked: 104 times
Been thanked: 239 times

Re: Useful SSH Commands For MiSTer?

Unread post by Newsdee »

That's a shame, the gdrive script was really useful
User avatar
Natrox
Scripting Wizard
Posts: 36
Joined: Thu Aug 04, 2022 2:05 pm
Has thanked: 8 times
Been thanked: 75 times

Re: Useful SSH Commands For MiSTer?

Unread post by Natrox »

On Google Drive, the binary still downloads just fine on my end. You may have to reinitialize the entire thing by deleting the ".gd" folder and such. Or you can manually wget the binary from here https://github.com/odeke-em/drive/relea ... rive_armv7. You can put this in "/media/fat/linux/" and rename it to "gdrive", chmod +x it and it should work.

There are many useful commands, but it comes down to how comfortable you are with Linux. As a daily driver and also someone experienced with ARM embedded Linux, I love to mess around to add extra functionality.

For example, I have done this:

Code: Select all

mount --bind /media/fat/opt /opt
To be able to install Entware generic armv7 binaries. I don't recommend you do this unless you understand Linux well enough, but installing Entware stuff gives you a package manager (opkg) allowing you to install many standard tools.

I've installed GCC, mosh-server (nice SSH alternative), btrfs-progs, and most importantly, borg.

Borg is a tool to do deduplicated backups. I've made a backup of the whole system including SD (around 100GB total) to my SMB share. After compression and deduplication it only takes up 33GB.

Here's an example of the script I use to incrementally backup the SD:

Code: Select all

cd /media/fat
borg create -s -v -C lz4 -e "_CIFS" -p /media/fat/_CIFS/Borg::$(date +%s) .
I can run this at any time and it will only archive the differential changes, making it very compact unless you completely swap out every ROM.

Next, I want to look into using BTRFS with compression and deduplication for the SD. Considering ROMs have a lot of dead space and repetition (except .chd), there's a lot of extra space you can get out of an SD card. I am not sure if the kernel supports BTRFS, but I already installed the tools. I will have to check later.

Here's a script I'll share that can be used to open a terminal on the MiSTer itself. It goes into "/media/fat/Scripts" and I've named it "open_screen.sh":

Code: Select all

#!/bin/sh
screen -R htty
It's fairly simple but effective, it opens up a new "screen" and sets you up with a prompt. You can run whatever command you'd like and then use "CTRL+A" and then "D" to detach and return to the menu. Once you run the script again, you will return to the prompt you were using. You can use it to run things in the background without the need for SSH.

There is much more you can do with Entware. I've also got git installed, so I can clone new repositories right on the MiSTer itself. I've got "axel" so I can do fast multithreaded downloads - beats "wget" for big stuff. You can install "transmission" to run torrents on the MiSTer (although not super useful if you run a home server). There are also quite a lot of VPN tools which may be useful if you are away from home but want to access ROMs stored in your home network. Hell there is even "apache" and "nginx" so you could run a HTTP server on the MiSTer as an alternative way to work with it (maybe useful if you run an arcade cabinet).

Also, mandatory neofetch:

W4y9wFD.png
W4y9wFD.png (78.28 KiB) Viewed 4579 times
Shuffle7
Posts: 112
Joined: Sun Jan 17, 2021 5:43 pm
Has thanked: 134 times
Been thanked: 7 times

Re: Useful SSH Commands For MiSTer?

Unread post by Shuffle7 »

Very helpful thread. I like the way i can have an open session to my mister. Can I load up games directly from SCP? or is that a stupid question.
Im updating from SCP and dropping files in and out so got that far.
User avatar
Natrox
Scripting Wizard
Posts: 36
Joined: Thu Aug 04, 2022 2:05 pm
Has thanked: 8 times
Been thanked: 75 times

Re: Useful SSH Commands For MiSTer?

Unread post by Natrox »

Shuffle7 wrote: Fri Aug 26, 2022 9:56 pm Very helpful thread. I like the way i can have an open session to my mister. Can I load up games directly from SCP? or is that a stupid question.
Im updating from SCP and dropping files in and out so got that far.
I don't think you can, SCP is purpose-built for linear file transfer whereas games require random access. You can of course SCP to a temporary folder, and set up a script to clear it at boot.

There are two other ways:
- Using Samba, or Windows File Sharing. It's possible to set up shares on either Windows or Linux which can hold your games. Using this, you can mount the share on the MiSTer and stream your games over the network directly. Do keep in mind that access can be a bit slower. I've noticed for instance that running PSX games with "Fast Seek" on causes some stutter now and then, probably because my wifi can't keep up with the seek speed. See "cifs_mount.sh" in the scripts folder.
- Similar to Samba, you can also use NFS if you have a Linux computer that stores your games! Although you can set up NFS on Windows too, I am not familiar with it and I think you need third-party software. The benefit of NFS is that it couples well with SSH, and you have more flexibility in choosing which folder(s) to mount. In terms of performance, it's basically like Samba.

Of course, you can also use an external USB drive - maybe fitted with an SSD. I would recommend building your own by buying an NVMe drive and an enclosure. These things are blazingly fast, although the MiSTer probably won't use its full potential, transferring games onto it is super quick.
held
Posts: 209
Joined: Sun Sep 26, 2021 2:18 pm
Has thanked: 27 times
Been thanked: 32 times

Re: Useful SSH Commands For MiSTer?

Unread post by held »

Natrox wrote: Wed Aug 24, 2022 2:45 am For example, I have done this:

Code: Select all

mount --bind /media/fat/opt /opt
To be able to install Entware generic armv7 binaries. I don't recommend you do this unless you understand Linux well enough, but installing Entware stuff gives you a package manager (opkg) allowing you to install many standard tools.

I've installed GCC, mosh-server (nice SSH alternative), btrfs-progs, and most importantly, borg.
How does one install Entware?
Post Reply