Installing Ubuntu 18.04 for Dual Boot alongside Windows on seperate drives

Alright you’ve had it with Windows and their horrible, data thieving, privacy breaching ways. But you still want to be able to use it because of other reasons. Well you can dual boot – boot into the platform of your choosing with sperate drives, I will be showing you how to do this,

This is going to be a quick guide to installing Ubuntu 18.04 Desktop for Dual Boot on seperate drives

Quick Steps for your Dual Boot Ubuntu 18.04 and Windows Desktop on Seperate Drives

  1. Go to Download Ubuntu and click download Ubuntu desktop
  2. Go through this tutorial to create a bootable USB with windows, it was a bit tricky as some options were different from the screenshots. I went with MSDOS, master boot record.
  3. Make sure you have an empty drive at least 128gb for your ubuntu install.
  4. Plug in the usb and restart your computer. Press F2 or del to get into the bios and ensure you are booting with your usb. Sometimes this will happen automatically.
  5. Install it and make sure to allow third party software, I’ve had issues with not allowing it before.
  6. When it comes to that scary screen about your isntallation options the best thing to do is click manual.
  7. On your empty drive you want to put Ubuntu 18 on, it’ll be called sda or sdb, clear out existing partitions with-. Then add a parition for 300mb and change the type to Boot EFI this is the important part for the dual boot setup. Add another partition with + for the remaining amount of space you have and change the file system to ext4 and the mount point to /
  8. Now continue, set the timezone and everything should be swell.

Trying the Pelican Static Site Generator and Abandoning it

I have a Jekyll site called fixes

I wanted to move away from Ruby and try the language I prefer and saw that pelican was the most popular. I also wanted to move away to improve the way categories are shown and to speed up the site.

Don’t Use Pelican

After trying it out I have come to the conclusion that it is best to avoid it.

The problems I had:

  • When setting up it creates a fab file for you, for the convenience of deploying and running the site locally. Unfortunately it is based off of the old fabric that required python 2. Using fabric > 2 gave errors.
  • It is September 2018, the last release of Pelican was in January 2017. The author is relying on the community to review pull requests and it seems the community is not alive and kicking anymore.
  • The default theme is not what I deem elegant or simple.
  • AWS is used by default to show assets (like the github ribbon), which is slower and less reliable than a locally hosted version in my opinion. I don’t want to be reliant on some external service.
  • It also uses Google fonts for the default font. Yet more bloat and reliance on Google.
  • Themes are in a seperate repo and are complicated to use.
  • I found that 50% of the themes give errors when you are building them
  • All themes require significant customization.
  • Extra stuff is in yet another repo called pelican plugins, which also requires more technical skill and doc reading to make work.
  • None of the themes I tried were light weight and looked descent and required not much effort.

All in all, things have just gotten a bit too complex and complicated. Too much unnecessary shit is included in the standard package and too much necessary stuff requires external repos and customisation.

Things don’t just work, so I am going to look for another solution or stick with Jekyll.

Authenticated Functional Tests with Selenium and Django

In the Test Driven Development Book for Python and Django by Harry Percival called Obey The Testing Goat, there is a chapter about enhancing the functional test base class and adding pre-authentication so you don’t need to login via the login screen with Selenium.

It uses a custom Email Authentication Backend, but I needed to implement this on a standard: django.contrib.auth.backends.ModelBackend.

My First Attempt


    def create_pre_authenticated_session(self, user):
        '''Create an authenticated user quickly'''
        session = SessionStore()
        session[SESSION_KEY] = user.pk
        session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
        session.save()
        # visit domain (404 quickest)
        self.browser.get(self.live_server_url + "/404_no_such_url/")
        self.browser.add_cookie(dict(
            name=settings.SESSION_COOKIE_NAME,
            value=session.session_key,
            path='/',
        ))

I ran my functional test and something weird was happening, the cookie was getting killed right after this method is called an going to any page.

So I compared based on the cookie itself compared to one that existed in firefox developer tools.

The difference was the httpOnly thingy. So I added it…


        self.browser.add_cookie(dict(
            name=settings.SESSION_COOKIE_NAME,
            value=session.session_key,
            path='/',
            secure=False,
            httpOnly=True
        ))

Nothing changed, the cookie was still gone.

So then I compared an existing decoded session with the one created via the method above.

To find the decoded session:

$ python manage.py shell
[...]
In [1]: from django.contrib.sessions.models import Session

# substitute your session id from your browser cookie here
In [2]: session = Session.objects.get(
    session_key="8u0pygdy9blo696g3n4o078ygt6l8y0y"
)

In [3]: print(session.get_decoded())
{'_auth_user_id': 'obeythetestinggoat@gmail.com', '_auth_user_backend':
'accounts.authentication.PasswordlessAuthenticationBackend'}

The Session Difference

I noticed there was a difference a working session looked like this:

{'_auth_user_id': '1', '_auth_user_backend': 'django.contrib.auth.backends.ModelBackend', '_auth_user_hash': '6a34097f6dab2a1fc68f262e9e67186d2ad5ba93'}

whereas the one I created looked like this:

{'_auth_user_id': 1, '_auth_user_backend': 'django.contrib.auth.backends.ModelBackend'}

So the _auth_user_hash was a problem. I search the django source and found it in auth.

So I set the hash session key with: session[HASH_SESSION_KEY] = user.get_session_auth_hash()

It then worked.

The Solution


    def create_pre_authenticated_session(self, user):
        '''Create an authenticated user quickly'''
        session = SessionStore()
        session[SESSION_KEY] = user.pk
        session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
        session[HASH_SESSION_KEY] = user.get_session_auth_hash()
        session.save()
        # visit domain (404 quickest)
        self.browser.get(self.live_server_url + "/404_no_such_url/")
        self.browser.add_cookie(dict(
            name=settings.SESSION_COOKIE_NAME,
            value=session.session_key,
            path='/',
            secure=False,
            httpOnly=True
        ))