Author Archives: Mike

Ubuntu – Change Hostname Permanently Using the Command Line

ubuntu-logo

On Ubuntu the hostname is stored in both the /etc/hosts and /etc/hostname files. There are several ways that we can change the hostname in these files.

1. Manually Edit the hostname

We can manually edit these files using a basic text editor like nano:

sudo nano /etc/hosts
sudo nano /etc/hostname

In /etc/hostname simply overwrite the existing hostname with a new one. In /etc/hosts you will find the hostname on the line beginning 127.0.0.1 – overwrite only the hostname with the new one, and then reboot.

Editing /etc/hosts using nano

Editing /etc/hosts using nano

sudo reboot

2. Use sed to change the hostname

Another way to achieve the same goal is to use the sed command to replace the existing hostname with a new one.

For example, my Ubuntu Server has the default hostname of ‘ubuntu’.

Use the hostname command to check what your hostname is.

With sed we can look for our hostname (in /etc/hosts and /etc/hostname) and then replace it with the desired new-hostname:

sudo sed -i 's/ubuntu/new-hostname/g' /etc/hosts
sudo sed -i 's/ubuntu/new-hostname/g' /etc/hostname

Reboot:

sudo reboot

3. Write a Bash Script

It’s always handy to have a script to do things – so here is a quick bash script that I put together that uses sed to change the hostname and then reboot:

#!/bin/bash
#Assign existing hostname to $hostn
hostn=$(cat /etc/hostname)

#Display existing hostname
echo "Existing hostname is $hostn"

#Ask for new hostname $newhost
echo "Enter new hostname: "
read newhost

#change hostname in /etc/hosts & /etc/hostname
sudo sed -i "s/$hostn/$newhost/g" /etc/hosts
sudo sed -i "s/$hostn/$newhost/g" /etc/hostname

#display new hostname
echo "Your new hostname is $newhost"

#Press a key to reboot
read -s -n 1 -p "Press any key to reboot"
sudo reboot

Ubuntu Server – Apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

ubuntu-server-logo

Restarting the Apache Web Server on Ubuntu Server (12.04 at the time of writing) gives me the following error:

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

To fix this error add ServerName localhost to /etc/apache2/httpd.conf, as follows:

echo 'ServerName localhost' | sudo tee -a /etc/apache2/httpd.conf

Restart Apache to make sure that the issue is resolved:

sudo /etc/init.d/apache2 restart

Ubuntu Server – Unattended Installation (Custom CD)

ubuntu-server-logo

I’ve lost count of the number of times that I have installed Ubuntu Server on my VMware vSphere box – so I finally looked in to performing an unattended install.

I could have setup DHCP and TFTP servers and done PXE boot from images over the network – but I wanted to work on something quicker than that (and I don’t have that much spare RAM on my vSphere box as it is).

So I settled on re-mastering an Ubuntu Server .iso image. The result is an unattended install, except for the initial boot screen (where I need to select a minimal virtual machine installation anyway).

The following steps were performed on Ubuntu Desktop.

Download Ubuntu Server – I am using the 32 bit version of Ubuntu 12.04.

Open a Terminal and create a directory to mount the Ubuntu Server iso to.

sudo mkdir -p /mnt/iso

The -p switch is very useful as it allows you to create a directory structure which does not already exist (as opposed to creating a single directory).

Change directory to Downloads:

cd Downloads

I renamed my download UbuntuServer.iso.

Mount UbuntuServer.iso to /mnt/iso:

sudo mount -o loop UbuntuServer.iso /mnt/iso

Create a directory and copy the mounted Ubuntu Server files:

sudo mkdir -p /opt/serveriso
sudo cp -rT /mnt/iso /opt/serveriso

The -r switch copies directories recursively and -T specifies no (singular) target directory.

Now we have a copy of our Ubuntu .iso to work on in /opt/serveriso – but we need to make these files writable:

sudo chmod -R 777 /opt/serveriso/

With this preparation done we can start customizing things.

If we look at the isolinux/langlist file we see all the supported languages listed that Ubuntu supports (in an abbreviated format):

am
ar
ast
be
bg ...

I am only interested in an English install so I am going to overwrite the contents of isolinux/langlist with the single abbreviation for English, which is “en”.

cd /opt/serveriso
echo en >isolinux/langlist

This stops the language selection menu from appearing during installation.

The next step of the process is to create a kickstart file – this will provide the server install with the answers to the various questions asked during installation, such as timezone, username, password, partition structure and so on.

Install Kickstart Configurator:

sudo apt-get install system-config-kickstart

Click the Dash button and type kickstart and then click on the kickstart application.

kickstart

Obviously you should customize your settings as you see fit – I have provided mine for reference.

Basic Configuration

Basic Configuration: Set Timezone

Installation Method

Installation Method: Choose the CD-ROM installation method

Boot Loader Options

Partition Options: Add an ext4 partition to the root file system that fills all unused space on the disk

Partition Options: Add an ext4 partition to the root file system that fills all unused space on the disk

Partition Options: Add a swap file system that uses the recommended swap size

Partition Options: Add a swap file system that uses the recommended swap size

Network Configuration: Add network device eth0 and set to DHCP

Network Configuration: Add network device eth0 and set to DHCP

User Configuration: Provide username and password

User Configuration: Provide username and password

Click File, Save File and save the kickstart file ks.cfg to /opt/serveriso.

While using the Kickstart Configurator you may have noticed that the Package Selection screen did not work. Fortunately we can manually edit the ks.cfg file so that the packages that we want are installed during Ubuntu Server installation.

At the end of ks.cfg add %packages and then list the packages that you want installed. I chose to install nano, openssh-server and open-vm-tools:

%packages
nano
openssh-server
open-vm-tools --no-install-recommends

–no-install-recommends installs open-vm-tools in headless mode.

Now we need to configure the CD boot command line to use the kickstart ks.cfg file.

Browse to and open /opt/serveriso/isolinux/txt.cfg.

We need to edit the append line of the default install section at the top of the file.

default install

At the end of the append line add ks=cdrom:/ks.cfg. You can remove quiet – and vga=788.

My append line is as follows:

append  file=/cdrom/preseed/ubuntuserver.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg

The final step is to create a new Ubuntu Server .iso using this command:

sudo mkisofs -D -r -V "ATTENDLESS_UBUNTU" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /opt/autoinstall.iso /opt/serveriso

The finished .iso is /opt/autoinstall.iso.

Test your .iso in a virtual machine to make sure that everything works as it should.

The minimal interaction that I need to set my Ubuntu Server install going is documented below:

1. Press the Enter key to confirm the English language selection

Press the Enter key to confirm the English language selection

Press F4, select Install a minimal virtual machine, and then press Enter

Press F4, select Install a minimal virtual machine, and then press Enter

Press Enter to install Ubuntu Server

Press Enter to install Ubuntu Server

From here installation continues without any further input being required.

Sources: http://askubuntu.com/questions/122505/how-do-i-create-completely-unattended-install-for-ubuntu

Windows 8 – How to Refresh and Retain Desktop Applications

Windows 8 Logo

Windows 8 has two new features -  Reset and Refresh. Reset is like a factory restore – it reverts you back to a fresh Windows 8 installation without any user data or applications. Refresh retains user data, settings and Windows Store applications (but not desktop applications).

The reason that refresh does not retain desktop applications is that a refresh point is created when Windows 8 is first installed (before any desktop applications can be installed).

We can however create custom refresh points using the Administrator Command Prompt.

From the desktop press the Windows + X keys together and then select Command Prompt (Admin) from the pop-up menu.

The first thing that we want to do is create a new directory for our custom refresh point:

mkdir C:\CustomRefreshPoint

