Mount & Fstab

Partitioning a disk tool from terminal
fdisk -l
cfdisk /dev/sdb
Permanent mount disk
/dev/sdb1 /mnt/backup_drive ext3  users,noatime,auto,rw,nodev,exec,nosuid 0 0
/dev/sdb1 /mnt/backup_drive ntfs  users,noatime,auto,rw,nodev,exec,nosuid 0 0
Fstab notes
  • /dev/sdb1 – media to mount
  • /mnt/backup_drive – location to mount to with a friendly name
  • ext3 – filesystem
  • users – allow all users, alternatively use user
  • noatime – don’t waste resources recording last access time or, if you want this info, change to atime.
  • auto – mount on boot
  • rw – read write access
  • nodev – prevents unauthorized device mounts
  • exec – execute programmes from disk
  • nosuid – do not allow set-user-identifier
Reload fstab και mtab
mount -a
List all mount points and mounted drives
df -h

Firstly I will tell you how to unmount any filesystem you mount after trying these commands. Unmounting is done through the “umount” command, which can be given a device or a mount point so:

sudo umount /mnt
sudo umount /dev/hda1

Would both unmount the filesystem on /dev/hda1 if it is mounted on /mnt.

Remember that a filesystem cannot be in use when it is unmounted, otherwise umount will give an error. If you know it is safe to unmount a filesystem you can use:

sudo umount -l /mountpoint

To do a “lazy” unmount

Note that files are often stored temporarily in the RAM to prevent filesystem fragmentation and speed up access times for slow devices like floppy disks. For this reason you should always unmount filesystems before you unplug or eject the device or you may find that your files have not actually been written to your device yet.

Mount a server share

First we have to install CIFS package:

sudo apt-get install cifs-utils
sudo apt-get install smbfs

This is the mount command

mount -t cifs //your_server/folder_of_your_server /your_local_mount_folder -o user=your_user,password=your_password,workgroup=WORKGROUP,ip= 

After you add the entry to /etc/fstab type:

sudo mount -a
This will (re)mount all entries listed in /etc/fstab.
Mount a password-protected share

Mounting unprotected (guest) network foldersFirst, let’s create the mount directory. You will need a separate directory for each mount.

sudo mkdir /media/windowsshare

Then edit your /etc/fstab file (with root privileges) to add this line:

//servername/sharename  /media/windowsshare  cifs  guest,uid=1000,iocharset=utf8  0  0
  • Where
    • guest indicates you don’t need a password to access the share,
    • uid=1000 makes the Linux user specified by the id the owner of the mounted share, allowing them to rename files,
    • iocharset=utf8 allows access to files with names in non-English languages. This doesn’t work with shares of devices like the Buffalo Tera Station, or Windows machines that export their shares using ISO8895-15.

Mount password protected network folders. The quickest way to auto-mounting a password-protected share is to edit /etc/fstab (with root privileges), to add this line:

//servername/sharename  /media/windowsshare  cifs  username=msusername,password=mspassword,iocharset=utf8,sec=ntlm  0  0

This is not a good idea however: /etc/fstab is readable by everyone and so is your Windows password in it. The way around this is to use a credentials file. This is a file that contains just the username and password.

Using a text editor, create a file for your remote servers logon credential:

gedit ~/.smbcredentials

Enter your Windows username and password in the file:


Save the file, exit the editor.

Change the permissions of the file to prevent unwanted access to your credentials:

chmod 600 ~/.smbcredentials

Then edit your /etc/fstab file (with root privileges) to add this line (replacing the insecure line in the example above, if you added it):

//servername/sharename /media/windowsshare cifs credentials=/home/ubuntuusername/.smbcredentials,iocharset=utf8,sec=ntlm 0 0 

Save the file, exit the editor.

Finally, test the fstab entry by issuing:

sudo mount -a

If there are no errors, you should test how it works after a reboot. Your remote share should mount automatically.

Create a folder and mount a NFS folder
sudo mount -t nfs4 192.168.X.X:/nfs-folde-name /mount-folder/
Display disk label
sudo e2label /dev/sda1
Change disk label
sudo e2label /dev/sda1 <<disk-label>>

Disk & Folder size

Sizes of all subdirectories

if you want to see the sizes of all subdirectories of /var/log compared with each other. You can do the following:

du -h --max-depth=1
Check File System Disk Space Usage
df -h ; Show Disk Space Usage in Human Readable Format