In this article, we are going to enable or create a service to boot with the system Ubuntu 20.04 LTS. In it, we’ll insert a script to mount the share of a Windows machine. This will be redone every time Ubuntu reboots. In the tutorial, we will use the vim text editor, however, feel free to use your preferred editor.
In this tutorial you will learn:
- How to check service enabled/disabled/ state
- How to enable service to start on boot
- How to disable service to start on boot
From the Ubuntu console, use the following commands to create the service and change its permission to become an executable file:
# touch /etc/systemd/system/mapeamento.service
# chmod 664 /etc/systemd/system/mapeamento.service
After creating the service, you need to edit it, enter the content below:
# vim /etc/systemd/system/mapeamento.service
[Unit]
After=network.service
[Service]
ExecStart=/usr/local/bin/mapeamento.sh
[Install]
WantedBy=default.target
Note: on the ExecStart line you must put the full path of the script or command to run.
Now, let’s enable the mapping.service service:
# cd /etc/systemd/system/
# systemctl daemon-reload
# systemctl enable /etc/systemd/system/mapeamento.service
Install Python on Rocky Linux 8
As a last step, you will need to create the shell script and assign the necessary permissions:
# touch /usr/local/bin/mapeamento.sh
# chmod 744 /usr/local/bin/mapeamento.sh
Later, it is necessary to edit it with the command below:
# vim /usr/local/bin/mapeamento.sh
And after that, insert the script content below:
#!/bin/bash mount -t cifs -o vers=1.0,_netdev,username=user,password=pass,uid=1000,gid=1000 //192.168.x.x/mapeamento01 /mnt/mapeamento01 mount -t cifs -o vers=1.0,_netdev,username=user,password=pass,uid=1000,gid=1000 //192.168.x.x/mapeamento02 /mnt/mapeamento02
In the above content, the is being mounted share existing of a Windows host and presented in both /mnt/mapping01 and /mnt/mapping02 directories.
And finally, create the following directories to receive the mappings.
# mkdir /mnt/mapping01
# mkdir /mnt/mapping02
Conclusion
Every time you need to reboot the Ubuntu system, the mapping.sh script will be run in which case the mapping will be remounted automatically.
Leave a Reply Cancel reply