Rather than layering the Samba service on Fedora Atomic, shares can be run in a Container. In order to provide relevant examples, this document will imagine a scenario where a backup drive attached to a Fedora IOT device is being shared over the network so that a Fedora Silverblue desktop can use it to store backups taken with a local utility such as Pika Backup, however this should work with for other distros (Atomic or otherwise) as well. The container engine is assumed to be Podman as this comes with Fedora Atomic, but should also work with Docker.
Contents
- Create a location on your host system for your Samba share, you may want to create a sub-directory for the actual share, so that the config files can be stored in the parent. You may need
sudo
depending on where the share is mounted and who the owner is. In this example, our backup drive is mounted in/mnt/backup
and the owner isroot
, our Samba share will bearchive
as this will store our Pika Backup archive:
sudo mkdir -p /mnt/backup/archive
- Ensure the directory has the correct permissions to be mounted in the container:
sudo chmod -R 0777 /mnt/backup/archives
- Run the following to set the correct SELinux context:
sudo chcon -Rt svirt_sandbox_file_t /mnt/backup/archives
- Navigate to the parent directory, and create a file called
smb.conf
, which should like this (amended thepath
variable as necerssary):
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = HOME
security = user
map to guest = Bad Password
passdb backend = tdbsam
load printers = No
disable spoolss = yes
printcap name = /dev/null
[volume]
comment =
path = /mnt/backup/archive
browsable = yes
writable = yes
guest ok = yes
read only = no
force user = root
inherit acls = yes
- In the same directory, create a file called
Containerfile
(if using Docker instead create aDockerfile
), this should look like the following, amending the directories as necerssary:
FROM registry.fedoraproject.org/fedora-minimal:latest
RUN microdnf -y update; microdnf -y install samba; microdnf -y install passwd; microdnf clean all; systemctl enable smb
RUN mkdir -m 777 /mnt/backup
RUN mkdir -m 777 /mnt/backup/archive
EXPOSE 445 139 137/udp 138/udp
CMD [ "/sbin/init" ]
- Tell SELinux it is ok to allow systemd to manipulate its Cgroups configuration:
sudo setsebool -P container_manage_cgroup true
- Open the firewall:
firewall-cmd --permanent --zone=trusted --add-interface=cni-podman0
sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload
- Build the container by running the following command, replacing
backup
with the name you'd like to give your image:
sudo podman build -t backup .
- Run the container, again amending the directories as necerssary (note, the
smb.conf
must be mounted at/etc/samba/smb.conf
inside the container):
sudo podman run \
-m 512m \
-u 0 \
-d \
-p 445:445 \
--name backup \
-v /mnt/backup/smb.conf:/etc/samba/smb.conf:Z \
-v /mnt/backup/archives:/home \
backup
- The exact method of connecting to a Samba share will differ depending on the file manager, but the command should be the same. Using Nautilus, you would navivate to
Other Locations
and in theEnter server address
box, enter the following, replacing<address-of-samba-share-host>
with either the DNS name or the IP address of the host, in our example this is the Fedora IOT server:
smb://<address-of-samba-share-host>/volume
- If you don't have
cifs-utils
installed, do so with your systems pacakge manager. For a Fedora Atomic system run the following to layer it, or install it in a container (which is beyond the scope of this document). If you are using a Universal Blue image, this is provided OOTB and you can skip this step:
rpm-ostree install cifs-utils
systemctl reboot
- Create a location to mount the drive, such as
/mnt/backup
:
sudo mkdir /mnt/backup
- Create a credentials file,
/etc/samba-creds
, in our example the credentials are for our Fedora IOT user:
username=user
password=password
- Secure the file by running:
sudo chown root: /etc/samba-creds
sudo chmod 600 /etc/samba-creds
15: To mount the drive enter the following, replacing <address-of-samba-share-host>
with either the DNS name or the IP address of the host, in our example this is the Fedora IOT server:
sudo mount -t cifs -o credentials=/etc/samba-creds,dir_mode=0755,file_mode=0755 //<address-of-samba-share-host>/volume /mnt/backup
-
Follow steps 11 through 14 as with running from the command line.
-
Update
/etc/fsab
with the following line, replacing<address-of-samba-share-host>
with either the DNS name or the IP address of the host, in our example this is the Fedora IOT server:
///volume /mnt/backup cifs credentials=/etc/samba-creds,file_mode=0755,dir_mode=0755 0 0
Contributions are what make the open source community such an amazing place to learn, inspire, and create. This is a living document and any contributions you can make are greatly appreciated. Just pop a comment below.