We currently migrate to MediaWiki from our old installation, but not all content has been migrated yet. Take a look at the Wiki Team page for instructions how to help or browse through our new wiki at wiki.linux-vserver.org to find the information already migrated.

Repartitioning the Filesystem via remote access

In this howto I want to show you how to renew your harddisks partitions with the use of your swap partition without having direct access to the server - SSH only :). The use of this howto should be that you can resize your partitions on a running system without having data loss. Please take care of what you are doing!!

1. First we need to deactivate the swap partition on the system:

swapoff -a

2. Then we need to comment out the swap line in our /etc/fstab file.

pico /etc/fstab

example: your line is: /dev/hda2 swap swap defaults 0 0

change it to: # /dev/hda2 swap swap defaults 0 0

3. Now let's create a fresh filesystem on that original swap-partition. Simply type:

mke2fs /dev/hda2

(Attention: Replace /dev/hda2 through your device name as you can see it in your fstab file!!!)

4. Create a new mountpoint, mount the newly created partition to it and change to that mountpoint:

mkdir /mnt/disk

mount /dev/hda2 /mnt/disk

cd /mnt/disk/

5. In the next step we want to copy the operating system to that partition. Please be advised that the following steps can vary for each linux distribution. If you have a swap partition that is big enough (let's say 1GB or higher) you can use the following command to copy your complete system to that partition:

dump 0f - /dev/hda3 | restore rf -

(assuming that your complete system is on the partition /dev/hda3, mounted as /)

If your system is splitted in more partitions, such as /dev/sda1 (mouted as /usr), /dev/sda2 (mounted as /bin) and so on you can use the same command more than once, such like this:

dump 0f - /dev/sda1 | restore rf -

dump 0f - /dev/sda2 | restore rf -

You should transfer at least /usr /var /sbin /bin /boot /lib /etc to that swap partition to get your system to work again after a reboot :) ).

You can use restore in interactive mode if you use 'if' instead of 'rf', this way you can for example exclude some parts of the filesystem from being restored. Please have a look at the manpage of restore(8) for details.

6. Now we tell the system about our "experience" - that we want to boot our new system from the swap partition. To do that we need to edit our fstab file ON THE SWAP PARTITION:

pico /mnt/disk/etc/fstab

Insert the following:

/dev/hda2 / ext3 defaults 1 1

(be sure to change /dev/hda2 to your device name)

7. Now we need to tell lilo the same - that it has to boot from swap:

pico /etc/lilo.conf

Insert the following:

image=/boot/<your kernel>

label=swap

initrd=/boot/<your kernel image>

read-only

root=<your entry you put in /mnt/disk/etc/fstab>

Type:

lilo

to activate the changes

lilo -R swap

to tell lilo to boot from the swap - if reboot fails, it automatically reboots from the kernel set by default

shutdown -r now

8. Well done, if your server is up again, check with

df -h

from what partition your machine booted up. If it shows /dev/hda2 (mounted as /) as device: Congratulations.

If not, check, if you copied all neccessary files and/or directories and try again.

9. Now we want to resize our original root partition - let's say to 4 GB:

resize2fs /dev/hda3 1048576

How to get "1048576"?

Simple:

1 GB = 1024 x 1024 x 1024

(((1024 x 1024 x 1024) x Disk space in GB)) / Blocksize)

To get the blocksize of your harddisk, simply type:

dumpe2fs -h <device name of your /boot>

There you see a line e.g. "Block size: 4096"

(((1024 x 1024 x 1024) x 4 GB)) / Blocksize) = ((1073741824 * 4) / 4096) = 1048576

10. Now going on to the fdisk tool to create new partitions:

fdisk /dev/hda

First we need to delete our old partition(s).

Type:

d

and press enter to delete a partition. You are now asked which one you would like to delete. Please take care on what number you enter!!

number of partition to delete

Creating new partition(s)

Type:

n

and press enter to create a new one.

p

to select

3

(this is our 3rd device on that hard disk)

+10G

to set its size to 10 GB.

Next partition

n

p

4

<enter>

to use the rest of the unpartitioned area from your harddisk.

To write the partition to the disk press

w

11. For Linux getting to know what we did we need to initiate a reboot:

reboot

12. Now we can give our newly created partition /dev/hda3 its full filesystem size back:

resize2fs /dev/hda3

13. On /dev/hda4 we want to create a new filesystem:

mke2fs /dev/hda4

That's all! We now have re-partitioned our filesystem(s).