Wednesday 21 September 2016

Updating Minecraft Spigot build

Download the buildtools


wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar

git config --global --unset core.autocrlf

java -jar BuildTools.jar

copy the created spigot-1-x-xx.jar file to the main spigot directory and update the start.sh batch file to use the new version of the jar file.


Friday 16 September 2016

Ubuntu new external Hard Drive setup partitioning, formatting and tuning

# Checking the location of the new drive. It is /dev/sdb.
sudo lshw -C disk

# Creating the GUID Partition Table (GPT)
sudo parted /dev/sdx mklabel gpt

# Checking that the GPT has been created
sudo parted /dev/sdx print

# see 6001175MB size
sudo parted /dev/sdb print unit MB print free

# Creating partition label
sudo parted --align optimal /dev/sdx mkpart primary ext4 0% 100%

# Creating the partition
# -b sets the block size (do not use for standard drive, set to 64k (65536) if mostly video and images large files

sudo mkfs.ext4 -b size=65536 /dev/sdx1

# Check the drive surface for bad blocks
# -n is non destructive test, it takes longer but does not destroy data on the disk
# -w is destructive (and faster) and will write over any data on the drive
# -s shows progress indicator
# -b specifies the blocksize which is optional but will speed up the scan
# -f force checking even if the volume seems clean
# -c the size of the block written for each test, speeding up the test but using more memory

sudo badblocks -nsvf -b 4096 -c 65536 /dev/sdx
sudo badblocks -wsvf -b 4096 -c 65536 /dev/sdx

sudo badblocks -nsvf -b 65536 -c 1024 /dev/sdx
sudo badblocks -wsvf -b 65536 -c 1024 /dev/sdx

# NOTE - Smartmontools smartctl tests will be a better faster test than badblocks
The SMART surface test is almost certainly a single, and certainly non-destructive, read pass. As has been pointed out it is also internal to the drive; with the possible exception of minor control data, no data is being passed to or from the host during the test.

On the other hand, badblocks -w makes four passes over the drive, each with one write and one read. That alone accounts for an 8× difference in time taken for the test, plus rotational latency. Since it's software running on the host, all that data needs to be shuffled through the disk interface to RAM and handled by the software (badblocks, in our case).

# -t type of test
# -C run the test in the foreground

sudo smartctl -t long -C /dev/sdx

# Show the test results

sudo smartctl -a /dev/sdx


# mount the drive on a folder
sudo mount /dev/sdx1 /media/usb

# Remove reserved blocks (i.e. set to 0%), since this drive is just for user data
sudo tune2fs -m 0 /dev/sdx1

Friday 5 August 2016

Discovering and Mounting USB Drives/Flash Drives using the command line on Ubuntu Server

Discovering which drives are connected

There are many ways to see which drives are connected to the ubuntu system:

To show full detailed information about all drives connected to the system.

sudo fdisk -l

This will list, in detail, all of the drives connected.

Here is an example of the drive we are interested in. A 500mb external HDD:

Disk /dev/sdi: 465.8 GiB, 500107706368 bytes, 976772864 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe38f367e

Other options:

blkid
lsblk -f
lsusb
sudo lshw
df -h -T

To see if the drive is FAT16 or FAT32

sudo file -s /dev/sdi1


This will show is the following details for the drive


/dev/sdi1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "BSD  4.4", sectors/cluster 64, Media descriptor 0xf8, sectors/track 32, heads 255, hidden sectors 2, sectors 976772862 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 119206, serial number 0xfd44150c, label: "500-FREECOM"

Mount the drive

USB drives are usually mounted under the /media directory. Create a directory to mount the drive on.

cd /media
mkdir external

sudo mount -t vfat /dev/sdb1 /media/external
If no -t option is given, or if the auto type is specified, mount will try to guess the desired type.


Thursday 2 June 2016

Using Ubuntu Server to set up a home server and NAS

A reminder about screen


Use screen to create terminal sessions that will persist when the terminal window is closed. Good when doing long copies or running a minecreaft server.

Change the SSH port

modify /etc/ssh/sshd_config

where it says:

# What ports, IPs and protocols we listen for
Port 22 <---change port to what you need it to be

then save and restart ssh serverSetup ZFS
http://www.howtogeek.com/175159/an-introduction-to-the-z-file-system-zfs-for-linux/

Install ZFS

Notes mainly taken from https://www.latentexistence.me.uk/zfs-and-ubuntu-home-server-howto/

$ sudo apt-get install zfsutils-linux

List disks by ID

The creators of ZFS on Linux recommend that you use disk names starting with /dev/disk/by-id/ rather than /dev/sda, /dev/sdb etc as they are more consistent (particularly the wwn identifier) so look in that folder to see what disk names you have.

$ ls -l /dev/disk/by-id/

List ZFS datasets

$ sudo zfs list

Create a two disk mirror

