Saturday, December 13, 2008

Setting up NFS share on Ubuntu

This post summarizes steps I've done to setup a NFS share on Ubuntu 8.10 VM host and mount it on an another Linux machine (Debian Linux running on embedded arm in my case).

Host machine: Ubuntu, 192.168.1.110
Client machine: Debian, 192.168.1.175

1. Install NFS package by either going to Synaptic Package Manager (System->Administration->...) and searching for nfs-kernel-server or typing the following on the command line:
$ sudo apt-get install nfs-kernel-server

This will download and install all the required dependencies.

2. Add the directory desired to be shared, permissions and other information to /etc/exports file.
$ vi /etc/exports
Add without quotes: "/path/to/nfsshare 192.168.1.110/255.255.255.0(rw,no_root_squash,insecure)"

Here, 192.168.1.110 is the IP of the host. The mask allows NFS connections from the following IP addresses: 192.168.1.0-255. This can be modified to suit the needs.

3. Restart NFS and update the exports list.
$ sudo /etc/init.d/nfs-kernel-server restart
$ sudo exportfs -a

4. To mount NFS root, run on the client:
$ portmap &

5. Mount NFS shared directory on the client machine.
$ mkdir /mnt
$ mount -t nfs 192.168.1.110:/path/to/nfsshare /mnt

6. Now the files placed into /path/to/nfsshare/ on the host are accessible from the client!

Notes
1. Mounted devices can be found here:
$ cat /proc/mounts
or just run
$ mount

2. For automatic mounts after restart of the client, I added the following line to ~/.bashrc file:
mount -t nfs 192.168.1.110:/path/to/nfsshare /mnt

3. To check the IP addresses of the Linux machines, run 'ifconfig'.
To check the connection between the machines, use the ping command:
-from client: 'ping 192.168.1.110'
-from host: 'ping 192.168.1.175'

References:
[1] Enabling NFS in Ubuntu
[2] Easy-Peasy Ubuntu Linux NFS File Sharing

Adding a root user without root access (Ubuntu)

If you are trying to run a root command and your username is not in the sudo list (i.e. getting a message like " is not in sudoers file ubuntu" when running 'sudo '), then add yourself to the sudoers file.

1. Reboot the machine and enter the recovery mode (press ESC a few times during the startup and select Recovery Mode)
2. Execute 'visudo'. Copy the line containing 'root ...' from sudoers file replacing root with your username.
3. Save the file and root. Your username now should be allowed to run sudo command.

Password Reset in Linux (Ubuntu Recovery Mode)

Here is another password recovery post that I previously used for dual boot system with Grub:
http://cybercamping.blogspot.com/2007/04/easy-password-reset-in-linux-using-grub.html

This post explains how to reset a password using Ubuntu's Recovery Mode. I used it on my Ubuntu 8.10 VM running under Windows.
1. Boot the machine and hit ESC few times to skip hardware boot options, and go into the grub menu
2. Select a Recovery Mode option.
3. If a Recovery Menu window popped up, select "root Drop to root shell prompt"
4. Type 'passwd ', hit enter and select your password.

To see the list of user names on the machine, look in /home/ directory (ls /home). Also, one can check the passwd file (tail /etc/passwd).