Showing posts with label Linux Mint. Show all posts
Showing posts with label Linux Mint. Show all posts

Wednesday, September 21, 2022

Running VNC or Other Program at Startup on Linux Mint 21 or other Linux Using Systemd

Linux Mint Screenshot from their page
Note:  If you are just trying to get "your" program to run on boot as a service in Linux, skip to the instructions at the bottom.  I expect these steps to work on any systemd based machine, and I will continue refining this to work on my own Debian laptops.  For now, it works beautifully on Linux Mint which is derived from Debian via Ubuntu.

...

Between power pops and other instabilities here in South Florida’s own FPL, and their abysmal service, I managed to build a server.  We literally had one power outage and multiple "pops" over the last week and the weather has been gentle recently.

No, really, FPL is the Comcast of electrical services. You need a generator, Battery Backup, filters and so on.  I lost two desktops before learning this and luckily laptops are better suited to take Utility Company Mishaps.

I need the server.  I was given a list of hardware, specifically a desktop server from about 10 years ago.  Acer Aspire Easystore H340.

Immediately I got a cable that terminated on the motherboard and turned my widescreen analog VGA monitor into an older style 1080 by 768 Square by stretching pixels.

Removed all drives and installed a laptop boot drive.

Turned off the Bios for booting from anything but USB Sticks and first hard drive.

I installed Linux Mint 21 Xfce from the ISO.

Since this machine is an appliance, I installed it completely stock – taking the most “normal” choices under install.

When it is installed, turn off all screensavers – my machine would be a headless server.  The password protecting screensaver that "came up" when it timed out as a security measure would crash the machine when you were connected with VNC.  My own machine is in my house, behind a firewall, and only turned on when I need it.  If it had Wake On LAN enabled it would be perfect for the task.  Apparently the original software from the discontinued M$ Windows Home Server product had it so it's a matter of proving it can be used.

The hardest part of headless is getting VNC to work on startup.  I went through a long list of distributions and a long list of software “tricks” to try to get it to work when you sign on it.

The answer is this link - https://community.linuxmint.com/tutorial/view/2334

I will reproduce its text literally from before.  Reason is that forum documentation often will disappear.  I use this blog as a scratch pad so I want this to be here 10 years down the road.

Secondly at time of writing, I could not find a “cookbook” of how to add VNC protocol to the machine except for this one.  The hang up was getting VNC to start as a Service at boot.

Thanks to Linux Mint and their excellent documentation, it works.  Mind you it was written for version 18 and mine is version 21, hence my leaving it here for me to see in the future.  As of today, this original is a 5 year old posting derived from something older.  I want to make sure I have it because it should work with any systemd based linux machine.

As I go onward, I will add the next steps – configuring a /etc/fstab to mount a drive optionally at boot, and the samba configuration.

For now, here is Linux Mint’s documentation on how to make a service start at boot.  I am presenting it literally as of my date of publishing, and I recommend that you find it there. This is really just a note taped to the underside of my keyboard for all to share.




HOWTO: Setup VNC Server (x11vnc) on Linux Mint 18


This tutorial was adapted from here.

1. Remove the default Vino server: (Note, LM 21 did not have vino)

sudo apt-get -y remove vino

2. Install x11vnc:

sudo apt-get -y install x11vnc

3. Create the directory for the password file:

sudo mkdir /etc/x11vnc

4. Create the encrypted password file:

sudo x11vnc --storepasswd /etc/x11vnc/vncpwd

You will be asked to enter and verify the password.  Then press Y to save the password file.

5. Create the systemd service file for the x11vnc service:

sudo xed /lib/systemd/system/x11vnc.service

Copy/Paste this code into the empty file:

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -noxdamage -repeat -rfbauth /etc/x11vnc/vncpwd -rfbport 5900 -shared

[Install]
WantedBy=multi-user.target

6: Reload the services:

sudo systemctl daemon-reload

7. Enable the x11vnc service at boot time:

sudo systemctl enable x11vnc.service

8. Start the service:

Either reboot or

sudo systemctl start x11vnc.service

Wednesday, May 1, 2019

Distro Hopping is pointless because the Answer Is Always Debian

If you have an Axe, and you replace the handle.
Later you replace the blade.
Sharpen the blade again.
Chop the wood for the fireplace this winter.

But... Is it the same Axe?

There are indeed options.  Alternatives, even with computers.  That's what this is all about.

"This" is "Distrohopping".

Think of it as remodeling your computer instead of your bathroom - which is a very small area that results in your emptying your bank account into a small hole in the floor where all your money turns to sh... sewage.

Windows and Mac people don't really understand the concept, but it is more like the ultimate theme.

You see, I actually enjoy tweaking things on my computer.  I have the freedom to tweak away.  Change fonts, colors, even the entire way that the work flow happens on the thing.

I expect everything to just work.  Why not, I've got the tools.  I can change almost everything.

I stopped running Windows when I found out that Microsoft gave themselves the right to watch every little thing that I am doing on my computer.   Since they are not paying me for that right, I dumped Windows.

On the spot.  "F" that spyware.

Not completely sure how Mac fits in that, however I finally got the chance to play around with the Apple operating system and found its rigidity never fit with my innate curiosity.

So here I am on Linux.  Debian Linux to it's friends.  BSD People know what I am talking about when I refer to absolute control, so come close, little cousins, lets laugh at the normies.

I have a spare laptop.  Still quite useable, an i3 with 4 GB soldered in.  That is all it will ever be, and it was bequeathed to me when a friend passed.  So we shall call this machine David as a result, In His Honour.

David doesn't get used too much.  It is the slowest "i" machine I have here, but with the right operating system it will run quite fast enough to be useable.

By the right operating system, I mean a Distribution of Linux.  I did try a version of BSD called Nomad BSD that boots from a stick.  It says that it never touches your hardware, which is intriguing and it does show promise.

Since BSD is even less used than Linux in the home market (Less than 1% vs about 2-3%) it is inherently more secure due to "Security by Obscurity".

But I digress.

I run Debian Linux on my computers.  It is Utterly Stable.  As in that granite counter top that some have will chip before my Debian computer will crash.  Stability comes from the Debian Foundation testing the ever loving daylights out of it.  I got tired of instability along with Windows' snooping, and settled in on Debian.

Stability comes with older, more stable software due to all that testing, but it can be quite old to be on what is called "Debian Stable".  That is a problem for some people who want newer and more cutting edge software, but that is easily solved by installing "Debian Testing".  It's the last (arbitrary last) time Debian moved the "Unstable" version to save it off.

As of this date, Debian Testing is the "Release Candidate" for the next version of Debian.  I am running that every day on two computers.  Still stable, still no problems.

Since Testing is what many other foundations use for their own base to spawn off a software library for their own Distribution, Testing is much more stable than many other distributions efforts.

In fact, the largest distributions, Ubuntu, Linux Mint, and many others are all derived from that.

Ok, enough background.

I wanted a change for David.  Ubuntu just recently went to their newest version called Disco Dingo, and since I still unironically listen to Classic Disco, I chuckled at that name and installed it.

Except it had no way to hibernate David.  David is also a laptop and a mere "suspend" is worthless.  Write the data to disc (or SSD in my case) and turn the thing off so you are not wearing out the batteries.

Ubuntu is the base for Linux Mint.  The hibernate issue is a requirement so any distribution without hibernate is a "Non-Starter" for me.  

Ubuntu?  Fix that.  It works in Debian Stable and Debian Testing.  You being arbitrary because "Some Systems May Crash So We Turned Hibernate Off" is an explanation on the order of having your child paint their younger sibling with Peanut Butter because they liked it.

It Does Not Work Because You Broke It, So Fix It.

That leaves Linux Mint off the table too as well as anything based on Ubuntu or derivatives including the alphabet soup of versions.

If you're counting, this is Ubuntu, Xubuntu, Lubuntu, Linux Mint, plus some other newer distributions like MXLinux and a few others that the names slipped my mind.

Yes, I can install another version of linux on a laptop in 15 to 30 minutes while watching old bad sitcoms at night, and I have, and I got bored with it.

Another thing I require is a fast interface.  I settled on XFCE4 because it looks like the versions of windows, broadly, before they went insane and decided everything should be giant ugly blocks and resemble something like Legos On Acid.  

My usual configuration of XFCE4 looks like Windows 7 once I get through with it, Base fonts are usually something that looks like the London Underground with a font called "Gill Sans".

Helvetica and Arial, as fonts, both look like hell.  A Lower Case Letter L and an Upper Case Letter I should look very distinct.   With Helvetica, it does not.  It irks the daylights out of me, along with the strange spacing between the letters (Kerning) and other very subtle things that some people have grown used to without realizing it.

So after churning through the top ten Debian Derived Distros, I tried CentOS.  It's a Community Based option that is the shared version of the same software that runs on all the servers.  At least all the Linux Based ones that aren't running Debian.

It was what I started with on Linux around 2000, give or take a few years.  I had a Pentium 3 Mobile laptop that I kept on the couch in my house in Philly down in the living room that was still useable in 2013 or so when CentOS dropped all support for that particular version.  Centos 3 I think.  Maybe Centos 4.  I forget.

But, CentOS is not geared towards you - or me.

It's a place to rest my head.  To hang my Skating Helmet I guess.  You see, while it is a Server Operating System, and I could do some serious web development on that little computer, it has a major problem.

The last version of CentOS 7 was announced, and while they have a long term support for it, they do not have an upgrade path for it.

Even Windows 2000 had an upgrade that you could run to get to XP, 7, 8 (ick), 8.1 (UGLY still) and that obscene spyware that is called Windows 10.

So it's a stop gap.  I wanted something different.  I'll continue all that searching later.

The laptop runs well on Centos but it won't stay there.  I'm considering a BSD for it, but not just yet.

The other problem I have with Centos is that it uses a different piece of software to install software called YUM.  They also have a newer package manager, but it also has the same problem that I see and it's called Dependency Hell.

It is what happens when you get a circular reference while installing software.

A game is written.  It needs something to manage the way a sprite works or how it gets information into it.  That is in a library.  It requires a very specific version.  So installing the game requires you install both, Manually. 

By Hand.

But... Debian (any version) does not require that.  The Debian Foundation made very sure that it just works.

Period.

So why fuss with YUM (or DNF) and Dependency Hell.

Especially when Debian has the same software library that everybody else has and I can install what I like on it.

All that just proved what the meme says.  When installing Linux, if you have any questions:

"The Answer Is Always Debian"

Seriously, anything I want for the home, for a server, for a laptop, The Answer Is Always Debian.
  • Server to write web pages?  LAMP using Debian.
  • Wordpress Server?   LAMP with Wordpress using Debian.
  • Graphics Work?  Debian.  In fact, it comes out of the box with Inkscape for vector grapics and GIMP for very fine photoshop work, as well as Krita and others.
  • How about Video Processing?  Debian.  Install Flowblade for Video Editing, Handbrake for Transcoding.
  • Um...Word or Excel and the rest of Office?  Debian.  Libre Office is extremely stable.
  • An old Windows Program?  Debian.  Add WINE and you can run some, but not all, Windows programs once you figure out the configuration.
  • File Server?  Debian, install and configure Samba.
  • Learn Spanish? Watch Video? Listen to the Radio?  Debian.  Doing all that right now.
  • How about DOS?  Debian.  DOS Box works great.
Haven't you got this down yet?  

Actually the exception people always bring up is Windows Games.  Some of them run on WINE, others via Steam.  I don't play those.  Too busy, just check that list above and ... you get the picture - with graphics, labels, and effects added.

I won't go on here.  I have a feeling that little machine, David, will eventually end up with Sid, because Debian Sid is cutting edge, more up to date than Ubuntu or what ever flavor of the month that people are enamored with on this week, and because it is a Debian flavor, it will be more stable than you should expect.

