LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-29-2013, 04:20 PM   #1
doni49
LQ Newbie
 
Registered: Jun 2013
Posts: 12

Rep: Reputation: Disabled
Question Raspberry Pi: move home & var folders to USB HDD?


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:
Quote:
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

Partition table entries are not in disk order

Command (m for help):

Last edited by doni49; 06-29-2013 at 04:29 PM.
 
Old 06-29-2013, 06:45 PM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,657
Blog Entries: 33

Rep: Reputation: 283Reputation: 283Reputation: 283
Hi, seems the naming of your partitions is not the way the system would like to read them.

they should be(not familiar with Pi) listed and named like this...

for hdd sda.
sda(n) where n = partition number (integers only)

so yours should look like...
Quote:
Device Boot Start End Blocks Id System
/dev/sda1 1936269394 3772285809 918008208 4f QNX4.x 3rd part
/dev/sda2 1917848077 2462285169 272218546+ 73 Unknown
/dev/sda3 1818575915 2362751050 272087568 2b Unknown
/dev/sda4 2844524554 2844579527 27487 61 SpeedStor
The mount points for your partitons are quite flexible and you may try again once you have corrected the partition naming conventions.

If you move /var while the system is running a migration will take place, writing to usb chips is slow.

I hope this helps.
 
Old 06-29-2013, 06:49 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,740

Rep: Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923
As the error message stated you selected the wrong device. The MBR is not associated with a partition. You need to select the drive device i.e. /dev/sda vs /dev/sda1 when running fdisk.
 
Old 06-29-2013, 07:53 PM   #4
doni49
LQ Newbie
 
Registered: Jun 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks guys. I'll dig into that. But would you mind commenting on the question about using symlinks to ID where these directories are?

And do I need to umount the home and var directories before I mount them to the HDD? If yes, how do I go about that?

I greatly appreciate your time and efforts!
 
Old 06-29-2013, 08:14 PM   #5
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,657
Blog Entries: 33

Rep: Reputation: 283Reputation: 283Reputation: 283
the linking would be taken care of by /etc/fstab which holds most, if not all the mount points.

for instance, mine looks like this.
/etc/fstab
Code:
# Entry for /dev/sdb5 :
UUID=13d5963d-e719-4f21-8c0a-961a3cbbf639 / ext4 acl,relatime 1 1
# Entry for /dev/sdb1 :
UUID=61f81580-1eff-42b8-b699-8cf84f543e31 /boot ext4 acl,relatime 1 2
# Entry for /dev/sdb6 :
UUID=a6553178-8e7b-49da-815c-c738c1a4d54e /home ext4 acl,relatime 1 2
# Entry for /dev/sda7 :
UUID=6b198f0d-a1f1-4e7a-b4ea-3991bb8c6971 /home/glenn/local/Archive ext4 acl,relatime 1 2
# Entry for /dev/sda12 :
UUID=49ee8726-6d3f-4487-8405-68716f191d7f /home/glenn/local/backup ext4 acl,relatime 1 2
# Entry for /dev/sdc5 :
UUID=92702c8f-be86-4ef3-937e-4daf454193e5 /home/glenn/local/data ext4 acl,relatime 1 2
# Entry for /dev/sdc7 :
UUID=5d0126f8-cda3-46dd-8fbf-89ea3db6e6f7 /home/glenn/local/music ext4 acl,relatime 1 2
# Entry for /dev/sdb11 :
UUID=80afabb4-b9a3-448f-856f-5a583ce179bc /home/glenn/local/vm1 ext4 acl,relatime 1 2
# Entry for /dev/sdc6 :
UUID=a0b61e55-5353-4d2c-a111-64dcb3f6b385 /home/glenn/local/video ext4 acl,relatime 1 2
# Entry for /dev/sda11 :
UUID=8d40e507-73d5-4af3-8603-a39270b33c1e /home/glenn/local/spare ext4 acl,relatime 1 2
# Entry for /dev/sda8 :
UUID=FE2A27D12A27862D /media/win_c ntfs-3g defaults,umask=000 0 0
# Entry for /dev/sdc1 :
UUID=587C2B0D7C2AE60A /media/win_c2 ntfs-3g defaults,umask=000 0 0
none /proc proc defaults 0 0
# Entry for /dev/sdb8 :
UUID=c14ad173-62d7-45ac-9dd1-e9ca93539c0a /tmp ext4 acl,relatime 1 2
# Entry for /dev/sda1 :
UUID=a55b2d80-d67e-465a-92d4-e8e5caa48255 /usr ext4 acl,relatime 1 2
# Entry for /dev/sdb9 :
UUID=8469f117-92aa-4b7b-b8c7-232b347d6099 /usr/local ext4 acl,relatime 1 2
# Entry for /dev/sda9 :
UUID=a642f6dc-ad12-4580-b3ce-0a95398423ee /usr/src ext4 acl,relatime 1 2
# Entry for /dev/sda5 :
UUID=e58b782d-da89-45e0-9c33-128887857be0 /var ext4 acl,relatime 1 2
# Entry for /dev/sdb10 :
UUID=5984d472-bb1b-4f27-b6c9-c0affcac8d47 /var/spool ext4 acl,relatime 1 2
# Entry for /dev/sda10 :
UUID=793cff6f-5a0b-41e0-8984-dc899345ce93 /var/www ext4 acl,relatime 1 2
# Entry for /dev/sda6 :
UUID=dcd0b80e-51dd-4fee-a4f6-a0bf7217f903 swap swap defaults 0 0
# Entry for /dev/sdb7 :
UUID=70b0a67c-4b3f-40dc-9018-1cc534c833d2 swap swap defaults 0 0
# load tmpfs
tmpfs /dev/shm tmpfs defaults 0 0
#Get read/write access to usb, load usbfs
none /proc/bus/usb usbfs devgid=43,devmode=664 0 0
fstabmanual.

/var is a system directory and might be in use, the migration would occur upon next boot. That is after you change fstab to point to your new /var directory.

/home you can move/copy as root. and clean up after. change fstab to point to your new /home.

There's probably a cleaner way to do this...
 
Old 06-29-2013, 10:02 PM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.

Last edited by Shadow_7; 06-29-2013 at 10:06 PM.
 
Old 06-30-2013, 07:35 AM   #7
doni49
LQ Newbie
 
Registered: Jun 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-30-2013, 10:40 AM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
Old 06-30-2013, 06:34 PM   #9
doni49
LQ Newbie
 
Registered: Jun 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Shadow_7 View Post
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?

TIA!

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?

Last edited by doni49; 06-30-2013 at 07:01 PM.
 
Old 07-02-2013, 04:23 PM   #10
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
Old 07-02-2013, 06:53 PM   #11
doni49
LQ Newbie
 
Registered: Jun 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
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.
  1. I cleaned up my HDD so that there were ONLY 2 folders on it: shares and home.
  2. I took the SD card out of this RasPi and put it in my USB SD card reader.
  3. I took an SD card from one of the other RasPi units and put it in this one.
  4. I booted the RasPi.
  5. I used sudo fdisk -l to find out what the devices were named.
  6. I created a folder in root called homepi.
  7. I mounted /homepi on /dev/sda2 (the partion of the inactive linux that contained 'var' and 'home').
  8. I mounted /media/USBHDD1 on /dev/sdb1 (what the currently running linux sees as the HDD).
  9. Using mv, I moved /homepi/var to /media/USBHDD1/var.
  10. 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.
 
Old 07-03-2013, 11:17 PM   #12
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Move /boot from hdd to usb wally.nl Linux - Server 1 11-02-2010 01:03 AM
Moving /var or /home to another HDD martinezjr Linux - Hardware 2 09-05-2008 07:52 PM
Postfix won't move mail from /var/spool/mail to /home/vmail jmoschetti45 Linux - Server 13 03-07-2007 06:03 AM
FC6 box add new HDD and move HOME folder to it titel Linux - Hardware 1 12-28-2006 12:34 PM
spam_buttons move from /var/spool/mail/user to $HOME/mail/Junk paul_mat Linux - Software 0 05-25-2006 02:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration