1

I am completely new to Linux and Ubuntu 13. So far, I'm loving it. The writers really tried to think of everything, and have done a good job of keeping the O/S modern. Nonetheless, it is still a bit of a learning curve to me. I have some experience using a terminal from OS X, but I'm still learning my way around and how things are done. So to anyone who answers, please assume I know nothing, and explain each step.

During the O/S installation, I chose to place my 'home' on a separate partition. I did this so I could use this space as portable area where I could store frequently accessed files, use it to transfer stuff between O/S's, and be able to retrieve them easily in an emergency. I formatted this partition using XFS, thinking it was an acronym for exFAT File System, an ideal cross-platform FS which supports files larger than 4GB. Doh! Turns out XFS is a somewhat obscure journaled, server FS. Also turns out 'home' likes to live in a FS that supports permissions, so that rules out exFAT anyway. OK so that was a learning experience, but now I want to move 'home' back to the partition which Ubuntu is installed on, and reformat the XFS partition to something else (decide later).

I read a few related questions here on Ask Ubuntu, but I didn't get anywhere. Either because there were some differences in my situation or version, or I got unexpected results, or I simply didn't know what I was doing. Any help would be much appreciated.

enter image description here

7
  • 1
    I'm assuming that there's nothing on the /home partition that you need, correct? – Alaa Ali Jun 30 '13 at 6:09
  • 1
    here would be my suggestion to you boot up a live CD backup all files that are in /home then use Gparted to format /home as Ext2 or Ext3. there is a driver for Windows that supports read/write of Ext2/3 filesystems after formatting place the files back and reboot I can give more detailed instructions if you like? – Taylor Ramirez Jun 30 '13 at 6:14
  • Thanks for the quick replies. Alaa: There's nothing on the /home partition that I need, but I was under the impression that Linux needs that directory. Also, Ubuntu has placed a directory there labelled with my user name, and it contains more directories called documents, pictures etc... – timelessbeing Jun 30 '13 at 7:22
  • 1
    Okay, if I understand you correctly, you can accomplish what you are trying to do in another way. The "/home" folder will be in the Ubuntu partition, but your /home/userName/Documents and all those folders will be on another partition. This other partition can be set to FAT or NTFS, so that you can access those folders through Windows for example. However, all of the files under those folders will have a fixed set of permissions and ownership in Linux. These fixed permissions can be changed, but they change the whole partition, not single files. – Alaa Ali Jun 30 '13 at 7:26
  • 1
    Is this feasible for you? Or do you want to proceed with what you are asking in the question, to just bring back /home to the Ubuntu partition? The first set of steps for both of these solutions is the same, but I'm asking just for the sake of what to type when answering your question. – Alaa Ali Jun 30 '13 at 7:27
1

Note 1: The below will assume that you have a USB stick which you used to install Ubuntu, but the same goes for using a CD. So, wherever you see "USB", it's basically "the media at which you made bootable with Ubuntu".

Note 2: Wherever you see userName in the commands, replace it with your actual username that you use in your Ubuntu.

Okay, what we'll be doing is booting into live Ubuntu using a LiveUSB. So, if you still have the USB you used with Ubuntu on it, then just boot from it, as if you were going to install Ubuntu from scratch, except, we'll choose to Try Ubuntu, not install Ubuntu. This will boot up Ubuntu from the USB, so this is not your actual installed Ubuntu. [Too many "Ubuntu's".]

All of the following will be typed in a terminal. You can open one by Ctrl+Alt+T.

