Home Map Index Search News Archives Links About LF
[Top bar]
[Bottom bar]
[Photo of the Author]
Olivier Chapuis

About the author:

In real life, the author does mathematics, in particular logic, algebra and theory of computation. He recently discovered Linux and that was for him a true revelation. He loves Muriel and his current hobby is scuba diving. He also enjoys Brittany, the sea, boating, skiing and good food.

Content:

  1. Introduction
  2. Principal Steps
  3. Preparation and sources of difficulty
  4. Rebuilding the windows partition
  5. Using the <<new>> partition.
  6. Problems.
  7. References

How to remove windows

[Ilustration]

Abstract:

In this article, I explain how to remove windows from a machine which contains both Linux and windows, and moreover, how to use the available space for Linux. This article is intended for naïve users (I am one of them myself).



 

Introduction

It occurred to me one day, about two months after having installed Linux, that I wanted to remove windows. The reason was simply that I didn't use it anymore! I imagine that a number of new Linux users are in the same situation, and I wrote this document to help them (the gurus can also read it and suggest improvements). If you are in this situation, two strategies are available.

The first is to reinstall Linux. The advantage of this strategy is that with a little Linux experience, you will make better choices on installation, in particular those to do with partition sizes. The main disadvantage is that you will loose everything. You can avoid this in part by backing up everything that isn't on your installation CDROM. But reinstalling this backup will cost you time and sweat.

The second strategy is to remove windows (which is easy), then use the space available for Linux. That is to say, <<repartition>>, an operation a bit tricky and little documented. The advantage of this method is if you succeed, your system will be <<as before>> but with more disk space. The second advantage is that if you fail, you will always be able to use the first strategy. In this document, I explain how I did it. Of course, the method will depend on your configuration. In particular, if you have an enormous virgin disk, you can probably first backup your files to this disk and then install from scratch. I imagine that this is a safer strategy which gives a better result. Me, I back up onto 1.44 Mb floppies. In any case, I hope the strategy described below will help a new user.

I would like to thank Olivier Tharan for his detailed response to a message posted in fr.col.moderated which was version -1 of this document. I would also like to thank Finn Bo Jorgensen and Chmouel Boudjnah for their response.

 

Principal Steps

- Preparation: backup, examine and take notes on certain important files before proceeding. Read the document to understand what you are going to do. (section 3 below).

- Remove windows (section 4 below).

- Repartition, the tricky bit (section 5 below).

 

Preparation and sources of difficulty

Above all, back up the essential files. In particular, the configuration files and your work. I won't say anything more below.

A preliminary step is to understand what you are going to do. There is some explanation of the commands and files in what follows, but it is very incomplete. Read the man pages! In this case, fdisk, mk2ext, cp (a not so stupid command), lilo, lilo.conf and fstab (there are also man pages for certain configuration files). Very detailed docs on lilo are in the directory /usr/doc/lilo-0.20/doc/ (if your system is correctly installed). In particular there is a <<user guide>> of 46 pages! For fdisk see the file /usr/doc/util-linux-2.7/README.fdisk, also very complete. In writing this document I learned of a very useful mini-Howto which is relevant: Hard Disk Upgrade Mini How-To.

First, here is my partition table:


   [olivier@snoopy  olivier]# /sbin/fdisk -l         (as su)

   Disk /dev/hda: 128 heads, 63 sectors, 788 cylinders
   Units = cylinders of 8064 * 512 bytes

      Device Boot  Begin   Start     End  Blocks  Id System
   /dev/hda1   *       1       1     397 1600672+  c Unknown
   /dev/hda2         398     398     601  822528  83 Linux native
   /dev/hda3         602     602     627  104832  82 Linux swap
   /dev/hda4         628     628     788  649152  83 Linux native

We see that windows is on hda1. It is not unusual for fdisk to say <<Unknown>> for a FAT32 partition. My kernel (currently 2.0.34) knows how to access this type of filesystem, but that's not the case for my fdisk. To demonstrate, here is the output of df (with the dos partition mounted).


    [olivier@snoopy olivier]# df

    Filesystem        1024-blocks    Used   Available  Capacity  Mounted on
    /dev/hda2            796065    506992      247947     67%    /
    /dev/hda4            628351    226366      369528     38%    /home
    /dev/hda1           1594456    850420      744036     53%    /mnt/dos

You will have to edit two configuration files /etc/fstab and /etc/lilo.conf. They will look something like this:


    [olivier@snoopy olivier] less /etc/fstab

    /dev/hda2          /                 ext2         defaults        1 1
    /dev/hda4          /home             ext2         defaults        1 2
    /dev/hda3          swap              swap         defaults        0 0
    /dev/fd0           /mnt/floppy       ext2         user,noauto     0 0
    /dev/cdrom         /mnt/cdrom        iso9660      user,noauto,ro  0 0
    none               proc              proc         defaults        0 0
    /dev/hda1          /mnt/dos          msdos        user,noauto     0 0

    [olivier@snoopy olivier] less /etc/lilo.conf

    boot=/dev/hda
    map=/boot/map
    install=/boot/boot.b
    prompt
    timeout=500
    image=/boot/vmlinuz-2.0.34-1
            label=linux
            root=/dev/hda2
            read-only
    other=/dev/hda1
           label=dos
           table=/dev/hda

 

Rebuilding the windows partition

Now you must do everything as root. For psychological reasons, I advise you to log in as root (don't su from your account). If you use vi to edit, you may have to use w! to save. In any case, I advise you to verify that your modifications were indeed saved (leave your editor and look at the file with less).

You are going to use the commands fdisk and mke2fs. These commands work with hard disk partitions and all other storage systems. It is better to use these commands on partitions that are not mounted. It is all done in three steps.

- If your partition is mounted, unmount it: umount /mnt/dos.

- Start fdisk. Change the identity of hda1: we will tell linux that this partition will now be a Linux native partition. Do this with the command t (t, 1, 83). Look at: p , the only thing which changes is the Unkown which becomes linux native and the c which becomes 83. Save and quit: w. Look again at: fdisk -l. In quitting fdisk I received the following error message:


   The partition table has been altered!
       Calling ioctl() to re-read partition table.
       Syncing disks.
       Re-read table failed with error 16: Device or resource busy.
       Reboot your system to ensure the partition table is updated.

As far as I know, this message is normal and harmless: I didn't reboot.

- Format: mke2fs /dev/hda1. Plenty of numbers appear then the system works for a bit and poof! windows 98 is no longer! The prudent will add the -c option which does a rapid check for bad blocks.

There you have it. Windows is gone. I wasn't especially thrilled by this (I don't have anything personal against win98, as opposed to Microsoft ...). But I was happy for Linux ...

 

Using the <<new>> partition.

Good, now I have a 1.5 Gb partition with nothing on it, a 600 Mb partition for /home and an 800 Mb for / (and a swap partition of 100 Mb). There is 100 Mb in /home/myaccount which should be in /usr/local/ (I will leave it on /dev/hda2) and there is 10 Mb in /usr/local. I will move / to hda1 and put /usr/local on hda2. This will give:


   Filesystem      1024-blocks  Used   Available Capacity Mounted on
   /dev/hda1        1600672    465000   1130672     29%    /
   /dev/hda2         796065    110000    696065     13%    /usr/local 
   /dev/hda4         628351     40739    587612      6%    /home

Enough space for a dozen years ....

Now to make it so. To access hda1 you must mount it somewhere. Generally you use /mnt.

