Add new partitions to an existing system

From ArchWiki
Revision as of 06:18, 14 April 2012 by Fengchao (talk | contribs) (Provisional remounting and checking: Clean up command output.)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Add new partitions to an existing system#)


You may find yourself in the situation where you either:

  • want to create a new partition to give yourself more flexibility, for example for backup operations.
  • are forced to use new partition(s) because your original is full and to free up space you need to move data from the full partition to a new one.

Here are the steps to add new partition:

  1. Create new partitions.
  2. Mount the new partitions in a temporary location.
  3. Copy the existing files from old partition to the newly created partitions in their temporary locations.
  4. Delete the files under the original directories
  5. Move new partition from their temporary mount points to their permanent homes
  6. Update fstab accordingly.

Creating the New Partitions

Warning: Changing, Resizing and/or Creating partitions has the VERY REAL potential to cause DATA LOSS Use common sense. BACKUP ANYTHING YOU DO NOT WANT TO LOSE!

New partitions can be created either on previously unpartitioned sections of an existing disk (or raid array in my case) or simply on an additional newly installed drive.

You will need your filesystems to be UNMOUNTED when you make changes such as adding new partitions to the free space on your disk or shrinking partitions. Therefore you will need to boot into an environment such as provided by the install CD in Rescue mode.

Command line utilities such as fdisk, cfdisk or sfdisk can be used, but if you are unfamiliar with creating partitions and filesystems Gparted-Live iso is recommended. It provides a nice gui and additional checks to make sure what you are doing is okay. See also GParted for how to use GParted.

Extended Growth & Logical Partitioning

Partitions come in three main flavors: Primary, Extended and Logical. An Extended partition is for the most part just a "wrapper" to contain logical partitions.

If you have a typical Linux partition scheme, then you probably have a single "extended" partition with "logical" partitions of '/', '/home' and possibly a '/boot' partition. Your logical partitions will probably completely fill the extended partition they reside in. Before you can add additional partitions, you must grow the current extended partition to make room for your new logical partitions, or you can create a new extended partition. I prefer to grow the extended partition then add the new logical partitions. I find no need for primary partitions unless dual booting windows.

You will need to create a filesystem on the new partitions with 'mkfs -t <fstype>' or you may select the desired filesystem when defining your partition with Gparted. If you do not know which filesystem you are using, then from the command line type "df -hT" and check the type column.

Moving Existing Data to the New Partitions

To benefit from the extra space provided by the new partitions, the new partitions need to be integrated into the filesystem. In my case I was replacing the directories /srv and /var with the new partitions /srv and /var. The solution:

  1. copy everything from the existing directories to the new partitions
  2. delete the contents of the existing /srv and /var directories
  3. mount the new partitions under /srv and /var
Warning: check to confirm a good copy

Files should not be written to the parts of the filesystem you are moving during this process. The safest way to accomplish the copy and delete is to either boot from your install cd into rescue mode and create mount points to hold your / filesystem and the new partitions, or alternatively shutdown anything that could write to or read from the existing directories. /srv was not an issue, but for /var, syslog-ng needed to be shutdown. (If using dmraid, issue "dmraid -ay" to activate your raid sets when booting from the install CD into rescue mode.)

My new partitions were /dev/mapper/nvidia_ecaejfdip9 and /dev/mapper/nvidia_ecaejfdip10. Usually they are similar to /dev/sda5 so substitute as necessary. The basic process (as root) is:

Stop any processes that might write to the old directories.

 # /etc/rc.d/syslog-ng stop

Create temporary mount points for your new partitions.

 # mkdir /mnt/newsrv
 # mkdir /mnt/newvar

Mount the new partitions on the temporary mount points.

 # mount /dev/mapper/nvidia_ecaejfdip9 /mnt/newsrv
 # mount /dev/mapper/nvidia_ecaejfdip10 /mnt/newvar
Warning: before doing this ensure that the system does not still need read or write access to these folders

Copy the information from the old directories to the new partitions.

 # cp -a /srv/* /mnt/newsrv
 # cp -a /var/* /mnt/newvar

Confirm the information was written to the new partitions with ls, diff, etc. When you are certain the information was written correctly to the new partitions delete the information from the old directories.

 # rm -r /srv/*
 # rm -r /var/*

Remounting the New Partitions on the Filesystem

Now you have new partitions containing your data and have deleted the original copy of the data from the / filesystem to free-up space. Next the new partition(s) should be unmounted from their temporary location(s) and assigned their proper place in the filesystem.

Provisional remounting and checking

# Unmount the new partitions from the temporary mount point
umount /mnt/newsrv
umount /mnt/newvar

# Mount the new partitions as /srv and /var
mount /dev/mapper/nvidia_ecaejfdip9 /srv
mount /dev/mapper/nvidia_ecaejfdip10 /var

Now the new partitions are in the proper location in the filesystem and you can confirm the new room with df -h

Permanent remounting

Finally make the new changes permanent by adding the new mount configuration to /etc/fstab. As root edit /etc/fstab adding something similar to the following corresponding to your own new partitions:

# New Partitions, /srv and /var on separate partitions

/dev/mapper/nvidia_ecaejfdip9 /var ext3 defaults 0 1
/dev/mapper/nvidia_ecaejfdip10 /srv ext3 defaults 0 1

(See the fstab article for more details.)

If you have disabled any running processes, restart or enable them, check the files on your new partitions to insure all is well and check the logs for any permission errors. Then reboot and make sure it all works as expected.