identify_and_mount_a_drive
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
identify_and_mount_a_drive [2016/07/27 18:56] – created walkeradmin | identify_and_mount_a_drive [2017/01/08 21:47] – walkeradmin | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Identify and Mount a Drive ====== | ====== Identify and Mount a Drive ====== | ||
\\ | \\ | ||
- | \\ | ||
- | |||
- | first we need to identify disk(s) please add this first..... | ||
- | |||
- | |||
- | If you are connected to the RasPi with a terminal window or via ssh use fdisk to view and recreate the partitions. (make sure you are root, su - root or sudo -s) | ||
\\ | \\ | ||
- | fdisk /dev/sda | + | This guide assumes you only have 1 external hard drive connected to the Pi. If so then it should be attached to /dev/sda1 – additional drives will use /dev/sdb1 and /dev/sdc1 etc. If you have multiple external hard drives you will need separate mount points for each drive (e.g. / |
\\ | \\ | ||
- | while in fdisk you can verify the partitions with the the p command | ||
- | Disk /dev/sda: xxx GB, xxx bytes | ||
\\ | \\ | ||
+ | Prepare the Mount Point | ||
+ | | ||
+ | First make a directory in which to mount the USB drive | ||
+ | sudo mkdir / | ||
+ | \\ | ||
+ | Make pi the owner of the mounted drive and make its permissions read, write and execute for it | ||
+ | | ||
+ | sudo chown -R pi:pi / | ||
+ | sudo chmod -R 775 / | ||
+ | \\ | ||
+ | Set all future permissions for the mount point to pi user and group. | ||
+ | | ||
+ | sudo setfacl -Rdm g:pi:rwx / | ||
+ | sudo setfacl -Rm g:pi:rwx / | ||
+ | \\ | ||
+ | Determine the USB Hard Drive Format | ||
- | Use the d command | + | You also need to know the file system the drive is formatted with |
- | + | | |
- | use the n command creates a new partition, use p for primary partition, Enter to default to partition 1, Enter to select first sector | + | sudo blkid |
- | + | \\ | |
- | now use the p command again to see your new partition | + | You will see something like this. Again it is the sda1 line we are interested in. Note the TYPE=" |
- | + | ||
- | Command (m for help): p | + | / |
- | Device Boot Start | + | / |
- | /dev/sda1 | + | / |
- | the changes need to be written to the partition table, so use the w command to commit. | + | / |
- | + | /dev/mmcblk0p6: SEC_TYPE=" | |
- | run the fdisk -l command | + | / |
- | + | / | |
- | Now you can make your file system. Use the mkfs command. | + | / |
- | + | \\ | |
- | mkfs /dev/sda1 | + | Update your repositories if your hard drive is anything but ext4 as the TYPE above |
- | after the superblocks | + | |
- | + | sudo apt-get update | |
- | mkdir /mydisk | + | \\ |
- | now mount it | + | Now mount the usb stick in there. If it is NTFS you will need to install some utilities first |
- | + | ||
- | mount /dev/sda1 /mydisk | + | sudo apt-get install ntfs-3g -y |
- | use df to verify disk is mounted. If you reboot | + | \\ |
- | + | If the drive is exfat install these utilities | |
- | try writing a file to the disk | + | |
- | + | sudo apt-get install exfat-utils -y | |
- | touch /diskname/test | + | \\ |
- | was the file created or did you get an err? | + | For all drive types mount the usb with this command, -o insures pi is the owner which should avoid permission issues |
+ | |||
+ | sudo mount -o uid=pi, | ||
+ | \\ | ||
+ | | ||
+ | |||
+ | sudo mount -t uid=pi, | ||
+ | \\ | ||
+ | If the mount -t command | ||
+ | |||
+ | sudo mount uid=pi, | ||
+ | \\ | ||
+ | If you are getting this drive is already mounted errors then you are probably using a distro which automounts the drives which you can either continue using but then you should remove the /etc/fstab entries. You will have to uninstall the automounting software if you want to mount using the method in this guide. | ||
+ | |||
+ | Remove the automounting software with this command | ||
+ | |||
+ | sudo apt-get remove usbmount --purge | ||
+ | \\ | ||
+ | Automount the USB Hard Drive on Boot | ||
+ | |||
+ | / | ||
+ | sudo ls -l / | ||
+ | \\ | ||
+ | You will see some output like this. The UUID you want is formatted like this XXXX-XXXX for the sda1 drive. If the drive is NTFS it can have a longer format like UUID="BABA3C2CBA3BE413". Note this UUID, for me it is BA8F-FFE8 | ||
+ | total 0 | ||
+ | |||
+ | lrwxrwxrwx 1 root root 15 Jan 1 1970 3d81d9e2-7d1b-4015-8c2c-29ec0875f762 -> ../../ | ||
+ | | ||
+ | | ||
+ | \\ | ||
+ | Now we will edit fstab to mount the USB by UUID on boot | ||
+ | |||
+ | sudo nano /etc/fstab | ||
+ | \\ | ||
+ | Add the line in red to the bottom, replace XXXX-XXXX with your UUID and exfat with your type if it is | ||
+ | different (e.g. ntfs, vfat, ext4). You may or may not need the quotation marks wrapped around the UID, you do | ||
+ | not need quotation marks wrapped around the file system type (ext4, vfat, NTFS etc). | ||
+ | \\ | ||
+ | The umask 0002 sets 775 permissions so the pi user and group can read, write and execute files | ||
+ | on the external USB drive. To completely eliminate permission issues you can set the umask to 0000 | ||
+ | which equals 777 permissions so anybody can read, write and execute. Note that 777 permissions are | ||
+ | considered a security risk. | ||
+ | \\ | ||
+ | If you have issues here then try replacing uid=pi, | ||
+ | \\ | ||
+ | This is an example for exfat | ||
+ | / | ||
+ | / | ||
+ | |||
+ | UUID=XXXX-XXXX | ||
+ | \\ | ||
+ | For NTFS, note that it is ntfs and not ntfs-3g | ||
+ | |||
+ | / | ||
+ | / | ||
+ | |||
+ | UUID=XXXX-XXXX | ||
+ | \\ | ||
+ | For ext4 using uid and gid is not recommended so use at your own risk as it could cause issues | ||
+ | |||
+ | / | ||
+ | / | ||
+ | |||
+ | UUID=XXXX-XXXX | ||
+ | \\ | ||
+ | If you get any errors you can replace uid=pi, | ||
+ | |||
+ | | ||
+ | / | ||
+ | |||
+ | | ||
+ | \\ | ||
+ | For using /dev/sda1 and defaults if you have troubles with UUID | ||
+ | |||
+ | / | ||
+ | / | ||
+ | |||
+ | / | ||
+ | \\ | ||
+ | Now test the fstab file works | ||
+ | |||
+ | sudo mount -a | ||
+ | \\ | ||
+ | If you didn’t | ||
+ | mount -a again until it succeeds | ||
+ | |||
+ | sudo reboot | ||
+ | \\ | ||
+ | \\ |
identify_and_mount_a_drive.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1