Do you have an older router that is lying around collecting dust? Well you can repurpose it! I was inspired to create these script after watching a few of OneMarcFifty's videos, particularly:
- Building a managed switch with OpenWrt on old Wifi Router
- cheap DIY NAS from old Router with OpenWrt and Samba for your home network
The scripts in this repo will help you to convert a router into a NAS using OpenWRT. These scripts assume you already have OpenWRT installed and it's uninitialized (i.e. it's been fully reset).
To transfer files to the router, run the following command from a terminal (by default, the router IP address is 192.168.1.1):
scp *.sh root@192.168.1.1:~
Next, run the initial file by running the following commands:
ssh root@192.168.1.1
./initial_setup.sh initial_setup
The script will prompt you to set the intial password. By default, the scripts will change the router from a Static IP address to a DHCP address.
You'll need to install the relevant packages to enable the router to be a file server.
To do so, you will need to first SSH into the router. The IP address will no longer be same, since it was changed in the previous section. If you specific a static IP address in the previous section (e.g. 192.168.1.2), then 192.168.1.x
(below) will be 192.168.1.2
. If you specified DHCP, then you will need to find the IP address by logging into the main router (if you have access to it) and looking up the new IP address.
ssh root@192.168.1.x
Next, you will need to install the relevant packages, including:
- Kernel filesystem packages for the filesystems like NTFS, ext4, etc.
- Kernel drivers for USB storage, USB3.0, etc.
- Samba4 Server + LuCI interface
- Utilities like
fdisk
,block-mount
, etc. - Other relevant packages (I've included
acme
,python3
since those are packages that I use often)
To install them, run the following script:
./package_installation.sh
- OpenWRT NAS Guide
- This guide provides additional information and instructions, inlcuding how to set up SCSI devides and set more granular firewall rules.
- OpenWRT Filesystems
To mount the drives, make sure you have the following packages installed:
block-mount
: provides an interface for mounting the driveskmod-usb-storage
: provides the kernel modules to be able to detect USB storage deviceskmod-usb3
for USB 3.0 drivers (if your router has USB3.0 ports).kmod-usb-storage-uas
- Kernel modules and utilities for the filesystems you want to use; examples:
kmod-fs-ext4
for ext4 filesystems.kmod-fs-ntfs
andntfs-3g
for NTFS filesystems.
TODO
TODO
To convert a router to purely a home server or file server (i.e. not using as an actual router), your best bet is to create a custom OpenWRT image for it. The reason being is that router firmware is flashed to a read-only section. Meaning: if you want to uninstall a built-in package (e.g. the DHCP server), you won't be able to recover the space it took up. Hence why you want to build a custom image: to recover the space lost to unwanted/unneeded packages.
For more information:
- Which packages can I safely remove to save space?
- Build image for devices with only 4MB flash
- Saving firmware space and RAM
To build a custom OpenWRT image, the easiest way would be to use the Image Builder.
- Download the Image Builder archive from the same place where you would download your router's firmware.
- For example: I have a Linksys WRT1900AC v1 router. The OpenWRT 22.03 downloads for the router are listed here: https://downloads.openwrt.org/releases/22.03.0/targets/mvebu/cortexa9/
- The image I would normally download is linksys_wrt1900ac-v1-squashfs-factory.img
- The image builder is openwrt-imagebuilder-22.03.0-mvebu-cortexa9.Linux-x86_64.tar.xz
- For example: I have a Linksys WRT1900AC v1 router. The OpenWRT 22.03 downloads for the router are listed here: https://downloads.openwrt.org/releases/22.03.0/targets/mvebu/cortexa9/
- Unzip the archive and switch to the directory:
tar -J -x -f openwrt-imagebuilder-*.tar.xz cd openwrt-imagebuilder-*/
- Create the custom image with the router profile and the packages you want to add or remove. Run
make info
to get the profiles - this is where I gotlinksys_wrt1900ac-v1
seen in the example below:NOTEs:make image \ PROFILE="linksys_wrt1900ac-v1" \ FILES="files" \ DISABLED_SERVICES="dnsmasq odhcpd" \ PACKAGES="kmod-usb-storage kmod-fs-ext4 kmod-fs-ntfs kmod-usb-storage-uas kmod-fs-exfat kmod-fs-f2fs kmod-fs-vfat \ ntfs-3g ntfs-3g-utils block-mount e2fsprogs f2fs-tools dosfstools libblkid \ fdisk gdisk mount-utils usbutils lsblk blkid jq \ sudo shadow-useradd shadow-groupadd shadow-groups shadow-usermod \ luci luci-app-samba4 luci-app-hd-idle \ kmod-usb3 acme python3 git libupm-nrf24l01-python3 \ -wpad-mesh-wolfssl -odhcpd -ppp -ppp-mod-pppoe -odhcpd-ipv6only"
- The second-last line are additional optional packages. The
kmod-usb3
package is needed if your router supports USB3.0. The others are ones that I personally use frequently. - The files parameter will add the configuration files under
<buildroot>/files/etc
, e.g.:<buildroot>/files/etc
has the configs for SSH settings, custom SSL certificates, users/groups, etc.; and<buildroot>/files/etc/config
has the configs for network, Firewall, switch, etc.
- The second-last line are additional optional packages. The
TODO