[SOLVED] Raspberry Pi: move home & var folders to USB HDD?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I have a Raspberry Pi running raspian. I've installed Apache2, PHP & MySQL. Apache & MySQL are both configured to use sub-directories of /var. I'd like to use a directory on my USB HDD instead of my SD card.
I'd also like to move the /home directory to the USB HDD.
I'd like to avoid re-partioning my HDD if possible. I thought maybe I could use a symlink to tell raspian that /var is really at /media/USBHDD1/var and /home is really at /media/USBHDD1/home. I tried it but couldn't get it to work.
Since I couldn't get the symlink to work, I also tried resize my partition so that I could go ahead and mount new partions. I used this tutorial. But it didn't work either. I don't know if I missed a step or what. But it didn't work and when I tried to start over and try again, I got a message telling me that ntfsresize did not work because the drive was scheduled
for a check.
I just had fdisk list the partitions for this HDD.
Following is the output:
sudo fdisk /dev/sda1
Command (m for help): p
Disk /dev/sda1: 2000.4 GB, 2000396746752 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907024896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6e697373
This doesn't look like a partition table
Probably you selected the wrong device.
Device Boot Start End Blocks Id System
/dev/sda1p1 ? 1936269394 3772285809 918008208 4f QNX4.x 3rd part
/dev/sda1p2 ? 1917848077 2462285169 272218546+ 73 Unknown
/dev/sda1p3 ? 1818575915 2362751050 272087568 2b Unknown
/dev/sda1p4 ? 2844524554 2844579527 27487 61 SpeedStor
UUID is the way to go on removeable media. Or pretty much any media these days. It's an ID that is partition specific.
Just change the /etc/fstab to match your wishes (in theory).
# blkid /dev/sdg1
On whatever device applies to find the actual UUID of it. If you're changing the / (root) location, you'll want to change /etc/fstab and the boot loaders configuration (/boot/grub/grub.cfg). YMMV
$ cat /proc/partitions
To see what /dev/ names exist for known devices at any given moment.
EDIT: the mount points (directories) should exist on the host partition (/ aka root). But should not contain any files. Not that having stuff there will outright fail, but it can get a little unpredictable.
Thanks guys. I think I better understand how fstab & fdisk work.
However, I was able to figure out how to use a symlink to put my home folder on the HDD. Now I'd like to put the var folder on it too. But to do so, I'm going to need to use the mv command to actually move the folders/files over and then create a symlink to point at the new location.
How do I figure out what service(s) use this folder so that I can stop them long enough to make the move? I'd really rather not make a separate partition just for var -- which means I'd like to use a symlink here too if possible.
No need to figure that out. Just boot a live disc, or a usb stick with linux on it and do it from a different running linux. To do it on a live system is hazardous at best.
But to answer your question for curiosities sake, use lsof or fuser to see what files are actively in use and by what. But still don't move that on a running system. And you'll probably want to avoid using a symlink for /var/. /home/ should be okay perhaps, but only because it doesn't really get used until a non-root user logs in.
No need to figure that out. Just boot a live disc, or a usb stick with linux on it and do it from a different running linux.
I have 3 RasPi units. I can take an SD card from one of the others and boot from that. Then I'll put the SD card from this one in my USB SD card reader. But how do I tell raspian to create the "/var" symlink for the INACTIVE RasPi session?
EDIT: I just now saw your comment about not using a symlink with var.
I currently have two folders on the HDD:
/media/USBHDD1/shares (users can place files/folders via SAMBA).
/media/USBHDD1/home (symlink for /home)
If I mount the partition to /var, can I safely create "shares" and "home" folders on this same partion?
In days of old, mount points were dedicated devices or partitions. So all you needed to do was mount the device to that location. There's a certain efficiency in terms of write and read speeds going this route. And for /var/log/ that has relatively heavy traffic on a server, you can swap out the hardware as needed. Obviously on a desktop /home/ gets most of the heavy traffic. If only from a browsers cache.
Certain things need to happen in a certain sequence. A symlink is pointless if the thing it points to isn't available. With a regular directory, it can write to / in the absence of the availability of the pointed to thing. Which gives you an opportunity to diagnose and recover. Versus not having a /var/ which implies not having /var/log/ and other potentially hazardous outcomes.
As far as making the change. We're basically talking about editing files on a filesystem. You do not need to do this with a pi. Any linux that can read the filesystem can make the change. A linux laptop or desktop, or whatever works. It could be arm based like the pi or x86 or powerpc, or whatever runs linux and supports the filesystem. As in you're probably over thinking it. I know I tend to do that a lot of the time.
As to the point of not needing to do it on the Pi goes, my 3 RasPi devices are the only linux machines I have access to.
I think I accomplished what I needed last night.
I cleaned up my HDD so that there were ONLY 2 folders on it: shares and home.
I took the SD card out of this RasPi and put it in my USB SD card reader.
I took an SD card from one of the other RasPi units and put it in this one.
I booted the RasPi.
I used sudo fdisk -l to find out what the devices were named.
I created a folder in root called homepi.
I mounted /homepi on /dev/sda2 (the partion of the inactive linux that contained 'var' and 'home').
I mounted /media/USBHDD1 on /dev/sdb1 (what the currently running linux sees as the HDD).
Using mv, I moved /homepi/var to /media/USBHDD1/var.
I edited /homepi/etc/fstab to tell RasPi to mount /var on the HDD.
Having done this, everything that was under /var is now STILL under /var but that is on the HDD. And because I had shares and home on the HDD before rebooting, now I see /var/home and /var/shares.
Last, I created a symlink pointing /home at /var/home.
I'm not concerned about browser cache (and for the most part, I'm not really concerned about user files at all). This device is headless there will not be multiple users actively using it. But it does use cron and there are user files involved there as well as bash scripts that get run via cron. I don't want to have to recreate those user files if and when the SD card crashes.
I'm sure symlinks work. But on the surface there isn't a fail gracefully option if the link is wrong or the linked to location isn't available at the time that it's needed. And /var/ is needed super early in the boot sequence. To include /var/log/kern.log. And certain methods of replicating a system (like cp) that do not play well with some link types. At least not with the "default options". Which can vary between distros.