Use the following command to create a custom refresh point in the directory we just created:

recimg /createimage C:\CustomRefreshPoint

It will take quite a while for this process to complete.

Windows 8 will use the last created custom refresh point during a refresh – unless you tell it otherwise.

If you have created multiple directories that each contain a refresh point you can specify which one should be used during a refresh with the following command:

recimg /setcurrent <directory>

If you have a custom refresh point set and do not want to use it you should use this command:

recimg /deregister <directory>

If you need to check the directory of the current custom refresh point use this command:

recimg /showcurrent

A refresh can be initiated as follows – from the start screen open the charms menu by pressing the Windows + C keys together. Click on the Settings icon and then click Change PC Settings at the bottom right of the screen.

Change PC Settings

On the PC settings window click General and then click Get started under Refresh your PC without affecting your files and then follow the prompts.

Refresh your PC

Windows 8 – Disable or Enable the Lock Screen (Without Group Policy)

Windows 8 Logo

While Windows 8 Pro and Enterprise users can use the local Group Policy editor to enable or disable the Lock Screen, everyone else will need to use the Registry Editor.

From the Start Screen type regedit and then click on the regedit icon displayed.

In the User Account Control window click the Yes button to continue.

Browse to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows and create a new key called Personalization (if it does not already exist).

In the Personalization key create a new DWORD called NoLockScreen and change its value to 1 to disable the Lock Screen. Conversely changing the DWORD to 0 will enable the Lock Screen again.

win8 registry disable lock screen

Windows 8 – Customizing the Lock Screen Applications

Windows 8 Logo

Windows 8 displays notifications on the lock screen for various applications such as Mail, Calendar and Messaging.

Win8 Lock Screen

Windows 8 lock screen showing a notification from the Mail app.

To customize which apps give notifications on the lock screen press the Windows key and I to bring up the settings fly out menu – then click on Change PC Settings.

Win+I - Settings

My current lock screen apps are Messaging, Mail and Calendar.

Win8 Lock Screen Apps

To add an app to the lock screen simply click on an available placeholder (one of the squares with the plus sign) and select an app from the list.

win8 Lock Screen Choose App

To remove an app click on it and then click Don’t show quick status here.

win8 Lock Screen Remove App

A quick-start guide for showing tile and badge updates on the lock screen is available here: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868216.aspx

Windows Server 2012 – Installing Active Directory Domain Services

server 2012 logo

Today I set about installing Windows Server 2012 in a virtual test environment. Further down the road I plan to look at publishing remote applications, but for now let’s begin with installing Active Directory.

This is a basic outline of the post-installation steps that I will follow:

  • Change the machine name
  • Set a static IP address
  • Install Windows Updates
  • Install Active Directory Domain Services
  • Promote server to Domain Controller

1. Change the machine name

From the desktop press Ctrl + X and then click System on the pop-up menu. Under Computer name, domain and workgroup settings click Change Settings.

Serv2012-CompName-ChangeSettings

In the System Properties window click the Change button and then change the Computer name. Click OK to exit.

2. Set a Static IP Address

From the Start Screen click Control Panel and then click Network and Sharing Center and then click the link for your Ethernet connection.

Serv2012-NetworkSharingCenter-Ethernet

In the Ethernet Status window click the Properties button. Scroll down and select Internet Protocol Version 4 (TCP/IPv4) and then click the Properties button.

Set your static IP address, Subnet mask, Default gateway and Preferred DNS server.

Serv2012-IP-DNS-Settings

My settings are provided just so that you have a screenshot. I am using a NAT network provided by VMware Player.

Reboot.

3. Check for Windows Updates

From the Start Screen click Control Panel and then click Windows Update. If necessary turn updates on and then Check for updates and install them.

4. Installing Active Directory Domain Services (ADDS)

From the Server Manager Dashboard click Add roles and features.

Install ADDS 01

Review the Before you begin screen for any actions that are required prior to installing roles, role services or features, and then click Next.

Install ADDS 02

Select Role-based or feature-based installation and then click Next.

Install ADDS 03

Select your server from the server pool and then click Next.

Install ADDS 04

Select Active Directory Domain Services from the list.

Install ADDS 05

Review the role services and features to be installed and click the Add Features button.

Install ADDS 06

You will be returned to the Server Roles page of the Add Roles and Features Wizard, click Next to proceed.

On the Features page of the Wizard the Group Policy Management feature is automatically selected, click Next.

Install ADDS 07

Review the AD DS page and then click Next. If you do not have a DNS server on your network you will be prompted to install DNS later.

Install ADDS 08

The Confirmation page gives the option to Export configuration settings and to Restart the destination server automatically if required. Configure as required and then click Install.

Install ADDS 09

The previously selected roles and features will now be installed. Click Close to exit the wizard.

Install ADDS 10

5. Promote Windows Server 2012 to a Domain Controller

An Alert notification will appear on the Server Manager Dashboard prompting you to Promote this server to a domain controller.

Install ADDS 11

Review the domain deployment options. I will Add a new forest called Pricklytech.local. Click Next.

Install ADDS 12

Select the Forest functional level (FFL) and the Domain functional level (DFL) from the two drop-down menus – they should be set to the highest level that your environment supports (to enable as many AD features as possible). The FFL, for example, can be set to Server 2003, 2008, 2008 R2 or 2012.

Next specify domain controller capabilities. I have Domain Name System (DNS) server selected as I do not yet have a DNS server in this particular test environment. You will also notice that Global Catalog is checked and greyed out – because this is the first domain controller in a new forest.

Type and confirm the Directory Services Restore Mode (DSRM) password. DSRM is  a safe mode boot option that is used to repair / recover Active Directory.

Click Next.

Install ADDS 13

Review the DNS delegation alert. In my environment no action is required – so after closing the alert I clicked Next.

Install ADDS 14

The NetBIOS domain name is supplied – click Next.

Install ADDS 15

The default paths for the AD DS database, log files, and SYSVOL are displayed. Click Next.

Install ADDS 16

Review your selections. You can export a Powershell script to automate additional installations by clicking the View script button. Click Next.

Install ADDS 17

Install ADDS 18

A prerequisite check is run. If All prerequisite checks passed successfully click Install to continue.

Install ADDS 19

Once the server is successfully promoted it was automatically rebooted.

Install ADDS 20

Firefox – Server Not Found Error

Windows 8 Logo

Recently I have been getting random Server Not Found pages in Firefox (v18.02) on my Windows 8 laptop. Clicking the Try again button on this page takes me to the page I want, but this is annoying.

Update: The fix below turned out to be temporary. I had to open a command prompt and enter ipconfig /flushdns to resolve the issue.

The solution for me was to change the proxy setting in Firefox to Auto-detect proxy settings for this network as follows.

  • Click the Firefox button
  • Click Options on the drop-down menu and then click Options on the pop-out menu
  • Click the Advanced button and then click the Network tab
  • Click the Settings button in the Connection section of the window (Configure how Firefox connects to the internet)
  • Click the Auto-detect proxy settings for this network radio button and then click OK to exit the menus.
  • Restart Firefox.

Ubuntu – Ripping Audio CDs to FLAC and MP3 with abcde

ubuntu-logo

I have an aging laptop that with Ubuntu 12.04 (Lucid) installed that I wanted to use to rip my CD collection to FLAC and MP3.

I didn’t want to have to use a GUI and I wanted the process to be as automated as possible – so I settled on the command line tool abcde (A Better CD Encoder).

First I installed all of the software required:

sudo apt-get install abcde cd-discid lame cdparanoia id3 id3v2

Then I made a backup of the abcde configuration file:

cp /etc/abcde.conf /home/myusername

I then copied and pasted a great abcde.conf file that I found online to /etc/abcde.conf:

sudo nano /etc/abcde.conf

This is the abcde.conf that I used:

# -----------------$HOME/.abcde.conf----------------- #
# 
# A sample configuration file to convert music cds to 
#       MP3 format using abcde version 2.3.99.6
# 
#       http://andrews-corner.org/abcde.html
# -------------------------------------------------- #

# Specify the encoder to use for MP3. In this case
# the alternatives are gogo, bladeenc, l3enc, xingmp3enc, mp3enc.
MP3ENCODERSYNTAX=lame 

# Specify the path to the selected encoder. In most cases the encoder
# should be in your $PATH as I illustrate below, otherwise you will 
# need to specify the full path. For example: /usr/bin/lame
LAME=lame

# Specify your required encoding options here. Multiple options can
# be selected as '--preset standard --another-option' etc.
LAMEOPTS='--preset extreme' 

# Output type for MP3.
OUTPUTTYPE="mp3"

# The cd ripping program to use. There are a few choices here: cdda2wav,
# dagrab, cddafs (Mac OS X only) and flac.
CDROMREADERSYNTAX=cdparanoia            

# Give the location of the ripping program and pass any extra options:
CDPARANOIA=cdparanoia  
CDPARANOIAOPTS="--never-skip=40"

# Give the location of the CD identification program:       
CDDISCID=cd-discid            

# Give the base location here for the encoded music files.
OUTPUTDIR="$HOME/music/"               

# Decide here how you want the tracks labelled for a standard 'single-artist',
# multi-track encode and also for a multi-track, 'various-artist' encode:
OUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}'
VAOUTPUTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}'

# Decide here how you want the tracks labelled for a standard 'single-artist',
# single-track encode and also for a single-track 'various-artist' encode.
# (Create a single-track encode with 'abcde -1' from the commandline.)
ONETRACKOUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}'
VAONETRACKOUTPUTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${ALBUMFILE}'

# Put spaces in the filenames instead of the more correct underscores:
mungefilename ()
{
  echo "$@" | sed s,:,-,g | tr / _ | tr -d \'\"\?\[:cntrl:\]
}

# What extra options?
MAXPROCS=2                              # Run a few encoders simultaneously
PADTRACKS=y                             # Makes tracks 01 02 not 1 2
EXTRAVERBOSE=y                          # Useful for debugging
EJECTCD=y                               # Please eject cd when finished :-) 

I found that this configuration work very well for me and I especially liked that it put my FLAC and MP3 files into different folders.

The only issue that I had was that abcde would ask me if I wanted to edit metadata for the CD that I was ripping, requiring user input to continue.

Fortunately I found a setting in my backed-up abcde.conf that lets abcde run in non-interactive mode:

# Define if you want abcde to be non-interactive.
# Keep in mind that there is no way to deactivate it right now in the command
# line, so setting this option makes abcde to be always non-interactive.
#INTERACTIVE=n

So, I simply added the following line to my abcde.conf and then I was set:

INTERACTIVE=n

All I have to do now is simply put a CD in the CD-ROM drive and then open a terminal and type:

abcde

Then when the CD ejects I simply put in the next CD, press the up arrow to bring up the last terminal command (abcde), and then press the Enter key to start the process over again.

Other than that I shared my music folder so that I can copy the FLAC and MP3 files to my desktop for backup.

All in all a great way to back up my CD collection with minimal fuss and interaction!

Sources: Ubuntu Forum

Windows 8 – How to move the Start Screen between monitors

Windows 8 Logo

To move the Windows 8 Start Screen to a different monitor, first open any Windows Store application. Move the mouse to the top middle of the screen and when you see the hand icon click and drag the open application to another screen.

Grabbing the top of a Windows 8 Store Applicationto move it to another monitor.

Grabbing the top of a Windows 8 Store Application to move it to another monitor.

You will now find that the Start Screen and Windows Store applications will open on the other monitor by default.