Since I have officially been using Ubuntu on my office laptop for more than a solid month without once booting into Windows, it’s time to mothball the Windows partition in order to give Linux more room to breathe.

I seriously considered removing Windows entirely as I don’t believe that I’ll have any legitimate need for it in the future. However, I think that I can get the Windows partition down to a manageable size  and then forget about it.

Introduction

My office laptop is a Dell Studio 17. It shipped with Windows Vista pre-installed. After many frustrations with Vista BSoDing once a day on average, I finally decided to switch over to Linux as my main work OS. I decided on Ubuntu as a good distro to cut my teeth on since I had never run Linux as my desktop solution other than just playing around with Live Distros.

I installed Ubuntu alongside Windows by giving Ubuntu its own partition. Ever since then, things have been peachy.

Now that I no longer use Windows, I started thinking up plans for how I could use the space. I decided that I wanted to be able to install multiple Linux distros so that I can try out different ones. I also wanted to do the shared /home partition so that these different distros could be used productively with very little setup beyond installing.

There are a couple of hurdles between me and this desired setup however: The Windows partition takes up the majority of the drive. The /home folder is on the / partition and not on its own.

So, before I can start installing all the distros I want to try out, I need to fix up my partitions. That brings me to my first step.

Preparing Windows for Long-Term Storage

In order to streamline Windows while still keeping it functional, I need to load it up for the first time in a month.

Removing Data Files

I hooked up an external hard drive and migrated all the data files to this drive. This included all the files in my User folder (Documents, Desktop, Pictures, Videos, etc).

I then went through all my application folders to check for any unique data files I might want to save. These were also moved over to the external drive.

Removing Unneeded Programs

The first thing I did was to remove all the programs that I wouldn’t have any use for. I only intend to use Windows in a pinch situation, so I only left programs that help me connect to servers and work with files. I also left all the pre-installed Dell stuff which I have no use for but decided should stay.

Doing this removed many gigs of disk usage.

Removing Unneeded Files/Folders

At this point, I systematically went through the entire C:, removing folders and files that were no longer needed. Some of these were remnants from removed applications that left files and folders behind. Some of the unneeded files were just random junk that weren’t worth moving to the external hard drive.

An easy way to determine whether it is worth going through a folder to remove items is to right-click it and select Properties. This brings up a window that will show how much space all the files and folders contained in that folder take up. If the folder takes less than a 100MB, move on to the next folder. Otherwise, dig into the folder and see what you can delete.

An important thing to keep in mind as you’re doing this is you want to keep Windows usable, so don’t go crazy and try to delete things in the Windows folder.

Putting Windows on a Diet

There are many files that Windows has all over the place that can be cleaned up.

Load up Explorer (Win+E), right-click your Windows drive (C:), and click Properties. Click “Disk Cleanup”. Check all the boxes and click OK. Note that if you select the hibernation file when you do the cleanup, not only with the hibernation file (which is the same size as your RAM) be removed but hibernation will also be disabled. This removed about 5GB of data from my drive.

This next step is optional. I reduced my page file (virtual memory) usage since the pagefile.sys file was taking 4GB of space. You can get to this by going to Start > Control Panel > System, clicking the Advanced tab, clicking the Performance “Settings…” button, selecting the Advanced tab, clicked “Change…”, and made modifications in the resulting dialog. Yes, it is so incredibly easy to get to this panel. I had made changes to this before, but it’s so hard to find, that I had to use Google to “remind” me how to get to it. Windows was set to automatically size my page file, so I removed the automatic option and limited the size to 512MB. After restarting, this cleared up an additional 3.5GB of storage.

Finishing Up

In order to make the process of resizing the partition as effective as possible, I then ran defrag on the drive to compact all the files on the drive. You can do this by loading up Explorer (Win+E), right-click your Windows drive (C:), select Properties, select the Tools tab, click “Defragment Now…”, and click “Degragement Now…” on the window that loads.