Note: If, at any point, you get an error, stop, and let us know.

  1. sudo mkdir /media/rt
    • This will create a directory called rt under /media. This will be the folder that will be housing your actual Ubuntu root partition.
  2. sudo mount /dev/sda3 /media/rt
    • As apparent from the command, this will mount (make accessible) /dev/sda3 (your root partition) on the folder /media/rt.
    • Note: if the command gives you an error about the "file system type", do sudo mount -t ext4 /dev/sda3 /media/rt instead.
  3. cd /media/rt
    • This will change our working directory to that directory, which is now your Ubuntu's / partition.
  4. sudo chroot --userspec=userName:userName . Don't forget, replace userName with your Ubuntu username.

    • This...well...basically, the prompt that you see now would be the same prompt you would get if you opened a terminal in your actual Ubuntu installation. Your prompt should change to userName@hostname:$, something like that.
  5. sudo cp /etc/fstab /etc/fstab.bak

    Note: I'm not entirely sure if this command will ask you to enter a password. But if it does, enter your username's password. This goes for all the remaining commands.

    • This is taking a backup of the file fstab that we're going to edit in the following couple of steps.
  6. sudo gedit /etc/fstab
    • This will open up that fstab file, of your Ubuntu installation, in a text editor. This file is responsible for mounting the /home partition at startup when you boot up your Ubuntu. It's also responsible for mounting the / partition, so be careful with editing this file.
  7. Look for the following two lines:

    # /home was on /dev/sda4 during installation
    UUID=<random-numbers> /home           ext4    defaults        0       2
    

    They won't be exactly the same as this. You'll probably find exactly the first line, but the second line might be slightly different. It could start with /dev/sda4 instead of UUID=<random-numbers>. But essentially, what we're looking for are the lines that have /home in them.

  8. Put a # in front of the second line of the two. So, it should look like this:

    # /home was on /dev/sda4 during installation
    #UUID=<random-numbers> /home           ext4    defaults        0       2
    

    Putting that # basically means that 'this line is a comment', so we're essentially deleting it, but we're not going to actually delete it.

  9. Save and close the editor. This will take you back to the terminal.
  10. ls /home. You should not see any output. If you don't see any output, continue on with the steps. If you see your username as the output (highly unlikely), go to step 13.
    • This command is basically checking if you already have a home folder. You should not see any folders there because all of your /home directory was mounted on a separate partition anyways.
  11. sudo mkdir /home/userName. Don't forget, replace userName with your Ubuntu username.
    • This is creating a new home directory for your username. But it has incorrect ownership, so we'll fix it in a while.
  12. sudo cp /etc/skel/{e*,.[a-z]*} /home/userName
    • This will copy some essential files to your new home folder.
  13. sudo chown -R userName:userName /home/userName

    • This is changing the ownership of your new home folder to be you.

    Note: There might be an easier, one command method to accomplish steps 11, 12 and 13, but meh, I don't know of it.

  14. exit
  15. exit

This should close the terminal.

At this point, we have removed auto-mounting your /home partition, created a new home folder for your username, copied some essential files to it, and gave it the correct permissions.

Shutdown this live Ubuntu. Remove the USB stick. Boot into your Ubuntu as you normally would. Cross your fingers. You should boot normally, and find that you have a home folder with all the subdirectories (Documents, Pictures, etc.) just like you did, but now, all of this is under one partition, the root partition.

Let's do some checks.

  1. cat /etc/fstab. Look for the # that we added to that line. It should be there.
  2. ls -l /home. You should see something like this:

    drwxr-xr-x 43 userName userName  4096 Jun 30 20:49 userName

    As long as those bold words are your username, everything is good.

  3. ls -l /home/userName. You should see all of those subdirectories created, and all of them should have your username in place of those bold words above as well.
  4. Open GParted. You should not see /home as the mount point for that partition (/dev/sda4) like in your screenshot.

If all of this checks out, congratulations!

At this point, your other partition (the one that used to be /home) is now free for you to do whatever you want with. Open GParted, and delete it, format it, burn it, throw it out the airlock, whatever.

Phew.

10
  • Wow, thanks for writing all that out. Bad news ... I needed to run Windows repair and it ate my GRUB. I'm going to try booting from my Ubuntu install DVD and try replacing it. I'll have come back to this later. I appreciate all the help so far! – timelessbeing Jul 1 '13 at 4:57
  • Sorry, I had some unrelated technical issues, and I finally got around to trying this out. I got stuck on step #4. It tells me "chroot: missing operand". – timelessbeing Jul 3 '13 at 18:31
  • oops ... disregard that last comment ... forgot the space+period at the end. Problem on step #5 though: "joe is not in the sudoers file. This incident will be reported". Should I expect the authorities at my door shortly? ;) – timelessbeing Jul 3 '13 at 18:36
  • 1
    Ha, no, we'll hide from them. Before step 4, do sudo chroot ., then adduser joe sudo, then exit, then continue with the steps, starting from 4. – Alaa Ali Jul 3 '13 at 20:46
  • 1
    Step 6: nano /etc/fstab. This will open the file in an editor within the terminal. Navigate using the arrow keys. When you're done adding the # (step 8), do Ctrl+X, then Y, then Enter to save and close the file. – Alaa Ali Jul 4 '13 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.