Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: How to Install and Configure an Ubuntu Server 16.04 LTS

  1. #1
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    How to Install and Configure an Ubuntu Server 16.04 LTS

    Greetings and salutations,

    I hope this thread will be helpful to those who follow in my foot steps as well as getting any advice based on what I have done / documented.

    Link to original post: HammondsLegacy Forums (best when viewed at original location due to custom formatting)

    High-level overview

    This document will cover installation of a dedicated Ubuntu server. This will be the "base" installation of the server as a prerequisite for other documents that will build upon it (e.g. MediaWiki and MySQL). The server will be installed inside a virtual machine using vSphere running on ESXi servers. Notes will also be supplied for doing the same thing for Oracle's VirtualBox on a Windows 10 PC. Although there are some VMware-specific and VirtualBox-specific steps, they are very few and the majority of this documentation will work for other Virtual Machines or even directly installed onto a physical machine (e.g. bare-metal install).

    This document will also cover some custom scripts to help automate tasks such as backing up, automatically growing the file system when free space is low, etc.

    Tools utilized in this process





    Helpful links

    The list below are sources of information that helped me configure this system as well as some places that might be helpful to me later on as this process continues.




    Assumptions

    This documentation will need to make use of some very-specific information that will most-likely be different for each person / location. This variable data will be noted in this section and highlighted in red throughout the document as a reminder that you should plug-in your own value rather than actually using these "place-holder" values.

    Under no circumstance should you use the actual values listed below. They are place-holders for the real thing. This is just a checklist template you need to have answered before you start the install process.

    Wherever you see RED in this document, you need to substitute it for what your company uses. NOTE: Ubuntu Forums does not allow me to use color tags in code blocks like on my forums so be careful about missing these placeholders based on color. (do a search/find)



    • Ubuntu Server name: srv-ubuntu
    • Internet domain: mydomain.com
    • Ubuntu Server IP address: 192.168.107.2
    • Ubuntu Server IP subnet mask: 255.255.255.0
    • Ubuntu Server IP gateway: 192.168.107.1
    • Internal DNS Server 1: 192.168.107.212
    • Internal DNS Server 2: 192.168.107.213
    • External DNS Server 1: 8.8.8.4
    • External DNS Server 2: 8.8.8.5
    • Ubuntu Admin ID: administrator
    • Ubuntu Admin Password: myadminpass
    • Email Server (remote): 192.168.107.25
    • Windows Share ID: myshare
    • Windows Share Password: mysharepass


    It is also assumed that the reader knows how to use the VI editor. If not, you will need to beef up your skill set or use a different editor in place of it.
    Last edited by LHammonds; October 3rd, 2017 at 04:02 PM. Reason: Modify formatting for UbuntuForums

  2. #2
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Analysis and Design

    The Ubuntu Server Long-Term Support (LTS) is great choice for companies because it is a solid operating system that happens to be free. If professional support is needed, there is an option to buy support for the Long-Term Support (LTS) versions of the operating system.

    The large decision over the configuration of Ubuntu is how the hard drive space is sliced up (partitioned). This documentation will focus on partitioning the drives in such a way that it allows for growth depending on what is needed for the specific application.

    This following design allows for dynamic growth and fine-tuning if need be. Being caught offguard with a scenario where space is filled up with no immediate option other than deleting files is never a good thing. Long-term life and growth of the system as well as budgeting concerns have to be taken into consideration.

    Isolating the root volume to mainly just static data that will not grow much over time is the central concern. Pushing the other folders into their own volumes will be done so their dynamic growth will not affect the root partition. Filling up the root volume on a *nix system is a very bad thing and should be avoided at all costs. The file systems will also not take up 100% of the logical volume. This will allow the file systems (through automated scripts) to grow as needed and give the administrators some time to add more drives if necessary or shrink other volumes to get more space.

    The volumes will initially be sliced up as follows:



    • boot - This will remain static in size. It is also the only space residing outside the Logical Volume Manager (LVM)
    • root volume - Operating system and everything else which should remain fairly static.
    • swap volume - This will remain static in size. However, if the amount of RAM is adjusted, this might need to be adjusted as well.
    • home volume - This is where personal files will be stored but likely not be used in most server configurations.
    • tmp volume - This location will be used for temporary storage. Size should be adjusted to match however it is being used.
    • usr volume - This will contain mostly static data and should not grow unexpectedly.
    • var volume - This is the app/database/log storage and will continue to grow over time.
    • srv volume - This will contain the files stored in the Samba share.
    • opt volume - This will contain specific software you add but may not be utilized at all depending on configuration.
    • bak volume - This will contain a local backup of the application. So space needs to be about double the size of your app data (typically double the /var size).
    • Offsite Storage - This will be handled elsewhere but will be mounted on this server.


    The partitions will be increased later as needed but will start off with a lower number.

    To get a good idea of the initial hard drive layout and to understand the process better, here is a graphical representation of the initial design for the server:



    These numbers will be used for the initial build of the system:

    boot = 200 MB
    root = 2 GB
    swap = 2 GB
    home = 0.2 GB
    tmp = 0.5 GB
    usr = 2.0 GB
    var = 2.0 GB
    srv = 0.2 GB
    opt = 0.2 GB
    bak = 0.5 GB

    NOTE: When the logical volumes and file systems are initially created, they consume the maximum amount of space allocated so that the file system size will initially equal the logical volume size. These partition sizes above are artificially small for that reason. These will be later modified so that the logical volume will be larger than the file system so that the file system has room to expand when needed in a safe and automated manner.

    Important info:
    - The /tmp folder is strictly temporary. By default, each time the server reboots, this folder is deleted and re-created.
    - The /bak folder will retain the most recent backup and is considered the "local" copy of the backup.

    VMware Virtual Machine Settings


    • Configuration: Custom
    • Name: srv-ubuntu
    • Datastore: DS3400-LUN0
    • Virtual Machine Version: 8
    • Guest Operating System: Linux, Version: Ubuntu Linux (64-bit)
    • Number of virtual processors: 1
    • Memory Size: 1024 MB
    • Number of NICs: 1
    • NIC 1: VM Network
    • Adapter: E1000, Connect at Power On: Checked
    • SCSI controller: LSI Logic Parallel
    • Select a Disk: Create a new virtual disk
    • Create a Disk: 10 GB, No thin provisioning, No cluster features, Store with the virtual machine
    • Advanced Options: Virtual Device Node = SCSI (0:0)
    • Remove Floppy Drive
    • Mount CD/DVD Drive to Ubuntu ISO (ubuntu-16.04-server-amd64.iso). Make sure CD/DVD is set to Connect at power on
    • Set boot options to Force BIOS Setup so you can set CDROM to boot before the Hard Disk


    VirtualBox Virtual Machine Settings


    • Name: srv-ubuntu
    • Operating System: Linux
    • Version: Ubuntu (64 bit)
    • Memory: 1024 MB
    • Check - Start-up Disk
      - Create new hard disk
      - VMDK
      - Dynamically allocated
      - Size: 10 GB
    • Select srv-ubuntu and click Settings (CTRL+S)
      - System, Processor, Enable PAE/NX
      - Network, Attached to: Bridged Adapter, Advanced, Adapter Type: Intel PRO/1000 MT Server
      - Storage, IDE Controller, Choose a virtual CD/DVD disk file, ubuntu-16.04-server-amd64.iso


    Install PuTTY

    When running inside a virtual machine, the response time for screen refreshes can be painfully slow to view man (manual) pages and navigating in VI (text editor). However, when using PuTTY via SSH, it is a far better solution for your Ubuntu console because it handles the screen draws much faster when scrolling and allows copying and pasting text between windows.

    For example, selecting and copying a command in this document and then right-clicking in the PuTTY window will paste the command and have it ready to execute. Any text/lines highlighted with the mouse will be automatically copied into clipboard memory.

    Download the portable edition and run the install...except it does not really "install" like a normal program, it simply extracts to a specified folder and will run from that folder even if you put it on a USB stick and carry over to a new computer (requires no install to run and thus leaves no footprint on your system)



    1. Start PuTTY
    2. Type the following and click the Save button:
      Host Name: SRV-Ubuntu (or the IP such as 192.168.107.2)
      Port: 22
      Connection type: SSH
      Saved Sessions: SRV-Ubuntu
    3. Now all you have to do is double-click on the session and it will connect to your server (when online).
    Last edited by LHammonds; October 3rd, 2017 at 04:03 PM. Reason: Modify formatting for UbuntuForums

  3. #3
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Install Ubuntu Server

    NOTE: During the setup process throughout this entire document, most commands will require "sudo" as a prefix. However, this document will be using "sudo su" to temporarily gain root privileges so that subsequent commands will work without the need for the "sudo" prefix.



    1. Power on the Virtual Machine (VM)
    2. Press {ENTER} to accept English
    3. Select Install Ubuntu Server {ENTER}
    4. Press {ENTER} to accept English
    5. Press {ENTER} to accept United States
    6. Select No to not detect keyboard layout
    7. Press {ENTER} to accept English (US)
    8. Press {ENTER} to accept English (US)
    9. Type srv-ubuntu {ENTER} (this is your hostname)
    10. Type Administrator, {ENTER} for the full name
    11. Press {ENTER} to accept the default of the lowercase name of administrator
    12. Type myadminpass, {ENTER}, myadminpass, {ENTER}
    13. Select No, {ENTER} to not encrypt your home directory
    14. Press {ENTER} to accept detected time zone (America/Chicago)
    15. Select Manual {ENTER}
    16. Select SCSI3 (0,0,0) (sda) - 10.7 GB VMware Virtual disk {ENTER}
    17. Select Yes to create new empty partition table, {ENTER}
    18. Select pri/log 10.7 GB FREE SPACE {ENTER}
    19. Select Create a new partition {ENTER}
    20. Type 500MB, {ENTER} (NOTE: This will be the /boot partition)
    21. Select Primary {ENTER}
    22. Select Beginning {ENTER}
    23. Select Use as: Ext4 journaling file system {ENTER}
    24. Select Ext2 file system {ENTER}
    25. Select Mount point: / {ENTER}
    26. Select /boot - static files of the boot loader {ENTER}
    27. Select Label: and type boot and press {ENTER}
    28. Select Bootable flag: off {ENTER} (NOTE: This toggles it on)
    29. Select Done setting up the partition {ENTER}
    30. Select Configure the Logical Volume Manager {ENTER}
    31. Select Yes to write change to disks and configure LVM, {ENTER}
    32. Select Create volume group {ENTER}
    33. Type LVG {ENTER}
    34. Select /dev/sda free #1 (10537MB; FREE SPACE), {SPACEBAR}, {ENTER}
    35. Select Yes to write change to disks and configure LVM, {ENTER}
    36. Select Create logical volume {ENTER}
    37. Select LVG (10531MB) {ENTER}
    38. Type root {ENTER}
    39. Type 2G {ENTER}
    40. Select Create logical volume {ENTER}
    41. Select LVG (8535MB) {ENTER}
    42. Type swap {ENTER}
    43. Type 2G {ENTER} (NOTE: This is double the amount of RAM)
    44. Select Create logical volume {ENTER}
    45. Select LVG (6538MB) {ENTER}
    46. Type home {ENTER}
    47. Type 0.2G {ENTER}
    48. Select Create logical volume {ENTER}
    49. Select LVG (6341MB) {ENTER}
    50. Type tmp {ENTER}
    51. Type 0.5G {ENTER}
    52. Select Create logical volume {ENTER}
    53. Select LVG (5842MB) {ENTER}
    54. Type usr {ENTER}
    55. Type 2G {ENTER}
    56. Select Create logical volume {ENTER}
    57. Select LVG (3846MB) {ENTER}
    58. Type var {ENTER}
    59. Type 2G {ENTER}
    60. Select Create logical volume {ENTER}
    61. Select LVG (1849MB) {ENTER}
    62. Type srv {ENTER}
    63. Type 0.2G {ENTER}
    64. Select Create logical volume {ENTER}
    65. Select LVG (1652MB) {ENTER}
    66. Type opt {ENTER}
    67. Type 0.2G {ENTER}
    68. Select Create logical volume {ENTER}
    69. Select LVG (1455MB) {ENTER}
    70. Type bak {ENTER}
    71. Type 0.5G {ENTER} (we will have a small amount leftover in LVG)
    72. Select Finish {ENTER}
    73. Select #1 2.0 GB directly under LVM VG LVG, LV root, {ENTER}
    74. Select Use as: do not use {ENTER}
    75. Select Ext4 journaling file system {ENTER}
    76. Select Mount point: none {ENTER}
    77. Select / - the root file system {ENTER}
    78. Select Label: none {ENTER}
    79. Type root {ENTER}
    80. Select Done setting up the partition {ENTER}
    81. Select #1 2.0 GB directly under LVM VG LVG, LV swap, {ENTER}
    82. Select Use as: do not use {ENTER}
    83. Select swap area {ENTER}
    84. Select Done setting up the partition {ENTER}
    85. Select #1 197.1 MB directly under LVM VG LVG, LV home, {ENTER}
    86. Select Use as: do not use {ENTER}
    87. Select Ext4 journaling file system {ENTER}
    88. Select Mount point: none {ENTER}
    89. Select /home {ENTER}
    90. Select Label: none {ENTER}
    91. Type home {ENTER}
    92. Select Done setting up the partition {ENTER}
    93. Select #1 499.1 MB directly under LVM VG LVG, LV tmp, {ENTER}
    94. Select Use as: do not use {ENTER}
    95. Select Ext4 journaling file system {ENTER}
    96. Select Mount point: none {ENTER}
    97. Select /tmp {ENTER}
    98. Select Label: none {ENTER}
    99. Type tmp {ENTER}
    100. Select Label: tmp {ENTER}
    101. Select Done setting up the partition {ENTER}
    102. Select #1 2.0 GB directly under LVM VG LVG, LV usr, {ENTER}
    103. Select Use as: do not use {ENTER}
    104. Select Ext4 journaling file system {ENTER}
    105. Select Mount point: none {ENTER}
    106. Select /usr {ENTER}
    107. Select Label: none {ENTER}
    108. Type usr {ENTER}
    109. Select Done setting up the partition {ENTER}
    110. Select #1 2.0 GB directly under LVM VG LVG, LV var, {ENTER}
    111. Select Use as: do not use {ENTER}
    112. Select Ext4 journaling file system {ENTER}
    113. Select Mount point: none {ENTER}
    114. Select /var {ENTER}
    115. Select Label: none {ENTER}
    116. Type var {ENTER}
    117. Select Done setting up the partition {ENTER}
    118. Select #1 197.1 MB directly under LVM VG LVG, LV srv, {ENTER}
    119. Select Use as: do not use {ENTER}
    120. Select Ext4 journaling file system {ENTER}
    121. Select Mount point: none {ENTER}
    122. Select /srv {ENTER}
    123. Select Label: none {ENTER}
    124. Type srv {ENTER}
    125. Select Done setting up the partition {ENTER}
    126. Select #1 197.1 MB directly under LVM VG LVG, LV opt, {ENTER}
    127. Select Use as: do not use {ENTER}
    128. Select Ext4 journaling file system {ENTER}
    129. Select Mount point: none {ENTER}
    130. Select /opt {ENTER}
    131. Select Label: none {ENTER}
    132. Type opt {ENTER}
    133. Select Done setting up the partition {ENTER}
    134. Select #1 499.1 MB directly under LVM VG LVG, LV bak, {ENTER}
    135. Select Use as: do not use {ENTER}
    136. Select Ext4 journaling file system {ENTER}
    137. Select Mount point: none {ENTER}
    138. Select Enter manually {ENTER}
    139. Type /bak {ENTER}
    140. Select Label: none {ENTER}
    141. Type bak {ENTER}
    142. Select Done setting up the partition {ENTER}
    143. Here is what the screen looks like at this point: Partitions
    144. Select Finish partitioning and write changes to disk {ENTER}
    145. Select Yes to write changes to disk, {ENTER}
    146. Press {ENTER} to accept a blank line for the HTTP proxy
    147. Select No automatic updates, {ENTER} (* We will schedule a script for this later *)
    148. Set the following and press {ENTER} to continue:
      Uncheck - Manual package selection
      Uncheck - DNS server
      Uncheck - LAMP server
      Uncheck - Mail server
      Uncheck - PostgreSQL database
      Uncheck - Samba file server
      Check - standard system utilities (enabled by default)
      Uncheck - Virtual Machine host
      Check - OpenSSH server (allows us to use PuTTY after installation to connect to the server)
    149. Select Yes, {ENTER} to install GRUB boot loader to the master boot record
    150. Installation Complete - from the VM menu, select VM --> Edit Settings and select CD/DVD Drive 1 and change to "Client Device" which will effectively remove the ISO. Now press {ENTER} to reboot.



    Initial Configurations



    1. At the login prompt, login with your administrator account (administrator / myadminpass)
    2. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    3. Type the following to give you a list of interfaces. It will likely show you a loopback interface (lo) and an Ethernet interface (eth0, ens32, etc.) Be sure to remember the Ethernet name. The following steps will assume "eth0" was the name.
      Code:
      ip link
    4. Type vi /etc/network/interfaces {ENTER} and change the Ethernet interface: (We need to change it from using DHCP to a static IP)
      From:
      [mycode]iface eth0 inet dhcp[/mycode]
      To:
      [mycode]iface eth0 inet static
      address 192.168.107.2
      netmask 255.255.255.0
      gateway 192.168.107.1
      network 192.168.107.0
      broadcast 192.168.107.255
      dns-nameservers 192.168.107.212 192.168.107.213 8.8.8.4 8.8.8.5[/mycode]

      NOTE #1: You may need to manually remove the DHCP record (lease) associated to this Ubuntu server from your DHCP server so the correct IP can be found by other machines on the network. This can be avoided by temporarily configuring the VM Network Adapter connection to be "Host Only Network" instead of "VM Network" so the server is isolated during setup...at least until you reach the testing of the static IP below.

      NOTE #2: You might also need to manually add a HOST(A) record to your Windows DNS server (for srv-ubuntu.mydomain.com and srv-ubuntu.work.mydomain.com)
    5. Restart the network by typing the following:
      [mycode]ip address flush eth0
      systemctl restart networking.service[/mycode]
    6. Sanity check! Type ifconfig and make sure the settings are correct. Then type ping www.google.com or similar and see if ping works.
    7. Shutdown and power off the server by typing shutdown -P now
    8. At this point forward, you can use PuTTY to access the console rather than the console itself for better performance, ability to scroll, etc.
    9. In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 1 and description of Ubuntu Server 16.04 LTS, clean install, Static IP: 192.168.107.2 and click OK



    16.04.1 LTS Reboot/Shutdown Bug

    If you are experiencing a 10 minute delay when issuing a reboot or shutdown command, you might need to edit line 120 of the unattended upgrades script and change "False" to "false"

    I have documented the problem description here and others have pointed to the bug fix here.

    The problem was fixed in version "0.90ubuntu0.5" which means you can do "apt search unattended-upgrades" and compare your installed version to see if you will be affected (by having an earlier version installed). In Ubuntu Server 16.04.3, we have version 0.90ubuntu0.8 which means this issue is not present in the current release of the operating system.

    Operating System Patches



    1. Start the Ubuntu server and connect using PuTTY.
    2. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    3. Install the patches by typing the following commands:
      Code:
      apt update
      apt upgrade
      apt dist-upgrade
    4. Shutdown and power off the server by typing shutdown -P now
    5. In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 2 and description of Ubuntu Server 16.04 LTS, Patches applied, Static IP: 192.168.107.2. The Snapshot Manager should now have a nice hierarchy of snapshots (STEP 1 --> STEP 2 --> You are here)
    Last edited by LHammonds; October 4th, 2017 at 03:30 PM. Reason: Updated Reboot/Shutdown Bug info

  4. #4
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Volume / Disk Management

    Earlier, it was mentioned that the partition design needed to have some breathing room in each volume so that the file system inside can grow as needed. When the volumes were created during setup, the file systems were automatically expanded to fill the entire volume. We will now correct this by adding more "drives" to the system and then extend each logical volume to gain some breathing space.

    Most logical volumes will be increased in size and then the file systems contained in them will be increased but not to the maximum amount.

    This design will allow growth when needed and ensure that there will be time to add additional hard drives BEFORE they are needed which will keep the administrators from being stuck between a rock and a hard place! Nobody wants to lose a job because somebody did not estimate growth correctly or the budget did not allow for large capacity when the system first rolled out.

    Here are the planned adjustments for each logical volume:

    root = 2 GB to 3 GB
    swap = 2 GB (no change)
    home = 0.2 GB to 1 GB
    tmp = 0.5 GB to 2 GB
    usr = 2.0 GB to 4 GB
    var = 2.0 GB to 3 GB
    srv = 0.2 GB to 2 GB
    opt = 0.2 GB to 2 GB
    bak = 0.5 GB to 4 GB

    Here are the planned adjustments for each file system:

    root = 2.0 GB (no change)
    swap = 2.0 GB (no change)
    home = 0.2 GB to 0.5 GB
    tmp = 0.5 GB to 1.0 GB
    usr = 2.0 GB to 3.0 GB
    var = 2.0 GB (no change)
    srv = 0.2 GB to 1.0 GB
    opt = 0.2 GB to 1.0 GB
    bak = 0.5 GB to 2.0 GB

    We started off with a 10 GB drive to hold these volumes but now need 22 GB. For this exercise, we will add two 12 GB drives to cover the additional storage needs. (NOTE: This was an arbitrary number in order to demonstrate how to add additional hard drives to the system)

    Here is a graphical representation of what needs to be accomplished:



    If we were to type df -h right now, we should see something like this:

    Code:
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/LVG-root  1.9G  429M  1.4G  24% /
    udev                  489M  4.0K  489M   1% /dev
    tmpfs                 200M  244K  199M   1% /run
    none                  5.0M     0  5.0M   0% /run/lock
    none                  498M     0  498M   0% /run/shm
    /dev/sda1             179M   47M  122M  28% /boot
    /dev/mapper/LVG-home  187M  9.5M  168M   6% /home
    /dev/mapper/LVG-tmp   473M   23M  427M   5% /tmp
    /dev/mapper/LVG-usr   1.9G  460M  1.4G  26% /usr
    /dev/mapper/LVG-var   1.9G  367M  1.5G  21% /var
    /dev/mapper/LVG-srv   187M  9.5M  168M   6% /srv
    /dev/mapper/LVG-opt   187M  9.5M  168M   6% /opt
    /dev/mapper/LVG-bak   473M   23M  427M   5% /bak
    Adding more space in VMware is easy. In this exercise, each drive will be added as a separate disk just as if we were to add a physical drive to a physical server.


    1. Shutdown and power off the server by typing shutdown -P now
    2. In the vSphere client, right-click the Virtual Machine and choose Edit Settings.
    3. On the hardware tab, click the Add button and select Hard Disk. Click Next, choose "Create a new virtual disk", click Next, set the size to 12 GB, click Next, Next, Finish.
    4. Add another 12 GB disk using the same steps above and click OK to close the settings and allow VMware to process the changes.


    Collect information about the newly added drives.


    1. Start the server and connect using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass) and then temporarily grant yourself super user privilages by typing sudo su
    3. Type pvdisplay which should show something similar to this:
      Code:
      --- Physical volume ---
        PV Name               /dev/sda5
        VG Name               LVG
        PV Size               9.81 GiB / not usable 3.00 MiB
        Allocatable           yes
        PE Size               4.00 MiB
        Total PE              2511
        Free PE               228
        Allocated PE          2283
        PV UUID               NkfC3i-ROqv-YuLZ-63VO-RTAU-l01p-suqi4O
      The important bits of info here are the PV Name and VG Name for our existing configuration.
    4. Type fdisk -l which should show something similar to this (however I abbreviated it to show just the important parts):
      Code:
      Disk /dev/sda: 10.7 GB, 10737418240 bytes
         Device Boot      Start         End      Blocks   Id  System
      /dev/sda1   *        2048      391167      194560   83  Linux
      /dev/sda2          393214    20969471    10288129    5  Extended
      /dev/sda5          393216    20969471    10288128   8e  Linux LVM
       
      Disk /dev/sdb: 12.9 GB, 12884901888 bytes
      Disk /dev/sdb doesn't contain a valid partition table
      Disk /dev/sdc: 12.9 GB, 12884901888 bytes
      Disk /dev/sdc doesn't contain a valid partition table
      The important bits of info here are the device paths for the new drives which I highlighted in red.


    Prepare the first drive (/dev/sdb) to be used by the LVM

    Type the following:
    Code:
    fdisk /dev/sdb
    n (Create New Partition)
    p (Primary Partition)
    1 (Partition Number)
    {ENTER} (use default for first cylinder)
    {ENTER} (use default for last cylinder)
    t (Change partition type)
    8e (Set to Linux LVM)
    p (Preview how the drive will look)
    w (Write changes)
    Prepare the second drive (/dev/sdc) to be used by the LVM

    Do the exact same steps as above but start with fdisk /dev/sdc

    Create physical volumes using the new drives

    If we type fdisk -l, we now see /dev/sdb1 and /dev/sdc1 which are Linux LVM partitions.

    Type the following to create physical volumes:
    Code:
    pvcreate /dev/sdb1
    pvcreate /dev/sdc1
    Now add the physical volumes to the volume group (LVG) by typing the following:
    Code:
    vgextend LVG /dev/sdb1
    vgextend LVG /dev/sdc1
    Now that the space of both drives have been added to the logical volume group called LVG, we can now allocate that space to grow the logical volumes.

    To get a list of volume paths to use in the next commands, type lvscan to show your current volumes and their sizes.

    Type the following to set the exact size of the volume by specifying the end-result size you want:

    Code:
    lvextend -L3G /dev/LVG/root
    lvextend -L1G /dev/LVG/home
    lvextend -L2G /dev/LVG/tmp
    lvextend -L4G /dev/LVG/usr
    lvextend -L3G /dev/LVG/var
    lvextend -L2G /dev/LVG/srv
    lvextend -L2G /dev/LVG/opt
    lvextend -L4G /dev/LVG/bak
    or you can grow each volume by the specified amount (the number after the plus sign):
    Code:
    lvextend -L+1G /dev/LVG/root
    lvextend -L+0.8G /dev/LVG/home
    lvextend -L+1.5G /dev/LVG/tmp
    lvextend -L+2G /dev/LVG/usr
    lvextend -L+1G /dev/LVG/var
    lvextend -L+1.8G /dev/LVG/srv
    lvextend -L+1.8G /dev/LVG/opt
    lvextend -L+3.5G /dev/LVG/bak
    To see the new sizes, type lvscan
    Code:
    ACTIVE            '/dev/LVG/root' [3.00 GiB] inherit
      ACTIVE            '/dev/LVG/swap' [1.86 GiB] inherit
      ACTIVE            '/dev/LVG/home' [1.00 GiB] inherit
      ACTIVE            '/dev/LVG/tmp' [2.00 GiB] inherit
      ACTIVE            '/dev/LVG/usr' [4.00 GiB] inherit
      ACTIVE            '/dev/LVG/var' [3.00 GiB] inherit
      ACTIVE            '/dev/LVG/srv' [2.00 GiB] inherit
      ACTIVE            '/dev/LVG/opt' [2.00 GiB] inherit
      ACTIVE            '/dev/LVG/bak' [4.00 GiB] inherit
    The last thing to do now is the actual growth of the file systems. We want to grow the existing file systems but only to a certain amount so we do not take up all the space in the volume. We want room for growth in the future so we have time to order and install new drives when needed.
    Code:
    resize2fs /dev/LVG/root 2G
    resize2fs /dev/LVG/home 500M
    resize2fs /dev/LVG/tmp 1G
    resize2fs /dev/LVG/usr 3G
    resize2fs /dev/LVG/var 2G
    resize2fs /dev/LVG/srv 1G
    resize2fs /dev/LVG/opt 1G
    resize2fs /dev/LVG/bak 3G
    If we need to increase space in /var at a later point, we can issue the following command without any downtime (we will automate this in a nifty script later):

    Code:
    resize2fs /dev/LVG/var 2560MB
    We could continue to increase this particular file system all the way until we reach the limit of the volume which is 3 GB at the moment.

    If we were to type df -h right now, we should see something like this:

    Code:
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/LVG-root  1.9G  429M  1.4G  24% /
    udev                  489M  4.0K  489M   1% /dev
    tmpfs                 200M  260K  199M   1% /run
    none                  5.0M     0  5.0M   0% /run/lock
    none                  498M     0  498M   0% /run/shm
    /dev/sda1             179M   47M  122M  28% /boot
    /dev/mapper/LVG-home  488M  9.7M  454M   3% /home
    /dev/mapper/LVG-tmp  1004M   23M  931M   3% /tmp
    /dev/mapper/LVG-usr   3.0G  481M  2.3G  17% /usr
    /dev/mapper/LVG-var   1.8G  267M  1.5G  16% /var
    /dev/mapper/LVG-srv   989M  2.8M  940M   12% /srv
    /dev/mapper/LVG-opt   996M  2.8M  940M   1% /opt
    /dev/mapper/LVG-bak   2.0G   3.0M  1.9G   1% /bak
    Remember, df -h will tell you the size of the file system and lvscan will tell you the size of the volumes where the file systems live in.

    TIP: If you want to see everything in a specific block size, such as everything showing up in megabytes, you can use df --block-size m

    Shutdown and power off the server by typing shutdown -P now

    In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 3 and description of Ubuntu Server 16.04 LTS, Storage space adjusted, Static IP: 192.168.107.2. The Snapshot Manager should now have a nice hierarchy of snapshots (STEP 1 --> STEP 2 --> STEP 3 --> You are here)
    Last edited by LHammonds; October 3rd, 2017 at 04:49 PM. Reason: Modify formatting for UbuntuForums

  5. #5
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Software Configurations


    1. Turn on the server and connect using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    4. At the $ prompt, type the following to install various utilities which are described below:
      Code:
      apt -y install vim-nox p7zip-full ntpdate htop fsarchiver sendemail
      • vim-nox for use instead of the built-in VI editor. more info
      • p7zip-full is a 7-zip archive utility.
      • ntpdate is a time synchronization utility.
      • htop is a CPU/RAM monitoring utility.
      • fsarchiver is a backup utility.
      • sendemail is a command-line email utility.

    5. Change the default shell from dash to bash. Type ls -l /bin/sh to see that it points to /bin/dash. Type dpkg-reconfigure dash and answer No. Type ls -l /bin/sh and it should now be pointing to /bin/bash
    6. It might be necessary to remove AppArmor to avoid problems by typing the following:
      Code:
      /etc/init.d/apparmor stop
      /etc/init.d/apparmor teardown
      update-rc.d -f apparmor remove
      apt-get remove apparmor
    7. Type vi /etc/hosts and add your email server:
      Code:
      192.168.107.25    srv-mail
    8. Test the ability to send email by typing:
      Code:
      sendemail -f root@myserver -t MyTargetAddress@MyDomain.com -u "This is the Subject" -m "This is the body of the email" -s srv-mail:25



    SUDO Warning Message


    1. Enable the default warning message whenever "sudo" is used. Type vi /etc/sudoers and add the following line near the other defaults (instead of "always" you can use "once" too):
      Code:
      Defaults lecture=always
    2. To customize the message, you can create a custom message file. Type vi /etc/lecture and add the following text or whatever you want:
      Code:
      We trust you have received the usual lecture from the local System
      Administrator. It usually boils down to these three things:
      
          #1) Respect the privacy of others.
          #2) Think before you type.
          #3) With great power comes great responsibility.
    3. Now save the file and configure permissions to access that file. Type chmod 644 /etc/lecture
    4. Now point to the newly-created file in the sudoers config file. Type /vi /etc/sudoers
      Code:
      Defaults lecture_file=/etc/lecture



    SSH Login Message


    1. To enable login banners that are displayed before entering a password, edit the following:
      Code:
      vi /etc/issue.net
    2. Add your message however you like to word it and save/close the file:
      Code:
      *********************************************************************
        ALERT! You are entering into a secured area!
        Your IP, Login Time, Username have been recorded.
        This service is restricted to authorized users only.
        All activities on this system are logged.
        Unauthorized access will be reported to the law enforcement agencies.
      *********************************************************************
    3. Enable banners to be displayed by editing the SSH config file:
      Code:
      vi /etc/ssh/ssh_config
      Code:
      Banner /etc/issue.net
    4. Restart the SSH service:
      Code:
      service sshd restart



    Reboot the server by typing reboot

    VMware Tools

    VMware Tools need to be installed if the VM is using a VMware host. This will insure maximum performance in a virtual environment and allow ESXi to interact with the operating system.

    Starting with Ubuntu 16.04, open-vm-tools are installed automatically. We should not need to perform any actions in this section. It is kept for historical reasons.

    Starting with Ubuntu 14.04, we now install drivers from the repository rather than using the "Guest" VMware Tools menu to attach the CD-ROM and install manually.


    1. Connect to the server using PuTTY
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    4. Type the following:
      Code:
      apt install open-vm-tools
      reboot


    VMware Tools Upgrade

    There is no need to manually update the drivers since they are now part of the software repository. If you configure your system to get updates automatically, vmware drivers will get updated as well if there are any updates.

    VirtualBox Guest Additions - Installation

    The Guest Additions need to be installed if the VM is using a VirtualBox host. This will insure maximum performance in a virtual environment.


    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    4. You need to perform the following commands to fulfill the prerequisites:
      Code:
      apt install dkms
      reboot
    5. Connect to the server using PuTTY.
    6. At the login prompt, login with your administrator account (administrator / myadminpass)
    7. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    8. From the VirtualBox menu, click Devices, Install Guest Additions
    9. At the console, type the following:
      Code:
      mkdir -p /mnt/cdrom
      mount /dev/cdrom /mnt/cdrom
      /mnt/cdrom/VBoxLinuxAdditions.run
    10. NOTE: The X Windows System drivers will fail to load because this is a headless server with no GUI (which is OK)
    11. To see if the services are running, type /etc/init.d/vboxadd-service status or service vboxadd-service status



    VirtualBox Guest Additions - Upgrading

    If VirtualBox is updated on the host machine, each VM also needs the upgraded Guest Additions.

    Then mount the CDROM and run the installer just like the above. Reboot after it is upgraded.


    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    4. From the VirtualBox menu, click Devices, Install Guest Additions
    5. At the console, type the following:
      Code:
      mount /dev/cdrom /mnt/cdrom
      /mnt/cdrom/VBoxLinuxAdditions.run
      reboot



    VirtualBox Guest Additions - Uninstallation

    If a VM will be migrated from VirtualBox to something like a VMware, the Guest Additions on the VM will need to be removed.


    1. Connect to the server using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    4. Type the following:
      Code:
      cd /opt/VBox*
      ./uninstall.sh



    Configure Ubuntu for File Sharing

    This file sharing section is optional but can be handy if you need to swap files between the Linux server and a Windows machine.

    This documentation will utilize this share for passing pre-configured files (configs, scripts, etc.) to make it faster/easier during installation.


    1. Start the Ubuntu server and connect using PuTTY.
    2. At the login prompt, login with your administrator account (administrator / myadminpass)
    3. At the $ prompt, temporarily grant yourself super user privileges by typing sudo su {ENTER} and then provide the administrator password (myadminpass).
    4. Install Samba by typing apt -y install samba cifs-utils (NOTE: To share a folder with Windows, you just need the samba package, to connect to a Windows share, you need both samba and cifs-utils)
    5. Type the following commands:
      Code:
      cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
      mkdir -p /srv/samba/share
      chown nobody:nogroup /srv/samba/share/
      chmod 0777 /srv/samba/share
    6. Edit the configuration file by typing vi /etc/samba/smb.conf
    7. Change:
      Code:
      workgroup = WORKGROUP
      to:
      Code:
      workgroup = work
      (you are using the domain alias)
    8. Add the following section to the end of the file:
      Code:
      [share]
      comment = Ubuntu File Server Share
      path = /srv/samba/share
      browsable = yes
      guest ok = yes
      read only = no
      create mask = 0755
    9. Save and exit the file.
    10. Restart the samba services to utilize the new configuration by typing:
      Code:
      service smbd restart
      service nmbd restart
    11. You should now be able to click Start --> Run and type \\srv-ubuntu or \\192.168.107.2 {ENTER} and see an explorer window with a Share folder. Drag-n-drop a file into the Share folder. If it worked, it will not display an error message and you should be able to view it from the server by typing ls -l /srv/samba/share/
    12. Shutdown and power off the server by typing shutdown -P now {ENTER}
    13. In VM menu, select VM --> Snapshot --> Take Snapshot. Give it a name like STEP 4 and description of Ubuntu Server 16.04 LTS, File share configured, Static IP: 192.168.107.2. The Snapshot Manager should now have a nice hierarchy of snapshots (STEP 1 --> STEP 2 --> STEP 3 --> STEP 4 --> You are here)
    Last edited by LHammonds; October 3rd, 2017 at 04:54 PM. Reason: Modify formatting for UbuntuForums

  6. #6
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Scripting

    Much of the solutions beyond this point involve scripts (programming snippets / automated commands).

    In particular, they are Bash Scripts. I chose this due to its popularity and the fact it comes with Ubuntu. I try to make use of what comes with the system without requiring additional software / services unless they really add to the bottom line such as decreasing the time it takes for a process to run or to conserve storage and bandwidth usage.

    When setting up a server and testing things out, there is typically very little concern for procedures / process since much of the activity is exploration and experimentation as well as not having an impact on production. However, once a server goes into production, processes and procedures need to be in place to ensure the availability of the services being provided.

    In regards to these scripts, they will be treated like any other program and will require being tested, documented and go through a promotion process.

    The ideal situation would involve 3 servers (for a single server setup). A test / development server, a quality assurance staging server and the production server itself. If 3 servers cannot be utilized, then it can still work well with 2 servers. Testing scripts / programs / restore on the production server is not advisable and many times impractical...how can you test your restore process / data periodically if you only have a production server?

    The QA Staging server would resemble the production server as close as possible. The server should be setup in such a way that production backups are restored to this server which also tests and validates the backup / restore process as well as maintains a close representation of the production server to mitigate variable risk involved when testing new or modified programs and upgrades.

    The test / development server can serve as the QA server if absolutely necessary.

    The directory structure and how scripts can import other scripts will be configured to facilitate this process.

    Example:

    Directory path for scripts to import common variables, functions and server settings: /var/scripts/common/

    Directory path for production scripts: /var/scripts/prod/

    Directory path for QA staging area scripts: /var/scripts/qa/

    Directory path for test / development scripts: /var/scripts/test/

    Directory path for data for use by scripts: /var/scripts/data/

    With a production and test servers on physically different machines, the "common" scripts folder can be custom-tailored for that environment and allow for minimal changes to a script when running on the test, QA or production server. This is similar to "normalizing" a database. If you have a variable, path or function that is duplicated in multiple scripts, consider pulling it out and placing it in the common folder. If ever you need to change who receives the email reports, you only need to update a single script and all programs will use the new reference from that point on.

    Most of my scripts will import a file called "standard.conf" from the common script folder.

    /var/scripts/common/standard.conf (contents of the file on the production server)
    Code:
    ## Global Variables ##
    Company="abc"
    TempDir="/tmp"
    LogDir="/var/log"
    ShareDir="/srv/samba/share"
    MyDomain="mydomain.com"
    AdminEmail="admin@${MyDomain}"
    ReportEmail="LHammonds <lhammonds@${MyDomain}>"
    BackupDir="/bak"
    OffsiteDir="/mnt/backup"
    OffsiteTestFile="${OffsiteDir}/online.txt"
    ArchiveMethod="tar.7z"    ## Choices are tar.7z or tgz
    Hostname="$(hostname -s)"
    ScriptName="$0"
    ScriptDir="/var/scripts"
    MailFile="${TempDir}/mailfile.$$"
     
    ## Global Functions ##
     
    function f_sendmail()
    {
      ## Purpose: Send administrative email message.
      ## Parameter #1 = Subject
      ## Parameter #2 = Body
      sendemail -f "${AdminEmail}" -t "${ReportEmail}" -u "${1}" -m "${2}\n\nServer: ${Hostname}\nProgram: ${ScriptName}\nLog: ${LogFile}" -s srv-mail:25 1>/dev/null 2>&1
    }
     
    function f_sendusermail()
    {
      ## Purpose: Send end-user email message.
      ## Parameter #1 = To
      ## Parameter #2 = Subject
      ## Parameter #3 = Body
      sendemail -f "${AdminEmail}" -t "${1}" -u "${2}" -m "${3}" -s srv-mail:25 1>/dev/null 2>&1
    }
     
    function f_mount()
    {
      ## Mount the pre-configured Windows share folder.
      ## NOTE: The Windows share should have a file called "online.txt"
      mount -t cifs //srv-backup/myshare ${OffsiteDir} --options nouser,rw,nofail,noatime,noexec,credentials=/etc/cifspw
    }
     
    function f_umount()
    {
      ## Dismount the Windows share folder.
      ## NOTE: The unmounted folder should have a file called "offline.txt"
      umount ${OffsiteDir}
    }

    /var/scripts/common/standard.conf (contents of the file on the test server)
    Code:
    ## Global Variables ##
    Company="abc"
    TempDir="/tmp"
    LogDir="/var/log"
    ShareDir="/srv/samba/share"
    MyDomain="mytestdomain.com"
    AdminEmail="test1@${MyDomain}"
    ReportEmail="test2@${MyDomain}"
    BackupDir="/bak"
    OffsiteDir="/mnt/fakedir"
    OffsiteTestFile="${OffsiteDir}/online.txt"
    ArchiveMethod="tar.7z"    ## Choices are tar.7z or tgz
    Hostname="$(hostname -s)"
    ScriptName="$0"
    ScriptDir="/var/scripts"
    MailFile="${TempDir}/mailfile.$$"
     
    ## Global Functions ##
     
    function f_sendmail()
    {
      ## Purpose: Send administrative email message.
      ## Parameter #1 = Subject
      ## Parameter #2 = Body
      sendemail -f "${AdminEmail}" -t "${ReportEmail}" -u "${1}" -m "${2}\n\nServer: ${Hostname}\nProgram: ${ScriptName}\nLog: ${LogFile}" -s srv-mail:25 1>/dev/null 2>&1
    }
     
    function f_sendusermail()
    {
      ## Purpose: Send end-user email message.
      ## Parameter #1 = To
      ## Parameter #2 = Subject
      ## Parameter #3 = Body
      sendemail -f "${AdminEmail}" -t "${1}" -u "${2}" -m "${3}" -s srv-mail:25 1>/dev/null 2>&1
    }
     
    function f_mount()
    {
      ## Mount the pre-configured Windows share folder.
      ## NOTE: The Windows share should have a file called "online.txt"
      mount -t cifs //mypc/share ${OffsiteDir} --options nouser,rw,nofail,noexec,credentials=/etc/cifspw
    }
     
    function f_umount()
    {
      ## Dismount the Windows share folder.
      ## NOTE: The unmounted folder should have a file called "offline.txt"
      umount ${OffsiteDir}
    }

    When receiving administrative email notifications, the server name, script name and path will be included at the bottom of the email every time. It will be readily apparent if the email was generated from the test, qa or production server simply because of the location (even if test, qa and production are all on the same server).

    Here are the scripts to help automate the creation of this structure on the various servers (would run all of them if all are the same box)

    setup-script-prod.sh
    Code:
    #!/bin/bash
    if [ ! -d /var/scripts/prod ]; then
      mkdir -p /var/scripts/prod
    fi
    if [ ! -d /var/scripts/common ]; then
      mkdir -p /var/scripts/common
    fi
    if [ ! -d /var/scripts/data ]; then
      mkdir -p /var/scripts/data
    fi
    chown root:root -R /var/scripts
    chmod 0755 -R /var/scripts
    setup-script-qa.sh
    Code:
    #!/bin/bash
    if [ ! -d /var/scripts/qa ]; then
      mkdir -p /var/scripts/qa
    fi
    if [ ! -d /var/scripts/common ]; then
      mkdir -p /var/scripts/common
    fi
    if [ ! -d /var/scripts/data ]; then
      mkdir -p /var/scripts/data
    fi
    chown root:root -R /var/scripts
    chmod 0777 -R /var/scripts
    setup-script-test.sh
    Code:
    #!/bin/bash
    if [ ! -d /var/scripts/test ]; then
      mkdir -p /var/scripts/test
    fi
    if [ ! -d /var/scripts/common ]; then
      mkdir -p /var/scripts/common
    fi
    if [ ! -d /var/scripts/data ]; then
      mkdir -p /var/scripts/data
    fi
    chown root:root -R /var/scripts
    chmod 0777 -R /var/scripts
    Last edited by LHammonds; October 4th, 2017 at 05:48 AM. Reason: Modify formatting for UbuntuForums

  7. #7
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Check Storage Space

    In favor of managing by exception, this script that can be scheduled to run daily to check the file systems to see if they are getting close to filling up and will automatically expand them a little bit and give you an email notice. Everything is done at the megabyte level. If you do not want the script to perform the increase, simply add a pound sign in front of the resize2fs command on line 62 to comment it out. Might also want to modify the log and email messages so it does not look like it actually "performed" the resize but instead is telling YOU how to perform the resize.

    Here are the lines added to the root crontab schedule which will check each file system.

    The script check the specified file system and see if the amount of space free is less than the threshold (e.g. 100 MB). If the file system has free space that is less than the threshold, it will attempt to add the specified amount (e.g. 50 MB).

    crontab
    Code:
    0 1 * * * /var/scripts/prod/check-storage.sh root 500 100 > /dev/null 2>&1
    15 1 * * * /var/scripts/prod/check-storage.sh home 100 50 > /dev/null 2>&1
    30 1 * * * /var/scripts/prod/check-storage.sh tmp 100 50 > /dev/null 2>&1
    45 1 * * * /var/scripts/prod/check-storage.sh usr 100 50 > /dev/null 2>&1
    0 2 * * * /var/scripts/prod/check-storage.sh var 100 50 > /dev/null 2>&1
    15 2 * * * /var/scripts/prod/check-storage.sh srv 100 50 > /dev/null 2>&1
    30 2 * * * /var/scripts/prod/check-storage.sh opt 100 50 > /dev/null 2>&1
    45 2 * * * /var/scripts/prod/check-storage.sh bak 100 50 > /dev/null 2>&1
    /var/scripts/prod/check-storage.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : check-storage.sh
    ## Version       : 1.2
    ## Date          : 2017-03-17
    ## Author        : LHammonds
    ## Purpose       : Check available space for a file system and expand if necessary.
    ## Compatibility : Verified on Ubuntu Server 12.04 thru 16.04 LTS
    ## Requirements  : None
    ## Run Frequency : Recommend once per day for each FS to monitor.
    ## Parameters    :
    ##    1 = (Required) File System name (e.g. var)
    ##    2 = (Required) File System Threshold in MB (e.g. 50)
    ##    3 = (Required) Amount to increase File System in MB (e.g. 50)
    ## Exit Codes    :
    ##    0 = Success (either nothing was done or FS expanded without error)
    ##    1 = ERROR: Missing or incorrect parameter(s)
    ##    2 = ERROR: Invalid parameter value(s)
    ##    4 = ERROR: Lock file detected
    ##    8 = ERROR: Resize2fs error
    ##   16 = SEVERE: No room to expand
    ##   32 = ERROR: Script not run by root user
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-05-11 LTH Created script.
    ## 2013-03-11 LTH Added company prefix to logs.
    ## 2017-03-17 LTH Adjusted variable casing.
    #############################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LogFile="${LogDir}/${Company}-check-storage.log"
    LockFile="${TempDir}/${Company}-check-storage.lock"
    ErrorFlag=0
    ReturnCode=0
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    
    function f_cleanup()
    {
      if [ -f ${LockFile} ];then
        ## Remove lock file so other check space jobs can run.
        rm ${LockFile} 1>/dev/null 2>&1
      fi
      exit ${ErrorFlag}
    }
    
    function f_showhelp()
    {
      echo -e "\nUsage : ${ScriptName} FileSystemName ThresholdSizeInMB AmountToIncreaseByInMB\n"
      echo -e "\nExample: ${ScriptName} var 50 50\n"
    }
    
    function f_auto-increment()
    {
      let RoomInLV=${LVSize}-${FSSize}
      if [[ ${RoomInLV} -gt ${FSIncreaseBy} ]]; then
        ## There is room in the LV to increase space to the FS.
        resize2fs ${FSVol} ${NewFSSize}M
        ReturnCode=$?
        echo "`date +%Y-%m-%d_%H:%M:%S` --- resize2fs ${FSVol} ${NewFSSize}M, ReturnCode=${ReturnCode}" | tee -a ${LogFile}
        if [[ ${ReturnCode} -ne 0 ]]; then
          ## There was an error in resize2fs.
          return ${ReturnCode}
        fi
      else
        ## There is not enough room in the LV to increase space in the FS.
        return 50
      fi
      return 0
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    if [ -f ${LockFile} ]; then
      # Lock file detected.  Abort script.
      echo "Check space script aborted"
      echo "This script tried to run but detected the lock file: ${LockFile}"
      echo "Please check to make sure the file does not remain when check space is not actually running."
      f_sendmail "ERROR: check storage script aborted" "This script tried to run but detected the lock file: ${LockFile}\n\nPlease check to make sure the file does not remain when check space is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LockFile}'"
      ErrorFlag=4
      f_cleanup
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${ScriptName}" > ${LockFile}
    fi
    
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo "ERROR: Root user required to run this script."
      echo ""
      ErrorFlag=32
      f_cleanup
    fi
    
    ## Check existance of required command-line parameters.
    case "$1" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSName=$1
        ;;
    esac
    case "$2" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSThreshold=$2
        ;;
    esac
    case "$3" in
      "")
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      --help|-h|-?)
        f_showhelp
        ErrorFlag=1
        f_cleanup
        ;;
      *)
        FSIncreaseBy=$3
        ;;
    esac
    
    ## Check validity of File System name.
    case "${FSName}" in
      "root")
        FSVol="/dev/LVG/root"
        FSMap="/dev/mapper/LVG-root"
        ;;
      "home")
        FSVol="/dev/LVG/home"
        FSMap="/dev/mapper/LVG-home"
        ;;
      "tmp")
        FSVol="/dev/LVG/tmp"
        FSMap="/dev/mapper/LVG-tmp"
        ;;
      "opt")
        FSVol="/dev/LVG/opt"
        FSMap="/dev/mapper/LVG-opt"
        ;;
      "bak")
        FSVol="/dev/LVG/bak"
        FSMap="/dev/mapper/LVG-bak"
        ;;
      "usr")
        FSVol="/dev/LVG/usr"
        FSMap="/dev/mapper/LVG-usr"
        ;;
      "var")
        FSVol="/dev/LVG/var"
        FSMap="/dev/mapper/LVG-var"
        ;;
      "srv")
        FSVol="/dev/LVG/srv"
        FSMap="/dev/mapper/LVG-srv"
        ;;
      *)
        echo "ERROR: ${FSName} does not match a known file system defined in this script."
        f_showhelp
        ErrorFlag=2
        f_cleanup
        ;;
    esac
    
    ## Check validity of threshold value.
    test ${FSThreshold} -eq 0 1>/dev/null 2>&1
    if [[ $? -eq 2 ]]; then
      ## Threshold parameter is not an integer.
      echo "ERROR: ${FSThreshold} is not an integer."
      f_showhelp
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Check validity of increment value.
    test ${FSIncreaseBy} -eq 0 1>/dev/null 2>&1
    if [[ $? -eq 2 ]]; then
      ## FSIncreaseBy parameter is not an integer.
      echo "ERROR: ${FSIncreaseBy} is not an integer."
      f_showhelp
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Get available space for the file system.
    FSAvailable="`df --block-size=m ${FSMap} | awk '{ print $4 }' | tail -n 1 | sed 's/M//'`"
    
    ## Get the current size of the File System.
    FSSize="`df --block-size=m ${FSMap} | awk '{ print $2 }' | tail -n 1 | sed 's/M//'`"
    
    ## Get the current size of the Logical Volume for the File System
    LVSize="`lvs --noheadings --nosuffix --units=m ${FSMap} | awk '{ print $4}' | sed 's/[.].*//'`"
    
    ## Calculate the new size of the FS in case we need it.
    let NewFSSize=${FSSize}+${FSIncreaseBy}
    
    if [[ ${FSAvailable} -lt ${FSThreshold} ]]; then
      echo "`date +%Y-%m-%d_%H:%M:%S` - Starting expansion of ${FSVol}" | tee -a ${LogFile}
      echo "`date +%Y-%m-%d_%H:%M:%S` --- LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvail=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB" | tee -a ${LogFile}
      ## Run the auto-expansion function.
      f_auto-increment
      ReturnCode=$?
      case ${ReturnCode} in
      0)
        f_sendmail "NOTICE: File System Expanded" "${FSVol} was expanded because it was nearing max capacity.  Please review disk space usage and plan appropriately. LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB"
        ;;
      50)
        echo "`date +%Y-%m-%d_%H:%M:%S` - SEVERE: No room to expand ${FSVol}" | tee -a ${LogFile}
        ErrorFlag=16
        f_sendmail "SEVERE: No room to expand ${FSVol}" "There is not enough room in the Logical Volume to expand the ${FSVol} File System.  Immediate action is required.  Make sure there is free space in the Volume Group 'LVG' and then expand the Logical Volume...then expand the File System.\n\nLVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB.\n\nType 'vgs' to see if there is any free space in the Volume Group which can be given to the Logical Volume.\n\nType 'lvs' to see the current sizes of the LVs.\n\nType 'lvdisplay' to see a list of Logical Volumes so you can get the LV Name which is used in the lvextend and resize2fs commands.\n\nType 'lvextend -L+50M /dev/LVG/var' if you want to extend the var Logical Volume by 50 megabytes (assuming there is 50MB available in the Volume Group).\n\nType 'df --block-size=m' to see a list of file systems and their associated size and available space.\n\nType 'resize2fs /dev/LVG/var ${NewFSSize}M' to set the size of var to ${NewFSSize} megabytes. Make sure you set the size to the desired end-result which should be LARGER than the current FS size so you do not lose data."
        ;;
      *)
        echo "`date +%Y-%m-%d_%H:%M:%S` - ERROR: Expansion failure for ${FSVol}" | tee -a ${LogFile}
        ErrorFlag=8
        f_sendmail "ERROR: File System Expansion Failed" "${FSVol} Expansion failed with return code of ${ReturnCode}.  LVSize=${LVSize}MB, FSSize=${FSSize}MB, FSAvailable=${FSAvailable}MB, FSThreshold=${FSThreshold}MB, FSIncreaseBy=${FSIncreaseBy}MB"
        ;;
      esac
      echo "`date +%Y-%m-%d_%H:%M:%S` - Finished expansion of ${FSVol}" | tee -a ${LogFile}
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` - ${FSVol} ${FSAvailable}M>${FSThreshold}M No action required." | tee -a ${LogFile}
    fi
    
    ## Perform cleanup routine.
    f_cleanup
    Here is the typical output when it does not have to increase the FS:

    /var/log/check-storage.log
    Code:
    2017-02-01_01:00:00 - /dev/LVG/root 1377M>500M No action required.
    2017-02-01_01:15:00 - /dev/LVG/home 454M>100M No action required.
    2017-02-01_01:30:00 - /dev/LVG/tmp 776M>100M No action required.
    2017-02-01_01:45:00 - /dev/LVG/usr 1126M>100M No action required.
    2017-02-01_02:00:00 - /dev/LVG/var 1417M>100M No action required.
    2017-02-01_02:15:00 - /dev/LVG/srv 935M>100M No action required.
    2017-02-01_02:30:00 - /dev/LVG/opt 935M>100M No action required.
    2017-02-01_02:45:00 - /dev/LVG/bak 1871M>100M No action required.
    2017-02-02_01:00:00 - /dev/LVG/root 1377M>500M No action required.
    2017-02-02_01:15:00 - /dev/LVG/home 454M>100M No action required.
    2017-02-02_01:30:00 - /dev/LVG/tmp 776M>100M No action required.
    2017-02-02_01:45:00 - /dev/LVG/usr 1126M>100M No action required.
    2017-02-02_02:00:00 - /dev/LVG/var 1417M>100M No action required.
    2017-02-02_02:15:00 - /dev/LVG/srv 935M>100M No action required.
    2017-02-02_02:30:00 - /dev/LVG/opt 935M>100M No action required.
    2017-02-02_02:45:00 - /dev/LVG/bak 1871M>100M No action required.
    Here is a sample of what the log will look like when it performs increases:

    /var/log/check-storage.log
    Code:
    2017-02-02_01:30:00 - Starting expansion of /dev/LVG/tmp
    2017-02-02_01:30:00 --- LVSize=2048MB, FSSize=1004MB, FSAvail=93MB, FSThreshold=100MB, IncreaseBy=50MB
    2017-02-02_01:30:00 --- resize2fs /dev/LVG/temp 1054, ReturnCode=0
    2017-02-02_01:30:00 - Finished expansion of /dev/LVG/tmp
    2017-02-02_02:00:00 - Starting expansion of /dev/LVG/var
    2017-02-02_02:00:00 --- LVSize=3072MB, FSSize=1901MB, FSAvail=95MB, FSThreshold=100MB, IncreaseBy=50MB
    2017-02-02_02:00:00 --- resize2fs /dev/LVG/var 1951, ReturnCode=0
    2017-02-02_02:00:00 - Finished expansion of /dev/LVG/var
    2017-02-02_02:45:00 - Starting expansion of /dev/LVG/bak
    2017-02-02_02:45:00 --- LVSize=4096MB, FSSize=1996MB, FSAvail=91MB, FSThreshold=100MB, IncreaseBy=50MB
    2017-02-02_02:45:00 --- resize2fs /dev/LVG/bak 2044, ReturnCode=0
    2017-02-02_02:45:00 - Finished expansion of /dev/LVG/bak
    Last edited by LHammonds; October 3rd, 2017 at 04:09 PM. Reason: Modify formatting for UbuntuForums

  8. #8
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    APT Upgrade

    This script that can be scheduled to run daily to check for updates and then install them if available.

    The following is an example of a crontab entry to schedule the script to run once per day @ 3am.

    /var/scripts/data/crontab.root
    Code:
    0 3 * * * /var/scripts/prod/apt-upgrade.sh > /dev/null 2>&1
    /var/scripts/prod/apt-upgrade.sh
    Code:
    #!/bin/bash
    #############################################
    ## Name          : apt-upgrade.sh
    ## Version       : 1.3
    ## Date          : 2017-03-16
    ## Author        : LHammonds
    ## Purpose       : Keep system updated (rather than use unattended-upgrades)
    ## Compatibility : Verified on Ubuntu Server 16.04 LTS
    ## Requirements  : Sendemail, run as root
    ## Run Frequency : Recommend once per day.
    ## Parameters    : None
    ## Exit Codes    :
    ##    0 = Success
    ##    1 = ERROR: Lock file detected.
    ##    2 = ERROR: Not run as root user.
    ##    4 = ERROR: APT update Error.
    ##    8 = ERROR: APT upgrade Error.
    ##   16 = ERROR: APT autoremove Error.
    ##   32 = ERROR: APT autoclean Error.
    ##   64 = ERROR: APT clean Error.
    ################ CHANGE LOG #################
    ## DATE       WHO WHAT WAS CHANGED
    ## ---------- --- ----------------------------
    ## 2012-06-01 LTH Created script.
    ## 2013-01-08 LTH Allow visible status output if run manually.
    ## 2013-03-11 LTH Added company prefix to log files.
    ## 2017-03-16 LTH Made compatible with 16.04 LTS
    #############################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LogFile="${LogDir}/${Company}-apt-upgrade.log"
    LockFile="${TempDir}/${Company}-apt-upgrade.lock"
    ErrorFlag=0
    ErrorMsg=""
    ReturnCode=0
    AptCmd="$(which apt)"
    AptGetCmd="$(which apt-get)"
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    function f_cleanup()
    {
      if [ -f ${LockFile} ]; then
        ## Remove lock file so subsequent jobs can run.
        rm ${LockFile} 1>/dev/null 2>&1
      fi
      ## Temporarily pause script in case user is watching output.
      sleep 2
      if [ ${ErrorFlag} -gt 0 ]; then
        ## Display error message to user in case being run manually.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: ${ErrorMsg}" | tee -a ${LogFile}
        ## Email error notice.
        f_sendmail "ERROR ${ErrorFlag}: Script aborted" "${ErrorMsg}"
      fi
      exit ${ErrorFlag}
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    clear
    if [ -f ${LockFile} ]; then
      # Lock file detected.  Abort script.
      echo "** Script aborted **"
      echo "This script tried to run but detected the lock file: ${LockFile}"
      echo "Please check to make sure the file does not remain when check space is not actually running."
      ErrorMsg="This script tried to run but detected the lock file: ${LockFile}\n\nPlease check to make sure the file does not remain when check space is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LockFile}'"
      ErrorFlag=1
      f_cleanup
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${ScriptName}" > ${LockFile}
    fi
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo -e "ERROR: Root user required to run this script.\n"
      ErrorMsg="Root user required to run this script."
      ErrorFlag=2
      f_cleanup
    fi
    echo "`date +%Y-%m-%d_%H:%M:%S` - Begin script." | tee -a ${LogFile}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Apt-Get Update" | tee -a ${LogFile}
    ${AptGetCmd} update > /dev/null 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorMsg="Apt-Get Update return code of ${ReturnCode}"
      ErrorFlag=4
      f_cleanup
    fi
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Apt-Get Upgrade" | tee -a ${LogFile}
    echo "--------------------------------------------------" >> ${LogFile}
    ${AptGetCmd} --assume-yes upgrade >> ${LogFile} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorMsg="Apt-Get Upgrade return code of ${ReturnCode}"
      ErrorFlag=8
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LogFile}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Apt-Get Autoremove" | tee -a ${LogFile}
    echo "--------------------------------------------------" >> ${LogFile}
    ${AptGetCmd} --assume-yes autoremove >> ${LogFile} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorMsg="Apt-Get Autoremove return code of ${ReturnCode}"
      ErrorFlag=16
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LogFile}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Apt-get Autoclean" | tee -a ${LogFile}
    echo "--------------------------------------------------" >> ${LogFile}
    ${AptGetCmd} autoclean >> ${LogFile} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorMsg="Apt-Get Autoclean return code of ${ReturnCode}"
      ErrorFlag=32
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LogFile}
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Apt-get Clean" | tee -a ${LogFile}
    echo "--------------------------------------------------" >> ${LogFile}
    ${AptGetCmd} clean >> ${LogFile} 2>&1
    ReturnCode=$?
    if [[ "${ReturnCode}" -gt 0 ]]; then
      ErrorMsg="Apt-Get Clean return code of ${ReturnCode}"
      ErrorFlag=64
      f_cleanup
    fi
    echo "--------------------------------------------------" >> ${LogFile}
    echo "`date +%Y-%m-%d_%H:%M:%S` - End script." | tee -a ${LogFile}
    
    ## Perform cleanup routine.
    f_cleanup
    Here is the typical output:

    /var/log/apt-upgrade.log
    Code:
    2017-03-16_16:15:08 - Begin script.
    2017-03-16_16:15:08 --- Apt-Get Update
    2017-03-16_16:15:11 --- Apt-Get Upgrade
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Calculating upgrade...
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    --------------------------------------------------
    2017-03-16_16:15:12 --- Apt-Get Autoremove
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    --------------------------------------------------
    2017-03-16_16:15:13 --- Apt-get Autoclean
    --------------------------------------------------
    Reading package lists...
    Building dependency tree...
    Reading state information...
    --------------------------------------------------
    2017-03-16_16:15:13 --- Apt-get Clean
    --------------------------------------------------
    Last edited by LHammonds; October 3rd, 2017 at 04:09 PM. Reason: Modify formatting for UbuntuForums

  9. #9
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Backup Partitions Using LVM Snapshots and FSArchiver

    This method will allow online backup of the server at the partition level. It is designed to run via crontab schedule but can also be run manually.

    This should be considered a full backup which means you will probably need to rely on other methods for granular backups and restores such as using rsync at the file level.

    This method is great for backing up a system just prior to and just after a major upgrade of the OS or application. It is not very helpful for retrieving individual files although it could be done but would require a bit of work by temporarily restoring to an unused area, retrieving the file(s) and then destroying the temporary partition.

    The /bak partition is skipped because that is where the archives are being stored.

    The /tmp partition is skipped because there should not be anything in there that needs to be restored...but feel free to include it if you like.

    The script below was built around a few very basic commands that do the bulk of the work but most of the code is for error handling.

    Here are examples of the commands:
    Code:
    ## Create the snapshot volume of the partition to be backed up.
    lvcreate --size=5G --snapshot --name="tempsnap" /dev/LVG/root
     
    ## Create the compressed and encrypted archive of the snapshot.
    fsarchiver savefs --compress=7 --jobs=1 --cryptpass="abc123" --label="insert comment here" /bak/root.fsa /dev/LVG/tempsnap
     
    ## Create an informational text file about the archive.
    fsarchiver archinfo --cryptpass="abc123" /bak/root.fsa > /bak/root.txt 2>&1
     
    ## Remove the snapshot.
    lvremove --force /dev/LVG/tempsnap
     
    ## Create a checksum file about the archive.
    md5sum /bak/root.fsa > /bak/root.md5
     
    ## Verify that the checksum file can validate against the archive.
    md5sum --check /bak/root.md5
    Here is an example of a crontab entry to run the script once a day.

    /var/scripts/data/crontab.root
    Code:
    0 4 * * * /var/scripts/prod/back-parts.sh > /dev/null 2>&1
    Here is the script.

    /var/scripts/prod/back-parts.sh
    Code:
    #!/bin/bash
    #############################################################
    ## Name : back-parts.sh (Backup Partitions)
    ## Version : 1.3
    ## Date : 2017-10-04
    ## Author : LHammonds
    ## Purpose : Backup partitions
    ## Compatibility : Verified on Ubuntu Server 12.04 thru 16.04 LTS (fsarchiver 0.6.12)
    ## Requirements : Fsarchiver, Sendemail, run as root
    ## Run Frequency : Once per day or as often as desired.
    ## Parameters : None
    ## Exit Codes :
    ## 0  = Success
    ## 1  = ERROR: Lock file detected
    ## 2  = ERROR: Must be root user
    ## 4  = ERROR: Missing software
    ## 8  = ERROR: LVM problems
    ## 16 = ERROR: File creation problems
    ## 32 = ERROR: Mount/Unmount problems
    ###################### CHANGE LOG ###########################
    ## DATE       VER WHO WHAT WAS CHANGED
    ## ---------- --- --- ---------------------------------------
    ## 2013-01-09 1.0 LTH Created script.
    ## 2017-03-16 1.1 LTH Updated variable standards.
    ## 2017-08-31 1.2 LTH Added create folder if not exist.
    ## 2017-10-04 1.3 LTH Set file permissions.
    #############################################################
    
    ## Import standard variables and functions. ##
    source /var/scripts/common/standard.conf
    
    ## Define local variables.
    LogFile="${LogDir}/${Company}-back-parts.log"
    LockFile="${TempDir}/${Company}-back-parts.lock"
    LVG="/dev/LVG"
    TempLV="${LVG}/tempsnap"
    MaxTempVolSize=1G
    ErrorFlag=0
    ReturnCode=0
    CryptPass="abc123"
    
    #######################################
    ##            FUNCTIONS              ##
    #######################################
    
    function f_cleanup()
    {
      if [ -f ${LockFile} ];then
        ## Remove lock file so other check space jobs can run.
        rm ${LockFile} 1>/dev/null 2>&1
      fi
      if [ ${ErrorFlag} != 0 ]; then
        f_sendmail "ERROR: Script Failure" "Please review the log file on ${Hostname}${LogFile}"
        echo "`date +%Y-%m-%d_%H:%M:%S` - Backup aborted." >> ${LogFile}
      fi
      exit ${ErrorFlag}
    }
    
    function f_archive_fs()
    {
      FSName=$1
      FSPath=$2
    
      ## Purge old backup files.
      if [ -f ${BackupDir}/${Hostname}-${FSName}.fsa ]; then
        rm ${BackupDir}/${Hostname}-${FSName}.fsa
      fi
      if [ -f ${BackupDir}/${Hostname}-${FSName}.txt ]; then
        rm ${BackupDir}/${Hostname}-${FSName}.txt
      fi
      if [ -f ${BackupDir}/${Hostname}-${FSName}.md5 ]; then
        rm ${BackupDir}/${Hostname}-${FSName}.md5
      fi
    
      ## Unmount FileSystem.
      umount /${FSName}
    
      LVLabel="${Hostname}:${FSPath}->/${FSName}"
      ## Create the compressed and encrypted archive of the snapshot.
      fsarchiver savefs --compress=7 --jobs=1 --cryptpass="${CryptPass}" --label="${LVLabel}" ${BackupDir}/${Hostname}-${FSName}.fsa ${FSPath} > /dev/null 2>&1
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of the archive failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of ${BackupDir}/${FSName}.fsa failed, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Create an informational text file about the archive.
      fsarchiver archinfo --cryptpass="${CryptPass}" ${BackupDir}/${Hostname}-${FSName}.fsa > ${BackupDir}/${Hostname}-${FSName}.txt 2>&1
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of info text failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of info file failed for ${BackupDir}/${FSName}.txt, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Create a checksum file about the archive.
      md5sum ${BackupDir}/${Hostname}-${FSName}.fsa > ${BackupDir}/${Hostname}-${FSName}.md5
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of md5 checksum failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of checksum failed for ${BackupDir}/${FSName}.md5, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Verify that the checksum file can validate against the archive.
      md5sum --check --status ${BackupDir}/${Hostname}-${FSName}.md5
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Verification failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: md5 validation check failed for ${BackupDir}/${FSName}.md5. Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Set file permissions.
      chmod 0600 ${BackupDir}/${Hostname}-${FSName}.*
    
      BackupSize=`ls -lak --block-size=m "${BackupDir}/${Hostname}-${FSName}.fsa" | awk '{ print $5 }'`
    
      echo "`date +%Y-%m-%d_%H:%M:%S` --- Created: ${BackupDir}/${Hostname}-${FSName}.fsa, ${BackupSize}" >> ${LogFile}
    
      ## Make sure target folder exists.
      if [ ! -d ${OffsiteDir}/${Hostname} ]; then
        ## Create folder.  This is typical of 1st time use.
        mkdir -p ${OffsiteDir}/${Hostname}
      fi
      ## Copy the backup to an offsite storage location.
      echo "`date +%Y-%m-%d_%H:%M:%S` --- Copying archive file to offsite location." >> ${LogFile}
      cp ${BackupDir}/${Hostname}-${FSName}.* ${OffsiteDir}/${Hostname}/. 1>/dev/null 2>&1
      if [ ! -f ${OffsiteDir}/${Hostname}/${Hostname}-${FSName}.fsa ]; then
        ## NON-FATAL ERROR: Copy command did not work.  Send email notification.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- WARNING: Remote copy failed. ${OffsiteDir}/${Hostname}/${Hostname}-${FSName}.fsa does not exist!" >> ${LogFile}
        f_sendmail "Backup Failure - Remote Copy" "Remote copy failed. ${OffsiteDir}/${Hostname}/${Hostname}-${FSName}.fsa does not exist\n\nBackup file still remains in this location: ${Hostname}:${BackupDir}/${Hostname}-${FSName}.fsa"
      fi
    
      ## Remount FileSystem.
      mount /${FSName}
    }
    
    function f_archive_vol()
    {
      LVName=$1
      LVPath=${LVG}/${LVName}
    
      ## Purge old backup files.
      if [ -f ${BackupDir}/${Hostname}-${LVName}.fsa ]; then
        rm ${BackupDir}/${Hostname}-${LVName}.fsa
      fi
      if [ -f ${BackupDir}/${Hostname}-${LVName}.txt ]; then
        rm ${BackupDir}/${Hostname}-${LVName}.txt
      fi
      if [ -f ${BackupDir}/${Hostname}-${LVName}.md5 ]; then
        rm ${BackupDir}/${Hostname}-${LVName}.md5
      fi
    
      ## Create the snapshot volume of the partition to be backed up.
      lvcreate --size=${MaxTempVolSize} --snapshot --name="tempsnap" ${LVPath} > /dev/null 2>&1
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of temporary volume failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of temp volume failed for ${LVPath}, size=${MaxTempVolSize}, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=8
        f_cleanup
      fi
    
      ## Give the OS a moment to let the LV create command do its thing.
      sleep 2
    
      LVLabel="${Hostname}:${LVPath}"
      ## Create the compressed and encrypted archive of the snapshot.
      fsarchiver savefs --compress=7 --jobs=1 --cryptpass="${CryptPass}" --label="${LVLabel}" ${BackupDir}/${Hostname}-${LVName}.fsa ${TempLV} > /dev/null 2>&1
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of the archive failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of ${BackupDir}/${Hostname}-${LVName}.fsa failed, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Create an informational text file about the archive.
      fsarchiver archinfo --cryptpass="${CryptPass}" ${BackupDir}/${Hostname}-${LVName}.fsa > ${BackupDir}/${Hostname}-${LVName}.txt 2>&1
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of info text failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of info file failed for ${BackupDir}/${Hostname}-${LVName}.txt, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Create a checksum file about the archive.
      md5sum ${BackupDir}/${Hostname}-${LVName}.fsa > ${BackupDir}/${Hostname}-${LVName}.md5
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Creation of md5 checksum failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Creation of checksum failed for ${BackupDir}/${Hostname}-${LVName}.md5, Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      ## Set file permissions.
      chmod 0600 ${BackupDir}/${Hostname}-${LVName}.*
    
      ## Remove the snapshot.
      lvremove --force ${TempLV} > /dev/null 2>&1
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Removal of temporary volume failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Removal of temp volume failed. ${TempLV}. Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=8
        f_cleanup
      fi
    
      ## Give the OS a moment to let the LV remove command do its thing.
      sleep 2
    
      ## Verify that the checksum file can validate against the archive.
      md5sum --check --status ${BackupDir}/${Hostname}-${LVName}.md5
      ReturnCode=$?
      if [ ${ReturnCode} != 0 ]; then
        ## Verification failed.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: md5 validation check failed for ${BackupDir}/${Hostname}-${LVName}.md5. Return Code = ${ReturnCode}" >> ${LogFile}
        ErrorFlag=16
        f_cleanup
      fi
    
      BackupSize=`ls -lak --block-size=m "${BackupDir}/${Hostname}-${LVName}.fsa" | awk '{ print $5 }'`
    
      echo "`date +%Y-%m-%d_%H:%M:%S` --- Created: ${BackupDir}/${Hostname}-${LVName}.fsa, ${BackupSize}" >> ${LogFile}
    
      ## Make sure target folder exists.
      if [ ! -d ${OffsiteDir}/${Hostname} ]; then
        ## Create folder.  This is typical of 1st time use.
        mkdir -p ${OffsiteDir}/${Hostname}
      fi
      ## Copy the backup to an offsite storage location.
      echo "`date +%Y-%m-%d_%H:%M:%S` --- Copying archive file to offsite location." >> ${LogFile}
      cp ${BackupDir}/${Hostname}-${LVName}.* ${OffsiteDir}/${Hostname}/. 1>/dev/null 2>&1
      if [ ! -f ${OffsiteDir}/${Hostname}/${Hostname}-${LVName}.fsa ]; then
        ## NON-FATAL ERROR: Copy command did not work.  Send email notification.
        echo "`date +%Y-%m-%d_%H:%M:%S` --- WARNING: Remote copy failed. ${OffsiteDir}/${Hostname}/${Hostname}-${LVName}.fsa does not exist!" >> ${LogFile}
        f_sendmail "Backup Failure - Remote Copy" "Remote copy failed. ${OffsiteDir}/${Hostname}/${Hostname}-${LVName}.fsa does not exist\n\nBackup file still remains in this location: ${Hostname}:${BackupDir}/${Hostname}-${LVName}.fsa"
      fi
    }
    
    #######################################
    ##           MAIN PROGRAM            ##
    #######################################
    
    if [ -f ${LockFile} ]; then
      # Lock file detected.  Abort script.
      echo "Backup partitions script aborted"
      echo "This script tried to run but detected the lock file: ${LockFile}"
      echo "Please check to make sure the file does not remain when backup partitions is not actually running."
      f_sendmail "ERROR: Backup partitions script aborted" "This script tried to run but detected the lock file: ${LockFile}\n\nPlease check to make sure the file does not remain when backup partitions is not actually running.\n\nIf you find that the script is not running/hung, you can remove it by typing 'rm ${LockFile}'"
      ErrorFlag=1
      exit ${ErrorFlag}
    else
      echo "`date +%Y-%m-%d_%H:%M:%S` ${ScriptName}" > ${LockFile}
    fi
    
    ## Requirement Check: Script must run as root user.
    if [ "$(id -u)" != "0" ]; then
      ## FATAL ERROR DETECTED: Document problem and terminate script.
      echo "`date +%Y-%m-%d_%H:%M:%S` ERROR: Root user required to run this script." >> ${LogFile}
      ErrorFlag=2
      f_cleanup
    fi
    
    ## Requirement Check: Software
    command -v fsarchiver > /dev/null 2>&1 && ReturnCode=0 || ReturnCode=1
    if [ ${ReturnCode} = 1 ]; then
      ## Required program not installed.
      echo "`date +%Y-%m-%d_%H:%M:%S` ERROR: fsarchiver not installed." >> ${LogFile}
      ErrorFlag=4
      f_cleanup
    fi
    
    ## Mount the remote folder. ##
    f_mount
    
    if [ -f ${OffsiteTestFile} ]; then
      ## Found local file.  Assuming failed mount.
      echo "`date +%Y-%m-%d_%H:%M:%S` --- ERROR: Cannot detect remote location: ${OffsiteTestFile}" >> ${LogFile}
      ErrorFlag=32
      f_cleanup
    fi
    
    StartTime="$(date +%s)"
    echo "`date +%Y-%m-%d_%H:%M:%S` - Backup started." >> ${LogFile}
    
    f_archive_fs boot /dev/sda1
    f_archive_vol root
    f_archive_vol var
    f_archive_vol tmp
    f_archive_vol home
    f_archive_vol usr
    f_archive_vol srv
    f_archive_vol opt
    #f_archive_vol swap
    
    ## Unmount the Windows shared folder.
    f_umount
    
    ## Calculate total time for backup.
    FinishTime="$(date +%s)"
    ElapsedTime="$(expr ${FinishTime} - ${StartTime})"
    Hours=$((${ElapsedTime} / 3600))
    ElapsedTime=$((${ElapsedTime} - ${Hours} * 3600))
    Minutes=$((${ElapsedTime} / 60))
    Seconds=$((${ElapsedTime} - ${Minutes} * 60))
    
    echo "`date +%Y-%m-%d_%H:%M:%S` --- Total backup time: ${Hours} hour(s) ${Minutes} minute(s) ${Seconds} second(s)" >> ${LogFile}
    
    echo "`date +%Y-%m-%d_%H:%M:%S` - Backup Finished." >> ${LogFile}
    f_cleanup
    Here is an example of the log file:

    /var/log/back-parts.log
    Code:
    2017-02-28_18:19:36 - Backup started.
    2017-02-28_18:19:46 --- Created: /bak/srv-ubuntu-boot.fsa, 40M
    2017-02-28_18:19:46 --- Created: /bak/srv-ubuntu-home.fsa, 1M
    2017-02-28_18:20:33 --- Created: /bak/srv-ubuntu-root.fsa, 96M
    2017-02-28_18:20:44 --- Created: /bak/srv-ubuntu-opt.fsa, 1M
    2017-02-28_18:20:55 --- Created: /bak/srv-ubuntu-srv.fsa, 1M
    2017-02-28_18:22:21 --- Created: /bak/srv-ubuntu-usr.fsa, 162M
    2017-02-28_18:23:28 --- Created: /bak/srv-ubuntu-var.fsa, 189M
    2017-02-28_18:23:40 --- Backup time: 0 hour(s) 4 minute(s) 4 second(s)
    2017-02-28_18:23:40 - Backup Finished.
    An example email notification when a fatal error occurred:
    Code:
    From: admin@mydomain.com
    Sent: Tuesday, February 28, 2017 6:23:45 PM
    To: lhammonds@mydomain.com
    Subject: ERROR: Backup partitions script aborted
     
    This script tried to run but detected the lock file: /tmp/abc-back-parts.lock
    
    Please check to make sure the file does not remain when backup partitions is not actually running.
    
    If you find that the script is not running/hung, you can remove it by typing 'rm /tmp/abc-back-parts.lock'
    
    Server: srv-ubuntu
    Program: /var/scripts/prod/abc-back-parts.sh
    Log: /var/log/abc-back-parts.log
    An example email notification when no errors occur and email notifications turned on:
    Code:
    From: admin@mydomain.com
    To: lhammonds@mydomain.com
    Sent: Tuesday, February 28, 2017 6:23:45 PM
    Subject: Backup Completed
     
    INFO: The partition backup job has completed without any errors.
     
    Server: srv-ubuntu
    Program: /var/scripts/prod/abc-back-parts.sh
    Log: /var/log/abc-back-parts.log

    NOTE: If the snapshot volume could not be automatically removed, here is how you do it:

    Code:
    dmsetup ls
    Code:
    LVG-srv (252, 6)
    LVG-tempsnap    (252, 9)
    LVG-opt (252, 7)
    LVG-swap        (252, 1)
    LVG-root        (252, 0)
    LVG-opt-real    (252, 10)
    LVG-bak (252, 8)
    LVG-tmp (252, 3)
    LVG-tempsnap-cow        (252, 11)
    LVG-usr (252, 4)
    LVG-var (252, 5)
    LVG-home        (252, 2)
    Code:
    dmsetup remove LVG-tempsnap
    dmsetup remove LVG-tempsnap-cow
    Backup Test

    Before the partitions are backed on your server, create a couple of empty test files to verify that the restore in the next section will work.

    Type the following commands:

    Code:
    touch /important.txt
    touch /srv/samba/share/important.txt
    Make sure the above files are included in your backup before testing the restore in the next section.
    Last edited by LHammonds; October 4th, 2017 at 02:59 PM. Reason: Updated back-parts.sh to v1.3

  10. #10
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,343
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: How to Install and Configure an Ubuntu Server 16.04 LTS

    Restore Partitions Using SystemRescueCD and FSArchiver

    Partitions cannot be mounted when restoring to them. If services can be stopped that use files on a specific partition, it can be unmounted and restored. However, the root partition can never be restore while the server is online so these instructions will cover the common denominator which requires taking the server offline.

    The server needs to be booted up with a CD but not just any CD will do because it needs to have FSArchiver on it. For this document, the ISO image from www.sysresccd.org will be used.

    Once downloaded, the ISO can be burned to a CD-ROM disc or uploaded to your ISO repository such as a LUN. VMware and VirtualBox can attach an ISO image and mount it in the CD-ROM device to allow the virtual machine to boot the ISO image.

    For this example, the root and srv partitions will be restored.

    Be sure the partitions have been backed up and the files are sitting in the /bak volume.

    Code:
    ls -l /bak
    Code:
    -rw-r--r-- 1 root root  41515916 Jun 28 18:19 srv-ubuntu-boot.fsa
    -rw-r--r-- 1 root root        59 Jun 28 18:19 srv-ubuntu-boot.md5
    -rw-r--r-- 1 root root       732 Jun 28 18:19 srv-ubuntu-boot.txt
    -rw-r--r-- 1 root root      8467 Jun 28 18:19 srv-ubuntu-home.fsa
    -rw-r--r-- 1 root root        59 Jun 28 18:19 srv-ubuntu-home.md5
    -rw-r--r-- 1 root root       730 Jun 28 18:19 srv-ubuntu-home.txt
    -rw-r--r-- 1 root root      5045 Jun 28 18:20 srv-ubuntu-opt.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:20 srv-ubuntu-opt.md5
    -rw-r--r-- 1 root root       729 Jun 28 18:20 srv-ubuntu-opt.txt
    -rw-r--r-- 1 root root  99626058 Jun 28 18:20 srv-ubuntu-root.fsa
    -rw-r--r-- 1 root root        59 Jun 28 18:20 srv-ubuntu-root.md5
    -rw-r--r-- 1 root root       732 Jun 28 18:20 srv-ubuntu-root.txt
    -rw-r--r-- 1 root root      5458 Jun 28 18:20 srv-ubuntu-srv.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:21 srv-ubuntu-srv.md5
    -rw-r--r-- 1 root root       728 Jun 28 18:20 srv-ubuntu-srv.txt
    -rw-r--r-- 1 root root 169110383 Jun 28 18:22 srv-ubuntu-usr.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:22 srv-ubuntu-usr.md5
    -rw-r--r-- 1 root root       730 Jun 28 18:22 srv-ubuntu-usr.txt
    -rw-r--r-- 1 root root 198015579 Jun 28 18:23 srv-ubuntu-var.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:23 srv-ubuntu-var.md5
    -rw-r--r-- 1 root root       730 Jun 28 18:23 srv-ubuntu-var.txt
    As a little test of the restore, let's delete the two text files created in the previous section:

    Code:
    rm /important.txt
    rm /srv/samba/share/important.txt
    These files should have been included in the backup image. When the restore is complete, these files should return.

    Insert the CDROM (or mount the ISO image) and boot the server with it.

    Here is the 1st screen:


    The server in this document is a 64-bit server so option #6 was chosen.

    The next screen takes you to the command prompt:




    root@sysresccd /root % mkdir /mnt/test
    root@sysresccd /root % fsarchiver probe simple
    Code:
    [======DISK======] [=============NAME==============] [====SIZE====] [MAJ] [MIN]
    [sda             ] [Virtual disk                   ] [    10.00 GB] [  8] [  0]
    [sdb             ] [Virtual disk                   ] [    12.00 GB] [  8] [ 16]
    [sdc             ] [Virtual disk                   ] [    12.00 GB] [  8] [ 32]
    [sr0             ] [VMware IDE CDR10               ] [   378.96 MB] [ 11] [  0]
     
    [=====DEVICE=====] [==FILESYS==] [======LABEL======] [====SIZE====] [MAJ] [MIN]
    [loop0           ] [squashfs   ] [<unknown>        ] [   297.63 MB] [  7] [  0]
    [sda1            ] [ext2       ] [boot             ] [   190.00 MB] [  8] [  1]
    [sda5            ] [LVM2_member] [<unknown>        ] [     9.81 GB] [  8] [  5]
    [sdb1            ] [LVM2_member] [<unknown>        ] [    12.00 GB] [  8] [ 17]
    [sdc1            ] [LVM2_member] [<unknown>        ] [    12.00 GB] [  8] [ 33]
    [dm-0            ] [ext4       ] [root             ] [     3.00 GB] [253] [  0]
    [dm-1            ] [swap       ] [<unknown>        ] [     1.86 GB] [253] [  1]
    [dm-2            ] [ext4       ] [home             ] [     1.00 GB] [253] [  2]
    [dm-3            ] [ext4       ] [tmp              ] [     2.00 GB] [253] [  3]
    [dm-4            ] [ext4       ] [usr              ] [     3.00 GB] [253] [  4]
    [dm-5            ] [ext4       ] [var              ] [     3.00 GB] [253] [  5]
    [dm-6            ] [ext4       ] [srv              ] [     2.00 GB] [253] [  6]
    [dm-7            ] [ext4       ] [opt              ] [     2.00 GB] [253] [  7]
    [dm-8            ] [ext4       ] [bak              ] [     4.00 GB] [253] [  8]
    root@sysresccd /root % mkdir /bak
    root@sysresccd /root % mount --read-only /dev/dm-8 /bak
    root@sysresccd /root % ls -l /bak
    Code:
    -rw-r--r-- 1 root root  41515916 Jun 28 18:19 srv-ubuntu-boot.fsa
    -rw-r--r-- 1 root root        59 Jun 28 18:19 srv-ubuntu-boot.md5
    -rw-r--r-- 1 root root       732 Jun 28 18:19 srv-ubuntu-boot.txt
    -rw-r--r-- 1 root root      8467 Jun 28 18:19 srv-ubuntu-home.fsa
    -rw-r--r-- 1 root root        59 Jun 28 18:19 srv-ubuntu-home.md5
    -rw-r--r-- 1 root root       730 Jun 28 18:19 srv-ubuntu-home.txt
    -rw-r--r-- 1 root root      5045 Jun 28 18:20 srv-ubuntu-opt.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:20 srv-ubuntu-opt.md5
    -rw-r--r-- 1 root root       729 Jun 28 18:20 srv-ubuntu-opt.txt
    -rw-r--r-- 1 root root  99626058 Jun 28 18:20 srv-ubuntu-root.fsa
    -rw-r--r-- 1 root root        59 Jun 28 18:20 srv-ubuntu-root.md5
    -rw-r--r-- 1 root root       732 Jun 28 18:20 srv-ubuntu-root.txt
    -rw-r--r-- 1 root root      5458 Jun 28 18:20 srv-ubuntu-srv.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:21 srv-ubuntu-srv.md5
    -rw-r--r-- 1 root root       728 Jun 28 18:20 srv-ubuntu-srv.txt
    -rw-r--r-- 1 root root 169110383 Jun 28 18:22 srv-ubuntu-usr.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:22 srv-ubuntu-usr.md5
    -rw-r--r-- 1 root root       730 Jun 28 18:22 srv-ubuntu-usr.txt
    -rw-r--r-- 1 root root 198015579 Jun 28 18:23 srv-ubuntu-var.fsa
    -rw-r--r-- 1 root root        58 Jun 28 18:23 srv-ubuntu-var.md5
    -rw-r--r-- 1 root root       730 Jun 28 18:23 srv-ubuntu-var.txt
    root@sysresccd /root % md5sum --check /bak/srv-ubuntu-srv.md5
    Code:
    /bak/srv-ubuntu-srv.fsa: OK
    root@sysresccd /root % fsarchiver restfs --cryptpass="abc123" /bak/srv-ubuntu-srv.fsa id=0,dest=/dev/dm-6
    Code:
    Statistics for filesystem 0
    * files successfully processed:....regfiles=1, directories=4, symlinks=0, hardlinks=0, specials=0
    * files with errors:...............regfiles=0, directories=0, symlinks=0, hardlinks=0, specials=0
    root@sysresccd /root % mount --read-only /dev/dm-6 /mnt/test
    root@sysresccd /root % ls -l /mnt/test/samba/share
    Code:
    -rw-r--r-- 1 root root 0 Jun 28 09:21 important.txt
    root@sysresccd /root % umount /mnt/test
    root@sysresccd /root % md5sum --check /bak/srv-ubuntu-root.md5
    Code:
    /bak/srv-ubuntu-root.fsa: OK
    root@sysresccd /root % fsarchiver restfs --cryptpass="abc123" /bak/srv-ubuntu-root.fsa id=0,dest=/dev/dm-0
    Code:
    Statistics for filesystem 0
    * files successfully processed:....regfiles=8938, directories=1693, symlinks=855, hardlinks=11, specials=80
    * files with errors:...............regfiles=0, directories=0, symlinks=0, hardlinks=0, specials=0
    root@sysresccd /root % mount --read-only /dev/dm-0 /mnt/test
    root@sysresccd /root % ls -l /mnt/test
    Code:
    drwxr-xr-x   3 root root  1024 Jun 27 12:25 bak
    drwxr-xr-x   2 root root  4096 Jun 26 12:37 bin
    drwxr-xr-x   4 root root  1024 Jun 26 12:36 boot
    drwxr-xr-x  14 root root  4400 Jun 28 09:17 dev
    drwxr-xr-x  90 root root  4096 Jun 28 09:17 etc
    drwxr-xr-x   4 root root  1024 Jun 26 10:20 home
    -rw-r--r--   1 root root     0 Jun 28 09:20 important.txt
    lrwxrwxrwx   1 root root    33 Jun 26 10:33 initrd.img -> /boot/initrd.img-3.2.0-25-generic
    lrwxrwxrwx   1 root root    33 Jun 26 10:16 initrd.img.old -> /boot/initrd.img-3.2.0-23-generic
    drwxr-xr-x  17 root root  4096 Jun 26 12:34 lib
    drwxr-xr-x   2 root root  4096 Jun 26 10:16 lib64
    drwx------   2 root root 16384 Jun 26 10:15 lost+found
    drwxr-xr-x   4 root root  4096 Jun 26 10:16 media
    drwxr-xr-x   3 root root  4096 Jun 26 12:35 mnt
    drwxr-xr-x   3 root root  1024 Jun 26 10:15 opt
    dr-xr-xr-x 111 root root     0 Jun 28 09:17 proc
    drwx------   3 root root  4096 Jun 26 19:57 root
    drwxr-xr-x  15 root root   500 Jun 28 09:18 run
    drwxr-xr-x   2 root root  4096 Jun 26 12:37 sbin
    drwxr-xr-x   2 root root  4096 Mar  5 11:54 selinux
    drwxr-xr-x   4 root root  1024 Jun 28 08:34 srv
    drwxr-xr-x  13 root root     0 Jun 28 09:17 sys
    drwxrwxrwt   4 root root  1024 Jun 28 09:18 tmp
    drwxr-xr-x  11 root root  4096 Jun 26 10:16 usr
    drwxr-xr-x  14 root root  4096 Jun 26 13:08 var
    lrwxrwxrwx   1 root root    29 Jun 26 10:33 vmlinuz -> boot/vmlinuz-3.2.0-25-generic
    lrwxrwxrwx   1 root root    29 Jun 26 10:16 vmlinuz.old -> boot/vmlinuz-3.2.0-23-generic
    root@sysresccd /root % umount /mnt/test

    Eject the CDROM/ISO and reboot the server.

    If it worked right, the server will boot up (we restored the root file system) and the test files should have been restored.

    NOTE: If you noticed any ext file systems that had <unknown> labels, you can update them using the tune2fs command.
    Example 1:
    Code:
    tune2fs /dev/sda1 -L boot
    Example 2:
    Code:
    tune2fs /dev/dm-0 root
    Last edited by LHammonds; October 4th, 2017 at 06:03 AM. Reason: Modify formatting for UbuntuForums

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •