User Tools

Site Tools


howto:repartition_harddrive

I wanted to repartition my hard drive for two reasons:

(1) To make a swap partition. The system was sluggish out of the box and sometimes froze up for a few seconds at a time. I began to suspect that this was because there was no swap partition. I was right. Adding a swap partition fixes these problems, and the system actually runs like a 900 MHz machine.

(2) To increase the size of my system partition. I like running large packages such as build-essential and texlive, and want them on my system partition. I also got tired of having to spend hours reinstalling and reconfiguring everything every time I did the equivalent of an “F9 Restore”.

To do this job, you will need, in addition to your EeePC, a separate computer with a DVD drive, the EeePC Linux Recovery disk, the EeePC Support disk, and a spare USB flashdrive with at least 4GB of space. (You will lose all data on this flashdrive!)

Since you'll be doing a lot of mounting and unmounting the USB stick, as well as writing to it as a raw device, it's helpful to get rid of usbstorageapplet before proceeding. As root,

apt-get --purge remove usbstorageapplet

Then

mkdir /media/D: /media/E:

Now let's get started. Step 1 is optional, but recommended.


Step 1: Restore EeePC to factory conditions.

Get usb.img.gz from the boot directory of the Linux Recovery DVD. Copy usb.img.gz to your EeePC, and then do

gunzip -c usb.img.gz | dd of=/dev/sdb

Put the USB stick back in the machine with the DVD drive, and copy the files
2008.07_24_20.55.bld blockcount.dat P701l.gz user_start.dat
from the Linux Recovery DVD to the USB stick.

Copy the file ver.tag from the Support DVD to the USB stick.

Pull the battery from your EeePC for about 30 sec. This will help ensure that you can get into BIOS setup when you boot.

Replace the battery and insert your USB stick. Turn the machine on and hold down the F2 key. (You may have to do the following every time you boot from your USB stick. BIOS likes to change the following settings a bit whenever you pull your USB stick.)

Under Boot Settings/Boot Device Priority, make the 1st Boot Device your USB stick and the 2nd Boot Device your hard drive.

Under Boot Settings/Hard Drives make the 1st Drive your USB stick and the 2nd Drive your hard drive.

To make it easy to get into BIOS setup each time you boot, you may want to change Boot Settings/Boot Settings Configuration and Boot Settings/Boot Booster.

Disable Quick Boot, Quiet Boot, and Boot Booster

Save BIOS settings and let your EeePC boot from the USB stick. You will be led through the restore process. Type yes when asked to, and at the end when it says its ready to reboot, you can pull your USB stick and proceed.

When you're finished booting, you'll want to get rid of usbstorageapplet as above. (You can ignore any complaints from apt-get at this point.)


Step 2: Prepare a new initramfs-eeepc.img and menu.lst

First, you're going to modify the stock initramfs-eeepc.img file.

cd /boot
mkdir tmp
cd tmp
gunzip -c ../initramfs-eeepc.img | cpio -i

Replace the init file with the following: (The characters <ESC> must be erased, and in their place, in vi, type Ctrl-V and then the ESC key.)

#!/bin/sh

mount -t proc proc /proc
mount -t sysfs sys /sys

echo "0 0 0 0" > /proc/sys/kernel/printk

if [ -n "$RESCUE" ] ; then
  insmod /modules/usbcore.ko
  insmod /modules/uhci-hcd.ko
  insmod /modules/ehci-hcd.ko
  insmod /modules/libusual.ko
  insmod /modules/usb-storage.ko
  insmod /modules/fat.ko
  insmod /modules/vfat.ko
  insmod /modules/nls_cp850.ko
  insmod /modules/nls_iso8859-1.ko
  /bin/busybox sh
  set -x
fi

ROOT=`cat /proc/cmdline | sed 's/.*root=// ; s/ .*//'`

if [ -n "$NOUNIONFS" ] ; then
  # Setup for system partition only.
  mount -t ext2 -o rw,noatime $ROOT /mnt
  if [ $? -ne 0 ] ; then
    echo Could not mount OS on $ROOT. Starting debugging shell....
    /bin/busybox sh
  fi
  if [ -z "`grep nosplash /proc/cmdline`" ] ; then
    echo -n "<ESC>[?25l"
    cp /mnt/boot/startup.fb /dev/fb/0
  fi
  # It's nice to have access to the user partition.
  # Put it on /mnt/.rw
  mount -t ext2 -o rw,noatime /dev/sda6 /mnt/.rw
else
  # Setup for normal user mode.
  mount -t ext2 -o ro $ROOT /mnt-system
  if [ $? -ne 0 ] ; then
    echo Could not mount OS on $ROOT. Starting debugging shell....
    /bin/busybox sh
  fi
  if [ -n "$USERSCAN" ] ; then
    exec switch_root /mnt-system /sbin/scanuser.sh
  fi
  if [ -n "$USERFORMAT" ] ; then
    exec switch_root /mnt-system /sbin/formatuser.sh
  fi
  if [ -z "`grep nosplash /proc/cmdline`" ] ; then
    echo -n "<ESC>[?25l"
    cp /mnt-system/boot/startup.fb /dev/fb/0
  fi
  if ! mount -t ext2 -o rw,noatime /dev/sda6 /mnt-user ; then
    echo Error mounting user partition. Must run filesystem scan!
    exec switch_root /mnt-system /sbin/scanuser.sh
  fi
  mount -t aufs -o br:/mnt-user:/mnt-system none /mnt
  if [ $? -ne 0 ] ; then
    echo Could not mount aufs on USER partition. Starting debugging shell....
    /bin/busybox sh
  fi
  mount --move /mnt-system /mnt/.ro
  mount --move /mnt-user /mnt/.rw
fi

umount /sys
umount /proc

if [ -n "$CONSOLE" ] ; then
  exec switch_root /mnt /bin/sh </mnt/dev/console >/mnt/dev/console
else
  exec switch_root /mnt /sbin/fastinit "$@" </mnt/dev/console >/mnt/dev/console
fi

# We shouldn't get here.

echo
echo Init Failed. Starting emergency shell....
/bin/busybox sh

Now you're going to copy some needed files into the image.

mkdir sbin lib

cd /lib/modules/2.6.21.4-eeepc/kernel/drivers/usb
cp core/usbcore.ko host/uhci-hcd.ko host/ehci-hdc.ko \
storage/libusual.ko storage/usb-storage.ko /boot/tmp/modules
cd ../../fs
cp fat/fat.ko vfat/vfat.ko nls/nls_cp850.ko nls/nls_iso8859-1.ko \
/boot/tmp/modules

cd /bin
cp bzip2 /boot/tmp/bin

cd /sbin
cp e2fsck tune2fs /boot/tmp/sbin

cd /lib
cp ld-linux.so.2 libc.so.6 libblkid.so.1 libdevmapper.so.1.02 \
libpthread.so.0 libbz2.so.1.0 libdl.so.2 libselinux.so.1 \
libcom_err.so.2 libe2p.so.2 libsepol.so.1 /boot/tmp/lib

cd /boot/tmp/dev
mknod sdb b 8 16
mknod sdb1 b 8 17

mkdir /boot/tmp/mnt/sdb1

Now you're going to pack it up again.

cd /boot/tmp
find . | cpio -H newc -o | gzip -9 > /home/user/initramfs-eeepc.img

Put the file somewhere safe. You'll need it later.

Make a file called menu.lst which contains the following. Put it in the same safe place.

# default boot entry
default=0

# Boot automatically after 3 seconds.
timeout=3

# Fallback to Rescue Console
fallback=1

title Normal Boot
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1
	initrd /boot/initramfs-eeepc.img

title Rescue Console
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1 RESCUE=y
	initrd /boot/initramfs-eeepc.img

title Root Console (No GUI)
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1 CONSOLE=y
	initrd /boot/initramfs-eeepc.img

title Modify System Partition (No UnionFS)
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1 NOUNIONFS=y
	initrd /boot/initramfs-eeepc.img

