Tag Archives: mount

Ubuntu Server fstab Failed Tips, Tricks and Tutorials 19 JUN 2014

Oh dear. On return from a lovely long weekend away at Piekenierskloof Mountain Resort, we discovered that our XBMC media server had inexplicably died – essentially the primary hard drive just would’t load the XBMCbuntu operating system any more. With a very dejected Jessica (no My Little Pony: Friendship is Magic for her), I set about re-installing XBMC 13.0 “Gotham”, and of course, I became just a little too clever for my own boots.

There are two old hard drives in the old machine, one larger than the other. So naturally I installed XBMCbuntu on the smaller of the two, formatted the larger drive to ext4 and then symbolic linked the Movies and TV Shows folders on the primary drive so that they point to the second drive (essentially I want to store all video content on the larger drive, but without going through all the hassles of maintaining multiple sources in XBMC).

Knowing that I need to auto-mount the second drive in order for this to work, I added the UUID mount command in the /etc/fstab file as per norm, and it was at this time that I spotted some great tips on optimizing drive speed by adding parameters like noatime and data=writeback. Without doing any proper research, I added in the options to all my hard drive mounts in fstab, and of course, on reboot the system fell over.

So how do your recover from a mount fail because of a bad or corrupt fstab file?

Essentially you need to be able to boot into the system with write access and a mounted / path so that you can alter the fstab file and try and get it back into a stable state. To do this, you need to access the GRUB menu and alter the kernel parameters of your Ubuntu load string.

First, if your box doesn’t come up with the GRUB menu automatically before continuing, you can force this by rebooting your computer and holding down SHIFT. Once the GRUB menu is up, select the Linux entry you want to load and press ‘e’ to edit it.

In the edit view, locate the kernel entry – it should look something similar to this:

linux   /boot/vmlinuz-3.5.0-23-generic root=UUID=862e9bd8-8641-478a-96a3-d5ad9a53b104 ro find_preseed=/preseed.cfg noprompt  quiet

Add the following at the end of the kernel entry:

rw init=/bin/bash

Save your changes and launch the edited entry – your machine will boot and you should end up in a bash prompt environment. The / path is mounted in read/write mode, meaning you can now go ahead and edit (read: fix) /etc/fstab, save your changes, and reboot!

ubuntu black and orange logo

Ubuntu Server: How to Attach and Mount a Hard Drive Tips, Tricks and Tutorials 24 JAN 2014

ubuntu orange logoThe other day we needed to pull data off a restored VM running an older LTS version of Ubuntu Server. My IT contact helpfully attached a small 500 MB drive to the VMware vSphere server and then left me to do the rest. This is what was needed to be done:

I first ran the fdisk utility to get a listing of devices currently seen by the system.

sudo fdisk -l

This gave me a list of all devices, from which I was able to determine the size and logical name assigned to the newly added disk, in this case a 500mb drive located as /dev/sdb.

Unfortunately for me, this time around the drive wasn’t actually picked up as being formatted, and as such I needed to first partition the disk using fdisk:

sudo fdisk /dev/sdb 

fdisk will display the following menu:

  Command (m for help): m <enter>
  Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

  Command (m for help):

We want to add a new partition. Type “n” and press enter.

  Command action
   e   extended
   p   primary partition (1-4)

We want a primary partition. Enter “p” and enter.

  Partition number (1-4):

Since this will be the only partition on the drive, number 1. Enter “1” and enter.

If it asks about the first cylinder, just type “1” and enter. (We are making 1 partition to use the whole disk, so it should start at the beginning.)

Now that the partition is entered, choose option “w” to write the partition table to the disk. Type “w” and enter.

If all went well (i.e. “The partition table has been altered!” appeared), you now have a properly partitioned hard drive that’s ready to be formatted. Since this is the first partition, Linux will recognize it as /dev/sdb1, while the disk that the partition is on is still /dev/sdb.

Next up, I needed to format the new partition.

There are a variety of options you could choose from, but seeing as I was working with Ubuntu server, ext3 made sense for this particular use case:

sudo mkfs -t ext3 /dev/sdb1

Of course, if you prefer to use something that would work under both Ubuntu and Windows, then FAT32 remains a good option:

sudo mkfs -t fat32 /dev/sdb1

(Note I had to do the whole partition and format thing because of the nature of drive plugged in. If this had not been the case, the system would have recognised the drive appropriately – as seen in the fdisk listing – and you would be able to skip straight to this mount part of the walkthrough).

With the disk partitioned, formatted and now ready for use, the next step is to actually make it usable on the system, in other words mount it.

First up, create a mount point, basically the path through which you will access it. (I would recommend using a mount point with “/media”, as it is the default used by Ubuntu.)

sudo mkdir /media/external

Now to actually mount the drive:

sudo mount /dev/sdb1 /media/external

Note, depending on the filesystem of your attached drive, you might have to alter the mount string accordingly. If the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point):

sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=1000,utf8,dmask=027,fmask=137

The options following the “-o” allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don’t use those extra options you may not be able to read and write the drive with your regular username.

Otherwise if the device is formatted with NTFS, run:

sudo mount -t ntfs-3g /dev/sdb1 /media/external

And you should be good to go, happily copying data to and from /media/external. When you are done and need to plug out the device, first unmount it using:

sudo umount /media/external


sudo umount /dev/sdb1

Note that the unmount command will fail if your current working directory is in the /media/external path. You need to step out of the disk if you want to unmount it! :)

Related Links: https://help.ubuntu.com/community/Mount/USB, https://help.ubuntu.com/community/InstallingANewHardDrive

Ubuntu Server: How to Mount a USB flashdrive from a Terminal Tips, Tricks and Tutorials 15 APR 2011

By default, an Ubuntu server installation does not auto mount USB flashdrives that are plugged into it. Thankfully though, doing this yourself is not particularly difficult.

Plug your USB thumb drive into the machine and run:

sudo fdisk -l

This displays a list of devices currently detected. Locate your device in the list – it will probably be something like /dev/sdb1

Now we need to create a mount point for the device. It makes sense to create it in the /media folder, so run:

sudo mkdir /media/external

In the above example we have decided to name the mount point external. You can name it anything you want, but avoid using spaces for multiple words – rather join multiple words with an underscore _ character.

Now to actually mount the drive. If the device is FAT16 or FAT32 (which most USB drives are), run:

sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137

If however you are plugging in a NTFS external hard drive, you would run:

sudo mount -t ntfs-3g /dev/sdb1 /media/external

Done. You can now access the contents on the USB flashdrive by accessing /media/external.

When you finish using the drive, it is critical to unmount it before removing – this will prevent corrupt data and drive failures. To unmount:

sudo umount /media/external


Ubuntu Lucid Lynx: Simple Way to Mount a Samba Drive in Your Home Directory CodeUnit 24 JUN 2010

Samba is a fantastic free software re-implementation of the SMB/CIFS networking protocol that allows for shared file and print services across a variety of Windows and Unix (and even Mac OS) platforms.

Today’s quick tip highlights a simple way of mounting a remote samba directory as a folder in one’s home directory in Ubuntu.

The terminal command is as follows:

sudo mount -t cifs //[server name/ip address]//[shared folder name] ~/[desired folder name] -o username=[samba username],noexec

So if for example we were running a samba server at and sharing a folder with the name craiglotter and a user account with the username of craig, we would end up with this:

sudo mount -t cifs // ~/UbuntuMediaServer -o username=craig,noexec

After entering your sudo password you will be asked to authenticate the samba user account by entering the associated password. If successful, you should now have a nice and shiny, fully accessible folder named UbuntuMediaServer in your home directory!

Simple stuff! :)