Category: Linux

Linux Blog Archives, by Peter Whyte (SQL Database Administrator). Includes random Linux posts, and Windows Subsystem for Linux (WSL).

  • Introducing DBASco: SQL Server Database Admin Blog

    Introducing DBASco: SQL Server Database Admin Blog

    Greetings Tech People!

    If you’ve been following my technical journey on peter-whyte.com, I’m excited to share a new platform that dives into the world of Database Reliability Engineering and beyond – welcome to DBASco.com!

    At DBASco.com, I share my latest technical writings, focusing on a spectrum of topics catering to IT enthusiasts, database/system administrators, and those passionate about the software behind reliability engineering. The primary categories align with the ones you’re familiar with at peter-whyte.com, ensuring a seamless transition for any dedicated readers.

    This site here is now my secondary tech blog site. If you’ve been on here before you will have seen a lot of display ads, which are disabled for the time being. I was using Ezioc, and I was earning around $50-60 per month, until I neglected things for too long during 2023 and there was a drop in earnings. The site certificate had issues during 2023 Q4, and we are back fully operational as of this week.

    My enjoyment is the technical writing, refining, and seeing where tests lead me, exploring my passion for the things I do as a career and on the side. I hope you enjoy what I write, and it serves a purpose if visiting via Online Search to understand a concept or resolve an issue.

    SSMS Logo

    DBASco Blog Categories

    DBASco: SQL Server: Explore Microsoft SQL Server with in-depth insights into queries, optimization techniques, and best practices. Uncover the holistic experience, including the realm of Windows Administration that intertwines seamlessly with the life of a SQL Server DBA.

    DBASco: PowerShell: Dive into the enchanting world of PowerShell scripting with hands-on guides, expert tips, and powerful tricks. Unearth the magic of automation as you streamline your workflow with carefully crafted scripts and comprehensive guides.

    DBASco: WSL and Linux: Journey into the world of Windows Subsystem for Linux (WSL) and Linux, discovering the synergy between these platforms and unraveling the potential for seamless integration. Benefit from real-world experiences and extensive testing, providing you with valuable insights into cross-OS platform development.

    DBASco: Other: From RDMS’s like MySQL, Postgres, Redshift to semi-related technologies like AWS, and even technical guides on WordPress and website management – expect a wealth of knowledge that keeps you at the forefront of the ever-evolving tech landscape.

    SSMS Logo

    DBASco Latest Articles

    RedShift: Script to Show Running Queries
    Published on January 24, 2024
    Uncover the power of Amazon Redshift, a cloud-based data warehousing giant. Learn how to efficiently manage and analyze extensive datasets with a detailed script to reveal running queries.

    RedShift: Creating a User and Promoting to Superuser
    Published on January 24, 2024
    Unlock the secrets of Amazon RedShift as we guide you through creating a user and elevating their privileges to superuser status. Essential insights for effective cluster management.

    PowerShell Script: List Files with Sizes and Dates
    Published on January 23, 2024
    Master a practical PowerShell script that simplifies listing files in a directory. Dive into efficient file management with sizes and dates at your fingertips.

    Backing Up a Database in SQL Server Using Command
    Published on January 22, 2024
    Ensure the safety and integrity of your data with a comprehensive guide on backing up a database in SQL Server using command-line tools. A crucial aspect of database management unveiled.

    SQL Server Script: Get Last Backup Dates
    Published on January 22, 2024
    Stay informed about the last backup times, a critical element in maintaining data integrity. Enhance your SQL Server skills with a script that simplifies tracking backup dates.

    PowerShell: Counting Files, Words and Rows
    Published on January 22, 2024
    Embark on a PowerShell journey with a script that counts files, words, and rows. Discover the power of PowerShell for efficient data processing and analysis.

    Adding a Filegroup in SQL Server
    Published on January 21, 2024
    Learn the process of adding a new filegroup to a database in SQL Server. Elevate your database architecture skills with a step-by-step guide.

  • Git Log Author

    Git Log Author

    If you’re a Git user, you’re likely familiar with the git log command, which allows you to view the commit history for a repository. This blog post is an extra tip on the git log command, showing the --author option parameter which allows you to filter the commits displayed by the author’s name.

    This can be particularly useful if you are working on a large project with multiple contributors and want to see only the commits made by a specific person.

    Show Commits by Author in Git

    To use the –author option, simply pass the name of the author as an argument when running the git log command.

    For example, if you only want to see the commits made by “pete”, you would run the following command:

    git log --author="pete"
    

    Hit ‘q‘ to exit out of the git log return feed.

    We can also use the git one-line parameter while searching commits for an author, with a wildcard:

    git log --author="Sukki*" --oneline
    

    This will display a list of commits, each on a single line, with the author, commit message, and SHA hash of the commit.

    The git log command has options that allow you to tailor the information it displays. For example, you can use the –oneline parameter, which I covered in another blog post (including git log formatting).

  • Git Log Command

    Git Log Command

    Git log is an essential command for working with Git. It allows you to see the history of a repository, including details about each commit like the author, date, and commit message.

    Using the git log command is simple. Just navigate to your Git repository in a terminal or command prompt and run the git log command. This will display a list of all the commits in your repository, starting with the most recent.

    $ git log
    commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
    Author: John Doe <john.doe@example.com>
    Date:   Tue Dec 1 13:45:26 2020 -0500
    
        Add new feature X
    
    commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
    Author: Jane Smith <jane.smith@example.com>
    Date:   Mon Nov 30 12:15:43 2020 -0500
    
        Fix bug Y
    

    The git log command offers several options that allow you to tailor the information it displays. For instance, you can use the –oneline parameter, which I covered in another blog post (including git log formatting).

  • How to Install PowerShell on Ubuntu 20.04

    How to Install PowerShell on Ubuntu 20.04

    This post is a guide on installing PowerShell on Ubuntu 20.04.

    The Ubuntu Linux distribution being used in this demo is running as a Windows Subsystem for Linux (WSL) instance. I have not yet encountered issues with the PowerShell, Ubuntu and WSL cocktail.

    Be sure to check out Microsoft Documentation, Installing PowerShell on Linux (Ubuntu) for up-to-date information, particularly for PS Linux version compatibility and end-of-support dates.

    The following is covered in this demo:
    # Install PowerShell on Ubuntu
    # Open PowerShell on Ubuntu

    Install PowerShell on Ubuntu

    As mentioned above, I’m installing PowerShell on Ubuntu WSL for this demo. Why would you want to emulate Linux on Windows to then install PowerShell? Because it’s a great cross-platform programming language? The reason I’m performing this on WSL is that the Windows Subsystem is great for spinning up a test Ubuntu instance.

    To install PowerShell on Ubuntu 20.04, run through the Linux commands below. This is as described in the Install via Package Repository Microsoft documentation page, be sure to check that out for any updated information.

    # Update the list of packages
    sudo apt-get update
    
    # Install pre-requisite packages.
    sudo apt-get install -y wget apt-transport-https software-properties-common
    
    # Download the Microsoft repository GPG keys
    wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
    
    # Register the Microsoft repository GPG keys
    sudo dpkg -i packages-microsoft-prod.deb
    
    # Update the list of packages after we added packages.microsoft.com
    sudo apt-get update
    
    # Install PowerShell on Ubuntu
    sudo apt-get install -y powershell
    Ubuntu Install PowerShell

    The above PowerShell installation should only take a minute or so to complete, including the Advanced Package Tool (apt) updates.

    Open PowerShell on Ubuntu

    Now that we have PowerShell installed on this Ubuntu WSL instance, we can check the running PowerShell version and open PowerShell in Ubuntu.

    The default Alias for PowerShell is pwsh. You can find information about pwsh and pwsh parameters within the MS Docs as linked.

    # Check PowerShell Version on Ubuntu
    pwsh -v
    
    # Start PowerShell on Ubuntu
    pwsh
    
    Run PowerShell Ubuntu

    The above shows the running PowerShell version of 7.2.7, and we are entering PowerShell using the pwsh command.

    We can also run $PSVersionTable while in pwsh to check the PowerShell version in Ubuntu, which will show more OS and system information.

    Get PowerShell Version Ubuntu

    I hope this has been a helpful informational guide on installing PowerShell on Ubuntu. If you are interested in running Ubuntu on Windows, check out my other post – How To Install Windows Subsystem for Linux (WSL).

  • How to Reboot WSL (Windows Subsystem for Linux)

    How to Reboot WSL (Windows Subsystem for Linux)

    To reboot WSL, run wsl --shutdown to stop WSL distros then enter back into WSL as you normally would to start it back up again.

    This post is a guide to help explain the process of how to reboot a Windows Subsystem for Linux (WSL) distribution on your local machine.

    A WSL reboot might be needed if your WSL instance or app within Linux has thrown an error message, or you are changing the .wslconfig file/memory limits as described in MS Docs – Advanced settings configuration in WSL

    In my demo below, I’m showing 2 methods for restarting installed WSL Linux distributions. The first option, running WSL commands is the most up-to-date method for restarting WSL distros:
    # Restart with WSL –Shutdown Command (Preferred approach)
    # Restart LxssManager Service via PowerShell

    Restart WSL with WSL –Shutdown

    We need to run a basic WSL command to shut down the Linux distro. First, I will list installed WSL distributions followed by the wsl --shutdown command. This will stop WSL distros running which we can verify with another list command run.

    # check wsl distros & status
    wsl -l -v
    
    # shutdown the running wsl host
    wsl --shutdown
    
    # check wsl distros & status
    wsl -l -v
    wsl --shutdown

    The shut-down command above immediately terminates all running distributions. When we list our WSL distributions again for the second time, we see they are all ‘Stopped’.

    To start up your WSL distribution, enter WSL as you would normally. That’ll be done by re-opening the Linux tab in Windows Terminal, or by running wsl to enter a new WSL session (as per your set default WSL distribution).

    WSL Ubuntu

    Restart LxssManager Service Using PowerShell

    We need to Run PowerShell as Administrator (or Windows Terminal as Admin) for this.

    From what I believe, the wsl --shutdown command was released later, and this LxssManager service restart is the old method. Either way, you’re probably getting what you need in the end, a disruptive stop of your WSL distros.

    Run the following command in PowerShell as Admin to restart your local LxssManager service:-

    # restart LxssManager service
    Get-Service LxssManager | Restart-Service
    WSL Restart LsxxManager

    The LsxxManager service restart has stopped the Ubuntu-20.04 distro I opened above in this post.


    Other notes: We are unable to reboot from within WSL due to the lack of systemd. There are some open-source projects in the works to enable systemd or even add a GUI to manage local WSL distributions. I hope to explore it at some point in the future.

    That’s all for this one. Feel free to check out my WSL Tagged blog posts for more random tips on administering WSL, or have a look at the following posts to help get more familiar with WSL:
    # How to Install Windows Subsystem for Linux (WSL)
    # How to Upgrade WSL from Version 1 to Version 2
    # How to Change Default Linux Distro in WSL
    # How to Check WSL Versions

  • How to Restart WSL (Windows Subsystem for Linux)

    How to Restart WSL (Windows Subsystem for Linux)

    This is a guide on how to restart a Windows Subsystem for Linux (WSL) distribution on your local machine.

    This might be needed if your WSL instance or app within has thrown an error message, or you are changing the .wslconfig file/memory limits as described in MS Docs.

    In my demo below, I’m showing 2 methods for restarting WSL distributions –

    # (Preferred approach) WSL –Shutdown
    # Restart LxssManager Service via PowerShell


    Restart WSL with WSL –Shutdown

    We need to run a basic wsl command to shut down the distro. First, I’m listing my installed WSL distributions followed by the ‘wsl –shutdown‘ command.

    # check wsl distros & status
    wsl -l -v
    
    # shutdown the running wsl host
    wsl --shutdown
    
    # check wsl distros & status
    wsl -l -v
    wsl shutdown

    The shut-down command above immediately terminates all running distributions. When we list our WSL distributions again for the second time, we see they are all ‘Stopped’.

    To start up your WSL distribution, enter WSL as you would normally. This’ll be done by re-opening Linux tab in Windows Terminal, or by running ‘wsl‘ to enter a new WSL session (as per your set default distribution).

    wsl ubuntu 20.04

    Restart LxssManager Service Using PowerShell

    We need to Run PowerShell as Administrator (or Windows Terminal) for this.

    From what I believe, the wsl –shutdown command was released later, and this LxssManager service restart is the old method. Either way, you’re probably getting what you need in the end, a disruptive stop of your WSL distros.

    Run the following command in PowerShell as Admin to restart your local LxssManager service –

    # restart LxssManager service
    Get-Service LxssManager | Restart-Service

    The LsxxManager service restart has stopped the Ubuntu-20.04 distro I opened above in this post.


    Other notes: We are unable to restart from within WSL due to the lack of systemd. There are some open-source projects in the works to enable systemd or even add a GUI to manage local WSL distributions. I hope to explore it at some point in the future.

    That’s all for now – have a look at the other WSL Tagged posts here if of interest!

  • How to Upgrade WSL from Version 1 to Version 2

    How to Upgrade WSL from Version 1 to Version 2

    This is a post on how to upgrade to WSL 2. The demo below will explain the process of upgrading an installed Windows Subsystem for Linux distribution from running WSL version 1 to WSL version 2.

    WSL has two versions, the latest (WSL 2), and the original version (WSL 1). You can have many different Linux Distributions installed on your machine, and you can easily change the WSL version of one of them.

    My other post, How to Check Installed WSL Versions, will help explain the key and why you might want to perform a WSL upgrade for particular development needs. If you are not going to be using advanced WSL features, then upgrading to WSL 2 is likely a good option for you.

    This is a guide to help upgrade WSL version 2 to WSL version 1. If you are looking to go the other way and downgrade from WSL v2 to WSL v1, see my other post -> How to Downgrade from WSL Version 2 to WSL Version 1

    How to Upgrade from WSL V1 to V2

    To upgrade a WSL distribution from WSL version 1 to version 2, run wsl <distro-name> --set-version 2. You can get the Linux distribution by running wsl -l- v.

    The WSL commands required for this are shared in the example below:

    # check wsl distro versions
    wsl -l -v
    
    # change wsl distro using name above to desired version
    wsl --set-version Debian 2
    WSL Upgrade

    The screenshot above shows us listing the installed WSL distros and setting the WSL version for the Debian instance from WSL 1 to WSL2.

    The WSL Linux distro will be updated immediately to WSL v2.

    To downgrade back to version 1, it’s as simple as changing the number from a 2 to a 1 in the command. As mentioned above in this guide, the following posts may also help provide more info on this:
    How to Check Installed WSL Versions
    How to Downgrade from WSL Version 2 to WSL Version 1

  • How to Downgrade from WSL Version 2 to WSL Version 1

    How to Downgrade from WSL Version 2 to WSL Version 1

    This is a post on how to downgrade from WSL version 2 to WSL 1. The demo below will explain the process of downgrading an installed Windows Subsystem for Linux (WSL) distribution, from WSL2 to WSL1.

    WSL has two versions, the latest WSL v2, and the original version WSL v1. You can have many different Linux distributions installed on your machine, and it’s easy to change the WSL version for one of them.

    My other post, How to Check Installed WSL Versions, will help explain the key and why you might want to perform a WSL upgrade for particular development needs. If you are not going to be using advanced WSL features, then having WSL running on version 2 will be the preferred option.

    If you wish to upgrade WSL from version 1 to version 2, instead of downgrading as we are doing in this post, then see my other post – How to Upgrade WSL from Version 1 to Version 2

    How to Downgrade from WSL 2 to WSL 1

    To downgrade a Windows Subsystem for Linux distribution from WSL 2 to WSL 1, run wsl <distro-name> --set-version 2. You can get the Linux distribution by running wsl -l- v.

    The first command below will check the version of WSL and the following command will set and update the new WSL version.

    # check wsl distro versions
    wsl -l -v
    
    # change wsl distro using name above to desired version
    wsl --set-version Debian 1
    WSL Set Version

    The Debian instance as marked in the screenshot above has now been downgraded from WSL2 to WSL1.

    To upgrade back to version 2, it’s as simple as changing the number from a 1 to a 2 in the command.

    For more WSL Tips, check out my WSL Windows page which has a list of all my WSL blog posts.

  • How to Check Linux Version in Ubuntu

    How to Check Linux Version in Ubuntu

    To check the Linux version in Ubuntu, run the lsb_release -a or cat /etc/os-release command. This is useful when accessing a host for the first time or checking the running Linux distribution and version.

    This blog post shows examples of 2 ways to check the Linux version of Ubuntu:
    # Method 1: lsb_release -a
    # Method 2: cat /etc/os-release

    The demo you see here was done on Ubuntu WSL. Note that the hostnamectl command does not work when running Ubuntu on the Windows Subsystem for Linux (WSL).

    Method 1: lsb_release -a

    The lsb_release command is a simple way to check the version of Linux that is running on your system. To use it, open a terminal and run the following command:

    # check linux version on ubuntu
    lsb_release -a
    
    Ubuntu lsb_release

    Method 2: cat /etc/os-release

    Another way to check your Linux version is to display the contents of the /etc/os-release file on your system. To do this, run the following command in your terminal:

    # check linux version on ubuntu
    cat /etc/os-release
    
    Ubuntu /etc/os-release

    To find out more about WSL and Ubuntu, check out my WSL Ubuntu tag. You’ll find random blog posts on using and managing Ubuntu within Windows Subsystem for Linux.

  • How to Open WSL Projects in Windows File Explorer

    How to Open WSL Projects in Windows File Explorer

    This is a guide on how to open WSL files in Windows File Explorer, with added descriptions.

    The best practice for managing project files in WSL is to store your files on the same Operating System as the tools your plan to use. So if the reason you’re using WSL is to develop an app in Linux, then keeping your files in WSL (use Linux root directories, not /mnt/c/Users/etc).

    Also to note, copying files to and from WSL and your local Windows machine can usually be avoided by storing all your WSL application code within source control (e.g. Git / Bitbucket).

    With that said, there are 2 ways to open WSL directories in Windows Explorer.

    The quick way of opening WSL project files in Windows Explorer is to run the following, while in your Linux terminal session –

    # open windows explorer from within wsl
    explorer.exe . 
    WSL Ubuntu

    This opens the directory you are already working in on your Terminal.

    … Now follows, the alternative method of opening WSL project files in Windows Explorer.

    Open Windows Explorer and navigate to \\wsl$\ as shown –

    WSL Windows File Explorer

    The above is showing my only running WSL Linux distribution, even though I have 3 WSL distros installed.

    WSL List Versions

    I’m going to open the Ubuntu 20.04 distro in a new tab in Windows Terminal to start it up –

    WSL Distros

    Now I can see both distributions files in Windows Explorer –

    WSL Windows Files

    From here we can drill into the folders and navigate to any directory –

    WSL Windows Explorer

    For further reading, see this Microsoft Docs link for more info on WSL Best Practises.