Move /var to external drive

Published by Adam Pielatowski on

Keeping our websites on a microSD card is not the best idea. These cards were not designed for this purpose. I thought it would be good to move my website into external hard drive, so I bought USB 3.0 SATA adapter from aliexpress for just 1$! Let’s connect it to our Raspberry and make this idea come true.

In this tutorial I assume you have formatted drive with one ext4 partition.

First we need to check UUID of target partition. SATA drives can be located in /dev/ named as sda, sdb, sdc and so on if we have more of them. First partition on sda drive is represented as sda1, second as sda2 and so on. We can use following command:


and we should get something like this:

/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="5203-DB74" TYPE="vfat" PARTUUID="6c586e13-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="2ab3f8e1-7dc6-43f5-b0db-dd5759d51d4e" TYPE="ext4" PARTUUID="6c586e13-02"
/dev/sda1: UUID="3a7b0cdc-e474-40af-992d-bdbc813b338e" TYPE="ext4" PARTUUID="44854fc9-01"

We are interested in the line 3 where is UUID=”3a7b0cdc-e474-40af-992d-bdbc813b338e”. Note your UUID down because it will be different then mine.

Now we need to create new mounting point (/mnt/newvar) where we will mount this partition:

sudo mkdir /mnt/newvar

and now we will mount partition:

sudo mount /dev/sda1 /mnt/newvar

If there is no error we can copy our current /var to external partition. We will use rsync command:

sudo rsync -agxP /var/* /mnt/newvar

Now all our websites are located in /var/www have their exact copy on the external hard drive. All we have to do now is to mount hard drive during boot. For this purpose we need to edit fstab file and here we will need noted UUID. Run a command:

sudo nano /etc/fstab

and add a line like this:

UUID=3a7b0cdc-e474-40af-992d-bdbc811b338e /var ext4 defaults,auto,rw,nofail 0 0

Reboot your system and verify if everything is connected like you want with the command:


If you see your drive mounted as /var like here in the line 3, you succeeded in moving /var to external hard drive.

sda           8:0    0 55.9G  0 disk
└─sda1        8:1    0 55.9G  0 part /var
mmcblk0     179:0    0   29G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 28.7G  0 part /

In next tutorial we will cover backup of our websites to another external hard drive or just a pen drive in my case.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *