Drive Partitioning

From The Brainwrecked Wiki
Revision as of 18:11, 27 January 2014 by BrainwreckedTech (talk | contribs) (Notes: Expounded Notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
File:Under construction icon-blue.svg

UNDER CONSTRUCTION

The author walked away without completing this article.
Most likely, it was beginning to drive them up the wall.

Most people don't know about hard drive partitioning. With the way most OEM computers and external storage medium is shipped, the only time a person would come face-to-face with partitions is when buying an internal hard drive or installing Linux. While this certainly makes things easier to set up, it can make things more difficult in the long run. Chiefly, when operating system data gets borked by a virus, bad system setting, or hardware failure. By using partitions to separate data, that data becomes easier to maintain.

Limitations of Partitions

While newer PCs are beginning to utilize UEFI and GPT, most computers still utilize BIOS and MBR introduced all the way back in 1980. MBR carries some serious limitations.

  • Limit of 4 primary partitions
    • 1 primary partition can be designated as an extended partition
    • The extended partition can contain any number of logical partitions
    • Windows will not allow you to install it to a logical partition
      • This includes recovery tools based on Windows.
  • Limit of 232-1 (4,294,967,295) addressable sectors
    • 512B sectors makes for 2TB
    • 4K sectors would make for 16TB
    • Manufactures are still falsely reporting 512B sectors to maintain compatibility.

If you are able to use GPT, by all means use it as it simplifies matters greatly.

Recovery Partition(s)

If you bought a pre-made computer and you did not receive any recovery discs, chances are that your OEM has created a partition at the beginning of the hard disk for use as a recovery partition. Worse yet, OEMs are starting to use more than one parition -- one that contains the Windows Pre-Installation Environment only and another with the files actually needed to perform the recovery. The partition(s) is/are usually marked as hidden but can be accessed during the BIOS boot process.

It's best just to get rid of the partition(s) all together.

  1. Find the OEM's recovery disc creation program in the installed OS and run it.
  2. Make ISO backups of the recovery discs to an external drive or network share.
  3. Re-partition the drive to suit your needs.
  4. Boot from the recovery discs to re-install your operating system.
  5. Select the recovery option that leaves the partition table as-is.

NB: Some recovery tools will state that they will delete the partition that they are going to install Windows on. This is technically incorrect. They are going to delete all data on that partition by formatting it. The partition itself will remain in tact.

Notes

decimal binary
KB kilobyte 103 1,000 bytes KiB kibibyte 210 1,024 bytes
MB megabyte 106 1,000,000 bytes MiB mebibyte 220 1,048,576 bytes
GB gigabyte 109 1,000,000,000 bytes GiB gebibyte 230 1,073,741,824 bytes
TB terabyte 1012 1,000,000,000,000 bytes TiB tebibyte 240 1,099,511,627,776 bytes

If you're using an Advanced Format (4K sector) drive, you'll want to start the first partition at sector 8 (4KiB). If you're using GRUB2, you'll want to start the first partition no sooner than sector 64 (32KiB). For broadest compatibility, allow partitioning programs to align partitions to 1MiB (2048 sector) boundaries.

The real reason is that 1MiB is ideal offset to keep partitions aligned on almost all random hardware. This offset is compatible with 512-byte, 4096-byte sector devices, many raid devices as well as old broken WD disks where physical sector size has been incorrectly reported. You can use dd(1) to move your PT + data to another device without care about physical device topology (I/O limits), etc.

GNU parted allows you to specify partition boundaries in sectors (s), bytes (B), decimal units (KB,MB,GB,TB) or binary units (KiB,MiB,GiB,TiB). Anything other than a decimal unit will be treated as a "hard" boundary and parted will not offer to adjust it. Decimal units are treated as "soft" boundaries and parted will automatically adjust the value to the nearest boundary. By default, those boundaries are 1MiB (-a optimal). GNU parted can also use 4K alignment (-a minimal) or no alignment at all (-a none).

Single OS Solutions

Use A Single Partition

WARNING: If you place all your data in a single partition, you can kiss it goodbye if the fliesystem becomes horribly corrupted. Even if you make backups, say hello to the aggravation of restoring from backups.

This is the default setup for Windows and Mac OS. However, both of these operating systems create a swap file within the main file system by default, whereas Linux does not. While Linux really doesn't care if you have swap space or not, it will also be more than happy to just freeze on you when you run out of memory.

Still want the swap space in Linux but don't want the added partition? The trick is to create the partition, format it, mount it, and then issue the following commands. Note that count=1024 will give you 1GB.

dd if=/dev/zero of=/mnt/swapfile bs=1M count=1024
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile

You can mount the swap file immediately by using:

swapon /mnt/swapfile

You can mount the swap file at boot time by editing /etc/fstab to include this line:

 /mnt/swapfile none swap sw 0 0

Use Two Partitions

This is a much better compromise between partition consolidation and data retention.

Size Usage FS Mnt
3GB
7GB
25GB
Linux Server
Linux Desktop
Windows Vista/7
any
any
NTFS
/
/
C:
Where the operating system and programs will reside.
free space Linux
Windows 2000/XP
Windows Vista/7
any
NTFS
NTFS
/home
C:\Documents and Settings
C:\Users
Kept separate so that it's easier to upgrade the OS without worrying about the data.

While Windows does not have the same filesystem mounting concept as Linux, Windows has had junctions (hard links) since Windows 2000. You can use this to craftily move C:\Users (C:\Documents and Settings in 2000 and XP) to another partition/drive.

Using More Partitions

Of course the choices are limitless. Some common things that you may want to partition off are:

Boot Loader
Needed only if using Linux with a root partition that is encrypted or RAIDed.
Games
Putting your games onto a separate partition usually makes it easier to backup and share games between OSes. Steam is a perfect candidate for this.
"Local" Share
Useful as a places to transfer files between OSes or for when network storage/transfer would really bog things down (Virtual Machines, DVD/Bluray ripping).
Swap
Creating a separate partition for this is normal for Linux but not for Windows. The only problem with Windows is that there will be file system overhead space-wise. (Example: An 8GB partition loses 10.5MB to the file system.)


Dual-OS Solutions

Windows requires installation to a primary partition and should be installed to the first partition on the hard drive. The Windows NT lineage (NT 4.0, 2000, XP, 2003, Vista, 7, 8) is extremely goofy with its boot loader in that it points to specific point on the disk relative to the whole disk instead of its own partition. This means that if you move the Windows partition Windows will fail to boot.

If you are not encrypting, RAIDing, or LVMing your hard drive(s), /boot does not need its own partition. This should free up one partition.

You can also use LVM to split one physical partition into two logical ones. In this event, join the values for swap and / (root), use the space for a single LVM group, and define the logical volumes accordingly.

Linux, with NFS, can have the /home directory hosted on a file server.

If all else fails, Linux will be happy to exist on Extended Partitions, unlike Windows.