Problem
I want to move a subdirectory tree to another filesystem, but I want my application to use the original paths. This procedure is useful when, for example, you are running out of room on the root filesystem for your application's data files directory, and room is available on a secondary filesystem.
Solution
Here is the procedure to move a subdirectory tree to another
filesystem. The specifics for the example presented are:Original subdirectory name: subdir
Original path to subdir tree: /usr
New subdirectory name: subdir (keeping it the same)
New path to subdir tree: /d2 (with /dev/d2 mounted to it)The example provided moves the subdirectory tree /usr/subdir
over to /d2/subdir, and creates a symbolic link from its original
location. Note that not all filesystem types handle symbolic links.
The original filesystem must be of type EAFS, HTFS or DTFS.Note that this procedure should be performed from System Maintenance
(Single-User) mode. The steps are:1. Make a backup of your system, and verify the backup is good.
2. Manually mount the secondary filesystem(s).# mount /dev/d1 /d13. Get current permissions of /usr/subdir:# ls -ld /usr/subdir4. Create the new subdirectory in /d1:
# mkdir /d1/subdir5. Change destination directory owner, group, & perms to match source:
# chown <origowner> /d1/subdir
# chgrp <origgroup> /d1/subdir
# chmod <origperms> /d1/subdir6. Recursively copy /usr/subdir to /d1/subdir:# cd /usr/subdir
# find . -depth -print | cpio -pdlmv /d1/subdirNotes: The "-l" option to cpio will only link if /usr
and /d1 had been in the same filesystem, in which case
steps 7 and 8 would not be necessary. cpio(C) is
recommended over the copy(C) command as cpio retains
permissions more successfully.7. Verify that the copy is successful:
# dircmp /usr/subdir /d1/subdir | tee /tmp/dirlog8. Create the symbolic link:# ln -s /d1/subdir /usr/subdir9. Unmount the secondary filesystem(s) when you are finished:
# cd
# umount /d1The procedure is now complete. Henceforth, (when /dev/d1 is
mounted), when you change directory to /usr/subdir, you will
really be in /d1/subdir.CAVEATS:Note that utilities that deal with the filesystem directory
structure may not function as desired unless additional options
are included. These utilities include, but are not limited to:
cd, ls, pwd, find, cpio, tar, and so on. .For example, if you do an "ls -ld /usr/subdir", you will see the symbolic link that references the /d2/subdir directory. To see the physical directory entry itself, with its owner, group and permission information, include a "-L" option as: "ls -ldL /usr/subdir".
If you want the "ls" command to always display this way, you
will need to setup a front-end real ls command. For example,
rename /bin/ls to /bin/ls.orig, and create a shell script /bin/ls
similar to::
/bin/ls.orig -L "$@"Another way to accomplish this is to alias the "ls" cmd to
"ls -L", but be aware of the limitations of aliasing in regards
to loop constructs, subshells, and so on. Caution should be
taken in regards to command functionality, as it may vary
according to the shell you are using. See also
Manual pages: cpio(C), mkdir(C), ln(C)Other articles in this database:TA103652, "Can't use long filenames and symbolic links on additional filesystems"
TA103654, "When I use l or ls -l to display directory, I see -> characters"
TA103650, "When I use lf or ls -F to display a directory, I see trailing @ signs"
TA103655, "Common problems using symbolic links."TA103657, "The permissions on symbolic links are lrwxrwxrwx(0777)"TA103659, "Errors when running Version 2.0 binaries on 4.0 with symbolic links"