On Sun, 02 Jun 2002 11:40:07 Ricardo Campos wrote:
However, as /usr contains most my programs, I am unsure as to how to do it.
My plan is to boot into a rescue disk (or would single user mode and a normal boot work? if I unmount /usr), change /etc/fstab (to not mount the /usr partition), make a dir called /usr on the root partition, copy the contents of the /usr partition to the /usr on the root partition. Reboot to check, then back into the rescue disk, cfdisk to enlargen the partition formerly known as /usr, mke2fs to create the file system,copy /usr on the root partition to the new one, change the /etc/fstab to mount the new /usr, and reboot.
I would certainly make sure of having a recsue disc available just in case this goes wrong, but you can do most of the work from the main system. Here's how I would so it (use at your own risk):
1. Shutdown to single user mode.
2. Mount the old /usr partition to another directory, e.g. /mnt/usr.
3. Make the permissions of the /usr empty mount point directory match those of the mounted /usr partition, i.e. what you see when running ls -l /mnt/usr.
4. Copy the contents of the old /usr partition to the new directory. Ideally you want to preserve:
a. permissions. b. times. c. links d. sparese files.
Hopefully the following commands would do this:
cd /mnt/usr find . -xdev -depth | cpio -padlm --sparse /usr
I haven't tried this sequence under Linux, i.e. with GNU cpio so it would be good to test this with a small subset, i.e. create a small set of files some of which have hard links to each other and try copying them so see if the links, modification times and ownership all survive.
Another possibility would be tar:
cd /mnt tar cf - --atime-preserve -l -p --same-owner -S usr | (cd /; tar xf - --atime-preserve -l -p --same-owner -S)
but again I would check that everything gets preserved correctly by running it on a test set of files first.
The obvious answer of course is 'cp -a' but that doesn't preserve links.
5. Edit /etc/fstab so the system doesn't mount /usr.
6. Reboot the system and check that is still works.
7. Re-partition the disk - this may require another reboot depending on whether the kernel can be made to re-read the partition table.
8. Make the new filesystem on the larger partition.
9. Mount the new partition to another directory, e.g. /mnt/usr again.
10. Use the same copy command sequence but in reverse to copy the files back to the new partition.
11. Update /etc/fstab again (to refer to /usr and not /mnt/usr).
12. Rename the current /usr (i.e. the files actually on the root partition to something else, e.g. old_usr and create a new mount point directory (suggest owned by root, perms 555).
12. Reboot to check.
13. If all is OK then you can rm -rf the old_usr directory.
It would be interesting to find your experiences of how well the command sequences to copy a filesystem preserving just about everything actually work, plus any other interesting things along the way.
Steve.