Just be aware when they upgrade software, it could break.  All the names for the different versions of Debian are from the movies Toy Story.  Sid is the neighbor kid that breaks all the toys.  Debian Sid could break your toy (computer) so do a backup before you proceed with an update or an upgrade.

Yes, even Debian Stable should be backed up, and I do it once a week.  After all I do author content, like this blather.

Yes, you should too, even if your preferred "distro" is Windows.
Even you Windows people.

Ick.

So I ended up going full circle.  I started on Centos, went "elsewhere" and put Centos on David.  I will get frustrated with it when I can't play FreeCiv because I can't find some obscure library because YUM (or DNF) is not very tasty.  I'll eventually give in and install Debian Sid, type in sudo apt install freeciv, it will install, it will work because:

The Answer is Always Debian.

So why did I distro hop again?  Because I have the memory sticks and the time to actually "Play with" my computers instead of "Play on" them!

Wednesday, March 9, 2016

Cloning a Hard Drive With Linux

Yeah well calling it Linux means I most likely lost 97% of the market.

Windows people don't realize that there is a painless way to get their windows computer to do some of this stuff - a Live Linux Distribution like Ubuntu.  If you get a live disc working, you can copy this shell into it, then follow the instructions.  It should work.

Mac people may even be able to run this natively.

Maybe.  Depends if PV is Mac Friendly, if not, convert the PV line to a copy of your choice.

A Live Linux can be "burned" to a USB stick or to a DVD and your computer can be booted from that.

And now you know!

But none the less...

What this is basically is my own shell.  I use this to completely back up my computer.  All the drive specifications are found and known, and do not change.

I run fdisk -l as root and use the information in there to edit the shell script to change things as needed.

This assumes that you know what your drive devices are, are willing to edit a shell script to make your own changes as is, then have an external USB hard drive slightly larger than your boot device.  My boot device is /dev/sda and most likely yours is as well.

This assumes that you have a second drive sitting in your chip reader.  If not, you can comment out the line that copies it to the hard drive.

This assumes that you have room enough to do everything.

I am doing this on Debian Linux, however the commands here are so very generic that you should be able to run this on most "full" distributions of Linux.  Debian, Ubuntu, Linux Mint, Centos, Fedora and the like come to mind.

Standard Internet Warranty - I make no warranties and it is at your own risk.  If you lose data, it is on you.  I take zero responsibilities for any miscoding or changing or whether a magic dragon comes out of the skies and takes you onward to valhalla.  Really.  None at all.

I will say that I ran this exact shell this morning and it worked for me.  You WILL have to change the file specifications to fit.   

Finally:
  • My boot drive is a 240gb SSD with about 120gb free.
  • My chip has about 12 gb worth of data on it.
  • Debian thinks that the chip is called "128GB" and it typically comes up in the file manager (thunar) on /media/bill/128 GB/

Prerequisites:

Installed versions of
How it runs:
  • This must be run as Root in Terminal.
  • This will pause after each step with an OK message in the Dialog box.
  • For me, the entire shell runs in about 2 hours on my i7 laptop with a USB 2.0 external hard drive.
First the shell in its entirety in blue:

#! /bin/bash

#backup.sh from www.ramblingmoose.com

dialog --no-lines --title 'Run This As Root' --msgbox 'This shell will backup SDA to SDB\nYou must click OK after each step so watch this.\nYour Disaster Recovery will thank you!' 10 70

dialog --no-lines --sleep 3 --title "update your sources" --prgbox "apt-get -y update" 10 70
dialog --no-lines --sleep 3 --title "update your software" --prgbox "apt-get -y upgrade" 10 70
dialog --no-lines --sleep 3 --title "update your distribution" --prgbox "apt-get -y dist-upgrade" 10 70

arg1="'/media/bill/128 GB'"

dialog --title "copying the chip to the drive" --prgbox "cp -avr $arg1 /home/bill/128GB" 10 70

