Oct 13

Shrink a Raspberry Pi or RetroPie .img On Windows with PiShrink

PiShrink is a bash script that automatically shrink a pi image that will then resize to the max size of the SD card on boot. However, thanks to Windows Subsystem for Linux (WSL), you can now run it on Windows!

Prerequisites

  • Install Linux on Windows with WSL
  • Rasberry Pi / RetroPie backup .img
    • An .img backup of a MicroSD includes all of the unused space and will be the size of the Micro SD Card (ie: a 16GB MicroSD Card will create about a 16GB .img backup). The simplest method for Windows is to use Win32 Disk Manager. Windows cannot read an EXT4, so it should show the Micro SD card as a Boot Drive (with a disk size of about 250MB) and another drive (with no disk size). Make sure you backup the second drive without a size listed in WIn32 Disk Manager, and this will backup the entire Micro SD card.
    • Note: Micro SD cards can vary slightly in size by manufacturer as well as between different models of Micro SD cards. Therefore, there’s no guarantee creating an .img backup of a Micro SD Card will be able to write back to the same size Micro SD card unless it’s the exact same manufacturer/model.
  • PiShrink.sh script
    • PiShrink will shrink an .img backup of Raspberry Pi / Retropie by removing the “unused” space. For example, if you create a backup image a 16GB Micro SD with 7GB of data on it, the original .img will be about 16GB but after running PiShrink, it will be about 7GB. Upon the first boot, the image will resize the max size of the SD card, so if you restore the 7GB image to a 32GB card, it will expand to have a max of 32GB.

Shrink Raspberry Pi / RetroPie .img on Windows with WSL

  1. Move your Raspberry Pi / RetroPie .img to C:\RPI\
    1. Ex: C:\RPI\RetroPie48.img
  2. Download PiShrink.sh and move it to C:\RPI\
  3. Open your WLS Linux Distro (ie: Ubuntu) and run the below commands:
    1. The time to complete will vary based on the size of the image and how much it can shrink. It took about 20min for me to shrink a 120GB image to 22GB.
cd /mnt/c/rpi
sudo ./pishrink.sh retropie48.img
Oct 13

Install Linux on Windows with WSL

Install a Linux distribution using the Windows Subsystem for Linux (WSL), which enables you to use Linux tools on you Windows File System.

Install WSL | Microsoft Learn

Prerequisites

  • Windows 10 version 2004 or higher (Build 19041 or higher)
  • Windows 11

Install WSL Command

From an elevated PowerShell or Command Prompt run the below command and you will need to reboot once complete. The command only works if WSL is not installed (See next section to determine WSL version & installed Linux distros), and by default will install Ubuntu (This can be change by specify -d <distributionname> in the command below).

wsl --install

After you reboot, the Ubuntu install will finish up and prompt you to create a username and password (Does not need to match your Windows username).

List and Install Linux Distributions

See a list of available Linux Distributions available for download through the Microsoft Online Store, run the below from an elevated PowerShell or Windows Command Prompt:

wsl --list --online

See a list of Linux Distributions installed

wsl --list -verbose

Install Linux Distribution

wsl --install -d <Distro>
wsl --install -d Debian

Ways to Run Multiple Linux Distributions with WSL

  1. Install Windows Terminal (Recommended). Open as many tabs or Window panes to quickly switch between multiple Linux Distros or other command lines (PowerShell, Command Prompt, Azure CLI, etc). This can be installed by search Windows Terminal in the Microsoft Store.
  2. Click Windows Start menu and start typing the name of the distro such as Ubuntu
  3. From PowerShell or Windows Command Prompt, you can enter the name of your installed distro such as ubuntu
  4. From PowerShell or Windows Command Prompt, open your default Linux distro by entering wsl.exe
  5. From PowerShell or Windows Command Prompt, you can use the default Linux distro

Access Linux File System from Windows

In the Windows Explorer address bar enter \\wsl$ and you will be able to access a hidden file share for your Linux Distros.

Access Windows File System from Linux

In your Linux Distro, it automatically mounts all of your Windows drives (ex: C:). You can list them by running

ls /mnt
Jul 08

vi Cheatsheet

OVERVIEW

