Category Archives: Linux

Ubuntu 14 Server – Change hostname

The Scenario

I have copied a virtualised Ubuntu 14.04 LTS server to expand my estate.

The Problem

The server still has the same name of the original server, this needs to be changed.

The Solution

Amend the hostname in the following files:



Then, to apply the changes, you either have to reboot the server or restart the hostname service:

sudo service hostname restart


Disclaimer: provided “AS IS” with no warranties and confer no rights


Debian apt-get update failing to reach internet sources “W: Failed to fetch”

The Scenario

I have a Debian Jessie 8.3 server on the company network that requires updates/patches installing for the first time. The server is configured to use online sources rather than the ISO/DVD.

The Problem

Every time I run “apt-get update” I get source connection errors “W: Failed to fetch…”

The Solution

My problem was the proxy – I had not yet defined the proxy settings the server should use.

  • vi /etc/apt/apt.conf – create this file if needed
  • Type the following (altering for your specific proxy settings of course):


  • Save the file (:wq!) and retry the “apt-get update” command which now worked, i.e the response was similar to “Hit jessie/main Sources..” and “Get:4 jessie/updates/main Sources [189 kB]”

Disclaimer: provided “AS IS” with no warranties and confer no rights

Extend Linux Partition

The Scenario

My Debian (Jessie 8.4) server has a 20GB root partition. It is a guest VM running in a VMware ESXi4.1 cluster.

The Problem

The root partition of the Debian server is only 20GB and the application hosted on this server won’t start as it is reporting the disk is full. There are no files i can delete from the disk so I need to expand it.

The Solution

There are two parts to this solution;

  1. Increase the vmdk file of the VM.
  2. Increase the disk size within the OS itself to utilise all the new disk capacity.

Phase 1: Increase the VM guest disk (.VMDK) file
In the vclient UI right click the VM and select settings then the hard disk you want to expand. Under disk provisioning increase the disk provisioned size to the required size. NB If this option is greyed out it is because there is at least one snapshot of that disk, you will have to delete all snapshots before proceeding).


In my case I increased the disk to 50GB, then click OK to have disk increased.

Phase 2: Backup Data on Disk

Whilst I have never experienced any data loss completing this operation, any disk reconfiguration does present a risk. Have a full data backup and a tested recovery process/plan at the ready before proceeding to Phase 3.

Phase 3: Increase the disk within the OS
At this point the OS has no idea you have expanded the capacity of its disk. You need to use the FDISK command to do this.

Step 1 – Check Operating System Detects New Disk Size:
Confirm that the disk has increased by running lsblk


In this example you can see that sda is the disk, which has been increased from 20GB on the VMware console to 50GB. The next step is to increase the partition size of /dev/sda1 to use all of this additional space

Step 2 – Remove Swap:
First unmount any Swap mount using swapoff -a

Step 3 – Print Partition Table:
Run fdisk /dev/sda (or whatever your main disk is called – see above). Then press P to print the Partition table. In this examples there is a single partition called /dev/sda1 . In this example it’s also importnat note that the * in the boot column, (no prizes for guessing this is the boot partition). If your partition is also a boot partition you will require an extra step once the new partition is created (see Step 6)


Important! The key number out of this entire list is the start number (in this example 2048) as you need this later in this process

Step 4 – Delete the Current Partition:
Yes, you heard me correctly, in order to expand a Linux partition you have to delete the existing one, then create a new larger partition. Please note that your data is secure during this process (though do have your backup at the ready).

Press d to delete /dev/sda1 partition. Upon pressing d you’ll be asked for the Id number of the partition you want to delete. In this example I want to delete /dev/sda1 which has the Id 83. If I had more than one partition I would have to stipulate Id 83 and press enter. However as this is my only partition it is automatically selected.

Important! DO NOT press w at this point, wait until the new partition has been created later in the process.

Press p to confirm /dev/sda1 has been deleted

Step 5 – Create a New Partition:
Press n to create a new primary partition. Select partition number 1, the start sector 2048 (the same start number as shown above) and select the default last sector i.e. the whole disk.


Step 6 – Make New Partition Bootable:
Press a to toggle the bootable flag on the new /dev/sda1


Step 7  – Write Changes
Press w to write the new partition table to disk. You’ll get a message telling that the kernel couldn’t re-read the partition table because the device is busy, but that it will applied at the next reboot.


Reboot the server with the reboot command.

Step 8 – Resize Partition

At this point the partition knows to use the full size of the new disk but it has yet to complete this process. The final task is to initiate the resizing of the partition.

Login as root and run resize2fs /dev/sda1 – this form will default to making the filesystem to take all available space on the partition. NB This process can take several minute depending on the size of the new disk.

Run df -h to confirm your new partition (/dev/sda1) is the size required.


Disclaimer: provided “AS IS” with no warranties and confer no rights

mount: wrong fs type, bad option, bad superblock

The Scenario:

I need to mount an NFS share on a Ubuntu server using the mount command

The Problem:

The mount command fails with the error “mount: wrong fs type, bad option, bad superblock". 

Also /sbin/mount.nfs is missing

The Solution:

Install NFS. Run the following: apt-get install nfs-common. Then rerun the mount command.


Disclaimer: provided “AS IS” with no warranties and confer no rights

NFS Mount Error: mount.nfs: mount system call failed

The Scenario:

I have created a NFS share on my Windows Server 2012 R2 file server. I want to mount this to a Ubuntu 12.04 server in the same domain and subnet.

The Problem:

The command mount -t nfs fileservername:/nfssharename /mountpoint_name produces the error “mount.nfs: mount system call failed”. However the same command on a Ubuntu 14 or Debian 8 server works fine

The Solution:

The Server for NFS role installed on the Windows file server uses NFS version 4 by default (To see how to check your environment click here) . Older versions of Ubuntu use either NFS version 2 or 3. Whilst Windows Server 2012 R2 is also capable of using these earlier NFS versions there is no auto-negotiation between the two servers to use a common version, Windows will only ever use the highest version enabled. The mount option must specifically state the version, in this case NFS version 3. So the command that worked included the option -o nfsvers=3:

mount -t nfs -o nfsvers=3 fileservername:/nfssharename /mountpoint_name

Disclaimer: provided “AS IS” with no warranties and confer no rights