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.
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. They can then be automatically mounted onto the appropriate part of the filesytem at boot time after fstab has been edited.
In my case, which I will use as an example, I developed a full root partition due to the size of my website files in Template:Filename and many packages such as kdemod3 and kde-unstable filling Template:Filename. Since I had available unpartitioned space on the dmraid array holding my Arch Linux install, I decided to move Template:Filename and Template:Filename to their own separate partitions to solve the problem. This would free up space which had taken by Template:Filename and Template:Filename on the Template:Filename partition and provide greater disk space for Template:Filename and Template:Filename on their own partitions.
After a routine drive status check, I was a bit surprised to find my root partition full:
I diagnosed the problem with kdiskfree, but you could use another other disk usage display program. The source was found to be the collection of files offered on my website (Template:Filename) and the pacman cache (Template:Filename) so I decided to:
2. Mount the new partitions in a temporary location.
Creating the New Partitions
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, the Gparted-Live CD or another live CD with the necessary utilities.
Command line utilities such as fdisk, cfdisk or sfdisk can be used, but if you are unfamiliar with creating partitions and filesystems I would recommend downloading and using the Gparted-Live iso; it provides a nice gui and additional checks to make sure what you are doing is okay.
You can download GParted here: http://gparted.sourceforge.net/download.php See the note about its use on some HP Pavilion Computers
With that cautionary statement, you can take comfort knowing that changing, resizing, creating and removing partitions is what the partitioning tools were created for. They work. Just make sure you understand what your are doing with the software and do not do anything strange (like clicking buttons willy-nilly or randomly trying out all of the commands available in the packages) and you should be just fine.
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 '/', 'Template:Filename' and possibly a 'Template:Filename' 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 Template:Filename and Template:Filename with the new partitions Template:Filename and Template:Filename. The solution:
- copy everything from the existing directories to the new partitions
- delete the contents of the existing Template:Filename and Template:Filename directories
- mount the new partitions under Template:Filename and Template:Filename
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 Template:Filename filesystem and the new partitions, or alternatively shutdown anything that could write to or read from the existing directories. Template:Filename was not an issue, but for Template:Filename, 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.)
Stop any processes that might write to the old directories. Template:Cli
Create temporary mount points for your new partitions. Template:Cli
Mount the new partitions on the temporary mount points. Template:Cli
Copy the information from the old directories to the new partitions. Template:Cli
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.
Remounting the New Partitions on the Filesystem
Now you have new partitions containing your data and have deleted the information from the Template:Filename filesystem to free-up space. Now 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 you have created on Template:Filename with "df -h"
[16:19 archangel:/home/david] # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/nvidia_ecaejfdip5 19G 11G 7.3G 59% / none 2.0G 0 2.0G 0% /dev/shm /dev/mapper/nvidia_ecaejfdip6 114M 17M 92M 15% /boot /dev/mapper/nvidia_ecaejfdip7 37G 12G 24G 32% /home /dev/mapper/nvidia_ecaejfdip9 15G 165M 14G 2% /mnt/var /dev/mapper/nvidia_ecaejfdip10 29G 7.4G 20G 27% /srv
All that remains is to make the new changes permanent by adding the new mount configuration to Template:Filename. Using your favorite editor as root, open Template:Filename and add something similar to the following:
# New Partitions, Template:Filename and Template:Filename 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.