Almost every Linux distribution includes the vi text editor, and it’s usually the only text editor included in minimal installations.  If you’ve never used vi, it can seem really confusing at first and can even be frustrating since you’ll need to use it to configure network settings prior to downloading another text editor such as nano.  If you’re not familiar with vi, it is important to note there is a “command” and “insert” mode. If you’ve never used vi, you’ll probably find it easier at first to enter “insert” mode when modifying a text file, escaping to command mode, and entering the command to save and quit.  Here’s a quick cheat sheet of the commands you’ll need:

Command Definition
i Enters “insert” mode
esc The escape key exits “insert” mode and returns to “command” mode
:wq In command mode this saves the file and quits once you press the enter key
:q! In command mode this quits the file without saving once you press the enter key

EXAMPLE

Open a file to edit with vi

vi /etc/ssh/sshd_config

Once you open the file, you’ll be in command mode by default and you’ll see the line count and character count at the bottom of the file

vi_opened

Now, if you press the ” i “ key you’ll now enter insert mode which is noted at the bottom.  Once in insert mode, you can edit text where the blinking cursor is located just like most other text editors.

vi_insert_mode

Once you’ve finished your modifications, press the Esc key to return to command mode.  In command mode, you’ll see your commands appear at the bottom of the screen when you type them.  Save and quite by pressing the colon key, w key, q key, and press the Enter to execute the commands.

vi_save_quit

Once complete, you’ll see a notification that the file was written.

vi_written

Jul 08

How to Configure Network Settings in CentOS 7

1 – FIND YOUR NETWORK ADAPTER

Once logged in, you’ll want to enable and configure your network adapter.  First, you’ll need to get the name of your network adapter(s) by running the following command:

nmcli d

Below you’ll see my results of running this command.  My results show I have an Ethernet adaptor called ens160 and it’s currently disabled.  Please take note of the name of your network adapter, which may be different.

"nmcli d" Results

2 – CONFIGURE NETWORK ADAPTOR

Once you have the name of your network adapter, you’ll want to enable it and configure it.  We will configure it using the vi text editor.  If you’re not familiar with vi, take a look at:

vi cheat sheet

Use the following command to use vi to configure your network settings.  Note: replace ens160 with the name of your network adapter you noted above)

vi /etc/sysconfig/network-scripts/ifcfg-ens160

The content will look something like this:

TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens160
UUID=7f1aff2d-b154-4436-9497-e3a4dedddcef
DEVICE=ens160
ONBOOT=no

To Configure a DHCP IP

Modify the following lines:

BOOTPROTO=dhcp
ONBOOT=yes

To Configure a Static IP

Modify the following line:

BOOTPROTO=static

Add the following lines and replace them with the static IP settings you need.  Note: DOMAIN is the default DNS Search domain and it’s optional to add that line.

IPADDR=192.168.2.11
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DOMAIN=sigkillit.com

3 – CONFIGURE HOST NAME (Optional)

Optionally, you can use vi to configure the host name and default search domain by running:

vi /etc/hostname

Modify the following line:

HOSTNAME=server.sigkillit.com

4 – RESTART NETWORK SERVICE

To apply your new network settings run the following command to restart the network service

systemctl restart network

 

Jul 08

How to Install CentOS 7 Minimal

1 – INSTALL OPERATING SYSTEM

Select Install CentOS 7 and press Enter

Install CentOS 7

Press Enter to begin the installation

Press the Enter Key to begin the installation process

Select your Language and click Continue

CentOS7_Language

Complete any items marked with the Exclamation icon.  Only the Installation Destination should be marked and will be automatic partitioning by default.  Click Installation Destination

CentOS7_Installation_Summary

By default automatic partitioning is selected.  Review the automatic partitioning and confirm it suits your needs and click Done.  Otherwise, you’ll need to manually complete the partitioning (beyond this tutorial).CentOS7_Installation_Destination

Once all the items marked with the exclamation icon are complete, click Begin InstallationCentOS7_Begin_Installation

CentOS 7 will now begin to install.  Click Root Password to set the password while you wait for the installation to finish.

CentOS7_Root_Password_Is_Not_Set

Enter your Root password twice and click Done.  CentOS will rate the strength of your password and obviously the stronger the better.

CentOS7_Root_Password

Once the installation completes, click Reboot.

CentOS7_Complete

The boot menu will automatically boot CentOS 7

