Монтирование томов fstab при запуске

В Ubuntu 18.04 я потерял возможность автоматического монтирования сетевых ресурсов из fstab при запуске. Каждый раз, когда я запускаю свой компьютер, мне приходится монтировать все общие ресурсы вручную с помощью sudo mount -a ... Я уже пытался включить @reboot mount -a в crontab, но это не работает ... Это случилось со мной с Ubuntu MATE 18.04 и Kubuntu 18.04, так что, похоже, это проблема ядра Ubuntu, а не проблема рабочего стола ...

Приветствия Бруно

1
задан 27 June 2018 в 21:08

3 ответа

Я попробовал эти варианты, чтобы решить ту же проблему в Ubuntu 18.04LTS:

  • Вставить «comment = systemd.automount» в соответствующие операторы монтирования в / etc / fstab. ПРОБЛЕМА: эта опция произвела несколько монтирований одного и того же сетевого ресурса, когда я пытался использовать его для двух разных сетевых ресурсов.
  • Вставьте «mount -a» в /etc/rc.local. ПРОБЛЕМА: Это, похоже, не имеет никакого эффекта! В качестве суперпользователя создайте сценарий со следующим текстом в каталоге /etc/network/if-up.d/ и предоставьте ему разрешения на выполнение:
  • В качестве суперпользователя создайте сценарий со следующим текстом в каталоге / etc / network / if-up.d / и предоставить ему права на выполнение:

#!/bin/sh mount -a

РЕШЕНИЕ ПРОБЛЕМЫ! Последнее решение работает хорошо. Сценарии, расположенные в /etc/network/if-up.d/, запускаются после установления сетевого подключения. Затем этот сценарий монтирует сетевые ресурсы (и любые другие ожидающие монтирования), уже указанные в /etc/fstab.

.
1
ответ дан 27 June 2018 в 21:08

Я имел ту же проблему и попытался использовать autofs и команды запуска и других, с неудовлетворительными результатами. Я наконец решил его путем записи моего собственного сценария, который я добавляю как сценарий Автоматического запуска. Этот сценарий требует Python и что у пользователя есть sudo полномочия (без пароля) для, по крайней мере, mount команда.

Вот сценарий Python (main.py):

"""
Code to do a user level mounts/unmounts

Usage:
    python3 main.py mount|unmount

The mounts list contains the information needed to perform the mount and unmount.
These mounts should not appear in the /etc/fstab file.
each element of the mounts list is itself a list in the format:
    [device, mount_dir, mount_options, ...]
where `device` is the device to be mounted such as '//192.168.1.3/Public'
      'mount_dir' is the mount point
      'mount_options' is the options to be used by the mount command.
            Each option must be an element itself.
            for example: '-t', 'cifs', '-o', 'rw,users,noperm,guest,soft,cache=none,sec=none'
Edit the `mounts` list to your needs.

The mount command issued will be 'sudo mount <mount_options> <device> <mount_dir>`.
The unmount command will be `sudo umount <mount_dir>`.
This requires that the user be in the `sudoers` group with the
"NOPASSWD" argument, for example:
    jra ALL=(ALL) NOPASSWD: ALL
gives user `jra` the ability to use the `sudo` command without ever
providing a password. (This can be modified to limit
the commands allowed without a password).

Upon start of this script, attempts will be made to mount each element
in the mounts list.
Failed mounts are added to the `waiting_mounts` list, and mounts for
those failures are retried after delays specified in 'SLEEP_SECONDS' list.

Unmounting is performed by the OS, normally not by this script.

A log directory `.simpleAutomount` is created in the users home directory.

"""

import subprocess
import time
import sys
from datetime import datetime
import os.path
import shutil

# this is the list of mounts to be performed (list of lists)
mounts=[
        ['//192.168.1.3/Public', '/mnt/mybook', '-t', 'cifs', '-o', 'rw,_netdev,users,noperm,guest,soft,cache=none,sec=none,vers=1.0' ],
#        ['/dev/sda4', '/windows', '-t', 'ntfs']
    ]

SLEEP_SECONDS = [5, 5, 5, 10, 20, 100, 100]  # number of seconds to sleep between successive mount attempts
MAX_TRIES = len(SLEEP_SECONDS)
waiting_mounts = []


def ping(host):
    """
    ping the specified host and return the exit value of the ping

    success == 0 means success
    success == 1 means no reply received
    success == 2 means no network available
    """
    cmd = ['ping', host, '-c 1']
    success = subprocess.call(cmd, stdout=subprocess.PIPE)
    return success


