Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
no, it is definitely more complex. You cannot move the /var of a living system.
when you reboot your system /var will be created again, most probably that will be an empty directory. But during boot some files/dirs will be also automatically created. I have never tried it, but I think /var/* is not a single directory.
I would rather boot a live cd, do the copy and reboot the original system only when /var was already copied.
no, it is definitely more complex. You cannot move the /var of a living system.
when you reboot your system /var will be created again, most probably that will be an empty directory. But during boot some files/dirs will be also automatically created. I have never tried it, but I think /var/* is not a single directory.
I would rather boot a live cd, do the copy and reboot the original system only when /var was already copied.
Okay. I will get back to your plan to move /var, but first I want to explain why rsync did not work as you expected. It is because you specified the destination with a wildcard.
On my system, rsync does not accept that command. No files are transferred, and I get an error message. You mentioned that the sda1 space changed, so something got tranferred. My rsync is probably a different version than yours.
Edited to add: Sorry, rsync on my system does accept that command. It failed for another reason, file permissions.
On your system. what probably happened is that the command interpreter expanded the wildcard and then rsync used the expansion. rsync would then copy the source directory which you intended to transfer, and all but the last item in the wildcard expansion, and add them all to the last item in the wildcard expansion. In other words, one of the subdirectories of /var now contains (1) some files that belong there, (2) the files you intended to transfer to /var, and (3) a lot of other files that don't belong there.
Okay. I will get back to your plan to move /var, but first I want to explain why rsync did not work as you expected. It is because you specified the destination with a wildcard.
On my system, rsync does not accept that command. No files are transferred, and I get an error message. You mentioned that the sda1 space changed, so something got tranferred. My rsync is probably a different version than yours.
On your system. what probably happened is that the command interpreter expanded the wildcard and then rsync used the expansion. rsync would then copy the source directory which you intended to transfer, and all but the last item in the wildcard expansion, and add them all to the last item in the wildcard expansion. In other words, one of the subdirectories of /var now contains (1) some files that belong there, (2) the files you intended to transfer to /var, and (3) a lot of other files that don't belong there.
pan64 is right. You should not move /var on a live system. You might be able to do it, but there are problems. The procedure in the article works because (1) you can copy /var to another drive, and (2) /var is reassigned to the external hard drive through fstab when you reboot.
The reverse process is harder. The difficulty is that you need to copy var back to sda1 before rebooting, and you need to copy it into the directory /var which is already being used as the mount point for the external hard drive. I don't know how to copy files to a mount point and not the mounted drive. Maybe there is a trick for this.
What you attempted to do is to copy the files after reboot. The problem, as pan64 wrote, is that upon reboot, the system immediately starts using the directory /var which was previously only a mount point. When you copy the files from the external drive to /var, you are attempting to overwrite files which the system is using.
Below I will give you the correctly-formed rsync command, but I cannot be sure it will work. The system may prevent some files from being copied, and if so, rsync will give error messages to let you know. If the system allows active files to be overwritten, the content of those files may become inconsistent, but perhaps the system will carry on satisfactorily after that.
Code:
rsync -aqxP /mnt/mydisk/* /var
As pan64 wrote, it would be safer to do this from a live cd, so that no active files are overwritten.
pan64 is right. You should not move /var on a live system. You might be able to do it, but there are problems. The procedure in the article works because (1) you can copy /var to another drive, and (2) /var is reassigned to the external hard drive through fstab when you reboot.
The reverse process is harder. The difficulty is that you need to copy var back to sda1 before rebooting, and you need to copy it into the directory /var which is already being used as the mount point for the external hard drive. I don't know how to copy files to a mount point and not the mounted drive. Maybe there is a trick for this.
What you attempted to do is to copy the files after reboot. The problem, as pan64 wrote, is that upon reboot, the system immediately starts using the directory /var which was previously only a mount point. When you copy the files from the external drive to /var, you are attempting to overwrite files which the system is using.
Below I will give you the correctly-formed rsync command, but I cannot be sure it will work. The system may prevent some files from being copied, and if so, rsync will give error messages to let you know. If the system allows active files to be overwritten, the content of those files may become inconsistent, but perhaps the system will carry on satisfactorily after that.
Code:
rsync -aqxP /mnt/mydisk/* /var
As pan64 wrote, it would be safer to do this from a live cd, so that no active files are overwritten.
root@machine:/var# ls
backup backups cache lib local lock log lost+found mail opt puppet run spool tmp www
root@machine:/var# cd www
root@machine:/var/www# ls
backup cache html local log mail prestashop run tmp
backups disk lib lock lost+found opt puppet spool
/var in the primary disk (after wrong command rsync -aqxP /mnt/mydisk /var/* )
Quote:
root@machine:/var# ls
backup backups cache lib local lock log lost+found mail opt puppet run spool tmp www
root@machine:/var# cd www
root@machine:/var/www# ls
backup cache html local log mail prestashop run tmp
backups disk lib lock lost+found opt puppet spool www
root@machine:/var/www# cd www
root@machine:/var/www/www# ls
backup cache html local log mail prestashop run tmp
backups disk lib lock lost+found opt puppet spool
root@machine:/var/www/www#
It looks like /var/www/www can be deleted, but it may be useful to keep it until you figure out what happened. I am not sure why /var/www/www is there. Did you run the incorrect rsync command two times, or more? Duplicate files and directories may exist in /var, /var/www, and /var/www/www. I am not sure of the best way for you to determine which are duplicates and may be deleted. (I would use md5deep but it is not very user-friendly.)
It looks like /var/www/www can be deleted, but it may be useful to keep it until you figure out what happened. I am not sure why /var/www/www is there. Did you run the incorrect rsync command two times, or more? Duplicate files and directories may exist in /var, /var/www, and /var/www/www. I am not sure of the best way for you to determine which are duplicates and may be deleted. (I would use md5deep but it is not very user-friendly.)
Yes, i run ithe wrong command many Times..
I think that the best way is to reinstall the os.. first i can backup data (prestashop directory and database), reinstall os and restore prestashop files and db..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.