CentOS7_Boot_Menu

2 – LOGIN AS ROOT

Once the OS boots, login using username root and the password you set during the installation.CentOS7_Login

3 – CONFIGURE NETWORK ADAPTER

How to Configure Network Settings in CentOS 7

4 – INSTALL VMWARE TOOLS (Optional)

If this installation of CentOS 7 is a VMWare Guest OS, you may wish to install the VMWare Tools by running the following command:

yum -y install open-vm-tools

5 – INSTALL NANO (Optional)

If you are not a fan of the vi text editor, you may wish to install Nano which has a more natural text editor feel to it by running:

yum -y install nano

6 – INSTALL UPDATES

Install updates by running:

yum -y update

7 – CREATE A SUDOER USER

It’s best practice to not use the root (super-user) user account.  Instead, you should always use a regular user account and allow them root privileges by adding them to the sudoers file.  You can then run privileged commands by use the sudo or su commands.  Let’s first start by creating a user by running the following command (where sigkill is the username):

adduser sigkill

Next, we want to set the password for our user by running the following command and enter the password twice when prompted:

passwd sigkill

Here is an example of the output you’ll receive

Add User

Now that your user is created, you want to add them to the sudoers file.  You can edit the sudoers file with vi by running the following command.  (NOTE: If you’re not familiar with vi, take a look at vi cheat sheet)

vi /etc/sudoers

Near the end of the sudoers file, locate the following lines

## Allow root to run any commands anywhere
root	ALL=(ALL)	ALL

Add the following line directly below the above lines then save and quit (:wq)

sigkill	ALL=(ALL)	ALL

Here is an example of how it should look

Sudoers File

8 – PREVENT REMOTE SSH ACCESS FOR ROOT

By default, SSH is installed and ready to work once you configure a network adapter.  Another best practice is to prevent remote SSH access to the root account.

vi /etc/ssh/sshd_config

Locate the following line

#PermitRootLogin yes

Modify the above line to the following then save and quit the file

PermitRootLogin no

Restart the SSH Service by running the following command

systemctl restart sshd

 

Feb 28

How to Make Fedora 18 a PS3 Media Server

PS3 Media Server is a DLNA-compliant UPnP Media server which supports Playstation 3 and any other DLNA compliant device.  It allows you to stream video, music, images, etc to your DLNA device even if it does not support the codec the media is encoded in.  For a complete list of supported devices please visit http://www.ps3mediaserver.org/about/.

Install RPM Fusion

sudo yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-branched.noarch.rpm

 

Install Software Dependencies

sudo yum -y install mencoder ffmpeg mplayer freeglut java wget

 

Install libzen and libmediainfo (Optional but recommended)

As of this writing, the current version of libzen is v0.4.28 which the below command references. You can check for updates by going to http://mediainfo.sourceforge.net/en/Download/Fedora and modifying the link below accordingly.

sudo yum -y install http://downloads.sourceforge.net/zenlib/libzen0-0.4.28-1.x86_64.Fedora_18.rpm

 

As of this writing, the current version of libmediainfo is v0.7.62 which the below command references. You can check for update by going to http://mediainfo.sourceforge.net/en/Download/Fedora and modifying the command below accordingly.

sudo yum -y install http://mediaarea.net/download/binary/libmediainfo0/0.7.62/libmediainfo0-0.7.62-1.x86_64.Fedora_18.rpm

 

 

Add Firewall Exceptions for PS3 Media Server

sudo firewall-cmd --permanent --add-port=5001/tcp
sudo firewall-cmd --permanent --add-port=5353/udp
sudo firewall-cmd --reload

 

 

Install PS3 Media Server, Make It Executable, and Start Media Server

As of this writing, the current version of PS3 Media Server is 1.72.0, which is used in the below command. You can check for an update by going to http://code.google.com/p/ps3mediaserver/downloads/list and modifying command below accordingly.

wget http://ps3mediaserver.googlecode.com/files/pms-generic-linux-unix-1.72.0.tgz
tar -zxvf pms-generic-linux-unix-1.72.0.tgz
chmod +x pms-1.72.0/PMS.sh
pms-1.72.0/PMS.sh

 

Configure Navigation/Share Settings

