Building a NAS using a Laptop (Based on Ubuntu)¶
Introduction¶
- A
Network Attached Storage (NAS)
is a dedicated file storage system that provideslocal area network (LAN)
users with centralized, consolidated disk storage through a standard Ethernet connection. - In this tutorial, we will guide you through the steps to turn your old laptop into a NAS using Ubuntu.
Prerequisites¶
- An old laptop with Ubuntu installed.
- An external hard drive or SSD for additional storage.
- A stable network connection.
- Basic knowledge of Linux commands.
Step 1: Update and Upgrade Your System¶
First, ensure your system is up to date. Open a terminal and run the following commands:
sudo apt update sudo apt upgrade
Step 2: Set Up a Static IP Address¶
To ensure your
NAS
has a consistent IP address, you need to set up astatic IP
. Open a terminal and edit the network configuration file:Why? We want your
NAS
to have a permanent IP (say,192.168.1.100
) so you always know where to find it.sudo nano /etc/netplan/01-netcfg.yaml
Add the following configuration, replacing the values with your network details (This is just a example, replace
address
andGateway
with yours):network: version: 2 renderer: networkd ethernets: eth0: dhcp4: no addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4]
Apply the changes:
sudo netplan apply
Alternative: Set Up Static IP Address Using GUI¶
If you prefer to use a graphical user interface (GUI) to set up a static IP address, follow these steps:
- Click on the network icon in the system tray.
- Select the WiFi network you are connected to and click on "
Settings
". - Go to the "
IPv4
" tab. - Change the "Method" to "Manual".
- Enter your desired
IP address
,Netmask
, andGateway
. - Add
DNS servers
if needed. - Save the settings and reconnect to the network.
Step 3: Install OpenSSH Server and Test It¶
To remotely access your NAS, you need to install the OpenSSH server. Open a terminal and run the following command:
sudo apt install openssh-server
Once installed, start and enable the SSH service:
sudo systemctl start ssh sudo systemctl enable ssh
Test the SSH status on your laptop
sudo systemctl status ssh
Test the SSH connection from another machine on the same network:
ssh username@192.168.1.100
Replace
username
with your actual username and192.168.1.100
with the static IP address you set up.
Additional Step: Set Up Remote Access with GUI Using Chrome Remote Desktop¶
- To access your NAS with a graphical user interface (GUI), you can use Chrome Remote Desktop. Follow these steps:
Install Chrome Remote Desktop¶
Open a terminal and run the following commands to install Chrome Remote Desktop:
wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb sudo dpkg -i chrome-remote-desktop_current_amd64.deb sudo apt-get install -f
Install Google Chrome¶
If you don't have Google Chrome installed, download and install it:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb sudo dpkg -i google-chrome-stable_current_amd64.deb sudo apt-get install -f
Install Desktop Environment¶
Install a desktop environment if you don't have one. For example, you can install Xfce:
sudo apt install xfce4 xfce4-goodies
Configure Chrome Remote Desktop¶
Link your Google account to Chrome Remote Desktop by visiting remotedesktop.google.com and following the instructions.
Set up a new remote access session and choose a name and PIN for your NAS.
Step 4: Mount All Drives Permanently and Set Up Easy-to-Remember Mount Paths¶
Identify Your Drives¶
First, identify the drives you want to mount. Open a terminal and run:
sudo fdisk -l
For GUI, go to
disk
to check your disk info
Create Mount Points¶
Create directories where you want to mount your drives. For example:
sudo mkdir -p /mnt/storage1 sudo mkdir -p /mnt/storage2
Edit the mount options in disk
(GUI)¶
Uncheck Default option, check
Mount at system startup
Change the
Mount Point
to where you just setup
Edit the mount option using cmd
¶
To mount the drives permanently, edit the
/etc/fstab
file:sudo nano /etc/fstab
Add entries for your drives. Replace
UUID
with the actual UUID of your drives, which you can find using theblkid
command:UUID=your-drive-uuid-1 /mnt/storage1 ext4 defaults 0 0 UUID=your-drive-uuid-2 /mnt/storage2 ext4 defaults 0 0
Mount the Drives
Apply the changes and mount the drives:
sudo mount -a
Verify the Mounts
Verify that the drives are mounted correctly:
df -h
Now your drives are mounted permanently with easy-to-remember names.
Step 5: Share Drives Using SMB¶
Install Samba¶
To share your drives over the network, you need to install Samba. Open a terminal and run the following command:
sudo apt install samba
Configure Samba¶
Edit the Samba configuration file to add your shared drives:
sudo nano /etc/samba/smb.conf
Add the following configuration at the end of the file, replacing the
paths
with your actual mount points:[share] comment = share folder browseable = yes path = /home/book/Share create mask = 0755 directory mask = 0755 valid users = book force user = book force group = book public = yes available = yes writable = yes
Create Samba User¶
Create a Samba user and set a password:
sudo smbpasswd -a your_username
Restart Samba Service¶
Restart the Samba service to apply the changes:
sudo systemctl restart smbd
Access Shared Drives¶
Mac
User, useConnect to Server
underGo
Windows
User, right click and selectAdd a network location
Now you're ready to explore the Hard drive connected your laptop use LAN
Additional Tips: Prevent Laptop from Sleeping When Lid is Closed¶
Method 1: Using the Graphical Interface¶
Open Power Settings:¶
- Click on the system menu at the top right corner.
- Select "Settings" and then go to "Power".
Adjust Lid Close Behavior:¶
- Find the option "When the lid is closed" or similar.
- Set it to "Do nothing" or "Turn off screen only". The exact options may vary depending on the version.
Save Settings:¶
- Close the settings window.
Method 2: Editing Configuration File¶
If the graphical interface does not have the relevant options, you can set it by editing the configuration file:
Open Terminal:¶
- Press
Ctrl+Alt+T
to open the terminal.
Edit logind.conf File:¶
Enter the following command to open the configuration file:
sudo nano /etc/systemd/logind.conf
Find and modify the following two lines: Ensure the following two lines exist and are uncommented (remove the
#
at the beginning), and modify them to:plaintext HandleLidSwitch=ignore HandleLidSwitchDocked=ignore
Save and Exit:¶
- Press
Ctrl+O
to save. - Press
Ctrl+X
to exit the editor.
Restart systemd-logind Service:¶
- To apply the changes, run the following command:
sudo systemctl restart systemd-logind