When I started, I had a 92GB partition which had 60GB used. I wanted to get down to the 10GB range so that I could reduce the partition to 15GB. I didn’t get down to 10GB, but I did get down to 14GB. I’m sure that I could have forced the size down to 10GB, but I wanted to keep things usable, and a 20GB partition with 14GB isn’t that large.

Resizing the Windows Partition

To resize the partition, I’m going to use GParted, the Gnome Partition Editor. I installed GParted on Ubuntu, but it refused to resize the partition. I booted the Linux Mint LiveCD, and its GParted didn’t have a problem with the NTFS partition, so I ended up using it instead.

I loaded up GParted by going to Menu > Administration > Partition Editor. When it loaded, I right-clicked my Windows partition, selected “Resize/Move”, dragged the right slider handle to the left enough to leave a 20GB partition, and clicked “Resize/Move”. After I double-checked what I had told GParted to do, I clicked the “Apply” button at the top of the window.

The resize process took around 25 minutes to complete, so I had plenty of time to load up Firefox and work on this post. 🙂

After I did the resize, I rebooted to see if Windows still works. The first boot produced an automatic system repair that took about 45 minutes to finish. After another reboot, the “we need to scan your drive” thing happened. Yet another reboot later, Windows loaded up just fine.

Moving /home to Its Own Partition

Now it’s time for the fun part. This is a delicate process, so if you intend to do this, make sure you follow each step carefully.

I needed to be able to modify all the partitions, so I want to use a LiveCD so that all the partitions are unmounted and available to use in GParted. I had a Linux Mint 6 “Felicia” disk handy, so I booted it up.

Since we need to create a partition, it’s time to load up GParted again.

Expanding the Extended Partition

Here are my partitions currently:

  • 150MB Dell partition
  • 10GB Dell recovery partition
  • 20GB Windows partition
  • 92GB unallocated space
  • Extended partition
    • 90GB Ubuntu partition
    • 15GB unallocated space
    • 5GB swap

The first level of partitions are called primary partitions. The max number of primary partitions is four. Since I already have four (the extended partition counts as one), I need to move that new block of unallocated space into the extended partition to use it.

Looking at GParted, my extended partition is locked. This is because even LiveCDs will make use of available swap partitions. I right-click the swap partition and select “swapoff” which frees up both the swap partition and the extended partition for modification.

I right-clicked the extended partition, selected “Resize/Move”, dragged the left handle all the way to the left in order to add the unallocated space, and clicked the “Resize/Move” button. I then clicked the Apply button at the top of the GParted window, and let GParted do its thing.

Creating /home Partition

Now that I have my unallocated space inside the extended partition, we just need to set up a new partition with that space. I right-clicked the 92GB unallocated space, selected New, selected a Filesystem of “ext3”, and clicked the Add button. I then clicked Apply to have GParted create the partition.

After this process finished, I found that my new partition had a name of /dev/sda7. This is important to know in order to properly mount and use the new partition.

Note: I had previously looked at exactly how much space my /home folder took by running “sudo du -h –max-depth=0 /home” from Terminal. This gave me the information I needed to make sure that my new partition would be sufficiently large to hold my current /home folder. If the size of your /home folder is larger than the amount of available free space, use an external drive to remove some of the files first or resize other partitions to create enough space.

Mounting the New /home Partition

Before copying the current /home files to the new partition, I need access to it.

First, I create a place for the partition to mount by loading up Terminal (Applications > Accessories > Terminal) and running:

sudo mkdir /mnt/home

And then mount the new partition by running the following command in Terminal:

sudo mount -t ext3 /dev/sda7 /mnt/home

Note: I got the “/dev/sda7” name from looking at the name of the newly created partition after GParted created it.

Now the new partition is accessible at /mnt/home.

Duplicating /home to /mnt/home

The following instructions are if you have only have one user on your system. If you have more than one user, see the next set of instructions.

Before I start adding files to the new location, I need to allow my user, chris, to add files to the new partition. I did this by running the following command:

sudo chown chris /mnt/home

Note: If you do this, you will need to change “chris” in the previous command to your own user name.

While Terminal is still up, I ran:

cd /home
find . -depth -print0 | cpio -–null –-sparse -pvd /mnt/home

Depending on how large your /home folder is, this could take a while. Go grab a sandwich and wait for this process to finish.

Skip ahead to “Replacing Old /home With the New /home” if you have just one user on your system.

Duplicating /home to /mnt/home With Multiple Users

Special care must be taken to ensure that the ownership of the copied files are set up properly if you have multiple user accounts in the /home directory.

Load up Terminal and run the following commands:

cd /home
find . -depth -print0 | sudo cpio -–null –-sparse -pvd /mnt/home

This will copy all the files from the /home directory to the new /mnt/home partition. This could take a while, so go do some errands or chores while you wait.

Once the copy is done, you will have a duplicate of all the data on your /home partition in /mnt/home; however, none of the owner or group rights will be correct. You will need to manually reset all the owner and group settings for all the files for each user.

For example, let’s say that I have two users: chris (/home/chris) and anna (/home/anna). I will need to run the following two commands :

sudo chown -R chris:chris /mnt/home/chris
sudo chown -R anna:anna /mnt/home/anna

Notice the bold portions of each command. These bold portions should be replaced with your own usernames. To clarify, you need to run the following command for each user:

sudo chown -R username:username /mnt/home/username

Time to actually shuffle the /home directories/partitions around.

Replacing Old /home With the New /home

First, unmount the new home partition:

sudo umount /mnt/home

We now need to move the existing /home directory to make room for the new mount point.

sudo mv /home /old_home

Now we need to create the new mount point and mount the new /home partition.

sudo mkdir /home
sudo mount /dev/sda7 /home

Note: The bold partition location will vary depending on your setup remember to use the partition location when you created the new partition with GParted.

If you didn’t receive any errors after running these commands, your setup worked. Go ahead and load up some applications, play some music, and generally just use your files. Make sure that everything works as expected.

If any problems have occurred, you can easily revert back to the old /home folder data:

sudo umount /home
sudo rmdir /home
sudo mv /old_home /home

If everything worked properly, you now have your new /home partition mounted and operating. Time to make the change permanent.

Adding New /home Partition to /etc/fstab

The /etc/fstab file contains setup information about your partitions. We’re going to add an entry to make sure that the /home partition is automatically mounted and used when the system loads. Since I can’t assume you know how to use the command line editors, I’ll have you open the file in Gedit, a Gnome editor.

gksu gedit /etc/fstab

This will load /etc/fstab for editing in Gedit with root privileges.

We need to go to the bottom of the file and add the following line:

/dev/sda7 /home ext3 nodev,nosuid 0 2

Note: Again, change the partition name to the one that matches your new partiton.

Now save the file and close Gedit. We can easily test if the new /etc/fstab entry is working by running the following:

sudo umount /home
sudo mount /home

If these commands ran without error and the /home directory is still functioning correctly, your system is good to go.

Finishing

Reboot your system a couple of times to ensure that everything is working correctly. Once you’ve confirmed that everything is working normally and have let the system run for at least an hour, it’s time to remove the old /home directory.

sudo rm -r /old_home

This will remove the /old_home directory and all of its contents.

Final Thoughts

The relative ease of this is a testament to the power of Linux. Not only was I able to completely reconfigure a very important directory that is integral to the operation of my distro, but I was able to do the most sensative part of it while actually running the OS being changed.

This nicely illustrates the power that Linux offers the user while also serving as a lesson to always be mindful of what you are doing while having root privileges. If you tell Linux to delete a very important file or directory and have root privileges when you do it, Linux will comply with no fuss. So, always be mindful of what you are doing when using the sudo command.

Now that I have /home as a separate partition, it’s a trivial matter to be able to share this partition with other distros.

Did I help you? Send me a tip.