Custom Search

How to mount external hard drive in Ubuntu server

This is a step by step guide on how to mount external hard drive in Linux for Ubuntu server beginner and Linux beginner in general. The guide includes error happened during the process to show how it to mount device in real situation.

Mount external hard drive in Ubuntu server

Insert external hard drive usb connector into the Ubuntu server usb port.  Ubuntu server automatically detect the external hard drive as a usb device. Below is the example screenshot when ubuntu detected the external hard drive:

 
We can see that the external hard drive has been detected as sdb. That is the name of the external hard drive to use when we are going to mount the device. We can check the device in /proc/scsi/scsi file. To do that, issue the command as in the example below:

luzar@ubuntu:~$ cat /proc/scsi/scsi
Attached devices:
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi3 Channel: 00 Id: 00 Lun: 00
  Vendor: Generic  Model: USB Disk         Rev: 9.02
  Type:   Direct-Access                    ANSI  SCSI revision: 02
luzar@ubuntu:~$

Create a proper directory in Ubuntu server to mount the external hard drive. In this example, we create a directory named extdisk in /mnt directory:

luzar@ubuntu:~$ sudo mkdir /mnt/extdisk
[sudo] password for luzar:
luzar@ubuntu:~$ ls /mnt/
dvd  extdisk  usb  win

Now we can mount the external hard drive with Linux mount command:

luzar@ubuntu:~$ sudo mount /dev/sdb /mnt/extdisk/
mount: you must specify the filesystem type

The external hard drive cannot be mounted. This happened when we mount a windows formatted external hard drive. We must specify the filesystem. Windows filesystem format is known as nsfs-3g in Linux. So we mount the external hard drive again with the complete command:

luzar@ubuntu:~$ sudo mount -t ntfs-3g /dev/sdb /mnt/extdisk/
NTFS signature is missing.
Failed to mount '/dev/sdb': Invalid argument
The device '/dev/sdb' doesn't have a valid NTFS.
Maybe you selected the wrong device? Or the whole disk instead of a
partition (e.g. /dev/hda, not /dev/hda1)? Or the other way around?

We still cannot mount the external hard drive. Again, we mount the external hard drive but this we change the device name from /dev/sdb to /dev/sdb1 as suggested by Ubuntu message above.

luzar@ubuntu:~$ sudo mount -t ntfs-3g /dev/sdb1 /mnt/extdisk/
luzar@ubuntu:~$ ls /mnt/extdisk/
ghost dell170l  ghost mimos  RECYCLER  System Volume Information
luzar@ubuntu:~$

We successfully mounted the external hard drive this time. Now that the external drive has been mounted, we can use it as other directory in Ubuntu.

To unmount the external hard drive, we can use the Linux umount command like in the example below:

luzar@ubuntu:~$ sudo umount /mnt/extdisk/
[sudo] password for luzar:
luzar@ubuntu:~$

That's all.

How to power off Ubuntu server with Linux shutdown command

The Linux shutdown command has several options that you can use to bring down the Linux system. In the previous post, we've seen how to reboot Ubuntu server with shutdown command. In this post,  we are going to use the Linux shutdown command again. This time is to power off the Ubuntu server.

There are several options available with shutdown command that can be used to power off Linux system. One example is -h option, which means to halt the system after it has been brought down. We can add other things such as a comment message when invoking shutdown -h command. As you can see from the example of Ubuntu restart post before, we have to specify a time argument after the shutdown option so the system know when to shutdown the system. Here are some examples on how to power off Ubuntu server using shutdown command with other things that you can do:

1) Using Linux shutdown command with -h option example:

luzar@ubuntu:~$ sudo shutdown -h now
[sudo] password for luzar:

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 11:32 ...

The system is going down for halt NOW!

The example above show a basic shutdown command used to power off Ubuntu server. We used '-h' option and a time argument 'now' which means to bring down the system after we press enter.

 2) Using Linux shutdown command -p option example:

luzar@ubuntu:~$ sudo shutdown -h -P +1

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 11:47 ...

The system is going down for power off IN ONE MINUTE! 

The example above shows the '-P' option is added after the '-h' option. The -P option means 'power off'. When -P is used after -h option, it means we tell the system to power off after the system halt. Also this time we used +1 in the time argument. That means we want to bring down the system after 1 minute.

3) If you have to warn all your users, you can write a message after the time argument. See the example below:

luzar@ubuntu:~$ sudo shutdown -h -P +3 Please save your work now!

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 11:57 ...

The system is going down for power off in 3 minutes!
Please save your work now!
shutdown: Shutdown cancelled

If you want to cancel shutdown after invoked the command, you can press Ctrl+C combination keys. That will work if you do not use the 'now' time argument. If you just want to warn users to log out and prevent other user to login without actually bring the system down, you can use '-k' option.

luzar@ubuntu:~$ sudo shutdown -k +3 Please save your work now!

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 12:11 ...

The system is going down for maintenance in 3 minutes!
Please save your work now!
luzar@ubuntu:~$

That's all.

Restart Ubuntu server

There are many commands that can be used to restart Ubuntu Server. We are going to look at some of them that I remember. The first one is the reboot command. In Linux reboot means restart. To use the reboot command, invoke reboot at the command line terminal. You must have root privilege, so add sudo before reboot.

Restart Ubuntu server with reboot command example:

luzar@ubuntu:~$ sudo reboot 
[sudo] password for luzar:

The second command that can be used to restart Ubuntu server is the shutdown command. In Ubuntu, you can use shutdown command to bring down the system to restart or to power off the system. That depends on the option given with shutdown command. To restart Ubuntu system with shutdown command, use shutdown with -r option and provide time to shutdown the system. See the example below.

Restart Ubuntu server with shutdown command example:

luzar@ubuntu:~$ sudo shutdown -r 18:00
[sudo] password for luzar:

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 16:24 ...

The system is going down for reboot in 96 minutes!

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 16:30 ...

The system is going down for reboot in 90 minutes!

Press Ctrl+c to cancel restart.

The system is going down for reboot in 90 minutes!
shutdown: Shutdown cancelled
luzar@ubuntu:~$

You can use shutdown command to restart the system on the spot using now as the time argument. See an example below:

luzar@ubuntu:~$ sudo shutdown -r now
[sudo] password for luzar:

Broadcast message from luzar@ubuntu
        (/dev/pts/0) at 16:44 ...

The system is going down for reboot NOW!

That's the command that you can used to restart Ubuntu server system if you have to.