By default, PS3 Media Server allows browsing All Drives on your system. For security reasons, you’ll want to modify the Share settings to only access specific folders such as music, pictures, and videos using the following steps:

  1. Click the Navigation/Share Settings Tab
  2. Under the Shared Folders section, click the Add button
    1. Select the folder you want to be accessible (ex: /home/<username>/music/)
  3. Repeat the previous step for each folder you want to be available
  4. Click the Save button
  5. Click the Restart Server button

PMS Navigation/Share Settings

 

Feb 26

How to Remotely Access Linux From Windows

There are many ways to remotely access Linux including VNC, SSH, FreeNX, NXFree, Hamachi, Teamviewer, and the list goes on.  When it comes to remote access a few questions come to mind…  Is it secure, is it GUI or Command Line, how’s the performance, what extra software is required, etc.  If you are connecting to your Fedora 18 install from Windows there’s a great solution called xRDP.  xRDP uses the Windows Remote Desktop protocol to present an X window’s desktop to the user.  The Windows Remote Desktop offers a secure connection to your Linux box, similar to VNC over SSH.  In addition, it does not require any additional software on your Windows machine since the Remote Desktop Client is built in.  If you are running Linux, you can remote into the server using RDesktop (Included in Fedora 18).

Install xRDP

sudo yum install xrdp

Start the xRDP Service and Set It to Start at Boot

systemctl start xrdp.service
systemctl enable xrdp.service

Add RDP Exception to the Firewall

firewall-cmd --add-port=3389/tcp
firewall-cmd --permanent --add-port=3389/tcp

Open the Windows RDP Client and Connect to Linux

WindowsRDPClient xRDPLogin

Customize Desktop Environment for xRDP Session

If you do not want to use the default desktop environment, you can customize it by creating a .Xclients file (X is capital!!!) in your home directory to launch the desktop environment you want and making it executable.  In order to do this, open a terminal and run one of the following commands

Gnome 3

sudo echo "gnome-session" > ~/.Xclients
sudo chmod +x ~/.Xclients
sudo systemctl restart xrdp.service

Gnome Fallback

sudo echo "gnome-fallback" > ~/.Xclients
sudo chmod +x ~/.Xclients
sudo systemctl restart xrdp.service

KDE

sudo echo "startkde" > ~/.Xclients
sudo chmod +x ~/.Xclients
sudo systemctl restart xrdp.service

MATE

sudo echo "mate-session" > ~/.Xclients
sudo chmod +x ~/.Xclients
sudo systemctl restart xrdp.service

Cinnamon

sudo echo "cinnamon" > ~/.Xclients
sudo chmod +x ~/.Xclients
sudo systemctl restart xrdp.service

Xfce4

sudo echo "startxfce4" > ~/.Xclients
sudo chmod +x ~/.Xclients
sudo systemctl restart xrdp.service

 

Feb 26

How to Install Mate, Cinnamon, KDE Plasma, and Xfce on Fedora 18

The Fedora 18 distribution ships using Gnome3 in most circumstances as the default desktop environment. There has been a lot of controversy about the direction Gnome3 has gone, which sparked many spin-off projects. If you are not a fan of Gnome3 or are just looking to try other desktop environments for Fedora, here are the directions you’ll need.  Please note, you need to be root to run the following commands.  You may switch to the root account in the terminal by issuing the ‘su’ command or by using ‘sudo’ in front of the commands below if your account is part of the administrators group.

 

Make Sure Fedora is Up to Date

Open a terminal and run the following command to update Fedora.

yum update

 

Install the MATE Desktop Environment

http://wiki.mate-desktop.org/download

Open a terminal and run the following command to install the MATE Desktop Environment

yum groupinstall "MATE Desktop"

Install the Cinnamon Desktop Environment

http://docs.fedoraproject.org/en-US/Fedora/18/html/Release_Notes/sect-Release_Notes-Changes_for_Desktop.html

Open a terminal and run the following command to install the Cinnamon Desktop Environment

yum groupinstall "Cinnamon Desktop"

Install the KDE Plasma Workspace

http://fedoraproject.org/wiki/KDE

Open a terminal and run the following command to install the KDE Plasma Workspace

yum install @kde-desktop

Install the Xfce Desktop Environment

http://fedoraproject.org/wiki/Xfce

Open a terminal and run the following command to install the Xfce Desktop Environment

yum groupinstall XFCE