User Tools

Site Tools


identify_and_mount_a_drive

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
identify_and_mount_a_drive [2016/07/28 21:35] walkeradminidentify_and_mount_a_drive [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Identify and Mount a Drive ====== ====== Identify and Mount a Drive ======
 \\  \\ 
-\\ 
-First we need to identify the disk(s): 
 \\  \\ 
 +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. /mnt/usbstorage1 and /mnt/usbstorage2).
 \\  \\ 
-    sudo blkid 
 \\  \\ 
-This will list any recognised devices:+    Prepare the Mount Point 
 +     
 +    First make a directory in which to mount the USB drive 
 +    sudo mkdir /mnt/usbstorage
 \\  \\ 
 +    Make pi the owner of the mounted drive and make its permissions read, write and execute for it
 +    
 +    sudo chown -R pi:pi /mnt/usbstorage
 +    sudo chmod -R 775 /mnt/usbstorage
 +\\ 
 +    Set all future permissions for the mount point to pi user and group.
 +    
 +    sudo setfacl -Rdm g:pi:rwx /mnt/usbstorage
 +    sudo setfacl -Rm g:pi:rwx /mnt/usbstorage
 +\\ 
 +    Determine the USB Hard Drive Format
 +
 +    You also need to know the file system the drive is formatted with
 +   
 +    sudo blkid
 +\\ 
 +    You will see something like this. Again it is the sda1 line we are interested in. Note the TYPE="exfat" at the end, you will need this for the fstab file. It is easiest to copy it now and paste it after running nano in the next step.
 +    
 +    /dev/sda1: UUID="31db83ca-ac6d-4bc7-b076-848c7c71025e" TYPE="ext2" PARTUUID="279bf5b4-01"
 +    /dev/mmcblk0: PTUUID="0006dd3f" PTTYPE="dos"
     /dev/mmcblk0p1: LABEL="RECOVERY" UUID="0403-0201" TYPE="vfat" PARTUUID="0006dd3f-01"     /dev/mmcblk0p1: LABEL="RECOVERY" UUID="0403-0201" TYPE="vfat" PARTUUID="0006dd3f-01"
     /dev/mmcblk0p5: LABEL="SETTINGS" UUID="705f6e2b-fac6-4f33-8611-d57a9c9f04e1" TYPE="ext4" PARTUUID="0006dd3f-05"     /dev/mmcblk0p5: LABEL="SETTINGS" UUID="705f6e2b-fac6-4f33-8611-d57a9c9f04e1" TYPE="ext4" PARTUUID="0006dd3f-05"
Line 15: Line 36:
     /dev/mmcblk0p8: LABEL="boot-rbp2" UUID="200C-EA5B" TYPE="vfat" PARTUUID="0006dd3f-08"     /dev/mmcblk0p8: LABEL="boot-rbp2" UUID="200C-EA5B" TYPE="vfat" PARTUUID="0006dd3f-08"
     /dev/mmcblk0p9: LABEL="root-rbp2" UUID="26d10fa3-fe0a-4044-b24a-9b85c2079122" TYPE="ext4" PARTUUID="0006dd3f-09"     /dev/mmcblk0p9: LABEL="root-rbp2" UUID="26d10fa3-fe0a-4044-b24a-9b85c2079122" TYPE="ext4" PARTUUID="0006dd3f-09"
-    /dev/mmcblk0: PTUUID="0006dd3f" PTTYPE="dos" 
-    /dev/sda: PTUUID="279bf5b4" PTTYPE="dos" 
 \\  \\ 
-In this example, the first 6 items are the SD card that Raspbian booted from **/dev/mmcblk0px**. The last device **/dev/sda** is a USB Hard Disk. This is the disk I want to add to Raspbian.+    Update your repositories if your hard drive is anything but ext4 as the TYPE above 
 +     
 +    sudo apt-get update
 \\  \\ 
 +    Now mount the usb stick in there. If it is NTFS you will need to install some utilities first
 +    
 +    sudo apt-get install ntfs-3g -y
 \\  \\ 
-Now that we know the disk we wish to work on is /dev/sda we can use:+    If the drive is exfat install these utilities 
 +     
 +    sudo apt-get install exfat-utils -y
 \\  \\ 
-    sudo fdisk /dev/sda+    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,gid=pi /dev/sda1 /mnt/usbstorage
 \\  \\ 
-    enter p to display partition information+    If you get an error use this syntax
          
-    Disk /dev/sda: 298.1 GiB320072933376 bytes, 625142448 sectors +    sudo mount -t uid=pi,gid=pi /dev/sda1 /mnt/usbstorage
-    Units: sectors of 1 * 512 512 bytes +
-    Sector size (logical/physical): 512 bytes / 512 bytes +
-    I/O size (minimum/optimal): 512 bytes 512 bytes +
-    Disklabel type: dos +
-    Disk identifier: 0x279bf5b4+
 \\  \\ 
-We can see the size is 298.1 GB.+    If the mount -t command returns an error then use this syntax 
 +     
 +    sudo mount uid=pi,gid=pi /dev/sda1 /mnt/usbstorage
 \\  \\ 
-    Use the d command to delete existing partition+    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.
          
-    No partition is defined yet! +    Remove the automounting software with this command 
-    Could not delete partition 81165   +     
 +    sudo apt-get remove usbmount --purge
 \\  \\ 
-In this case, there are no partitions to delete+    Automount the USB Hard Drive on Boot 
 +     
 +    /mnt/usbstorage will be the folder in which you store your media. We want it to be automounted on boot The best way to do this is through the UUID. Get the UUID by using this commmand 
 +sudo ls -l /dev/disk/by-uuid/
 \\  \\ 
-To create a new partition, use: +    You will see some output like this. The UUID you want is formatted like this XXXX-XXXX for the sda1 driveIf the drive is NTFS it can have a longer format like UUID="BABA3C2CBA3BE413"Note this UUID, for me it is BA8F-FFE8 
- +total 0
-    n This creates a new partition +
-    p - This is for a primary partition +
-    Enter - To default to partition 1 +
-    Enter - To select first sector +
-    Enter - To select last sector. +
-\\  +
-You should now have a new partition+
-\\  +
-    p - To display the new partition+
          
-    Device     Boot Start       End   Sectors   Size Id Type +    lrwxrwxrwx 1 root root 15 Jan  1  1970 3d81d9e2-7d1b-4015-8c2c-29ec0875f762 -> ../../mmcblk0p2 
-    /dev/sda1        2048 625142447 625140400 298.1G 83 Linux +    lrwxrwxrwx 1 root root 15 Jan  1  1970 787C-2FD4 -> ../../mmcblk0p1 
-\\  +    lrwxrwxrwx 1 root root 10 Oct 26 21:10 BA8F-FFE8 -> ../../sda1
-The changes need to be written to the partition table:+
 \\  \\ 
-    w - To commit changes+    Now we will edit fstab to mount the USB by UUID on boot
          
-    The partition table has been altered. +    sudo nano /etc/fstab
-    Calling ioctl() to re-read partition table. +
-    Syncing disks.+
 \\  \\ 
-Now run the following command to see your diskwhich will now include /dev/sda1+    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, vfatNTFS etc).
 \\  \\ 
-    sudo fdisk -l+    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.
 \\  \\ 
-There will be a large outputbut the important part is at the end:+If you have issues here then try replacing uid=pi,gid=pi with just the word defaults (typical for ext4). You can also try replacing the UUID with the /dev/sda1 line.
 \\  \\ 
-    Device     Boot Start       End   Sectors   Size Id Type +    This is an example for exfat 
-    /dev/sda1        2048 625142447 625140400 298.1G 83 Linux +    /dev/mmcblk0p1 /boot vfat defaults 0 2 
-\\  +    /dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1
-/dev/sda1 is the partition we have just created on device /dev/sda +
-\\  +
-Now we need to create the file system: +
-\\  +
-    sudo mkfs /dev/sda1+
          
-    mke2fs 1.42.12 (29-Aug-2014) +    UUID=XXXX-XXXX  /mnt/usbstorage exfat   nofail,uid=pi,gid=pi     0 
-    /dev/sda1 contains a ntfs file system labelled '300gb' +\\   
-    Proceed anyway? (y,n)    <---------------------------------You have to say 'Y' Here.+    For NTFSnote that it is ntfs and not ntfs-3g
          
-    Depending on drive sizethis will take a minute or two+    /dev/mmcblk0p1 /boot vfat defaults 0 2 
 +    /dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1
          
-    Creating filesystem with 78142550 4k blocks and 19537920 inodes +    UUID=XXXX-XXXX    /mnt/usbstorage    ntfs   nofail,uid=pi,gid=pi    0   0 
-    Filesystem UUID: 6af40af7-759f-4ee5-afea-882e9f58f17e +\\      
-    Superblock backups stored on blocks: +    For ext4 using uid and gid is not recommended so use at your own risk as it could cause issues (thanks mk2soldier).
-            3276898304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208+
-            4096000, 7962624, 11239424, 20480000, 23887872, 71663616+
          
-    Allocating group tables: done +    /dev/mmcblk0p1 /boot vfat defaults 0 2 
-    Writing inode tables: done +    /dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1 
-    Writing superblocks and filesystem accounting information: done+     
 +    UUID=XXXX-XXXX    /mnt/usbstorage    ext4   nofail,uid=pi,gid=pi    0   0
 \\  \\ 
-After the superblocks are created and you get a command prompt, Now you are ready to mount your disk.+    If you get any errors you can replace uid=pi,gid=pi with defaults or remove it entirely 
 +     
 +    /dev/mmcblk0p1 /boot vfat defaults 0 2 
 +    /dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1 
 +     
 +    UUID=XXXX-XXXX    /mnt/usbstorage    ext4   nofail,defaults    0   0
 \\  \\ 
-Lets create a mount point and call it NewDisk +    For using /dev/sda1 and defaults if you have troubles with UUID 
-\\  +     
-    sudo mkdir /mydisk    <-This creates a mount point (a folder) to mount our diskthe folder is called mydisk +    /dev/mmcblk0p1 /boot vfat defaults 0 2 
-\\  +    /dev/mmcblk0p2 / ext4 errors=remount-ro,noatime 0 1 
-To Mount the Disk +     
-\\  +    /dev/sda1    /mnt/usbstorage    ext4   nofail    0   0
-    sudo mount /dev/sda1 /NewDisk    <--- bear in mind that your disk might not be sda1 +
-\\  +
-Use df to verify disk is mounted. If you reboot you will need to remount it (you might want to add it to /etc/fstab)+
 \\  \\ 
-    df+    Now test the fstab file works
          
-    Filesystem     1K-blocks    Used Available Use% Mounted on +    sudo mount -a
-    /dev/root        7928236 3577848   3924612  48% / +
-    devtmpfs          469544          469544   0% /dev +
-    tmpfs             473880          473880   0% /dev/shm +
-    tmpfs             473880    6520    467360   2% /run +
-    tmpfs               5120            5116   1% /run/lock +
-    tmpfs             473880          473880   0% /sys/fs/cgroup +
-    /dev/mmcblk0p6     64366   20436     43930  32% /boot +
-    tmpfs              94776           94776   0% /run/user/1000 +
-    /dev/sda1      307665360   64344 291972508   1% /NewDisk    <---- here is our new disk+
 \\  \\ 
-Try writing a file to the disk to test it+    If you didn’t get errors reboot, otherwise try the suggestions above to get it working then 
-\\  +    mount -a again until it succeeds
-    sudo touch /NewDisk/test+
          
-    ls /NewDsik +    sudo reboot 
-     +\\ 
-    lost+found  test    +
 \\  \\ 
- 
- 
identify_and_mount_a_drive.1469738101.txt.gz · Last modified: 2023/03/09 22:35 (external edit)