Home Cloud & Networking Mastering Ubuntu Server

Mastering Ubuntu Server

By Jay LaCroix
books-svg-icon Book
eBook $43.99 $29.99
Print $54.99 $32.98
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $43.99 $29.99
Print $54.99 $32.98
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Deploying Ubuntu Server
About this book
Ubuntu is a Debian-based Linux operating system, and has various versions targeted at servers, desktops, phones, tablets and televisions. The Ubuntu Server Edition, also called Ubuntu Server, offers support for several common configurations, and also simplifies common Linux server deployment processes. With this book as their guide, readers will be able to configure and deploy Ubuntu Servers using Ubuntu Server 16.04, with all the skills necessary to manage real servers. The book begins with the concept of user management, group management, as well as file-system permissions. To manage your storage on Ubuntu Server systems, you will learn how to add and format storage and view disk usage. Later, you will also learn how to configure network interfaces, manage IP addresses, deploy Network Manager in order to connect to networks, and manage network interfaces. Furthermore, you will understand how to start and stop services so that you can manage running processes on Linux servers. The book will then demonstrate how to access and share files to or from Ubuntu Servers. You will learn how to create and manage databases using MariaDB and share web content with Apache. To virtualize hosts and applications, you will be shown how to set up KVM/Qemu and Docker and manage virtual machines with virt-manager. Lastly, you will explore best practices and troubleshooting techniques when working with Ubuntu Servers. By the end of the book, you will be an expert Ubuntu Server user well-versed in its advanced concepts.
Publication date:
July 2016
Publisher
Packt
Pages
430
ISBN
9781785284526

 

Chapter 1. Deploying Ubuntu Server

Ubuntu Server is an extremely powerful distribution for servers and network appliances. Whether you're setting up a high-end database host or a small office file server, the flexible nature of Ubuntu Server will meet and surpass your needs. In this book, we'll walk through all the common use-cases to help you get the most out of this exciting platform. In this chapter in particular, I'll guide you through the process of deploying Ubuntu Server on your system. We'll start off with some discussion on best practices, and then we'll obtain the software and create our installation media. Next, I'll give you a step by step rundown of the entire installation procedure. By the end of this chapter, you'll have an Ubuntu Server installation of your own to use throughout the remainder of this book. I'll even show you the process of installing Ubuntu Server on a Raspberry Pi for good measure.

In particular, we will cover:

  • Setting up our lab

  • Determining your server's role

  • Obtaining Ubuntu Server

  • Deciding between 32-bit and 64-bit installations

  • Creating a bootable Ubuntu Server flash drive (Windows)

  • Creating a bootable Ubuntu Server flash drive (Linux)

  • Creating a bootable Ubuntu Server flash drive (Mac)

  • Planning the partition layout

  • Installing Ubuntu Server

  • Installing Ubuntu Server (Raspberry Pi)

 

Setting up our lab


The first thing for us to do is to set up our environment. For the purposes of this book, it really doesn't matter what kind of hardware you use, if you even use physical hardware at all (virtual machines are also fine). If you have physical server hardware available to you, then by all means use it. Practicing on physical hardware is always preferred if you can, though not everyone has the money (or even the available space) to set up a complete lab. Nowadays, processing power and memory is cheaper than it's ever been, and the typical home PC is capable of running several virtual machines. Even better, software such as VirtualBox is free, so even if you have no budget at all, there are definitely options available to you. Perhaps you already have a server or two in your rack at work just waiting to be deployed, in which case, this will be even more exciting and fun. In the case of VirtualBox, it can be downloaded from here: https://www.virtualbox.org.

While I always prefer physical hardware, virtual machines have one major advantage. Not only are they easy to create and destroy at will, they are perfect for testing new or proposed solutions because you can easily take a snapshot of a VM and restore it if an experiment blows up in your face. In my case, it's common for me to create a virtual machine of a Linux distribution, fully update it, and then take a snapshot before making any changes. That way, I always have a base version of the OS to fall back on if I muck it up. Testing software roll-outs on virtual machines before graduating a solution to production is a good habit to get into anyway.