title System Partition Console
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1 NOUNIONFS=y CONSOLE=y
	initrd /boot/initramfs-eeepc.img

title Scan User Partition
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1 USERSCAN=y
	initrd /boot/initramfs-eeepc.img

title Reformat User Partition
	root (0x80,0)
	kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=normal nosplash=y irqpoll root=/dev/sda1 USERFORMAT=y
	initrd /boot/initramfs-eeepc.img

Step 3: Preparing the USB stick for the repartitioning job.

You're going to use the same usb.img.gz file you used in Step 1. But, this time you're going to make modifications.

gunzip -c usb.img.gz | dd of=/dev/sdb

mount /dev/sdb1 /media/D:
mkdir /home/user/tmp
cd /home/user/tmp
cp /media/D\:/boot/initrd.gz .
gunzip initrd.gz
mount -o loop initrd /media/E:

cd /media/E:/dev
mknod sda4 b 8 4
mknod sda5 b 8 5
mknod sda6 b 8 6
cd /bin
cp cpio bzip2 /media/E:/bin
cd /usr/bin
cp find /media/E:/bin
cd /sbin
cp tune2fs mke2fs mkswap mkfs.vfat fdisk /media/E:/sbin
mkdir /media/E:/lib
cd /lib
cp libc.so.6 ld-linux.so.2 libbz2.so.1.0 libext2fs.so.2 \
libcom_err.so.2 libblkid.so.1 libuuid.so.1 libe2p.so.2 \
libdevmapper.so.1.02 libselinux.so.1 libsepol.so.1 libpthread.so.0 \
libdl.so.2 libnsl.so.1 /media/E:/lib

cd /media/E:/etc/init.d

Edit rcS to read as follows:

#!/bin/sh
TAR_IMG="P701L.gz"

/bin/busybox mount -t proc proc /proc
/bin/busybox --install -s
mount -t sysfs sysfs /sys

echo "0 0 0 0" > /proc/sys/kernel/printk

insmod /modules/usbcore.ko
insmod /modules/cdrom.ko
insmod /modules/sr_mod.ko
insmod /modules/usbhid.ko
insmod /modules/uhci-hcd.ko
insmod /modules/ehci-hcd.ko
insmod /modules/libusual.ko
insmod /modules/usb-storage.ko
insmod /modules/fat.ko
insmod /modules/vfat.ko
insmod /modules/nls_cp850.ko
insmod /modules/nls_iso8859-1.ko

echo "Waiting 15 sec for USB subsystem..."
sleep 5
sleep 5
sleep 5

/bin/sh
set -x

Now pack it all up:

cd /home/user/tmp
umount /media/E:
gzip -9 initrd
cp initrd.gz /media/D:/boot/
umount /media/D:

Boot your USB stick. You will need to modify BIOS setup as outlined in step 1.


Step 4: Format your USB stick and back up the system partition.

Do

dd if=/dev/zero of=/dev/sdb bs=1024 count=1

fdisk /dev/sdb
<code>

Enter d to delete partition 1.

Enter n. Choose p and then 1. Accept the default for first and last
cylinders.

Hit t. Enter b for the hex code.

Hit w. This will write the new partition.

Now do

<code>
dd if=/dev/zero of=/dev/sdb1 bs=512 count=1
mkfs.vfat /dev/sdb1

To back up the system partition:

mount /dev/sdb1 /mnt
mkdir /mnt-system
mount /dev/sda1 /mnt-system
cd /mnt-system
find . | cpio -H newc -o | bzip2 -9 > /mnt/system-files.img.bz2
cd /
umount /mnt-system
umount /mnt

Step 5: Repartition /dev/sda

fdisk /dev/sda

Hit d and select partition 1.

Hit d and select partition 2.

Hit n. Choose p for a primary partition and select 1.

Start at cylinder 1 and choose whatever size you need for your system partition.

Hit n. Choose e for an extended partition. Partition 2 should be selected by default. Select default values for first and last cylinders.

Hit n. Select the default value for the first cylinder. Use +1024M as the partition size.

Hit t. Select partition 5. Specify hex code 82. (This will be the swap partition.)

