I’m about to set up a new computer for myself, and it’s going to run both Windows XP Pro and one or more flavors of Linux. Obviously, it’s going to be a multi-boot system. So I’ve been boning up on a lot of the issues associated with setting up such a system, such as:

  • What’s the best way to partition the system?
  • Can I use a single /home partition and just share it with every Linux distro I install?
  • How can I easily share files between WinXP and Linux?

There’s about a billion different ways to set up a system like that, and about a billion web sites that give snippets of information on what’s best and how to do it. After doing some reading for the past few days, I attempted to simulate a setup like this using my old notebook (that already dual-boots WinXP Home and Ubuntu 7.10).

Initially, my notebook had two primary partitions (one for WinXP and one for Ubuntu) and an extended partition containing a single logical partition (the swap partition). I wanted to change this to create two additional partitions. First, I wanted a separate NTFS partition that I could use for storing all my user-generated files (like the stuff that you’d store in My Documents in Windows, or in ~/Documents in Ubuntu). This was not a separate /home partition–just a separate partition for documents.

(Aside: Ubuntu 7.10 can read and write to NTFS partitions out-of-the-box. Earlier versions of Ubuntu cannot. If you’re running an earlier version, you’ll want to use FAT32 for your shared partition instead of NTFS.)

The other additional partition that I wanted to create was a small partition dedicated to GRUB, the boot loader used by Ubuntu (and many other flavors of Linux). It turns out that putting GRUB in its own partition makes it much easier to add and remove Linux distros on your system, if you’re in to that kind of thing.

There’s a nice overview of disk partitioning on the Illustrated Dual Boot HomePage, and there’s also a nice section on the hows and whys of creating and using a separate GRUB partition. In fact, I followed those instructions pretty-much verbatim to create my own GRUB partition.

WARNING: when you start dorking around with existing partitions, you run the risk of screwing things up and losing data. Do a backup before you embark on an experiment like this one.

I used the GParted Live CD in order to do all the partitioning work. You simply boot your system from that CD, and the GParted application is started for you. GParted allows you to create, delete, move, resize, and format partitions to your heart’s content. Rather than try to create a GParted tutorial here, I’ll let you discover one of the many sites that’ll walk you through using GParted. I’ll just say here that I used GParted to shrink the primary WinXP NTFS partition and the primary Ubuntu ext3 partition, to create a separate ext2 primary partition (only a few megabytes in size) for GRUB, and to expand the extended partition to fill the remaining space. I also created a new logical NTFS partition within the extended partition for holding my files to be shared between WinXP and Ubuntu.

Once I was finished with all the partitioning gymnastics, I rebooted. You really won’t notice many changes when you reboot, at least initially. In WinXP, you’ll see that there’s a new drive available (the logical NTFS partition I created for holding my documents), but that’s about it. The next step for me was to install GRUB to its newly-created partition, and I simply followed the instructions for doing so that I mentioned above.

A couple of test reboots later and I had convinced myself that the machine was indeed booting using the contents of the GRUB partition. Interestingly, you can set up the boot menu (menu.lst) a number of different ways. The coolest way, at least in my book, is to have the main GRUB menu.lst refer to the menu.lst files on the individual linux partitions. It’s all covered in the links I mentioned above.

The final step for me was to see if I could get WinXP and Ubuntu to both look at (and share) the same documents folder. The first thing to do was to boot WinXP and tell it to change the location of the My Documents special folder. You may know that the My Documents folder in Windows is actually a link to a folder under /Documents and Settings/username/My Documents. But you can tell Windows to change where the folder is physically located, simply by right-clicking on the My Documents folder that appears at the top of the Windows Explorer window and then clicking the Move button. I moved mine to the root of the second NTFS partition that I created (which Windows recognizes as the E: drive, in my case). In case my explanation isn’t clear, here’s the straight poop from Microsoft. My goal was simply to use the root of E: as the My Documents folder, so that (a) that’s where Windows would want to store things by default, and (b) I could then mount that partition in Linux as a folder under /home/dave named /home/dave/Documents.

Once I got the My Documents folder moved in Windows, it was back to Ubuntu and some learning about the mount command. It’s fairly simple to do. The partition that Windows calls E: is known on the Ubuntu side as /dev/sda6 (this, of course, will vary from system to system depending on how many partitions are present, what order they were created in, and what type of devices they are). I wanted /dev/sda6 to be mounted such that the contents would appear to be located in folder /home/dave/Documents (or simply ~/Documents, for short). So here’s the basic mount command (in Ubuntu 7.10) to do that:

sudo mount -t ntfs /dev/sda6 /home/dave/Documents/

After I typed that, I was able to access files on that partition. Cool.

But I noticed a couple of things. First, I wasn’t the owner of the files. Second, files that shouldn’t have been executable were being considered by Linux as executable. Both of these issues can be solved by specifying additional parameters for the mount command. I’ll get to that in a second.

The other issue to deal with was to figure out how to get the partition to be mounted automatically when I booted. That turned out to be reasonably easy–you simply edit the /etc/fstab file and add an entry that causes the partition to be mounted where you want it. In my case, I ended up adding a line to the end of that file that looks like this:

/dev/sda6 /home/dave/Documents/ ntfs users, auto,rw,uid=1000,gid=0,dmask=000,fmask=111

You can see exactly what all this means by looking at the man page for mount, but here are some highlights.

/dev/sda6 is the device we’re mounting, of course. The location that it’s being mounted to is /home/dave/Documents. It’s an ntfs volume and we want it to be mountable by all users, and auto mounted at boot time. The rw option means that we want the partition to be readable and writeable. The uid and gid options set the user and group who own the partition. In this case, the ID for my username (dave) is 1000 (I saw this by opening the Users and Groups manager in Ubuntu–the ID is shown for each user and group). Finally, dmask and fmask set the permissions for directories and files, respectively. They do it with a mask that’s the inverse of what you’d type for chmod, though. A dmask of 000 is the same as chmod 777, and an fmask of 111 is the same as a chmod of 666, if that makes any sense. The final result is that the partition gets mounted automatically at boot time to /home/dave/Documents as an ntfs volume with me as the owner and permissions that allow me to read and write the files but not execute them.

The upshot is that everything that appears in My Documents in WinXP also appears in ~/Documents in Ubuntu.

So there you have it (albeit in a nutshell). This was simply a proof-of-principle exercise for me, as I’ll be doing this again once my new hard drive arrives for the system my son gave me as a hand-me-d0wn. I’ll try to provide a more detailed blow-by-blow when I do this for keeps.

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required