This book makes no assumptions regarding your environment, because the hardware one has access to differs from person to person. While the installation procedure for Ubuntu Server differs based on hardware (for example, perhaps your server doesn't have a physical optical drive, forcing you to use USB media instead of a CD), all other concepts contained throughout will be the same regardless.

With that said, once we run through the install procedure, feel free to install Ubuntu Server on as many devices or VMs as you can. If I can make any recommendation, it would be to utilize both physical and virtual servers if you can. Not because this book requires you to, but because it's a good habit to get into. If all else fails, cloud Virtual Private Server (VPS) providers such as Linode and Digital Ocean have Ubuntu Server available as an option for a small monthly fee. See the following URLs for more information on those providers:

These cloud providers are great if you wish to get a server up and running quickly or if your goal is to set up a server to be available in the cloud. With that said, all you need to do is have Ubuntu Server installed on something (basically anything at all) and you're ready to follow along.

 

Determining your server's role


While at this point your goal is most likely to set up an Ubuntu Server installation for the purposes of practicing the concepts contained within this book, it's also important to understand how a typical server roll-out is performed. Every server must have a purpose, also known as its Role. This role could be that of a database server, web server, and so on. Basically, it's the value the server adds to your network or your organization. Sometimes, servers may be implemented solely for the purpose of testing experimental code. And this is important too—having a test environment is a very common (and worthwhile) practice.

Once you understand the role your server plays within your organization, you can plan for its importance. Is the system mission critical? How would it affect your organization if for some reason this server malfunctioned? Depending on the answer to this question, you may only need to set up a single server for this task, or you may wish to plan for redundancy such that the server doesn't become a central point of failure. An example of this may be a DNS server, which would affect your colleague's ability to resolve local host names and access required resources. It may make sense to add a second DNS server to take over in the event that the primary server becomes unavailable.

Another item to consider is how confidential the data residing on a server is going to be for your environment. This directly relates to the installation procedure we're about to perform, because you will be asked whether or not you'd like to utilize encryption. The encryption that Ubuntu Server offers during installation is known as encryption at rest, which refers to the data stored within the storage volumes on that server. If your server is destined to store confidential data (accounting information, credit card numbers, employee or client records, and so on), you may want to consider making use of this option. Encrypting your hard disks is a really good idea to prevent miscreants with local access from stealing data. As long as the miscreant doesn't have your encryption key, they cannot steal this confidential information. However, it's worth mentioning that anyone with physical access can easily destroy data (encrypted or not), so definitely keep your server room locked!

At this point in the book, I'm definitely not asking you to create a detailed flow chart or to maintain an IP roll-out spreadsheet, just to keep in mind some concepts that should always be part of the conversation when setting up a new server. It needs to have a reason to exist, it should be understood how critical and confidential the server's data will be, and the server should then be set up accordingly. Once you practice these concepts as well as the installation procedure, you can make up your own server roll-out plan to use within your organization going forward.

 

Obtaining Ubuntu Server


For starters, we'll need to get our hands on Ubuntu Server and then create bootable installation media in order to install it. How you do this largely depends on your hardware. Does your server have an optical drive? Is it able to boot from USB? Refer to the documentation for your server in order to find out. In most cases, it's a very good idea to create both a bootable CD and USB media of Ubuntu Server while you're at it. That way, regardless of how your server boots, you're most likely covered.

Unfortunately, the differing age of servers within a typical data center introduces some unpredictability when it comes to how to boot installation media. When I first started with servers, it was commonplace for all servers to contain a 3.5 inch floppy disk drive, and some of the better ones even contained a CD drive. Nowadays, servers typically contain neither and only ship with an optical drive if you ask for one nicely while placing your order. If a server does have an optical drive, it typically will go unused for an extended period of time and become faulty without anyone knowing until the next time someone goes to use it. Some servers boot from USB; others don't. In order to continue, check the documentation for your hardware and plan accordingly. Your server's capabilities will determine which kind of media you'll need to create.

Thankfully, we only need to download a single file in order to create our media, regardless of whether or not we plan on creating USB or CD media. To get started, navigate to http://www.ubuntu.com/ in your browser, which will bring you to the main site for Ubuntu. On the top right, there will be a download button, and if you hover your cursor over that, you'll see an option for the Server version. Alternatively, you can simply Google Ubuntu Server and it should be the first result, or close. Just make sure the URL in the search result has a domain of ubuntu.com before you click on it. The file that you download will be an ISO file, ending with a .iso file extension. This is an image file that we will later use to create bootable media.

When this book was written, Ubuntu Server 16.04 is the most recent version. Depending on when you're reading this, the next release, 16.10 (or newer) may also be available. So, on the Ubuntu website, you may have a choice between LTS and non-LTS. Ubuntu 16.04 is Long-Term Support (LTS) while 16.10 is not. What does this mean? Essentially, whether or not an Ubuntu release is an LTS release determines the length of time it will be supported with security updates. Non-LTS releases are supported with security updates for just nine months, while LTS releases are supported for five years. This makes LTS releases perfect for servers, since it's not typical for an administrator to upgrade the entire distribution frequently. Non-LTS releases can be very handy for testing code on a newer software stack, but that's the only reason I can think of to consider a non-LTS release on a server. When in doubt, stick with LTS.

Note

Periodically throughout the life cycle of an LTS release of Ubuntu, several "point releases" are published. These are similar to service packs in comparison with Windows, as they contain current software and security updates built in. They also contain the latest hardware drivers. Point releases for Ubuntu Server 16.04 will be 16.04.1, 16.04.2, and so on. You should always download the latest version as newer versions support newer hardware.

If you're setting up a virtual machine, then the ISO file you download from the Ubuntu download site will be all you need. In that case, all you should need to do is create a VM, attach the ISO to the virtual optical drive, and boot it. From there, the installer should start, and you can proceed with the installation procedure contained within this chapter. Going over the process of booting an ISO image on a virtual machine differs from hypervisor to hypervisor, so going over the process on each would be beyond the scope of this book. Thankfully, the process is usually straight-forward and you can find the details within the documentation of your hypervisor or from performing a quick Google search.

As I mentioned before, I recommend creating both a bootable USB and bootable CD. This is due to the fact that you'll probably run into situations where you have a server that doesn't boot from USB, or perhaps your server doesn't have an optical drive and the USB key is your only option. In addition, the Ubuntu Server boot media also makes great recovery media if for some reason you need to rescue a server. To create a bootable CD, the process is typically just a matter of downloading the ISO file and then right-clicking on it. In the right-click menu, you should have an option to burn to disc or similar. This is true of Windows, as well as most graphical desktop environments of Linux when a disc burning application installed. If in doubt, Brasero is a good disc burning utility to download for Linux.

The exact procedure differs from system to system, mainly because there is a vast amount of software combinations at play here. For example, I've seen many Windows systems where the right-click option to burn a CD was removed by an installed CD/DVD burning application. In that case, you'd have to first open your CD/DVD burning application and find the option to create media from a downloaded ISO file. As much as I would love to outline the complete process here, no two Windows PCs typically ship with the same CD/DVD burning application. The best rule of thumb is to try right-clicking on the file to see if the option is there, and if not, refer to the documentation for your application. Keep in mind that a "Data Disc" is not what you want, so make sure to look for the option to create media from an ISO image or your disc will be useless.

Note

At the time of writing, the Ubuntu Server ISO image will fit on a standard 700 MB CD-R disc. However, the desktop flavors will require a writable DVD, and each release of Ubuntu is larger than previous ones, so at some point perhaps the server version will require a writable DVD as well. If the image size is over 700 MB, be sure to grab a blank DVD instead.

Creating a bootable USB is a bit more involved but easier to outline in steps, since each platform has a generally agreed upon method of creating them. In Linux, we can use ddrescue, or simply dd, while in Windows we can use the Universal USB installer from http://www.pendrivelinux.com/. In later section in this chapter, I'll outline the procedure of creating a bootable USB in Windows, Linux, and Mac.

 

Deciding between 32-bit and 64-bit installations


You might be wondering which version of Ubuntu Server (32-bit or 64-bit) you should download and install. After all, it does give you an option for both when you go to fetch the ISO image. So, which one should you go for? Nowadays, most (if not all) servers that are currently being sold are compatible with 64-bit operating systems. In fact, the majority of end-user PCs are also compatible with 64-bit operating systems. However, it's often the case that you may have older hardware lying around, so any existing servers you already have may or may not contain processors with 64-bit registers. Generally speaking, though, the 64-bit version is recommended, but the decision really comes down to whether or not you wish to run legacy 32-bit applications and what your hardware is able to support.

Is a legacy application causing you to consider going with a 32-bit installation? It's often the case that legacy applications remain in use for quite some time in the enterprise, but thankfully 32-bit applications will run just fine (most of the time) in a 64-bit Linux installation, providing that the libraries required for the application have 32-bit versions available in Ubuntu's software repositories. We'll discuss software repositories and installing applications in more detail in Chapter 5, Managing Software Packages.

Often, the decision between 32-bit and 64-bit may come down to the misconception that 32-bit operating systems are unable to utilize more than 4 GB of RAM. In the Microsoft world, it's common to install 32-bit Windows on computers with less than 4 GB of RAM, and 64-bit Windows on computers with 4 GB or more. This is due to 32-bit versions of Windows being unable to utilize an address space of more than 4 GB. What many aren't aware of, however, is that this limitation is exclusive to Windows. Many 32-bit Linux distributions can access much more than 4 GB of RAM, by way of utilizing a Physical Address Extension (PAE), which is compiled into the kernel of most Linux distributions nowadays. Since Ubuntu 16.04 is able to utilize PAE, it can access more than 4 GB of RAM. If you prefer to use a 32-bit operating system and are concerned whether or not Ubuntu will be able to utilize all of your memory, you can forget your worries. It can support up to 64 GB!

If you're in doubt, choose the 64-bit version of Ubuntu on any computer or server you wish to install it on, unless you have a very specific use-case which makes the decision for you. You should consider the 32-bit version only when you need to run legacy applications or wish to install the distribution on a legacy server. With this discussion out of the way, we can move on to actually getting some Ubuntu Server installations going. Go ahead and download the Ubuntu Server ISO image from the Ubuntu website and then follow along with the relevant section for creating a bootable flash drive with your OS.

 

Creating a bootable Ubuntu Server flash drive (Windows)


In this section, I'll walk you through the procedure for creating a bootable flash drive for Ubuntu Server for those of you currently running Windows on your workstation:

  1. To get started, grab a flash drive that's 1 GB or larger and insert it into your PC. You'll also need to download the Universal USB installer from the pendrivelinux website. You can find it at http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3. This executable doesn't actually install anything on your system, it will run from wherever you saved it.

  2. Once the application is open, click on the Step 1 drop-down box and select Ubuntu Server Installer from the list of available Linux distributions. Next, click on Browse and select the Ubuntu Server ISO image you downloaded earlier. Then, select your flash drive in the Step 3 drop-down box and then click on Create. When you've selected all your options, your application should look like this:

    Utilizing the Universal USB installer to create a bootable flash drive in Windows

  3. At this point, you'll see a confirmation dialog box appear, giving you one last chance to abort the process in case you selected an incorrect drive. Double-check that you've selected the proper drive and then click on Yes:

    Confirming your selections for creating a bootable flash drive

  4. Next, you'll see a new dialog box open that will show you the progress as your flash drive is formatted and converted:

    Flash drive creation in progress

This process will take about 5 minutes or so to complete, depending on the speed of your flash drive and your computer. Once it's finished, remove the flash drive from your PC and you should be good to go.

Note

It's a good idea to keep the Universal USB installer around even after you're finished using it, as it is a handy tool for creating bootable media for more than just Ubuntu Server. In fact, all of the distributions within the Ubuntu family are featured, as well as others such as OpenSUSE and Fedora. If nothing else, you can use it to recreate your server media when the next point release comes out so that you're always installing the latest version.

 

Creating a bootable Ubuntu Server flash drive (Linux)


On Linux systems, we can use either ddrescue or dd to create our bootable media. In the case of ddrescue, you'll first need to install the package on your system. If your distribution is Debian-based, you should be able to install it with the following command:

# apt-get install gddrescue

If your distribution is not Debian-based, use your distribution's package manager to install gddrescue. If this package is not available to you in your chosen platform, you can always fall back to the dd command, which I will also give you in this section.

With the gddrescue package installed, we can move on. Make sure the flash drive is inserted into your PC. Next, we'll need to run the following command in order to determine the name the system has provided for our flash drive:

# fdisk -l

From the output, you should be able to deduce which of the listed drives refers to your flash drive. In my case, /dev/sdc is mine. I know this because the partition /dev/sdc1 is formatted as FAT32, and I don't have any other partition formatted this way:

Output from the fdisk -l command

If you are at all unsure which drive is which, you may consider executing the fdisk -l command before and after inserting your flash drive and comparing the results. For the remaining examples in this section, I will use /dev/sdc for the commands. However, please make sure that you change this to match however your flash drive is named. If you format the wrong drive, you'll lose data (or worse, end up with a PC that won't start the next time you turn it on). Pay careful attention here!