Hit n. Select defaults for the first and last cylinders. (This creates partition 6, which will be the user partition.)

Before you exit, you can hit p to see what you've done.

Hit w to write the partition table and exit.

Now format the new partitions.

mke2fs -m0 /dev/sda1
mkswap /dev/sda5
mke2fs -m0 /dev/sda6
mount /dev/sda1 /mnt
tune2fs -c0 -i0 /dev/sda1
umount /mnt
mount /dev/sda6 /mnt
tune2fs -c0 -i0 /dev/sda6
umount /mnt

Now restore the system partition files.

mount /dev/sda1 /mnt-system
mount /dev/sdb1 /mnt
cd /mnt-system
bzip2 -dc /mnt/system-files.img.bz2 | cpio -i
cd /
umount /mnt-system
umount /mnt

Step 6: Reboot your computer into Xandros Debug (Rescue) mode.

Your computer won't boot normally at this point because it will try to mount /dev/sda2 as the user partition instead of /dev/sda6.

Pull out your USB stick and reboot the computer. After the BIOS check, hold down the F9 key until the grub boot menu appears. Highlight “Normal Boot” and press e. Scroll down to the second line and press e again. Add XANDROSBOOTDEBUG=y to the end of the line. Hit enter, and then hit b to continue booting.

You will now need to do some setup to access your USB stick.

mount /dev/sda1 /mnt-system
cd /mnt-system/lib/modules/2.6.21.4-eeepc/kernel/drivers/usb
insmod core/usbcore.ko
insmod host/uhci-hcd.ko
insmod host/ehci-hcd.ko
insmod storage/libusual.ko
insmod storage/usb-storage.ko
cd ../../fs
insmod fat/fat.ko
insmod vfat/vfat.ko
insmod nls/nls_cp850.ko
insmod nls/nls_iso8859-1.ko

mkdir /lib
cd /mnt-system/lib
cp libc.so.6 ld-linux.so.2 /lib
cp /mnt-system/bin/chmod /bin

umount /mnt-system

cd /dev
mknod sdb b 8 16
mknod sdb1 b 8 17

mkdir /mnt/sdb1

Now get the files initramfs-eeepc.img and menu.lst you made in Step 2. I'll assume you have put them on your USB stick. (You may insert your USB stick at this point.)

Do the following:

mount /dev/sda1 /mnt-system
mount /dev/sdb1 /mnt/sdb1
cd /mnt-system/boot
mv initramfs-eeepc.img initramfs-eeepc.img.orig
cp /mnt/sdb1/initramfs-eeepc.img .
cd grub
mv menu.lst menu.lst.orig
cp /mnt/sdb1/menu.lst .

cd /mnt-system/dev
mknod sda4 b 8 4
mknod sda6 b 8 6
chmod 660 sda4
chmod 660 sda6

(sda5 is already present.)

cd /mnt-system/sbin

Modify formatuser.sh, changing mkfs.ext3 to mkfs.ext2, commenting out the tune2fs line, and changing all references to sda2 to sda6. Modify scanuser.sh, changing all references to ext3 to ext2, and all references to sda2 to sda6.

Now

cd /
umount /mnt-system
umount /mnt/sdb1

Pull out your USB stick.


Step 7: Boot to the system partition.

Reboot your computer. At the (new) grub menu, select Modify System Partition (No UnionFS)

You'll be taken through the firstrun sequence. When the desktop loads, Xandros will complain about an invalid license after a bit. Start a console with Ctrl-Alt-T, and do

sudo apt-get --purge remove xandros-explorer

Now modify the /etc/fstab file, adding the following line at the end:

/dev/sda5 none swap defaults 0 0

Now reboot your machine.


Step 8: Now do whatever you want with your system. Enjoy! :-)

Note: I noticed at one point that my swap file wasn't active after a reboot. To make sure it is, put the command

/sbin/swapon -a

somewhere in your /usr/bin/startsimple.sh file. (I recommend doing that on the system paartition.)

howto/repartition_harddrive.txt · Last modified: 2011/02/21 05:31 by unclechromedome