LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Keeping old data on disk (https://www.linuxquestions.org/questions/linux-newbie-8/keeping-old-data-on-disk-586807/)

agatone 09-23-2007 03:54 PM

Keeping old data on disk
 
Hello,

First I want to point out that although I have Ubuntu box for about year now I'm still newbie :)

After a year of runing simple web server the time came when i have to reinstall the box (clean install). Problem is that in that year i have alot of data in /var/www/ dir which i want to keep complete disk is mounted to / so i can't wipe it out so simply.

Is there any soulution to remount (and how) only certain dir that will not be formated when i run reinstall? Or is there some other approach to this problem?

thanks for any reply

Junior Hacker 09-23-2007 04:18 PM

It is possible if you have the space to shrink the / partition as it sounds like you say everything is in /. Then you can create a new partition in the free space and transfer all directories files and links from /var on the existing / partition to the new /var partition. Then you can re-install everything in that old / partition and either specify the /var partition without formatting it during the custom partitioning stage of the installation, or reset links after installation, or move everything in the new /var partition back to the /var in the / of the new installation, delete the separate /var partition and grow your / partition back to original size.
Or you can use tar and gzip to roll it all up into a ball and chuck it onto another drive/partition till the rebuild is done (minus most hidden application folders), then unroll it back in the new /var.

Below is a working method of moving the /home directory to it's own partition while keeping the file structure and links in tact. There should be no reason why it can't be adopted to move /var to it's own partition:
Code:

As root or sudo:
1: #mkdir /mnt/newhome
2: #fdisk -l  (to find device name of partition)
3: #mount -t ext3 /dev/???? /mnt/newhome (replace check marks in /dev/xxxx as per output of fdisk -l command)
4: #cd /home
5: #cp -ax * /mnt/newhome
6: #cd /
7: #rm -fr /home
8: #umount /mnt/newhome
9: #mv /mnt/newhome /home
10: #vim /etc/fstab (edit /etc/fstab with favorite editor if not vim, and add line below with proper /dev/xxxx)
11: /dev/???? /home ext3 defaults 1 2
12: re-boot

You'll need to put a line in /etc/fstab to have it mounted, you might want to investigate first and find what that line should contain.

syg00 09-23-2007 04:30 PM

Just create a new partition and copy the data. Then update /etc/fstab to include a new line; say for example (adjust as necessary)
Code:

/dev/hda10    /var/www    ext3  defaults 0 2
This will mount everything in directories "below" as well, so be sure to copy everything over; I like to use "cp -a <target> <source>" from a liveCD (recovery mode from the boot menu should be o.k. too).
Do this on your current system to ensure nothing gets "lost".

While you're in the mood, why don't you do likewise for the /home, so you don't lose that in the upgrade.
Just did similar on a Dapper to Feisty jump, although I used a new partition for the root; I think you'll need to use the alternate CD to assign your own mountpoint(s). And you'll probably need to do the fstab change for /var/www by hand again after the new system has been installed.

Edit: Whoa, you must type fast ...
All good, I'll go back to sleep.

agatone 09-24-2007 03:14 AM

So I need free disk space - at least same amount as the dir i'm trying to keep. But out of 72GB disk i have no free space left.

So no free space no solution for me?

syg00 09-24-2007 07:00 PM

As Junior_Hacker said, you'll probably be able to recover space from a current partition(s). Let's see the output from this (run in a terminal)
Code:

df -hT

agatone 09-25-2007 02:37 AM

Here you go

Code:

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/hda1    ext3    72G  66G  2.9G  96% /
varrun      tmpfs    253M  128K  252M  1% /var/run
varlock      tmpfs    253M  4.0K  253M  1% /var/lock
devshm      tmpfs    253M    0  253M  0% /dev/shm
lrm          tmpfs    253M  13M  240M  5% /lib/modules/2.6.12-9-k7/volatile


syg00 09-25-2007 03:52 AM

Then again, maybe not.
Go buy another disk. I use 100 Gig (external) USB disks to move stuff around, but in your case you'd be better off getting another disk unless you can find something (big) to delete.
Same advice as above applies.


All times are GMT -5. The time now is 08:56 PM.