Now that we know the device name for our flash drive, we can begin creating our media. If you have ddrescue available to you, use the following command:

# ddrescue -d -D --force <path and file name of the ISO> /dev/<device name>

For example, in my case, the command is the following:

# ddrescue -d -D --force /home/user/downloads/ubuntu-16.04-server-amd64.iso /dev/sdc

Note

Be sure to replace /dev/sdc with the device name of your flash drive and the name of the ISO with the filename and path of the Ubuntu Server ISO you downloaded earlier.

With the example ddrescue command I provided, pay special attention to the fact that I did not identify a partition for the dd command. For example, I didn't use /dev/sdc1, I used simply /dev/sdc. This is important—the flash drive will not be bootable if you targeted a specific partition. After all, the ISO image is an image of an entire disk, not just a single partition.

As for the options I chose, I'm choosing direct disk access for input and output (the -d and -D flags), forcing our device to be overwritten (the --force flag), and using the full path and file name of our downloaded ISO and directing the output to /dev/sdc. Once you start the process, it shouldn't take very long to complete. When it's finished, you're ready to begin using it to install Ubuntu Server:

ddrescue in the process of creating a bootable flash drive

For those of you without ddrescue available, you can use dd instead:

# dd if=/home/user/downloads/ubuntu-16.04-server-amd64.iso of=/dev/sdc bs=1M; sync