*NOTE* the below command is how it should be done but it fails due to a bug with ZFS (https://github.com/zfsonlinux/zfs/issues/3708)


sudo zpool create [pool_name] mirror /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WCC4N1VUU0LX /dev/disk/by-id/ata-WDC_WD30EFRX-68EUZN0_WD-WCC4N7FSX6F9

to make it work create the pool using /dev/sdb etc. but then:

sudo zpool create [pool_name] mirror /dev/sdb /dev/sdc

$ sudo zpool export [pool_name]
$ sudo zpool import -d /dev/disk/by-id [pool_name]

That will switch all /dev/sdx drives to the full ID.
Check the status of pools

$ sudo zpool status

Destroy a pool

$ sudo zpool destroy [pool_name]

While you can just start storing data in your newly-created filesystem (in /[pool_name] in our example) that isn’t the best way to use ZFS. Instead you should create additional filesystems within your storage pool to hold different types of data. This will allow you to do things like set compression, deduplication, quotas and snapshots differently for each set of data or backup an individual filesystem with zfs send. You use the zfs command to create your filesystems. Some examples:

$ sudo zfs create [pool_name]/music

$ sudo zfs create [pool_name]/videos

$ sudo zfs create [pool_name]/backups

The above examples will create filesystems in the pool and will automatically mount them as subfolders of the main filesystem. Note that the name is in the format pool / filesystem name and there is no leading slash on the pool name.

To list all the filesystems

$ sudo zfs list

List all drives

$ df -h

Add another 2 disk mirror to the ZFA Pool

Get the UUIDs of the drives

$ sudo blkid

$ zpool add unas mirror newDrive1 newDrive2

Sharing

Now we need to share the data, otherwise it’s not much of a server. ZFS will automatically manage sharing through NFS (Unix/Linux) or SMB (Windows) but you must first install the server software. For sharing to Windows clients use:

$ sudo apt-get install samba

To add NFS use:

$ sudo apt-get install nfs-kernel-server

You don’t need to configure much because ZFS handles most settings for you, but you might wish to change the workgroup name for Samba in /etc/samba/smb.conf.

To share a ZFS filesystem you change a property using the zfs command. For Windows clients:

$ sudo zfs set sharesmb=on tank/music

$ sudo zfs set sharesmb=on tank/videos

For Unix / Linux clients:

$ sudo zfs set sharenfs=on tank/backups

Or you can share the whole lot at once by sharing the main pool. The sub-filesystems will inherit the sharing property unless you turn them off:

$ sudo zfs set sharesmb=on tank
$ sudo zfs set sharenfs=on tank

$ sudo zfs set sharesmb=off tank/music

You can check whether your filesystems are shared or not:

$ sudo zfs get sharesmb,sharenfs

At this point you should be able to see your shares from other computers on the network but you probably won’t have permission to access them. You will need to ensure that the file permissions and owners are set correctly, and you will also have to add an account and set a password for  use when connecting through Samba. If your username is ella then use:

$ sudo smbpasswd -a ella

to set your Samba password, and make sure that ella has permission to access all the files in your shared folders:

$ sudo chown -R ella:ella /tank/videos

Create a share that just shows photos for amazon cloud drive backups

Amazon cloud drive gives unlimited photo backups, so, to exclude video files and photoshop fiels etc, create a share that vetoes anything but a photo file:

Full article below, with details added in the comments. Search for Samba Share on the page:

https://havecamerawilltravel.com/photographer/amazon-cloud-drive-photos

[Pictures-Only]
comment = Pictures Only
path = /storage/dd5/files/documents/pictures
public = yes
read only = yes
veto files = /Video/_Lightroom 5/*.rar/*.ini/*.exe/*.db/*.PDF/*.pdf/*.MOV/*.MPG/*.AVI/*.mpg/*.avi/*.zip/*.3gp/*.3GP/*.MTS/*.mts/*.mp4/*.mov/*.flv/*.mkv/*.arw/*.doc/*.info/*.mp3/*.est/*.blend*/*.mxp/*.max/*.bak/*.mdf/*.xml/*.3ds/*.blend2/*.cdf/*.fbx/*.pz3/*.txt/

Mount USB drive

Find the /dev name of the USB drive once it is connected


Create a directory names, day, /usb and mount the usb device on the newly created /usb directory

$ mount /dev/sdd /usb/

Automatically mount the USB at boot and share it

1). Mount the drive at boot time:
    * sudo vi /etc/fstab
    * then add this line:  /dev/sda3    /media/lnxBackUp  ext4  users,user      0  0
      In my case, sda3 is the drive that I would like to mount and ext4 is the partition of sda3.

2). Install samba server:
    * sudo apt-get install samba
    * sudo vi /etc/samba/smb.conf
      then edit its config file by adding these information at the end of the page:
    [lnxBackUp]
          writable = yes
          path = /media/lnxBackUp
          guest ok = yes
          create mask = 0777
          comment = Backup drive
          directory mask = 0777
    * Create a folder in /media
    * sudo mkdir /medir/lnxBackUp
    * sudo mount -a

Format and Partition a 3TB external USB drive

The full article is:

https://joshstrange.com/ubuntu-formatting-a-3tb-drive/

If you get the error "The resulting partition is not properly aligned for best performance", you can use the Simple Instructions at: https://blog.hqcodeshop.fi/archives/273-GNU-Parted-Solving-the-dreaded-The-resulting-partition-is-not-properly-aligned-for-best-performance.html

The Simple Way involves using percentages

<parted> mklabel gpt
<parted> unit s
<parted> mkpart LVM ext4 0% 100%
<parted> quit


  1. lsblk to find the drive name (will be something like /dev/sdX where X is a letter)
  2. sudo parted /dev/sdX
  3. In the parted interactive console type: 
    1. (parted) mklabel gpt
    2. (parted) unit TB
    3. (parted) mkpart primary 0.00TB 3.00TB (Changing 3.00TB to the size of your drive)
    4. (parted) quit
  4. sudo mkfs.ext4 /dev/sdX1 (Where X is the same as above and note the "1" now)
  5. sudo tune2fs -m 1 /dev/sdX1
  6. mkdir /Your/Mount/Point/Here
  7. sudo blkid (Copy the UUID of your drive)
  8. sudo nano /etc/fstab
  9. Add the line UUID=YOUR-UUID-HERE-XXXX /Your/Mount/Point/Here ext4 defaults 1 2 then save and exit
  10. sudo mount -a

NCDU Nice DU to show file sizes

Instal ncdu and use it show a tree of directory sizes that you can navigate with the cursor

Setup Samba

Not necessary as steps above cover this

https://help.ubuntu.com/community/How to Create a Network Share Via Samba Via CLI (Command-line interface/Linux Terminal) - Uncomplicated%2C Simple and Brief Way!

Install Avahi to announce the shared drive on the network

You have finished the most important part and basically you can use your file server now, but this little extra step is cool in my opinion. Instead of having to do Finder > Go > Connect to Server… Every time we want to connect to the server, why don’t we show up in Finder’s left bar?

To do that we need to install Avahi. Avahi is a simple file server daemon that announces to the network when it has connected, basically Bonjour. With this instead of telling OS X Mavericks to find the server, we can tell the server to tell everyone when it’s connected. In that way our server will appear as extractable media in the left bar of any finder Window, and it’s much easier and pleasant to interact with it using this method.
Luckily, installing and configuring Avahi is really fast and simple.
If you still have your su terminal window, type this in:
?
1
apt-get install avahi-daemon avahi-utils
Then open and edit the file
/etc/avahi/services/smb.service
(the file will be blank and that’s fine – you’re creating it from scratch):
?
1
gedit /etc/avahi/services/smb.service
And copy and paste this into it:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
   <type>_smb._tcp</type>
   <port>445</port>
 </service>
 <service>
   <type>_device-info._tcp</type>
   <port>0</port>
   <txt-record>model=RackMac</txt-record>
 </service>
</service-group>
And that’s it! You don’t even need to restart Avahi. It will automatically announce to the network and your Mac will see your file server in Finder to the left.

Setup Simple eMail


This guide is for you, if:
  • You don’t want to run a mail server
  • You want to send email, and you don’t care about receiving it
  • You want people to receive the emails that your server sends
I’ve used this method with Linode, and it works perfectly.
Install mailutils
~ sudo apt-get install mailutils
When the setup wizard launches, choose the unconfigured option. You don’t need to do any special configuration to get this to work.
Install and configure sstmp
  1. ~ sudo apt-get install ssmtp
  2. ~ sudo vim /etc/ssmtp/ssmtp.conf
  3. Hit “i” to enter Insert mode.
  4. Uncomment FromLineOverride=YES by deleting the #
  5. Add the following to the file:

    AuthUser=<user>@gmail.com
    AuthPass=Your-Gmail-Password
    mailhub=smtp.gmail.com:587
    UseSTARTTLS=YES
  6. Save and close the file:
    1. Hit Escape
    2. Type :wq
    3. Hit Enter
If you’re using two-factor authentication
Create a new application-specific password to use in the config file above. (If you’re using Gmail, you can manage those passwords here.)
Test it out
~ echo "This is a test" | mail -s "Test" <user>@<email>.com
Using a webmail service other than Gmail
You can follow the same pattern that I used above. You’ll need to:
  1. Subsitute the SMTP address and port for your email service (e.g. Yahoo!) where it says smtp.gmail.com:587. (587 is the port number.)
  2. Set up an application-specific password if your webmail provider allows it, and paste that into the password line, the way I did with Gmail. (Yahoo! appears to have something similar.)

SmartMonTools to monitor Hard Disk Drive Health

https://help.ubuntu.com/community/Smartmontools

sudo apt-get install smartmontools 

Syncing Directories


rsync -avh --stats data/ /media/backups/data

rsync -avP --delete data/ /media/backups/data

The / on the end of data/ means the contents of directory data. This is necessary to prevent copying the directory data and creating the hierarchy /media/backups/data/data

-a is archive recursively and maintain all file timestamps and properties
-v is verbose
-P is for both -progress and --partial. The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers.
-n is for Dry Run to test the output of a command before executing it.

--delete is necessary if you want the files in the destination folder to be deleted if they have been deleted in the source folder. By default, rsync does not delete anything.