Reinstalling Ubuntu without formatting /home, as well as without any old config files?

21,506

Solution 1

I've done this quite often now - almost every time I did upgrade my system or (especially) if I switched to another distro. I normally log out, go to a console and log in as root directly (or depending on system configuration, as another user and switch to root), cd to /home folder and simply change my user's home folder name e.g. to "myUserName.bak". e.g.:

sudo mv /home/myUserName /home/myUserName.bak

After installation I can safely move all data needed to the newly created home folder for my user. (That's also a good point for thinking whether you e.g. really need that folder of big files you never touched the last 2 years ;) )

edit as suggested by comments: before you can access the files and folders from your renamed home folder you have to

sudo chown -R newUser.newUsersGroup /home/myUserName.bak

Solution 2

I always have a /home partition separate from the / so when i'm on a fresh install/upgrade, when i get to the "set up partitions" step, I select one for / (formatted) and another for /home (not formatted) but with the same file system as the previous one (or compatible).

Then, when creating users, I make sure to use the same user names as the previous installation so /home/user gets to the same place. What is great about this is that it doesn't overwrite the user's directory.

Thus if I had /home/mike, after my upgrade I'll have a mount on /home again and create the user mike so it gets all the files and config files from the previous version on /home/mike.

The only thing missing here are the /etc config files that need a backup/restore.

Solution 3

This is what I always do:

On the livecd I mount the /home partition and use the command

sudo chown -hR  ubuntu /path/to/home/drive

The ubuntu gives ownership to the username ubuntu (the live cd's username is ubuntu) andfolder the path is whatever the drive is mounted to. On the live cd this is usually in /media/ and the name is made up of many numbers a letters.

Now delete all the config files (files and folders beginning with a dot), but I do leave a few (such as .minecraft for my game saves). Its not just folders but also files beginning with a dot.

During the installer. Go to the custom partition manager. Set your partition as mount point /home (by clicking on it and selecting edit or change, or whatever they call it now), and leave it so it is not formatted, (in the F column of the drives list check marks mean it will be formatted) and set your OS partition (one with system files) as mount point / and DO format that one.

HOWEVER

After you finish the install and login your home drive will be useless since its ownership is still on ubuntu. to change it again run

sudo chown -hR YourUsernameHere ~/

Solution 4

I have done this by moving the hidden files and folders into a separate directory (but I guess deleting them would work too) and then shutting down and installing from the live CD exactly as suggested by grahammechanical in his answer.

I can confirm that it works (or at least it did for me).

If you keep the hidden files and folders instead of deleting them you can use them to selectively restore any configurations that you may decide you want to keep after all.

Share:
21,506

Related videos on Youtube

Mizt H
Author by

Mizt H

Updated on September 18, 2022

Comments

  • Mizt H
    Mizt H over 1 year

    I have /home on a separate partition. I want to reinstall Ubuntu.

    I don't want to lose my personal files in /home (I already have a backup but I would like to avoid the hassle of restoring the backup). I know how to reinstall Ubuntu using an existing /home partition without formatting it, but I don't want any configuration from previous Ubuntu to be in the new install.

    In other words, I would like a new and fresh install of Ubuntu, with my previous personal files in /home but WITHOUT any configuration file from the previous Ubuntu install. Is this possible? How could I accomplish that?

    I was thinking about manually deleting all hidden configuration files in /home (those starting with a "dot") from the Live CD before starting the installer, but I'm not sure if the file permissions will allow me to delete those files. I'm also not sure if that will be enough to not bring any configuration settings from the previous install. I thought it would be good to ask here before trying to do that, for "safety" reasons ;)

  • Vincenzo
    Vincenzo over 12 years
    Can you access all files in the renamed folder after fresh Ubuntu installation ?
  • Roland Kohn
    Roland Kohn over 12 years
    sure - no prob. as long as you "chown -R user.group myUserName.bak" after the reinstallation
  • Lode
    Lode over 12 years
    This is also my way of original setup. Sounds really good that Ubuntu doesn't overwrite the user's home directory. I'm going to try it as well. Is there any list btw of /etc config files to check, that you probably want to backup?
  • MikkelTN
    MikkelTN almost 11 years
    +1 for confirming that a partition can be left without formatting on the installation.
  • Vinay Patel
    Vinay Patel over 10 years
    I installed a fresh 12.04 as per your valuable guidance. My user name is : 'aliyans'. I issued the following in a terminal:groups aliyans. And the output was: aliyans : aliyans adm dialout cdrom plugdev lpadmin admin sambashare debian-tor jupiter. So, what will be the change to newUser.newUsersGroup in my case? Will it be like sudo chown -R aliyans.aliyans.adm.dialout.cdrom.plugdev.lpadmin.admin.samb‌​ashare.debian-tor jupiter /home/myUserName.bak ?