Linux Homeserver

My newest Project is my own Linux Home Server.  This should be my personal cloud and much more. Also i plan to have a home automation with Z-Wave.

System Components

I decided to build a powerful home server. Of course, this is overkill for the most tasks, but at least it wont become outdated soon 😉

https://geizhals.at/?cat=WL-1039797

Setting up a RAID 1 / Mirror using Linux LVM

I installed Ubuntu 18.10 on the SSD and want to use both HDD in an RAID 1. Since LVM became much more sophisticated, i decided to set the mirrored volume up with LVM instead of an mda RAID1.

Both drives are located in /dev/ and in my case named sda and sdb.

Every step needs you to have root rights. Type in:

sudo su

enter your password and continue.

Partitioning

At first you have to make a partition on each drive. I used gdisk, since i have 4Tb drives and fdisk just supports up to 2Tb in size.

Start with the first drive:

gdisk /dev/sda

Press “n” for new partition. Then you can press “Enter” three times. This will choose partition 1 with the maximum possible size:

Partition number (1-128, default 1):
First sector (34-7814037134, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-7814037134, default = 7814037134) or {+-}size{KMGTP}:

At last, just press “w” to write and save your partition. Repeat the steps for /dev/sdb.

With “fdisk -l” you can control the correct size of your partitions.

Create Physical Volumes (pv)

Now we create two physical volumes in order to make them usable for LVM.

pvcreate /dev/sda1 /dev/sdb1

You can now view and control the physical volumes with:

pvdisplay

Create a Volume Group (vg)

The two physical volumes will now be united in an volume group. The first parameter is the vg name. I would suggest you don’t use any cryptic names for it.

vgcreate vg-MyDrive /dev/sda1 /dev/sdb1

Again you can control the volume group with:

vgdisplay

Create a Logical Volume (lv)

In the last step, we create a mirrored locical volume, using both drives / physical volumes.

lvcreate --type mirror -m 1 -l 100%FREE -n lv-MyDrive vg-MyDrive

“–type mirror” defines the volume as a mirrored volume.

“-m 1” means a simple mirror, using two drives

“-l 100%FREE” sets the maximum available size for the logical volume

“-n lv-MyDrive” sets the name to lv-MyDrive

“vg-MyDrive” uses the volume group vg-MyDrive

Control it with:

lvdisplay

Formatting with ex4

Find the path of your logical volume with:

fdisk -l

It should be something like “/dev/mapper/vg–MyDrive-lv–MyDrive”. In the next step, we will format the volume with ext4.

mkfs.ext4 /dev/mapper/vg--MyDrive-lv--MyDrive

Mounting/Integrating the Drive

You use your own folder to mount the logical volume.

Go to “/” and create a folder.

cd /

mkdir MyDrive

Now mount the drive inside our created Folder:

mount /dev/vg-MyDrive/lv-MyDrive /MyDrive/

If you want to mount the volume automatically on every boot, you have to edit /etc/fstab.

nano /etc/fstab

and add the following line:

/dev/vg-MyDrive/lv-MyDrive /MyDrive ext4 defaults 0 0

Network Storage with Samba Shares

Samba Setup

First, Install samba by typing in the following commands:

sudo apt update
sudo apt install samba

We now have to add our MyDrive folder to samba. Open samba’s config

sudo nano /etc/samba/smb.conf

and add the following lines:

[MyDrive]
   comment = MyDrive on Home Ubuntu Server
   path = /MyDrive
   writable = yes
   read only = no
   browsable = yes
   public = yes
   create mask = 0644
   directory mask = 0755
   force user = sambauser

The first field “[MyDrive]” is the name of the samba share. With this name, we can reach the folder from outside.

“Create mask” and “directory mask” set the right permissions for the folder.  See for more info (http://www.codecoffee.com/tipsforlinux/articles/032-2.html)

In order to connect to samba, we need a user. This user is only be created for samba, therefore it shouldn’t be able to login directly to the linux system. In my case, the name is “samba-user”

sudo adduser --no-create-home --disabled-password --disabled-login sambauser

We also need to change the folder’s owner to samba-user

chown -R samba-user /MyDrive

After we created the user, we can now add it to samba. You will be asked to enter a password for the user.

sudo smbpasswd -a sambauser

Restart the samba service and we’re done.

sudo service smbd restart

At last, we need to connect to our new samba share.

See https://www.nextofwindows.com/3-ways-to-map-network-drive-in-windows-10 for further information.

Now type in the IP adress, followed by the name of the samba share in this form:

\\192.168.1.1\MyDrive

Connect as your “sambauser” and your given samba password and you’re done.

 

To be continued…

 

 

 

Thank you for reading and if you have found any flaws, do not hesitate to contact me.