Partition a hard drive

From LQWiki
Jump to navigation Jump to search

Warning: 'Partitioning can DESTROY valuable data'

Please read the partition and disk-related articles before coming here. By the time you start partitioning you should understand the difference between /dev/hdb1 and /dev/hdc.

In addition to cfdisk used in this example, you could use a graphical partition editor, Qtparted. To start cfdisk, enter

 # cfdisk /dev/hdx

where the 'x' in /dev/hdx is replaced by the disk you want to partition. To use fdisk, leave off the 'c'.

Now you will see a screen that shows you your disk and how it is partitioned. Start by deleting the partitions you don't need. If there currently is only free space then you don't need to delete anything. You can move through the available actions with your left and right arrow.

Now it's assumed that you have deleted the partitions you didn't need. If you accidentally deleted something you shouldn't have press Ctrl+c and start from the beginning.

Now we will create new partitions. Partition 'design' is a matter of personal preference most of the time. On Desktop systems, you can get away with an absolute bare minimum of:

Primary Partition 1   /
Primary Partition 2   <swap>

Server environments are also a matter of personal preference, but a starting point may be to have everything in one partition - this reduces the danger that you have plenty of space while one directories space is exhausted to the minimum.

Vendor/OEM Partitioned Drives

Care should be taken when you are wanting to repartition a hard drive for Linux. If a vendor, like Dell or HP, setup the drive, it may have partitions or area where vendor specific information is contained. On some cheaper machines a partition contains the only copy of Windows that came with the machine.

First -- Check with the vendor that you can backup any vendor specific information. In some cases you can't. If you ever wanted to reload, you would have to resort to purchasing new OS media for the machine. You may also wipe out additional bloatware that the manufacturer may have shipped with the machine. For most, that is not an issue. But if you like the fancy card printing program that came with the machine, find a way to back it up - or order the program from another source.

Second -- Take care to note how the Master Boot Record is created. If you can back that up, then you should do so. Also note the original partitions and where they start and stop. What type of file system format do they follow. You never know when you will want to revert to the old software. Some restore CDs that came with the machine may abort if they find the machine configuration changed. Particularly with the partition table.

Third -- If you format the drive, be sure to do a sector by sector check for bad sectors. If you have a hard drive testing utility on a bootable CD then use it to test your drive. This is important on used equipment. If you have a factory machine, be sure that you don't void warrantee by removing the old software. The EULA can be a bear, always read the fine print.

Planning Your Partitions

Linux installation programs usually will partition the hard disk to a preset size based on current machine memory, disk space availability, and usually partition the drive into two partitions, the Root "/" partition, and the Swap "/swap" partitions. With you the administrator/end-user being left out of the decision making process.

For those of you who are more adventurous, here are some ideas on how to partition your hard disk into something more fault tolerant, and more logical and safe.

When planning for partitions, plan in rough numbers. Always add more than you need to use. The number of users or the type of use (server, workstation, personal PC) do not dictate how to partition your hard drive. A number of install packages will do this automatically. However, if you are the heavy programmer, graphics user, pack-rat, or other large disk storage consumer, you will need to plan carefully, then multiply that number by a minimum of 1.5. Typically the multiplier is three times the estimated current needed amount.

Memory actually will impact how much disk space will be used for the operating system. Even as uses a certain amount of hard disk space for a swap area. In Linux/Unix, that area is static. It is not a file, but an entire partition to be used for one purpose - memory swap space. This is usually the only other partition you have to deal with other than the main Linux partition - IF you use the install package defaults.

With the main Linux partition, there are differences between the root partition "/" and "/boot", or other directories/partitions. Current versions of Linux/Ubuntu/Unix will now use a single partition to house everything. As an administrator, you may want to rethink that practice.

If you plan to have lots of downloads, news feeds, personal files, or source code, you will want to possibly partition the drives into more parts. This will protect the system partitions in the event of running out of space, or if you accidentally tried to format a partition (even as 'root'), or delete files (such as a 'find . -name -print -exec rm {} \;' and forget you are in the root directory of the particular partition.

Swap Partitions ( /swap )

Swap should be set to three times (3) or more of actual physical memory. If you want to load the OS and add memory later, it would be recommended that you add the memory first, before you edit the partition for swap areas. Older versions of Linux may not allow you to change the swap area size after you add more memory.

Set the swap space to three times the size as a default. Some would say to 1.5 to 2 times the size. But you never know when you have a hankering for a massive parallel build or want to run a gauntlet of programs.

If you add memory to your computer you may end up fighting the operating system errors until you resolve your swap space. Increase memory and you need to increase swap space. Some versions of Linux will not allow you to define a larger swap space than a pre-set amount. More administrator friendly versions will allow you to set the swap space to anything larger than 1.5 times the amount of physical memory. If you cannot set your swap larger than you want, think about how much you want to use, allocate the swap to the max Linux will allow, then allocate another area as additional swap space that can be mounted later, or added later via repartitioning.

Boot Partition ( /boot )

With today's hard disk drives in the 120 Gig range and higher, you can allocate two or three gigs to this area. This will be useful when rebuilding kernels and wanting to keep different versions of kernels available. having a separate /boot also allows for protection against full disk problems. (See more below)

Root partition ( / )

The root partition should contain at least: /, /bin, /usr, /lib, /mnt or /media, /dev, /proc, and other directories that are critical to operating the system during boot process or in single user/maintenance mode. Usually these are static areas for programs that the operating system uses, or for applications that rarely change. Storage for mail, news, web, or other dynamic data functions should be avoided in these areas. The risk of file erasure or space issues may pose a problem in the future. Even if you think you have enough storage now, there is always the 'later' to think about.

/var use to stand for "Value Added Retailer" storage area. Now is has become "various" storage. Under this should be your programs that are not critical to the operating of the computer in a critical situation. Games, added applications, development programs, and some X11 programs should reside here.

/home is a directory where, on most versions of Linux and Unix, the user home directories are stored. Sometimes some of the administrative login areas are stored here. Should an administrative login have a location in /home, it is recommended that you move it to a directory under the root partition. This way you will have it available during single user mode maintenance. If you are going to use your system as a server, or you plan to do a LOT of heavy graphics, database work, or programming, you should allocate LOTS of disk space for this directory.

See also

This article is a stub and needs to be finished. Plunge forward and help it grow! (discuss here)