34

I am trying to make olddir accessible from newdir with the mount command:

mount olddir newdir

Why do I get the following error?

mount: olddir is not a block device

Mat
  • 52,586

5 Answers5

41

On Linux one can perform a bind mount, which will splice an existing directory to a new mount point.

mount --bind <olddir> <mountpoint>

Solaris supports an alternate syntax:

mount -F lofs <olddir> <mountpoint>

*BSD uses mount_null instead (although it does not come with OS X).

mount_null <olddir> <mountpoint>
  • 1
    Exactly the answer! – trusktr Mar 31 '13 at 09:21
  • 1
    What are the differences (pros and cons) between this and a soft link? – sancho.s ReinstateMonicaCellio Apr 30 '20 at 19:17
  • @sancho.sReinstateMonicaCellio mount binds are useful if the user needing the directory can't gain access to it otherwise, or if a disk doesn't support softlinks. Binds are more powerful and will work more often. Binds work because the kernel sort of 'lies' to the application and tells it a directory contains contents that is actually somewhere else. Binds don't however persist across reboots unless you add it to /etc/fstab. If in doubt, us ln -s - it's easier, more flexible, doesn't require root, will tell you where the actualy directory is, etc. You generally don't need a binds. – aggregate1166877 Jul 15 '21 at 00:14
  • This should be the accepted answer! Speacialy when dealing with legacy softwares – Slim Aloui Feb 21 '23 at 14:27
20

mount attaches block storage devices that contain a filesystem to a directory, which is not what you're trying to do, hence the error message. What you want is to create a link from the new directory name to the old existing name. For that you must use the ln command to create a symbolic link.

ln -s olddir newdir
Kyle Jones
  • 15,015
  • I'm trying what you suggested, but instead of linking from olddir to newdir, it create a symlink called olddir inside newdir. So for example, after doing ln -s /olddir /newdir I end up with /newdir/olddir@ which links to /olddir. How do I make it do what you said? – trusktr Mar 31 '13 at 09:19
  • newdir should be the name you want created that points back to olddir. newdir should not already exist. – Kyle Jones Mar 31 '13 at 20:05
  • I totally understand what you mean, and that's what I'm trying to do, but it's doing something really odd, completely different. /olddir exists, and /newdir does not exist. Then, after I run ln -s /olddir /newdir, it is creating /newdir/olddir which links to /olddir. I don't want it to create /newdir/olddir. I want it to create /newdir only, which should link to /olddir, but that's not what happening. So instead of making /newddir, it is making /newdir/olddir. It's so weird!!! Get what I mean? – trusktr Apr 09 '13 at 00:44
4

If you're trying to mount a logical HDD/SDD

  • I dual boot: Windows 10/Ubuntu
  • I found this searching for a way to mount my Windows drive in Linux

Steps Taken

  • show block devices

    ℹ️ your HDD/SDD is a block storage device

    sudo blkid
    
    /dev/sda5: UUID="a6aa3891-1dc2-439a-b449-b9b1848db028" TYPE="ext4" PARTUUID="e4887e0f-05"
    /dev/sda1: LABEL="System" UUID="C6F4E92AF4E91E05" TYPE="ntfs" PARTUUID="e4887e0f-01"
    /dev/sda2: LABEL="Windows" UUID="4ABAF478BAF461BD" TYPE="ntfs" PARTUUID="e4887e0f-02"
    
  • In my case, I want to mount the device labeled "Windows" /dev/sda2

What didn't work

  • Turns out I reversed the mount command arguments to get the "is not a block device" complaint
    mkdir Windows
    sudo mount Windows /dev/sda2
    mount: /dev/sda2: /home/casey/Windows is not a block device.
    

What did work ‍♂️️

  • mount works like a boss when you list the arguments in the right order!
    sudo mount /dev/sda2 Windows 
    cd Windows 
    ls
    Config.Msi                hiberfil.sys   Intel         pagefile.sys   ProgramData     'Program Files (x86)'  '$Recycle.Bin'  'System Volume Information'   WCH.CN
    'Documents and Settings'   home           msdia80.dll   PerfLogs      'Program Files'   Recovery               swapfile.sys    Users                        Windows
    
fusion27
  • 151
0

When use mount shareddir newdir, I get the same, then I appoint the nfs server host to mount, it turns ok. The command like:

mount host:shareddir newdir
nanxj
  • 1
0

This could also happen when you mess up the external device and mounting point:

sudo mount external_device mount_point // OK
sudo mount mount_point external_device // NOT WORKING

I did it once and got the same error

sudo mount /dev/sdb1 /mnt/my_usb  // OK
sudo mount /mnt/my_usb /dev/sdb1  // WRONG
Dorin
  • 101