AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / ubuntu / Perguntas / 1072821
Accepted
S. Nixon
S. Nixon
Asked: 2018-09-07 08:12:17 +0800 CST2018-09-07 08:12:17 +0800 CST 2018-09-07 08:12:17 +0800 CST

Adição automática de sistemas de arquivos a /etc/fstab

  • 772

Eu uso lvcreate e mkfs para criar novos sistemas de arquivos em meus sistemas Ubuntu Server 18.04 LTS . Uma coisa que acho confusa é que o sistema não adiciona automaticamente nenhum novo sistema de arquivos criado por mim ao arquivo /etc/fstab . Os únicos adicionados são aqueles que foram criados quando o sistema foi inicialmente criado durante a instalação.

Existe alguma maneira ( sinalizador mkfs ou pacote apt separado ) de novos sistemas de arquivos serem inseridos automaticamente no arquivo /etc/fstab em vez de exigir que o administrador edite manualmente o arquivo?

filesystem fstab
  • 2 2 respostas
  • 5901 Views

2 respostas

  • Voted
  1. Best Answer
    Ravexina
    2018-09-07T08:22:51+08:002018-09-07T08:22:51+08:00

    Isso é normal, pois não há como as ferramentas ou o sistema operacional saberem onde você deseja montar as partições, volumes lógicos ou etc que acabou de criar.

    Os que você cria durante a instalação do sistema são detectados por suas escolhas (quando você seleciona seu root, home, etc) e são adicionados ao fstab porque são necessários para inicializar o sistema.

    você tem que editar manualmente o arquivo fstab.

    MAS, existem outras maneiras de montar partições automaticamente, ferramentas como udisks.

    https://help.ubuntu.com/community/AutomaticallyMountPartitions

    • 5
  2. S. Nixon
    2018-09-07T12:05:53+08:002018-09-07T12:05:53+08:00

    Aqui está um exemplo de script de shell Korn que fiz para ver se era possível automatizar a criação do LV, sistema de arquivos e ponto de montagem em um e, em seguida, adicionar a entrada apropriada em /etc/fstab.

    Não tenho certeza se funciona em todos os sistemas e configurações, mas parece estar funcionando para minhas necessidades até agora. Está longe de ser um produto acabado (sem muita verificação de erros), mas apenas me mostra que automatizar as rotinas lvcreate/mkfs/mount em um comando deve ser possível.

    #!/bin/ksh
    typeset -i ERRVAL
    
    while getopts V:L:m:s:t:h FSTR
    do
      case ${FSTR} in
      V) {
         VGNAME=${OPTARG}
         };;
      L) {
         LVNAME=${OPTARG}
         };;
      m) {
         MNTPT=${OPTARG}
         };;
      s) {
         SIZE=${OPTARG}
         };;
      t) {
         FSTYPE=${OPTARG}
         };;
      h) {
         print "help screens go here"
         exit 0
         };;
      esac
    done
    
    if test "${VGNAME}" = ""
    then
      print "ERROR: Volume group name must be specified. Valid volume groups:"
      vgdisplay |grep -i "vg name" |awk '{print $3}'
      exit 1
    elif test "$(vgdisplay |grep -i "vg name" |grep "${VGNAME}$")" = ""
    then
      print "ERROR: Unrecognized volume group name. Valid volume groups:"
      vgdisplay |grep -i "vg name" |awk '{print $3}'
      exit 1
    fi
    
    if test "${LVNAME}" = ""
    then
      print "ERROR: Logical volume name must be specified."
      exit 1
    elif test "$(lvdisplay|grep -i "lv name"|awk '{print $3}'|grep "^${LVNAME}$")" !
    = ""
    then
      print "ERROR: Logical volume already exists with that name."
      exit 1
    fi
    
    if test "${FSTYPE}" = ""
    then
      print "Type of filesystem not specified, defaulting to ext4"
      FSTYPE=ext4
    fi
    
    if test "${SIZE}" = ""
    then
      print "ERROR: Logical volume size must be supplied."
      exit 1
    else
      TMPSIZE="$(echo "${SIZE}" |tr -d '[ a-fhijln-zA-FHIJLN-Z!@#$%~]')"
      SIZE="${TMPSIZE}"
      if test "$(echo "${SIZE}" |egrep "K|k|M|m|G|g")" = ""
      then
        print "ERROR: LV size must be listed in K, M, or G."
        exit 1
      fi
    fi
    
    if test "${MNTPT}" = ""
    then
      print "ERROR: Mount point not specified."
      print ""
      exit 1
    elif test -d ${MNTPT}
    then
      print "Mount point already exists: ${MNTPT}"
      print "Use this directory (Y/N)? \c"
      read YORN
      if test "${YORN}" != "Y" -a "${YORN}" != "y"
      then
        exit 1
      fi
    elif test ! -d ${MNTPT}
    then
      print "Mount point does not exist: ${MNTPT}"
      print "Create this directory (Y/N)? \c"
      read YORN
      if test "${YORN}" = "Y" -o "${YORN}" = "y"
      then
        mkdir ${MNTPT}
      else
        exit 1
      fi
    fi
    
    DEVNAME="/dev/${VGNAME}/${LVNAME}"
    
    # CREATE THE LOGICAL VOLUME
    print "Issuing command:"
    print "lvcreate -L${SIZE} -n ${DEVNAME} ${VGNAME}"
    lvcreate -L${SIZE} -n ${DEVNAME} ${VGNAME}
    ERRVAL=$?
    if test ${ERRVAL} -ne 0
    then
      print "ERROR: lvcreate command exited with non-zero status."
      exit 0
    fi
    
    # CREATE THE FILESYSTEM
    print "Issuing command:"
    print "mkfs -t ${FSTYPE} ${DEVNAME}"
    mkfs -t ${FSTYPE} ${DEVNAME}
    ERRVAL=$?
    if test ${ERRVAL} -ne 0
    then
      print "ERROR: mkfs command exited with non-zero status."
      exit 0
    fi
    
    # MOUNT POINT SHOULD ALREADY EXIST SO MOUNT THE NEW FILESYSTEM
    print "Issuing command:"
    print "mount ${DEVNAME} ${MNTPT}"
    mount ${DEVNAME} ${MNTPT}
    ERRVAL=$?
    if test ${ERRVAL} -ne 0
    then
      print "ERROR: mount command exited with non-zero status."
      exit 0
    fi
    
    # ADD TO /etc/fstab
    print "Obtain UUID value from blkid"
    UUID=$(blkid |grep "${VGNAME}-${LVNAME}:"|cut -f2 -d'='|cut -f2 -d'"')
    if test "${UUID}" = ""
    then
      print "ERROR: Unable to determine UUID to use for ${LVNAME}"
      exit 1
    fi
    print "Saving /etc/fstab as /etc/fstab.$$"
    /bin/cp -p /etc/fstab /etc/fstab.$$
    print "Adding /etc/fstab entry"
    echo "UUID=${UUID} ${MNTPT} ${FSTYPE} defaults 0 0" >> /etc/fstab
    ERRVAL=$?
    if test ${ERRVAL} -ne 0
    then
      print "ERROR: Could not save entry to /etc/fstab"
      exit 1
    fi
    # END OF SCRIPT #
    
    • 0

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Existe um comando para listar todos os usuários? Também para adicionar, excluir, modificar usuários, no terminal?

    • 9 respostas
  • Marko Smith

    Como excluir um diretório não vazio no Terminal?

    • 4 respostas
  • Marko Smith

    Como descompactar um arquivo zip do Terminal?

    • 9 respostas
  • Marko Smith

    Como instalo um arquivo .deb por meio da linha de comando?

    • 11 respostas
  • Marko Smith

    Como instalo um arquivo .tar.gz (ou .tar.bz2)?

    • 14 respostas
  • Marko Smith

    Como listar todos os pacotes instalados

    • 24 respostas
  • Martin Hope
    Flimm Como posso usar o docker sem sudo? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    led-Zepp Como faço para salvar a saída do terminal em um arquivo? 2014-02-15 11:49:07 +0800 CST
  • Martin Hope
    ubuntu-nerd Como descompactar um arquivo zip do Terminal? 2011-12-11 20:37:54 +0800 CST
  • Martin Hope
    TheXed Como instalo um arquivo .deb por meio da linha de comando? 2011-05-07 09:40:28 +0800 CST
  • Martin Hope
    Ivan Como listar todos os pacotes instalados 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    David Barry Como determino o tamanho total de um diretório (pasta) na linha de comando? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "Os seguintes pacotes foram retidos:" Por que e como resolvo isso? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford Como os PPAs podem ser removidos? 2010-07-30 01:09:42 +0800 CST

Hot tag

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve