Showing Posts From

Filesystem

Automatic mount hard drive or usb stick on Raspberry Pi

Requirements:Raspbian or similar distributionUSB hard drive or Memory stick with a partition (NTFS/Fat32/HFS+/Ext4)As a first step you need to update the package lists of Raspbian and install the drivers for NTFS and HFS+. sudo apt-get update && sudo apt-get -y install ntfs-3g hfsutils hfsprogsCreate a new folder in the directory /media in which you later on will mount the memory stick or USB hard drive. You can name the folder as you like, however, do not use special characters or spaces. Furthermore, change the owner of the folder to pi. In case you use a different user name you need to replace pi in the command below by the name you use.sudo mkdir /media/usbhdd sudo chown pi /media/usbhdd "In oder to attach a file system a mount point has to exist. A mount point is an empty folder through which additional file systems are mouted and accessed." ubuntuusers.deAttach the storage medium to the Raspberry.Now you need the path to the partition of the storage medium (in this case it is /dev/sda1). sudo fdisk -lFor the moment you manually include the storage medium with the following command. Replace /dev/sda1 with the path to the partion of the storage medium that we just figured. Ext4 sudo mount /dev/sda1 /media/usbhdd NTFS sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/usbhdd/ HFS+ sudo mount -t hfsplus -o force.uid=pi,gid=pi /dev/sda1 /media/usbhdd/ FAT32 sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/usbhdd/ From this point on you can already access the storage medium with cd /media/usbhdd/.</>We need the UUID of the hard drive that the storage medium will be automatically mounted after a restart. Enter the following command into the console: sudo blkid "UUID stands for Universally Unique Identifier and is a standard to identify information in computers. Each Linux file system has a UUID through which it can be identified. As an alternative the file systems can be identified through a device file /dev/sdaX but the labels can change in this case. " ubuntuusers.deOpen the file fstab with the Nano text editor sudo nano /etc/fstab and add one of the lines for your file system. Replace the UUID that you determined in the previous step. Exit the Nano editor afterwards with Strg+x (Win) ctrl+x (Mac) and confirm the changes with y or j ( depending on your language settings.#Ext4 UUID=13aa0627-fb13-4d2f-8d3f-53aea43b9439 /media/usbhdd ext4 defaults 0 0#NTFS UUID=10BF-F2D6 /media/usbhdd/ ntfs-3g defaults,umask=000,users 0 0#HFS+ UUID=10BF-F2D6 /media/usbhdd/ hfsplus defaults,umask=000,users 0 0#FAT32 UUID=10BF-F2D6 /media/usbhdd/ vfat defaults,umask=000,users 0 0 More information about fstab can be found here.Done! You can now access your files on the usb hard drive or memory stick and the drive will be mounted automatically after a restart.

Raspberry Pi: USB Stick / Festplatte (HDD) automatisch einbinden/mounten

Update 15.02.2022: Exfat hinzugefügt, Links aktualisiert und kleinere Optimierungen Voraussetzungen:Raspbian/Raspberry Pi OS oder ähnlich Distribution wie DebianUSB-Festplatte oder USB Stick mit einer Partition (NTFS/Fat32/EXFAT/HFS+/Ext4)Als erstes aktualisierst du die Paketlisten von Raspbian und installierst die Treiber für NTFS, EXFAT und HFS+. sudo apt-get update && sudo apt-get -y install ntfs-3g hfsutils hfsprogs exfatprogsErstelle einen Ordner im Verzeichnis /media, in den du später das USB-Speichermedium einbindest. Du kannst den Namen frei wählen (keine Sonder- und Leerzeichen). Ändere noch den Besitzer des Ordners in pi. Falls du einen anderen Benutzernamen verwendest, musst du pi durch deinen Namen in dem Befehl ersetzen.sudo mkdir /media/usbhdd sudo chown pi /media/usbhdd "Um ein Dateisystem einhängen zu können, muss zuerst ein Einhängepunkt (Mountpunkt) vorhanden sein. Dies ist ein zunächst leerer Ordner. … Über diesen Einhängepunkt wird dann später auf das eingehängte Dateisystem zugegriffen." ubuntuusers.deFestplatte/USB-Stick am Raspberry anschließen.Es wird die UUID der Festplatte/USB-Stick benötigt, damit bei einem Neustart das USB-Speichermedium automatisch eingebunden werden kann. Gib den folgenden Befehl in die Konsole ein. sudo blkid "UUID steht für Universally Unique Identifier und bezeichnet nach einem bestimmten Standard formatierte Identifikationsnummern Jedes Linux-Dateisystem besitzt einen UUID, über den es identifiziert werden kann. Zwar kann man das auch über die Geräte-Dateien /dev/sdaX tun, aber die Nummerierung kann sich hier ändern." ubuntuusers.deÖffne die Datei fstab mit den Nano Text Editor sudo nano /etc/fstab und füge eine der Zeilen für dein Dateiformat hinzu. Ersetz noch die UUID die du im vorherigen Schritt ermittelt hast.# Ext4 UUID=13aa0627-fb13-4d2f-8d3f-53aea43b9439 /media/usbhdd ext4 defaults 0 0#NTFS UUID=10BF-F2D6 /media/usbhdd/ ntfs-3g defaults,umask=022,users 0 0#HFS+ UUID=10BF-F2D6 /media/usbhdd/ hfsplus defaults,umask=022,users 0 0#FAT32 UUID=10BF-F2D6 /media/usbhdd/ vfat defaults,umask=022,users,nofail 0 0#EXFAT UUID=blskejeorio4dkal83 /media/usbhdd exfat defaults,umask=022,users,nofail 0 0 Beende den Nano Editor nach dem einfügen mit Strg+x (Win) ctrl+x (Mac) und bestätige die Änderung mit y oder j (je nach Spracheinstellung). Mehr Informationen zu fstab findest du hier. Die Option _umask=022_gibt euch die Rechte Lesen/Schreiben und ausführen. Gruppen und andere, haben nur Lese und Ausführrechte. Mit umask=022 gebt ihr allen Benutzern die Rechte zum Lesen/Schreiben, was aber ein Sicherheitsproblem sein kann. Hier ein umask Code Generator. Mit nofail legt fest das beim Bootvorgang die Festplatte übersprungen wird, falls sie nicht vorhanden ist. So wird ein Hängen-bleiben verhindert. users legt fest, dass jeder Benutzer das Gerät ein- und aushängen darf. Die Dump Option legt fest, ob bei einem Backup mit dem Programm dump die Partition mit gesichert werden soll. Mit 0 wird sie nicht gesichert.Führe folgenden Befehl aus, um zu testen ob das Mounten funktioniert.sudo mount -a Wenn alles funktioniert hat, sollte du mit df -l eine Liste ausgegeben werden, in der dein USB-Stick aufgeführt wird. Unter _Mounted on_ siehst du in welchem Ordner du auf die Dateien zugreifen kannst. Jetzt kannst du schon mit cd /media/usbhdd/ auf das USB-Speichermedium zugreifen.Geschafft! Du kannst auf deine Dateien auf dem USB-Stick oder USB-Festplatte zugreifen und nach einem Neustart wird das Speichermedium automatisch eingebunden.