Differences between revisions 16 and 18 (spanning 2 versions)
Revision 16 as of 2018-07-16 06:21:04
Size: 4379
Editor: SamatJain
Comment:
Revision 18 as of 2018-12-19 17:51:08
Size: 4580
Editor: SamatJain
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
Required for computers booting with UEFI. 64 MiB is more than large enough. Needs to have a partition type of EF00, and must be mounted at /boot/efi. Required for computers booting with UEFI. 64 MiB is more than large enough, though Ubuntu's default is 512 MiB. Needs to have a partition type of EF00, and must be mounted at /boot/efi.
Line 11: Line 11:
768 MB–1 GB, at minimum. This is enough to contain several kernels as well as a bootable ISO (i.e. grml) for use with grub2. If a boot partition is not needed (i.e. not doing RAID5), exclude it. 768 MB–2 GB, at minimum. This is enough to contain several kernels as well as a bootable ISO (i.e. grml) for use with grub2. Generally, a separate boot partition is not needed unless doing RAID5 boot, encrypted boot, bcache boot, etc.
Line 95: Line 95:
For a more high-level tool, you can also use sgdisk:

{{{#!highlight sh numbers=off
sudo sgdisk --clear /dev/sdX
}}}

Partitioning guidelines

EFI

Required for computers booting with UEFI. 64 MiB is more than large enough, though Ubuntu's default is 512 MiB. Needs to have a partition type of EF00, and must be mounted at /boot/efi.

Boot (/boot)

768 MB–2 GB, at minimum. This is enough to contain several kernels as well as a bootable ISO (i.e. grml) for use with grub2. Generally, a separate boot partition is not needed unless doing RAID5 boot, encrypted boot, bcache boot, etc.

Root (/)

For servers, a 4 GB partition is more than adequate. Most of my servers have less than 1 GB utilization.

For desktops/laptops, 10 GB is adequate for a machine with a set purpose and just running a desktop environment, while doing no/minimal development.

For a development workstation 20 GB or more is good. I always run out of space attempting to install debug packages and/or compile large software collections, such as KDE.

Logs (/var)

Space requirements for /var are always increasing. At minimum, 4 GB. If /var and /tmp are merged, 6 GB.

Temp (/tmp)

For servers, I notice /tmp is not used often, and usually lies empty. When it does it used, the frequency of use is similar to /var. I'll usually merge tmp and var for this reason (i.e. remount /tmp under /var/tmp).

For desktops, 2-4G is usually fine. I usually aim for the minimum required to store a CD or DVD image when burning discs.

Swap

Using swap files

Instead of letting space go to waste in a swap partition, Linux can use a small swap file instead:

sudo dd if=/dev/zero of=/swap-file bs=1M count=255
sudo mkswap /swap-file
sudo swapon /swap-file

To automatically bring it up on reboot, place into fstab:

/swap-file none swap sw 0 0

(!) Note: The Linux kernel does not support sparse files as swap files. It's also best to create the swap file immediately after filesystem creation to insure a contigiuous file. Other than that, choice of filesystem does not matter. Reference on LKML.

zram

The zram module (2.6.38+) lets you create an LZO-compressed block device in RAM. Derived from a project formally known as compcache, you can use these compressed devices for a compressed, RAM-based swapdisk.

To create a 4 GB device and use it as swap:

   1 echo $((4*2**30)) > /sys/block/zram0/disksize
   2 mkswap /dev/zram0
   3 swapon -p 60 /dev/zram0

For Ubuntu 12.04 or later, there's the zram-config package:

sudo apt-get install zram-config

Partition tables

Creating

To create a GPT partition encompassing the entire disk, run:

sudo sgdisk --clear /dev/disk-dev-device # Clear old partition table
sudo sgdisk --largest-new=1 /dev/disk-dev-device # Create new partition table. Should align to 2048-byte alignment

Erasing

Attacking the first sector (512 bytes) of a disk with dd will completely erase a partition table:

dd if=/dev/zero of=/dev/sdX bs=512 count=1

while attacking only the first 446 bytes will clear the MBR, uninstalling LILO or GRUB's stage 1:

dd if=/dev/zero of=/dev/sdX bs=446 count=1

For a more high-level tool, you can also use sgdisk:

sudo sgdisk --clear  /dev/sdX

Cloning

Cloning partition table geometry is useful for setting up RAID arrays. You don't want to copy the sector from disk to disk directly, because this will duplicate partition GUIDs (which will cause headaches later).

sfdisk can duplicate an MBR partition table across disks:

sfdisk -d /dev/sda | sfdisk /dev/sdb

sgdisk (0.6.8 and above) can duplicate GPT partition tables across disks:

sgdisk -b - /dev/sda | sgdisk -l - -Gg /dev/sdb

Information

file can be report information about a partition, particularly whether GRUB is installed. For example:

$ sudo file -s /dev/sda
/dev/sda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, stage2 address 0x2000, stage2 segment 0x200; partition 1: ID=0xfd, active, starthead 1, startsector 63, 1493982 sectors; partition 2: ID=0xfd, starthead 0, startsector 1494045, 1463650020 sectors, code offset 0x63


CategoryCheatSheet

SamatsWiki: CheatSheet/Partitioning (last edited 2022-06-28 20:12:45 by SamatJain)