Similar to the ddrescue command, in the example for dd I'm using the path and filename of the Ubuntu Server ISO image as the input file (if=) and directing the output file (of=) to be that of my flash drive (/dev/sdc) and a block size of 1 MB (bs=1M). Unlike ddrescue, we won't see any fancy output with dd, but the process should work just fine. Once finished, we'll be ready to plan our partition layout and get our installation started.

 

Creating a bootable Ubuntu Server flash drive (Mac)


The process for creating bootable USB media with Mac OS X is very similar to that of Linux, but there's a little preparation to do first. After you download the ISO, as mentioned earlier, we will need to convert the ISO file to the IMG format and then write the media.

First, let's convert the downloaded ISO image.

Open a terminal and then execute the following command:

hdiutil convert -format UDRW -o <path_to_save_IMG_file> <path_to_ISO_image>

In my case, the command is as follows:

hdiutil convert -format UDRW -o /Users/jay/ubuntu_server.img
/Users/jay/Downloads/ubuntu-16.04-server-amd64.iso

All you should need to do is change the paths accordingly. First, we're choosing the path we want the created IMG file to be saved to, followed by the path to the Ubuntu ISO. The following screenshot shows an example run of this process:

Converting the Ubuntu Server ISO to IMG format

With the conversion out of the way, we can run the following command to show information regarding the disks which are currently attached to the system. We need to do this so we know the device name OS X has given our USB drive, since we'll be referring to it later:

diskutil list

In the example screenshot, you can see what the process looks like on the system I was using. In my case, I know my USB media is /dev/disk2, as it's the only thing attached to the Mac, which is roughly 8 GB in size. In your case, double-check the output of the diskutil list command and make a note of which entry is referring to your USB media. If in doubt, run the command before and after inserting your flash drive and compare the results:

Listing attached disks on a Mac system

Now that we know the device name of your USB media, we can continue with the final command and perform the actual creation of our Ubuntu Server media. But first, we should make sure that the flash drive is not mounted:

diskutil unmountDisk /dev/disk2

Be sure to change the device name to match the one you saw in the results of the diskutil list command you performed earlier.

The following command will create our actual media:

# sudo dd if=<path_to_IMG_file> of=<device_node_of_usb_media> bs=1m

For example, using the paths and device name on my system, the command would become the following:

# sudo dd if=/Users/jay/ubuntu_server.img.dmg of=/dev/rdisk2 bs=1m

Note

Here, I'm using the sudo command, which means that I want to run the command using root privileges. From this point forward, I'll prefix commands with # if you need to run the commands with root privileges. It doesn't matter if you use sudo or switch to root whenever you see this mark. (Just keep in mind that commands prefixed with # needs to be executed either with root or sudo). Even though this section involves using a Mac, I thought it would be worth bringing up.

The next screenshot shows an example run of this dd command:

Writing the Ubuntu Server IMG file to a USB flash drive

Now that we have our media, you can remove it from your Mac and continue on and get some installations going. Before we get into that, though, we should have a quick discussion regarding partitioning.

 

Planning the partition layout


One of the many joys of utilizing Linux for server platforms is how flexible the partitioning is. Partitioning your disk allows you to segregate your storage in order to dedicate specific storage allocations to individual applications. For example, you can dedicate a partition for the files that are shared by your Apache web server so changes to other partitions won't affect it. You can even dedicate a partition for your network file shares—the possibilities are endless. The names you create for the directories where your partitions are mounted are arbitrary; it really doesn't matter what you call them. The flexible nature of storage on Linux systems allows you to be creative with your partitioning as well as your directory naming.

With custom partitioning, you're able to do some very clever things. For example, with the right configuration you're able to wipe and reload your distribution while preserving user data, logs, and more. This works because Ubuntu Server allows you to carve up your storage any way you want during installation. If you already have a partition with data on it, you can choose to leave it as is so you can carry it forward into a new install. You simply set the directory path where it's mounted the same, restore your configuration files, and your apps will continue working as if nothing happened.

One very common example of custom partitioning in the real world is separating the /home directory into its own partition. Since this is where users typically store their files, you can set up your server such that a reload of the distribution won't disturb user files. When they log in after a server refresh, all their files will be right where they left them. You could even place the files shared by your Apache web server onto their own partition and preserve those too. The possibilities are endless.

Another reason to utilize separate partitions may be to simply create boundaries or restrictions. If you have an application running on your server that is prone to filling up large amounts of storage, you can point that application to its own partition, limited by size. An example of where this might be useful is an application's log files. Log files are the bane of any administrator when it comes to storage. While helpful if you're trying to figure out why something crashed, logs can fill up a hard disk if you're not careful. In my experience, I've seen servers come to a screeching halt due to log files filling up all the available free space on a server where everything was on a single partition. The only boundary the application had was the entirety of the disk.

While there are certainly better ways of handling excessive logging (log rotating, disk quotas, and so on), a separate partition also would have helped. If the application's log directory was on its own partition, it would be able to fill up that partition, but not the entire drive. A full log partition will certainly cause issues, but it wouldn't have been able to affect the entire server. As an administrator, it's up to you to weigh the pros and the cons and develop a partitioning scheme that will best serve the needs of your organization.

Running an efficient server is a matter of efficiently managing resources, users, and security—and a good partitioning scheme is certainly part of that. Sometimes it's just a matter of making things easier on yourself so that you have less work to do should you need to reload your operating system. For the sake of following along with this book, it really doesn't matter how you install or partition Ubuntu Server. The trick is simply to get it installed—you can always practice partitioning later. After all, part of learning is setting up a platform, figuring out how to break it in epic ways and then fixing it up.

When we perform our installation in the next section, you'll have an opportunity to partition your system any way you'd like. However, you don't have to—having everything in one partition is fine too, depending on your needs.

 

Installing Ubuntu Server


Now, regardless of your platform, we should be ready to get an installation or two of Ubuntu Server going. In the steps that follow, I'll walk you through the process.

  1. To get started, all you should need to do is insert the media into your server or device and follow the onscreen instructions to open the boot menu. The key you press at the beginning of the POST process differs from one machine to another, but it's quite often F10, F11, or F12. Refer to your documentation if you are unsure, though most computers and servers tell you which key to press at the beginning. You'll probably miss this window of opportunity the first few times, and that's fine—to this day I still seem to need to restart the machine once or twice to hit the key in time. Once you successfully boot from the media, it should ask you to select your language. Use your arrow keys to change the selection, then press Enter:

    Language selection at the beginning of the installation process

  2. Next, we'll be brought to the installation menu, where we'll have a few options. We can get right into the installation process by pressing Enter to choose the first option (Install Ubuntu Server), though a few of the other options may be useful to you:

    Main menu of the Ubuntu installer

    First, this menu also offers you an option to Check disc for defects. Although I'm sure you've done well in creating your media, all it takes is for a small corruption in the download or with the dd command and you would end up with invalid media. This is extremely rare—but it does happen from time to time. If you have the extra time, it may make sense to verify your media.

    Note

    If boot media created from your PC is constantly corrupted or invalid, try creating the media from another machine and test your PC's memory. You can test memory right from the Ubuntu Server installation media.

    Second, this menu gives you the option to Test memory. This is an option I've found myself using far more often than I'd like to admit. Defective RAM on computers and servers is surprisingly common and can cause all kinds of strange things to happen. For one, defective RAM may cause your installation to fail. Worse, your installation could also succeed—and I say that's worse due to the fact you'd find out about problems later rather than right away. While doing a memory test can add considerable time to the installation process, I definitely recommend it, especially if the hardware is new and hasn't ever been tested at all. In fact, I make it a process to test the RAM of all my servers once or twice a year, so this media can be used as a memory tester any time you need one. The Rescue a broken system option is also useful to recover systems that, for some reason, are unable to boot at all.

    From this point forward, we will progress through quite a few screens in order to customize our installation. I'll guide you along the way.

  3. To navigate the installer, you simply use the arrow keys to move up and down to select different options, press Enter to confirm choices, and you press Tab to select between different buttons. The installer is pretty easy to navigate once you get the hang of it. Anyway, after you enter the actual installation process, the first screen will ask you to Select a language. Go ahead and do so. Please note that this selection refers to the language used for the installation process, not necessarily the language that will be used by default on your installation:

    Language selection screen

  4. On the Select your location screen, choose the area that is closest to you. As the installer notes, this will set your time zone and system locale:

    Selecting the system locale and time zone

  5. On the Configure the keyboard screen, you'll be given an option to have the installer automatically detect your keyboard. I recommend choosing No because it's just as easy (if not faster) to select it yourself. If you choose No, the next screen will ask you for your keyboard type.

    Keyboard configuration during the Ubuntu Server installation procedure

  6. On the next screen, I chose English (US), but make sure you choose the country of origin that best represents your keyboard:

    Selecting the country of origin for your keyboard

  7. Next, you choose your actual keyboard layout. Once you've highlighted yours, press Enter to continue:

    Selecting the keyboard layout

  8. After several progress bars complete, you'll be brought to the Configure the network screen, where the installer will ask you to choose a Hostname for your server. The hostname is basically the name that will appear in your command prompt and on your network if you open up file shares to others. Enter whatever you'd like for this and then choose Continue. If you're indecisive, we can always change this later (and I'll show you how to do so in future chapters).

    Entering in the host name for the new server

  9. On the Set up users and passwords screen, the installer will ask you for the Full name for the new user that will be created. Unlike Debian (on which Ubuntu Server is based), the root account is disabled by default. We can always enable this later, but with the way Ubuntu Server sets up your system, the user account you create during the installation process will be given sudo rights, which will allow that user to perform commands as root with the sudo command. We'll discuss sudo in more detail in the next chapter, so don't worry if you've never worked with this before. Anyway, put in the full name of the first user and continue on:

    Creating a system user for Ubuntu Server

  10. Next, the installer will ask you for the username for the sudo user. This will be the name you'll use to log in:

    Selecting a user name

  11. The next screen will ask you to enter and then confirm your password for our sudo user. Enter it both times, and we'll continue on:

    Entering in the password for the system user

  12. The final screen of the Set up users and passwords section will ask if you'd like to encrypt the home directory of your sudo user:

    Choosing whether or not to encrypt the home directory for the system user

    Although we'll talk more about encryption in Chapter 12, Securing Your Server, it's important to note that this is a bit different than doing full-disk encryption with software such as Linux Unified Key Setup (LUKS). Although there is a way you can go back and encrypt your home directory later, it's a relative pain. Therefore, if you'd like your home directory encrypted, you may as well do it now. Whether or not you do this is up to you, but if you do, it will make the contents of your home directory completely private should an unauthorized person get a hold of your server's hard disk. As a basic rule of thumb, if you're storing private data, encrypt. Otherwise, don't.

  13. On the next screen, the installer will recommend a time-zone based on your earlier choices. This is usually correct, but if it's not, you can select your time-zone from a list. With that out of the way, let's continue on.

    Confirming time zone selections

  14. Now comes the fun part, partitioning your system. As we discussed earlier in this chapter, creative partitioning can make your system easier to manage. Whatever you've decided in regards to partitioning, you'll implement that plan here.

    Choosing a partitioning method

  15. If you want to get through the installer quickly and you don't plan on any partitioning, you can select Guided – use entire disk to just set up a single partition. If you do decide to use a single partition, you'll basically be skipping the next dozen or so steps, and you'll jump ahead to manual partitioning steps. In the next steps, we'll go through a bit of manual partitioning.

    Note

    As an alternative to Guided – use entire disk, you can also choose Guided – use entire disk and set up encrypted LVM. Doing so will also allow you to skip the partitioning process but will encrypt your filesystem as well. This will help prevent people with physical access stealing information from the server if they boot it from live media. It's recommended that you do this if you plan on storing sensitive data.

  16. This part of the installer is assuming you chose to manually partition your system (by choosing the Manual option). You should now see your hard disk on the list on this screen. In my case, my disk is listed as SCSI3 (0,0,0) (sda) – 171.8 GB ATA VBOX HARDDISK since I'm using a virtual machine to show the process. Yours will say something different, but it will be similar:

    Main menu of the Ubuntu Server partitioner

  17. If you've already installed an operating system on this disk before, you may see several partitions here. In my case, if I select the VBOX HARDDISK, the system will ask me whether or not I'd like to create an empty partition table. If the hard disk you're using has never been formatted before, you'll see the same thing. Feel free to choose Yes here to have a fresh partition table created if this screen appears:

    Creating a new partition table

    Assuming you already have partitions on your disk, you should delete them. It likely goes without saying, but you should always back up any important data on your machine that you care about before partitioning your disk.

  18. To delete your current partitions, choose one by selecting it and pressing Enter, and you'll have an option to Delete the partition near the bottom of the list:

    Deleting an existing partition

  19. Now that you've deleted your existing partitions, you should only have empty space listed for your hard disk. Select this free space and choose to Create a new partition. To show how this process works, I'll walk you through setting up separate /, /home, and swap partitions. You don't have to follow this exact scheme; feel free to mix it up. You do need a / partition at a minimum, though:

    Creating a new partition on our disk

  20. After you choose to Create a new partition, you'll be prompted to enter the size for it. In my opinion, 30 GB is plenty for your root partition. Some opt for smaller, though I've found that eventually you'll find yourself having to keep a close eye on space after a year or two, and since hard disk space is cheap nowadays, 30 GB is reasonable, but the choice is yours.

    Choosing the size of the new partition

  21. You'll be prompted whether or not you'd like to create the partition as Primary or Logical. We'll always be choosing Primary each time we see this. Creating Logical volumes is a good idea only if you plan on creating more than four partitions.

    Choosing a partition type

  22. Next, you'll be asked whether or not you'd like the partition created at the Beginning or the End of the free space of your disk. Each time we see this, we'll choose Beginning:

    Choosing to create the partition at the beginning or end of the free space

  23. Next, we'll see a summary of our options, many with the defaults selected. In our case, make sure Use as is set to Ext4 journaling file system, the Mount point is set to /, and the Bootable flag is set to on. Compare your settings to the ones I've chosen in the following screenshot for reference. When finished, choose Done setting up the partition:

    Creating the root partition for our installation

  24. Next, we'll be taken back to the main Partition disks screen, where we should see the partition we created as well as some FREE SPACE remaining. Select FREE SPACE, and we'll set up our next partition:

    Preparing to create a second partition

  25. In this case, we're setting up a partition for swap. The swap partition will be used if our server runs out of RAM, so hopefully we'll never need to use this partition much since the hard disk is slower than RAM. I think 2 GB is healthy, but the choice is yours. Some will set this to 1.5 times the amount of RAM you have, which is also valid. If in doubt, choose a few gigabytes here, no less than 2:

    Selecting a size for our swap partition

    Note

    There is currently a lot of debate in the Linux community regarding whether or not swap is even necessary. Some administrators will even omit this altogether. While I won't get into that debate here, I really don't see the point in disregarding swap. After all, if you have even an average hard disk, how much of a difference would it really make if you save a few gigabytes? In my opinion, it doesn't hurt anything to create swap and it may even save you one day.

  26. Again, we'll choose Primary for the type:

    Choosing primary or logical for the swap partition

  27. Ensure Use as is set to swap area, then select Done setting up the partition to continue:

    Finishing the creation of our swap partition

    With the swap partition created, go ahead and repeat the process to create a partition for /home. If you're following my partition scheme in this example, go ahead and allocate the remainder of the drive for /home. All the other options should be the same as before.

  28. Once you have our three partitions created, select Finish partitioning and write changes to disk to continue on. Refer to the following screenshot for a comparison of all the options I've chosen during my installation:

    Previewing all of our partition selection so far

    Note

    In case you're wondering why I partition this way, I think it makes more sense to create the partition most likely to need growth as the last one. In our case, I created /home last. This is so if I need to upgrade the storage later, all I would need to do is resize /home on the new disk. If I had created the swap partition last (as most Linux installers do), I would have to delete (or move) swap and then recreate it again afterwards. It's all about saving time in the long run. If I were creating a web server, I would've used the same style but instead of /home, I would've mounted the last partition in a directory like /srv/www instead.

  29. Next, the following screen will confirm our selections one last time before the new partitions are written to disk:

    Confirming our choices one last time

  30. After the partitions are created, Ubuntu Server will be installed on your hard disk. This process should pass relatively quickly depending on the speed of your machine. You'll see a progress bar appear, detailing its progress:

    Installing the base system

  31. Once all the packages have been installed for the base system, the installer will ask you if you need a proxy to access the Internet. If you need one, enter it here. Otherwise, leave it blank and select Continue:

    Proxy prompt during the Ubuntu Server installation

  32. Another progress bar will scroll by, which will prepare a selection of additional software you can choose to install:

    Preparing to install additional software

  33. On the Configuring tasks screen, you'll be asked whether or not you'd like to enable automatic updates. Personally, I always choose No automatic updates here, because I like to handle this myself by writing a script. It's up to you, though. Be careful, because an updated application may become incompatible with custom configurations, which can be a disaster for production later. Security updates are definitely something you want to stay on top of, so if you don't enable automatic updates, make sure you at least come up with your own solution later. We'll discuss updating your system during Chapter 5, Managing Software Packages, so don't worry if you don't have an idea on how to handle updates just yet.

    Deciding between automatic and non-automatic security updates

  34. On the next screen, you'll be given some additional software collections you can install if you want to. You'll have the option to set up an OpenSSH server, Mail server, LAMP server, and more. Most of these options we'll set up manually further on into the book, so I suggest selecting only OpenSSH server for now. Leave standard system utilities checked:

    Selecting additional software

  35. The next screen that appears will offer us the option to Install the GRUB boot loader on the master boot loader. You should always say Yes to this prompt, unless you have your own process to boot the system you wish to implement. For 99.99% of you, you'll definitely want to do this:

    Confirming boot loader installation

  36. Finally, our installation is complete! At this point, you can remove your boot media and then select Continue at the final confirmation screen to reboot the system:

    Final confirmation prompt during installation

At this point, your server will reboot and then Ubuntu Server should start right up. Although the installation process contained quite a few steps, it's really quick once you get used to it. To make things easier, later on in this book I'll go over the process of creating images you can use to deploy Ubuntu Server, so you'll be able to create your own pre-configured environments to simplify the process greatly.

 

Installing Ubuntu Server (Raspberry Pi)


The Raspberry Pi has become quite a valuable asset in the industry. These tiny computers, now with four cores and 1 GB of RAM, are extremely useful in running one-off tasks and even offering a great place to test code without disrupting existing infrastructure. In my lab, I have three Pis on my network, each one responsible for performing specific tasks or functions. It's a very useful platform.

Thankfully, Ubuntu Server is quite easy to install on a Raspberry Pi. In fact, it's installed in much the same way as Raspbian, which is the distribution most commonly used on the Pi. Ubuntu Server is available for Raspberry Pi models 2 and 3. All you'll need to do is download the SD card image and then copy it directly to your SD card. Once you've done that, you can boot the Pi and log in. The default username and password is ubuntu for both.

Note

At the time of writing, the version of Ubuntu Server for the Raspberry Pi 3 is not officially supported but should work. The Pi 2 version is fully supported. The Pi 3 version is expected to be fully supported at some point.

To install Ubuntu on the Pi, perform the following steps:

  1. To get started, you'll first download the SD card image from here: https://wiki.ubuntu.com/ARM/RaspberryPi and check that it is compatible with your model of Raspberry Pi.

  2. In order to write the image to an SD card, first extract it and then use dd to do the actual copying. This is very similar to the process we used to create bootable USB media. In fact, it is the same; the only difference is the source and target. From a Linux system, you can perform the process with the following command:

    # dd if=/path/to/downloaded/file of=/dev/sdX bs=1M
    
  3. As before, replace if= and of= with the path to the downloaded and extracted file and the target respectively. If you are unsure about which device your SD card is on your system, execute:

    # fdisk -l
    
  4. In my case, this process can take some time to complete. Often, the command prompt will return even before the syncing process is actually finished. This means you'll more than likely see the access indicator LED on your card reader continue to flash for a while before the process is truly complete. It goes without saying, but make sure you remove your SD card only once the LED has stopped flashing. If you'd rather have the command prompt NOT return until after the process is complete, add the sync option, like the following:

    # dd if=/path/to/downloaded/file of=/dev/sdX bs=1M; sync
    
  5. So for example, on my system, the command will be:

    # dd if=/home/jay/downloads/ubuntu-server-16.04.img of=/dev/sdc bs=1M; sync
    

Depending on the speed of your card reader, this process will likely take at least 5 minutes to complete, if not longer. Once you're finished and you start up your Pi, you're likely to notice an issue straight away. If we execute:

df -h

We'll see that regardless of the size of our SD card, we'll have quite a bit of space that is not being utilized. This is because the SD card image will be the size of the SD card it was captured from, which will most likely not equal the size of yours. This will result in wasted space. What we'll need to do is resize the installation to match our SD card.

First, from the Pi after it's started up, enter fdisk by executing the following command:

# fdisk /dev/mmcblk0

Next, we'll need to delete the second partition, by pressing d + 2.

With the partition deleted (and while still within the fdisk console), we'll recreate the partition we deleted by pressing n + p + 2 and Enter (twice) +w.

With those commands executed, execute the reboot command to restart the Pi. However, we have one more command to execute. Once it starts backup, we can do the actual resizing with:

# resize2fs /dev/mmcblk0p2

After the resize procedure, you should be all set and able to utilize all the space of your SD card. You should also be able to use your Pi as a means of following along with the activities of this book. One last thing, though. If you execute this, you'll notice that your Pi doesn't have a swap partition:

free -m

This is normal, and while you can create a swap file to fill the role of a swap partition, I recommend you don't. SD cards are much too slow for swap, so you'd be better off without it. Since the Raspberry Pi 2 and Pi 3 only have about 1 GB of RAM, make sure whatever processes you plan on running fit within that restraint and you should be fine.

 

Summary


In this chapter, we covered the installation process in great detail. As with most Linux distributions, Ubuntu Server is scalable and able to be installed on a variety of server types. Physical servers, virtual machines, and even the Raspberry Pi have a version of Ubuntu Server available. The process of installation was covered step by step, and you should now have an Ubuntu Server of your own to configure as you wish. Also in this chapter, we covered partitioning, creating boot media, determining the role of your server, as well as some best practices.

In the next chapter, I'll show you how to manage users. You'll be able to create them, delete them, change them, and even manage password expiration and more. I'll also cover permissions so that you can determine what your users are allowed to do on your server. See you there!

About the Author
  • Jay LaCroix

    Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.

    Browse publications by this author
Latest Reviews (8 reviews total)
Well organized and comprehensive.
Includes good info for beginners.
Great book full of great tips