(pv -n -i 2 /dev/sda > /dev/sdb) 2>&1 | dialog --title "Backup SDA to SDB" --gauge 'Progress...' 7 70

dialog --title 'Message' --msgbox 'Cloning is done, click ok to clean up and end' 5 70

dialog --no-lines --sleep 3 --title "Removing the copy of the chip" --prgbox "rm -r /home/bill/128GB" 10 70 
dialog --no-lines --sleep 3 --title "Synchronize your drives" --prgbox "sync" 10 70
#end backup.sh


To actually use that mess...
  • Copy the entire text and paste it into your favorite text editor.
  • Save the file with a ".sh" extension somewhere you will be able to get to it - in your path.
  • Change the mode to executable - chmod 0770 backup.sh
  • Change the owner to root.  You never want to use this as a regular user - chown root backup.sh
  • Change the group to root.  chgrp root backup.sh
  • Run the shell as root: sudo ./backup.sh

Now, each line in excruciating detail!

---- Run the programs using bash interpreter

#! /bin/bash

---- I'm signing my work here

#backup.sh from www.ramblingmoose.com

---- This puts up a message box

dialog --no-lines --title 'Run This As Root' --msgbox 'This shell will backup SDA to SDB\nYou must click OK after each step so watch this.\nYour Disaster Recovery will thank you!' 10 70
---- The next three steps gets your distribution to date.  Don't want this, comment it out

dialog --no-lines --sleep 3 --title "update your sources" --prgbox "apt-get -y update" 10 70
dialog --no-lines --sleep 3 --title "update your software" --prgbox "apt-get -y upgrade" 10 70
dialog --no-lines --sleep 3 --title "update your distribution" --prgbox "apt-get -y dist-upgrade" 10 70

---- Store the directory that Linux mounts the chip to in "arg1"  If no chip to backup you can comment this.

arg1="'/media/bill/128 GB'"
---- Wrap the actual work of copying the chip out to a dialog box.  The flags "-avr" say copy the whole drive in $arg1 recursively to the destination.  If no chip to copy, comment this line.

dialog --title "copying the chip to the drive" --prgbox "cp -avr $arg1 /home/bill/128GB" 10 70
---- This line does the real work.  Now that you copied your chip out to the hard drive, clone the actual hard drive.  The flags on pv tell it to report to stdout the percentage of work done so that dialog can show a pretty gauge.  Ahh, so pretty!

(pv -n -i 2 /dev/sda > /dev/sdb) 2>&1 | dialog --title "Backup SDA to SDB" --gauge 'Progress...' 7 70
---- Copy is done, it is time to clean up message

dialog --title 'Message' --msgbox 'Cloning is done, click ok to clean up and end' 5 70

---- remove the data that you copied from the chip from the hard drive to be neat. if no chip, comment this out.

dialog --no-lines --sleep 3 --title "Removing the copy of the chip" --prgbox "rm -r /home/bill/128GB" 10 70 

---- Your work is done, make sure you flush your cache by doing a "sync".

dialog --no-lines --sleep 3 --title "Synchronize your drives" --prgbox "sync" 10 70  
#end backup.sh

Wednesday, February 24, 2016

The Netbook Server - How to Actually Share Part Of The Hard Drive

First, you installed Linux to a RaspberryPi or a Netbook, or whatever you had on hand.

Second, you made it so you could look into that machine from anywhere on your network.

If all you wanted was a taste of how to run Linux and have fun with all those free goodies there, you could have stopped.  Now I'm going to show you how to take a part of the hard drive (a folder) and share it out to the network.

Why?

So you can copy your pictures/recipes/important crap somewhere else.
So you can back up your computer across the network.
So you can brag to the co-workers that you have a proper Linux Home Server and sound like you know what you're doing.

Well the deal is that it took me a half hour to do this last night.  I was distracted by what was on the TV so it would have taken less time.

I did this on a RaspberryPi first.

Since my instructions were written there I then repeated the steps on my Netbook running Debian, so the instructions work.  It also works on anything derived from Debian Linux, so that if you have found this article using Linux Mint, Ubuntu, or any of the other derivatives from the Debian Family, you SHOULD be able to get this working with very little fuss.

If you are familiar with Linux and the way things work, you're used to finding instructions that promise to do something, get totally frustrated that the instructions are geeked out, and then realize that while it's working you don't actually understand WHY things are done this way.

I'm going to attempt to do it differently.  This way when I have to look at it later, I can look at my own B.S. here and say "Oh yeah, I remember this".

The information you need:

1) Your sign on name - this will be written assuming you are "bill".  Just change that to your own name from when you created the machine.

2) Your "root" and regular user (bill) Passwords.  

3) The name you gave the computer when you installed Linux.  It could be pi or rudolph or any other name you came up with.  


I will make assumptions and try to explain it all away.  Don't worry, I followed these same steps last night and the server now "serves" files out to the network.  As long as your network has a firewall, your stuff is safe.


---


Get the machine "up to date":

  1. Start your Terminal from the start menu.
  2. su and hit enter - Get "root" by giving it the root password.
  3. apt-get update - pull down all the headers of new stuff since the last time you got on the machine
  4. apt-get upgrade  - actually get all the upgraded software

Answer yes or Y to the prompt asking if you really want to update things, go make yourself something from the kitchen and come back in a bit.  It may take time.  There are always updates.  But if you never make changes to your "Repositories" on Debian or Raspbian, you are safe and free from any nasty viruses.


---


Get the Server Software Installed:

You'll be shocked how little has to be done here.   The server software is called SAMBA.  You know, like the great music from Brazil?   The current name has been made less fun - CIFS.  People tend to say it as "Siffs".

Geeks.

One line gets the software.  In terminal from the last part, as root enter the next line:

apt-get install samba samba-common-bin

---

Configure the Server Software:

You have to roll up your sleeves here.  You are actually going to change a text file, but I'm going to give you the information.  Remember - I am entering it as "bill".  If you are on RaspberryPi, your regular user will most likely be "pi".    Change "bill" to what you need it to be.

Second, a comment starts with a hash tag.  #

1) In terminal where you are signed on as "root", enter the following line to get into the "Nano" editor:

nano /etc/samba/smb.conf  

2) Find the line with "wins support" and change the line to read:

wins support = yes

3) Find "Share Definitions".  You are going to enter in a block of text.  Remember to change the path from "bill" to match your login name.

[Downloads]
    comment = Downloads Directory
    path = /home/bill/Downloads    
    browseable = no    

    writeable = yes
    only guest = no
    create mask = 0770
    directory mask = 0770
    public = no


#browseable limits logins to only see this directory and what is created there.  "yes" shares everything.

4) ctrl+x to exit, type y to save the file, then enter to get yourself back out to the root terminal prompt.

5) add a Samba user to be able to share that directory.  In terminal enter the following:

smbpasswd -a bill

Enter in a password, then enter it in again.  This is the password you will need to have to be able to get at the files from out on the network on another machine.  You will log in as (bill) and (password) from that other machine when you try to get there using File Manager.  Same thing with Mac or Linux.  They all need that password.

Write down your password.  I recommend using the same as your regular user password.  If you made them all the same as the Root password, well that may be easier.  You can also leave it blank, but I do not recommend that.  In fact, forget I mentioned it (or not...).

6) restart the computer

---



At this point, the netbook server is now visible on the network.  It is sharing the default login's "Downloads" directory. 

If you go into File Manager in Windows, you will be able to get to the files that are stored in the netbook's /home/bill/Downloads directory from any other machine on the network as long as you know the default user's login.  It will ask you for user and password.

If you have followed this, you can use the computer's name from when you created it.  I now have two servers "rudolph" for the netbook and the raspberryPi.  If computer names aren't your thing, you can also find them via IP addresses.

But at this point you have a functioning File Server.

You're done.  Next time it's getting this machine to serve out files from an external drive that you plugged in.