Creating a Software Raid 1 Filesystem
Having accumulated a fair amount of media I wanted to accomplish two goals: i) create a mirror of my data so that I would not lose all my data in the case of a drive failure, and ii) allow my media to be accessed from anywhere on my network. After some research I decided against a hardware RAID due to potential compatibility issues between different devices, which I felt limited my options. Instead I went with a software RAID, in this particular case using LVM.
Setting up a Virtual Group and Physical Volume
Use pvdisplay
to determine the size of the drive as you will need to keep 1 extent free for the Raid1 infrastructure. Here we are working with 2 physical drives with only one partition each: /dev/sda1
and /dev/sdb1
.
This is definitely not the most efficient way to setup the filesystem. In this case I copied files from a Windows drive to one of the LVs and then converted to a mirror as I was unfamiliar with how this would all work initially. The order that I selected the drives was arbitrary.
Also in this particular case I wanted to change my original naming for the vg
so I have shown that below as well for more breadth on the command usage possibilities:
sudo pvdisplay
sudo pvcreate /dev/sdb1
sudo vgcreate share /dev/sdb1
sudo pvdisplay
sudo fdisk -l
sudo vgrename share vg_share
sudo lvcreate --extents 1430790 -n share1 vg_share
Now the new volume share1
and be formatted and mounted like any physical drive/partition.
The Raid1 Mirror
Now to create the mirror of the existing drive:
sudo pvcreate /dev/sda1
sudo vgextend /dev/vg_share /dev/sda1
sudo pvdisplay
sudo lvdisplay
sudo lvconvert -m 1 --type raid1 /dev/vg_share/share1 /dev/sda1
You can track the progress of the mirror using sudo lvs -a vg_share
Monitoring the Health of the Drives
SmartMon setup for drive error detection:
edit /etc/smartmontools/smartd.conf to setup each drive and comment out the global check command restart smartd via systemctl Setup the mail system: (had installed mailx) sudo dnf install msmtp sudo vi /etc/msmtprc sudo vi /etc/mail.rc (add set sendmail="/path/to/msmtp") #Back in smartd.conf, edit mail to run script to avoid issues with 'from' address especially if still localhost #edit /path/to/smartd_script as below (remove from /etc/smartmontools): #make executable and change owner (chown) and change SELinux context or sudo semanage permissive -a fsdaemon_t Set Google account to allow lower security apps To do: store password encrypted, harden smartd via selinux, setup 2 factor Google loginExpanding the Capacity of the File Server
Setting up a Samba File Server
After getting the filesystem up and running, the next step was to get a file server and media server up and running. I'll focus this blog on the former, Samba in this case, and have a separate blog on the media server.
Installation and SELinux
The first step is ensuring that Samba is installed and running which is done easily via:
sudo dnf install samba
sudo systemctl enable smb
sudo systemctl enable nmb
sudo systemctl start smb
sudo systemctl start nmb
sudo setsebool samba_domain_controller on
sudo setsebool samba_share_nfs on
sudo setsebool samba_export_all_ro on
sudo setsebool samba_export_all_rw on
sudo firewall-cmd --add-service=samba
sudo firewall-cmd --permanent --add-service=samba
The Configuration File
Edit /etc/samba/smb.conf
and ensure the settings shown as below if you want public access to some or
all of your shared folders. Importantly, ensure that the interfaces
row is commented out for it to be
set automatically. If not, you may have issues with network discovery. Any entries here are shown for example
purposes and would have to be changed for your system.
;interfaces = lo eth0 wlp2s0
hosts allow = 127. 192.168.0.
max protocol = SMB2
name resolve order = lmhosts host bcast
guest account = nobody
map to guest = Bad user
The name resolve order
line ensures that the Samba server doesn't send multiple responses to share name resolution requests via different interfaces if you have both WiFi and Ethernet setup, for example.
In the shares section, use the following template for a public share:
comment = Name
path = /path/to/share
public = yes
guest ok = yes
read only = no
Finally we need to appease SELinux:
chcon -t samba_share_t /path/to/dir
Rygel Media Server
I also wanted to have DLNA/UPnP capability on my server which in this case I decided to use the Rygel Media Server in Gnome as this is already installed with Fedora.
Install GStreamer Add-Ons
Rygel is built on the GStreamer framework so the first step is to ensure all the GStreamer addons are installed. This step involves adding the appropriate RPM URL as the Fedora repositories don't support all media types, and then installing via DNF:
sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-25.noarch.rpm
sudo dnf install gstreamer*
Configuring Rygel
Next edit /etc/rygel.conf
to:
- Add the appropriate interface (use
ip addr
to confirm) - Change the media server titles (optional in 3 locations)
- Edit file URIs to point to your media directories
Setup Systemd Service
Create the following as /usr/lib/systemd/system/rygel.service
. As this will be run in the global session it needs to be in the system folder even though there may already be a similar file in the user folder for systemd:
[Unit]
Description=Rygel DLNA/UPnP server
After=syslog.target
[Service]
User=youruser
Group=yourgroup
ExecStart=/usr/bin/rygel
Restart=on-failure
[Install]
WantedBy=multi-user.target
Use the User
and Group
attributes to run Rygel as a user with limited privelages as it's not recommended to run the service as root. Finally start the server with:
sudo systemctl start rygel
sudo systemctl enable rygel
Note, that if for any reason your media export get corrupted, try deleting ~/.cache/rygel/mediaexport.db
in the home directory of the user specified in your rygel.service file.