- Create a new directory in /mnt, lets say /mnt/tmp, to provide a proper mount point for hda1 (mount doesn't create directories): mkdir /mnt/tmp.

- Mount hda1 on /mnt/tmp : mount -t ext2 /dev/hda1 /mnt/tmp (clearly -t ext2 gives the filesystem type).

- Copy / to /mnt/tmp/ while preserving its structure: cp -ax / /mnt/tmp/. For the -a option, the man page says: <<Preserve as much possible of the structure and attributes of the original file in the copy. The same as -dpR>>. See the cp man page for the significance of d, p and R, which will better explain the a. The -x option asks to skip the subdirectories which are on different filesystems from the one the copy started on. In my case, this avoids copying /home onto /dev/hda1. The copy operation will take some time (about 15 min with my IDE disk and my AMD K6 at 266 MHz), now for the usual phrase: go have a coffee or a double whisky while waiting.

- There are still some things missing from hda1. Because of the -x option, we are missing the two directories (empty) /home and /proc. So mkdir /mnt/tmp/home and mkdir /mnt/tmp/proc. These directories are the mount points that must be there so that /home (which is on hda3) and /proc can be mounted on the root.

Now things get a little complicated. We have / (=/-/home) on hda2 but also on /mnt/tmp/. We are going to get ready to restart. We must edit fstab and lilo.conf. Linux must be told that we are going to restart with the / which is on /mnt/tmp/. Thus, for fstab the file which we must modify is in fact /mnt/tmp/etc/fstab. For lilo.conf it is different. We must edit /etc/lilo.conf, run lilo and also copy the new /etc/lilo.conf to /mnt/tmp/etc/lilo.conf (to have a consistent system). Or we could edit only /mnt/tmp/etc/lilo.conf and run lilo with the -C option telling it that it must use a different configuration file. I chose the second method.

- /mnt/tmp/etc/fstab

This file indicates how and where to mount everything that is mountable on startup. When we restart, we want the root / to be hda1, so we need the first line of /etc/fstab as below. Of course, we can't mount two roots! Since we have to work on /dev/hda2, I'm mounting it on /mnt/tmp. The rest stays the same.


    /dev/hda1        /                ext2     defaults         1 1  
    /dev/hda2        /mnt/tmp         ext2     defaults         1 2
    /dev/hda4        /home            ext2     defaults         1 3
    /dev/hda3        swap             swap     defaults         0 0
    /dev/fd0         /mnt/floppy      ext2     user,noauto      0 0
    /dev/cdrom       /mnt/cdrom       iso9660  user,noauto,ro   0 0
    none             /proc            proc     defaults         0 0

- /mnt/tmp/etc/lilo.conf.

lilo.conf is the configuration file for lilo, the little program on the MBR. I won't go into the details. If some people aren't using lilo, I very strongly advise them to switch (lodelin is an absurdity in our case, and why boot off a floppy these days?). Here we tell just lilo that now the kernel is on hda1 (it was on hda2 before) and of course we remove everything concerning windows.


     boot=/dev/hda
     map=/boot/map
     install=/boot/boot.b
     prompt
      timeout=500
     image=/boot/vmlinuz-2.0.34-1
           label=linux
           root=/dev/hda1
           read-only

- Run lilo: /sbin/lilo -v -C /mnt/tmp/etc/lilo.conf. The v is so that lilo tells us a little more about what's going on. Here we mustn't see an error message! We can't make mistakes if we want to reboot. We should see something like:


    LILO version 20, Copyright 1992-1997 Werner Almesberger
    Reading boot sector from /dev/hda
    Merging with /boot/boot.b
    Boot image: /boot/vmlinuz-2.0.34
    Added linux *
    /boot/boot.0300 exists - no backup copy made.
    Writing boot sector.

- Reboot. Some small tests (df, fdisk -l, we see if the filesystem is as we have specified).

- Remove everything from /mnt/tmp/, which we do like this: rm -rf * in the directory /mnt/tmp. Next we copy the directory /usr/local which stays: cp -a * /mnt/tmp after cd /usr/local. Check if everything is okay, then delete /usr/local: rm -fr * in the directory /usr/local (note that we mustn't remove the <<name>> which we will soon give as the mount point for local!).

- Again edit /etc/fstab and change just the second line:


     /dev/hda2    /usr/local          ext2    defaults       1 2

- Reboot. Do some tests.

And the operation is done. I assure you that I was satisfied, especially after I tested a lot of programs and everything worked!

 

Problems.

True, I had a little problem. The above isn't exactly as it happened, but an idealization. The advice I can give you is to understand a little about what you are doing which will allow you to understand why it isn't working and to fix the situation. Olivier Tharan advised me to restart in single user mode (I didn't because the only documentatation that I had on single user mode is <<look at the files in single user boot mode>> and I was a little bit lazy). Before the first reboot it is perhaps prudent to have a good reboot disk (which perhaps must be adapted to the situation and I admit to not knowing exactly how to do it...)

Here is the problem I had. Before the first reboot I did nearly everything above. But after rebooting to the stage of mounting the filesystems a bunch of error messages flashed by at high speed. I managed to read: /proc ... error ... error ... /home ... error (without a trace in /var/log/messages). Then (phew) the login prompt appeared. I logged on as root and immediately


    [root@snoopy root]$ df
     Filesystem      1024-blocks    Used   Available  Capacity  Mounted on
     /dev/hda1          1548535   506977    961525     35%       /
     /dev/hda2           796065   506992    247947     67%       /mnt/tmp

Home wasn't mounted. I editted fstab, but all seemed normal. Then I had a brilliant idea (the double whisky?) to mount /home and I was greeted with the message <<mount: mount point /home does not exist>>. Then I understood that I didn't understand what a mount point was and that I had forgotten the option x of cp (I admit to being a little ashamed). I created the mount points /home and /proc and I mounted /home and /proc to see if it was okay. Then the operation was finished as described above.


 

References

  • man pages: fdisk, mk2ext, cp, mv, rm, lilo, lilo.conf and fstab
  • /usr/doc/lilo-0.20/doc/User_Guide.ps
  • /usr/doc/util-linux-2.7/README.fdisk
  • Hard Disk Upgrade Mini How-To
  • Original article in French translated to English by Paul Kienzle

    Webpages maintained by the LinuxFocus Editor team
    © Olivier Chapuis
    LinuxFocus 1999