All posts by markcerv_admin

Virtualbox – Your VM has become “inaccessible

Today, when I tried to boot up my linux virtualbox, I got this error:

C:\home\linux>vagrant up
Bringing machine 'default' up with 'virtualbox' provider... Your VM has become "inaccessible." Unfortunately, this is a critical error with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBox and clear out your inaccessible virtual machines or find a way to fix them.

That doesn’t sound good. A bit of googling around let me to this solution., which I’ll break down into the steps that worked for me.

In my “C:\Users{user}\VirtualBox VMs{vm-id}” folder are two files

  • {vm-id}.vbox-prev
  • {vm-id}.vbox-tmp

Renaming “{vm-id}.vbox-tmp” to “{vm-id}.vbox”

Then try running “vagrant up”

BOOM. It was that easy.

Whose IP address is it?

When looking at logs (web, email, ssh) at you don’t recognize an IP address, what are some easy ways to find out if it’s a “friendly” IP address (someone using Comcast wifi from different locations) versus a hacker from another country.

http://whois.arin.net/ui/ – Look up who owns the bigger netblock

https://search.arin.net/rdap/ – More useful for finding out where in the world that subnet might be

Certbot renewal script

By now you know that your website needs to run over HTTPS. One of the easiest and cheapest ways to do this is by using
https://certbot.eff.org/ which in turn deploys https://letsencrypt.org/ certificates.

Once you have it installed, you’ll want to install a crontab entry that will run the updates 2x per day:

23 3,15 * * * /usr/local/sbin/certbot-renew.sh
#!/bin/sh
#
# Save this file as /usr/local/sbin/certbot-renew.sh
#
UPDATE_FLAG_FILE=/var/lib/letsencrypt/updated

rm -f $UPDATE_FLAG_FILE
/usr/local/bin/certbot-auto renew --post-hook "touch $UPDATE_FLAG_FILE"

if [ $? -gt 0 ]; then
  exit $?
fi

if [ ! -f $UPDATE_FLAG_FILE ]; then
  exit 0
fi


service apache2 status

if [ $? -eq 0 ]; then
  service apache2 reload
  if [ $? -gt 0 ]; then
    >&2 echo failed to reload apache2
    exit 1
  fi
fi

Adding django via pipenv

Pip environments with python and django have evolved over the years, but once constant has remained: virtual environments to run the code and packages in. The latest consensus is to use pipenv to keep things separated. Let’s see how.

First, I’ll assume that you already have python 3.7 installed. If you need help, check out this other post I wrote: https://markcerv.com/2019/03/adding-python-3-7-to-ubuntu-18-x/

Next:

sudo apt install python-pip
sudo pip install pipenv

pipenv --python 3.7 install django

In order to use pipenv, you will need to cd to the directory where you want to put your code, and then:

cd  somename
pipenv --python 3.7 install django django-cors-headers \
         djangorestframework pytz
# a bunch of things will happen, including that a virtualenv
# will get get created like:
# ~/.local/share/virtualenvs/somename-oYSXMPkF

# to actually fire up the environment
pipenv shell

Next, you’ll need to setup a minimum of files to get django going. :

django-admin startproject test2

cd test2

python manage.py migrate     #will setup the needed database stuff
python manage.py createsuperuser    # lets you make a u/p for login

./manage.py  runserver  0.0.0.0:8000

You can now jump over to a browser, and visit http://127.0.0.1:8000/admin/ and sign in to your app. It’s pretty boring right now, but you can fix that.

Adding python 3.7 to ubuntu 18.x

If you quickly want to get the latest version of Python installed on Ubuntu and get future updates automatically, then you can install it from the below third-party PPA repository…

To do that, run the commands below to add the PPA.

First install Ubuntu software properties package if it’s not already installed on your system..

sudo apt update
sudo apt install software-properties-common

After that run the commands to add the PPA..

 sudo add-apt-repository ppa:deadsnakes/ppa 

Finally, run the commands below to install Python 3.7

sudo apt update
sudo apt install python3.7

That’s it!


Brother HL3140CW Printer – Reset ‘out of toner’ message

How to reset the fake “out of toner message” and instantly make the printer work again:

1. Open the top lid of the printer and leave it open.
2. Press and hold the “Secure” and “X Cancel” buttons at the same time.
3. Use the arrow keys to select the cartridge model you would like to reset and press “OK”.
4. Press the UP arrow to reset the cartridge.

Once reset is selected you will see “ACCEPTED” on the screen.

Reset them all by scrolling through the various colors on the menu.

5. Close the top lid. It will make a bunch of noise for a minute or so, then it will print like new again.

Now the printer thinks you installed brand new toner cartridges, and you will get double or more the amount of printed pages from the same old “out” toner. When you notice the quality of the printouts degrading, THEN its time to replace the toner. Not before. While you are waiting for your new toner to arrive, take the old one out and shake it- prints will look new again for a short period of time. Buy toner when you are out, not when the machine tries to tell you what to do.

Creating a password protected zip file

I’ve found that the easiest way to create a password protected zip file, is to use the freely available 7-zip.

C:\7z.exe a test.zip fileyouwantzipped -pPUT_PASS_PHRASE_HERE

7-Zip 18.05 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-04-30

Scanning the drive:
1 file, 13626 bytes (14 KiB)

Creating archive: test.zip

Add new data to archive: 1 file, 13626 bytes (14 KiB)


Files read from disk: 1
Archive size: 11376 bytes (12 KiB)
Everything is Ok

C:\

A pretty easy way to generate passwords/pass phrases is to visit: https://untroubled.org/pwgen/ppgen.cgi and change options as you see fit.

Moving over VirtualBox/Vagrant the easy way

There is a right way to move/copy over a VirtualBox to a new computer/colleague/etc.

Step 1 – Package up the old box

Run a command prompt and switch into the directory that contains the Vagrant box that you want to copy.

NOTE: Make sure that the box has been properly shutdown/powered off from VirtualBox manager.

vagrant  package  --output  project_20XX_XX_xx.box

==> default: Exporting VM...
   (about 10 minutes passed)
==> default: Compressing package to: c:/home/project_20XX_XX_xx.box
   (about 7 more minutes passed)
   (then complete.  Back to c:\

On my ThinkPad X1 Carbon with Intel I7-6600 CPU @2.7 GHz and 16GB ram, it took xyz minutes to create a xxx GB .box file.

Step 2 – Copy the .box file

Next, copy over the c:/home/project_20XX_XX_xx.box to the computer/directory you want it in. You might need

 vagrant  box  add  project  project_20XX_XX_xx.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'project' (v0) for provider:
    box: Unpacking necessary files from: file://c:/home/project_20XX_XX_xx.box
    box: Progress: 100% (Rate: 104M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'project' (v0) for 'virtualbox'!

Next, fire it up

vagrant  init   project
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.


vagrant  up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'jbv2'...
Progress: 90%
==> default: Machine booted and ready!

SSH in and you are good to go.

Moving over VirtualBox/Vagrant the hard way

There is a right way to move/copy over a VirtualBox to a new computer/colleague/etc.

And then there is the hard way.  What is the hard way?  The hard way is when you need to manually copy over .vbx and .box files and edit .xml files. 

Step 1 – Copy files over from the old drive.

Copy over the directory that contains the .vagrant folder. The way I have my environment it’s “c:\home\blah”.  I do by having 2 windows explorer windows open, and dragging and right-clicking on the destination folder, then clicking “Copy here” or “TerraCopy here.”

Take note of the value of c:\home\blah\.vagrant\machines\default\virtualboxes\id

067c8f42-0e93-4825-a02a-8ecf3a6586d3

Next, copy over the c:\Users\YOURNAME\VirtualBox VMs\xxx folder that corresponds/correlates to your Vagrant box.

Then, double click on the .vbox file in the directory you just copied over. This should automatically import it into VirtualBox.

Finally, open up c:\Users\YOURNAME\.VirtualBox\VirtualBox.xml and check that the uuid matches.

      <MachineEntry uuid="{aaaaaaa-bbbb-cccc-dddd-eeeeeeeeee}" src="C:/Users/YOURNAME/VirtualBox VMs/xxx/xxx.vbox"/>
    </MachineRegistry

Fire up your cmd prompt, switch to the c:\home\xxx\ directory and

vagrant up

Celebrate!