def process_mount(mnt):
    """
    attempt to perform one mount as indicated in the mnt list

    :param mnt: one element from the mounts list (which is a list in itself)
    :return: True if the mount was successful (or the mount should not be attempted again). False if the mount should be tried again later
    """
    host = None
    if mnt[0].startswith('//'):          # format is //host/directory
        index = mnt[0].index('/', 2)
        host = mnt[0][2:index]
    elif ':' in mnt[0]:                  # format is host:directory
        index = mnt[0].index(':')
        host = mnt[0][:index]
    mnt_cmd = ['sudo', 'mount']
    mnt_cmd.extend(mnt[2:])
    mnt_cmd.extend(mnt[0:2])
    if host is None:        # this is not a network mount, do not need to ping
        logFile.write('running ' + str(mnt_cmd) + '\n')
        logFile.flush()
        returnCode = subprocess.call(mnt_cmd)
        logFile.write('\t' + str(mnt_cmd) + ' finished with return code: ' + str(returnCode) + '\n')
        logFile.flush()
        return True
    elif ping(host) == 0:
        logFile.write('running ' + str(mnt_cmd) + '\n')
        logFile.flush()
        returnCode = subprocess.call(mnt_cmd)
        logFile.write('\t' + str(mnt_cmd) + ' finished with return code: ' + str(returnCode) + '\n')
        logFile.flush()
        return True
    else:
        return False


def usage(unrecognized_opt=None):
    if unrecognized_opt is not None:
        print('Unrecognized option: ' + str(unrecognized_opt) + '\n')
        logFile.write('Unrecognized option: ' + str(unrecognized_opt) + '\n')
    print('usage:\n\tpython3 ' + sys.argv[0] + ' mount|unmount\n')
    logFile.write('usage:\n\tpython3 ' + sys.argv[0] + ' mount|unmount\n')
    logFile.flush()


if __name__ == '__main__':
    """
    The starting point for the SimpleAutomount script

    Legal arguments are 'mount' or 'unmount'
    'mount' will inspect each element of the mounts list and attempt the mounts
    'unmount' will attempt to unmount each element of the mount list
    """
    if len(sys.argv) != 2:
        usage()
        sys.exit(1)

    theDate = datetime.now()

    # create a log file in the users ~/.simpleAutomount directory
    home = os.path.expanduser("~")
    sam = os.path.join(home, '.simpleAutomount')
    if not os.path.exists(sam):
        os.mkdir(sam, 0o755)
    logFileName = os.path.join(sam, "simpleAutomount.log")
    logFile = open(logFileName, 'a')

    # start logging
    logFile.write('\n\nSimpleAutomount started at ' + str(theDate) + ' with arg: ' + sys.argv[1] + '\n')
    logFile.flush()

    if sys.argv[1].lower() == 'mount':    # do mount
        os.spawnlp(os.P_NOWAIT, sys.executable, sys.executable, sys.argv[0], 'forked_mount') # fork so that systemd does not wait and delay login
        sys.exit(0) # indicate success
    elif sys.argv[1].lower() == 'forked_mount':  # we are forked, so we can take our time here
        for mnt in mounts:
            if not process_mount(mnt):  # the mount was not successful and should be tried again later
                logFile.write('appending ' + mnt[0] + ' to waiting mounts\n')
                logFile.flush()
                waiting_mounts.append((mnt))    # add this mount to the waiting_mounts list to be tried again later

        # if any mounts were unsuccessful and should be tried again, loop to try mounting again
        try_count = 0
        while len(waiting_mounts) > 0 and try_count < MAX_TRIES:
            logFile.write('sleeping for ' + str(SLEEP_SECONDS[try_count]) + ' seconds\n')
            logFile.flush()
            time.sleep(SLEEP_SECONDS[try_count])

            # process waiting_mounts, starting at the end for ease of deletion
            indx = len(waiting_mounts) - 1
            for i in range(indx, -1, -1):
                mnt = waiting_mounts[i]
                logFile.write('Attempting to mount ' + mnt[0] + ' for try number ' + str(try_count) + '\n')
                logFile.flush()
                # try this mount again
                if process_mount(mnt):
                    del waiting_mounts[i]    # mount was successful, so remove this entry from waiting mounts
            try_count += 1
        logFile.write('SimpleAutomount exiting with ' + str(len(waiting_mounts)) + ' remaining unmounted\n')
    elif sys.argv[1].lower() == 'unmount':    # do unmount
        for mnt in mounts:
            cmd = ['sudo', 'umount', mnt[1]]
            #journal.send('running ' + str(cmd), SYSLOG_IDENTIFIER='simple_automount', SYSLOG_PID=str(os.getpid()))
            logFile.write('running ' + str(cmd) + '\n')
            logFile.flush()
            returnCode = subprocess.call(cmd)
            logFile.write('\t' + str(cmd) + ' finished with return code: ' + str(returnCode) + '\n')
            logFile.flush()
        sys.exit(0)
    else:
        usage(unrecognized_opt=sys.argv[1])
        sys.exit(1)
0
ответ дан 27 June 2018 в 21:08

В Ubuntu 18.04 назначения жестких дисков изменились. Устройство / dev / sda3, которое я использовал в Ubuntu 16.04, переместилось в / dev / sde3 в Ubuntu 18.04.

Прежде чем я изменил запись в fstab, загрузка останавливается с серьезной ошибкой.

После того, как я нашел правильные назначения устройств, система продолжила загрузку и смонтировала все разделы, которые я назначил в fstab.

Чтобы получить возможные назначения, попробуйте команду:

sudo fdisk -l

С уважением,

0
ответ дан 27 June 2018 в 21:08

Другие вопросы по тегам:

Похожие вопросы: