Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm new to linux and want to check my understanding of how mounting/filesystems work. I read related manpages, but just want to be sure.

I have a partition say /dev/sda5 that is currently mounted to /home with various subdirs. It is my understanding that this means /dev/sda5 has its own portable filesystem that can be moved anywhere in the main filesystem.

Questions:

If I unmount /dev/sda5 from /home (# umount /home) and then mount it to /var/www/ (which is empty) (# mount -t ext3 /dev/sda5 /var/www) and replace the fstab entry, with /dev/sda5 /var/www ext3 defaults,noatime,nodev 1 2 and # mount -a,

Q1) are all of the contents of /home now accessible under /var/www/ (i.e. /home/username -> /var/www/username)?

Q2) Are all of the permissions from the /home filesystem kept intact in this new location?

Anything else I should be concerned with? Just want to make sure I don't go wipe/corrupt anything. Coming from Windows the filesystem architecture takes getting used to (though I'm loving the flexibility!).

share|improve this question

3 Answers 3

up vote 1 down vote accepted
Q1) are all of the contents of /home now accessible under /var/www/ (i.e. /home/username -> /var/www/username)?

yes, the directories will now be /var/www/username instead of /home/username

Q2) Are all of the permissions from the /home filesystem kept intact in this new location?

as long as it is remounted on the same system, the file ownership will be the same, and the permissions will be the same, even on a different system. ownership depends on /etc/passwd and /etc/groups to turn the numeric UIDs to human readable values, and if bob is uid 1000 on system x, but uid 1050 on system y, bob won't have ownership of the files on the new system.

unless you remake the user directories in /home once you do this, it will mess up how users can log in, since their home directory will be non-existent. none of their login scripts will be executed, and so forth.

to migrate the partition to /var/www/ you'll want to do;

mkdir /home2/
cp -R /home/* /home2/
umount /home/
mv /home2/* /home/
rm -rf /home2/      # be VERY careful with this command
mount -t ext3 /dev/sda5 /var/www/

then add something like:

/dev/sda5       /var/www            ext3    defaults        0       2

to /etc/fstab

share|improve this answer
    
Could I also do a selective mv of the stuff I want to put back in /home after mounting /dev/sda5 to /var/www, since its all resting under /var/www/ now? I.e. mv /var/www/dir_to_keep/* /home/dir_to_keep/ –  Tom H. May 14 '10 at 18:23
    
yes, you can. i was just writing the steps assuming nothing had been done yet. you can also just do mv /var/www/dir_to_keep /home/ if you're moving whole directories. –  cpbills May 14 '10 at 18:30

The Specific Questions:
1.Yes, they should be assuming the person has the directory permissions needed to make it to that directory. (More on directory permissions in this answer of mine).
2.Yes, the should be intact since the ownership is a uid/gid number stored on that particular filesystem.

Single Tree Vs a Forest:
As far as coming from Windows, the main difference is one big tree vs. a forest. In windows, the root of each drive, a letter, is its own tree structure. Since there can be multiple drives, you end up with a "forest" (many trees). In Unix / is the root of a single tree, and on each machine there is only one tree.

Some other (maybe random) things to keep in mind:

  • In Unix, there is the "Everything is file" philosophy. So devices, directories, and sockets are all represented as files.
  • A name, such as "foo" that represents a file is actually a link to that file. You can have multiple names (links) mapped to that file. These come in to types, hard and symbolic links. Hard links can only point to files that exist on that same filesystem, symbolic links can point to files on other filesystems.
  • You can actually mount a filesystem on a non-empty directory (although things probably throw warnings about this these days). These end up "hiding" (not overwriting) the files that you mounted over, but they won't be overwritten. These are called "overlay mounts".
  • This is just to confuse you a little :-) You can actually create a file that is itself a filesystem and mount it as a new filesystem somewhere else using the loopback device. This is kind of like using daemon tools in Windows to mount an ISO image.

Lastly, as an aside, sounds like you are putting in a good solid effort to learn *nix from a Windows background, which I think is a respectable thing to do (Same for other way around as well).

share|improve this answer
    
Some additions: 1) Windows allows mounting of drives on directories too (but only on empty ones). 2) Hardlinks and symlinks are supported in the same way. 3) You could argue that Windows does have one root `\\.\` (there are several naming schemes). –  grawity May 14 '10 at 18:15
    
hardlinks in windows... i shudder at the memory of that, accidentally wiped out a ton of my files, because i'd forgotten i'd used join to combine some directories... 'oh hey look, i have a bunch of duplicate files... that's wasting disk space.......' –  cpbills May 14 '10 at 18:33

You can do that kind of moving, but then /home will be empty which would break a number of things. For example, the home directories in /etc/passwd would be missing.

share|improve this answer
    
+1 Ya, the home directory is probably not the best directory to experiment with :-) –  Kyle Brandt May 14 '10 at 17:12
    
I'm doing this b/c the partition mounted to /home has the only free drive space on the system, and I'm moving a site from under /home to /var/www/. /var/www/ needs more space to accommodate the sites files. Other than the website, there wasn't much of anything in /home. I was planning on copying the contents of /home (sans website) back to /home after the mount. –  Tom H. May 14 '10 at 17:44
    
@Tom What you're looking for is probably a symbolic link. man ln for more info. If you take away the underlying filesystem /home will live on the / filesystem, and Bad Things will happen if you accidentally fill /... –  voretaq7 May 14 '10 at 17:50
    
@voretaq7 I'm the only non-system user on this box and nothing should be writing anything to /home, but point taken. I'll read up on symbolic links. Thanks. –  Tom H. May 14 '10 at 18:01
1  
or you could even change the root of your webserver to /home/www or something. DocumentRoot in your web server's configuration would allow you to change that. but, like you said, there's not a lot of data in /home/ so you may as well allocate the space in /var/www/ –  cpbills May 14 '10 at 18:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.