Search:  
Gentoo Wiki

HOWTO_Install_Gentoo_Linux:_Partitioning


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Image:Gentoo_tux.png

Base Install

  1. What is Gentoo?
  2. About
  3. Preparation
  4. Partitioning
  5. Configuring
  6. Stage Progression
  7. Kernel
  8. Bootloader
  9. Test
  10. Converting from or to a non-Gentoo distribution
  11. Troubleshooting
  12. Maintaining

Configuration

Base Extras

Server

Desktop

Other Articles

edit

Preparing Your Hard Disc(s)

If happen to be on a Linux box and you also happen to like doing things out of order, feel free to skip this step and come back to it later - just be sure you're sure that you know what you're doing. For instance. If you have a well working gentoo system that already has support for LVM2 [1][2], you can stage out your base installation, tarball it, and untar it onto another PC or hard drive.

Test the performance of your hard drive and improve it if necessary:

Code: Using hdparm
 hdparm -tT ${DISK}
 echo "Activate DMA:                       # hdparm -d 1 ${DISK}"
 echo "Activate Safe Performance Options:  # hdparm -d 1 -A 1 -m 16 -u 1 -a 64 ${DISK}"


The Old Fashioned Way (fdisk & cfdisk)

AFAIK, all systems have fdisk. Most systems have cfdisk. I prefer to use cfdisk rather than fdisk, as the interface is a little more (dare I say) user-friendly, but they perform the same function equally well.

Partitioning[3] is pretty simple, I'll let you figure out the bits and pieces of it on your own. However, here are some suggestions as regarding the setup of your partitions:

  1. Read the screen. If you miss this step, try again. Don't file a bug on it because it works for me.
  2. You'll need a /boot (0x83) and / (0x83) partition.
    • '/boot' doesn't really need to be more than 10MB, but 32MB is nice.
    • '/' you'll want to be at least 500MB, but maybe up to 2GB.
  3. You'll want swap (0x82) space.
    • You can get away with... none, to be honest (on a desktop that is), but the professional recommendation is 2x the amount of your RAM (maybe 3x if you want to use hibernation / software suspend).
    • For best results the swap area should be the first partition.
  4. Cut the remaining space into several equal multi-GB chuncks for LVM (0x8E).
    • The following example assumes that partition 1 is /boot, 2 is /, 4 is swap (and 3 is used to make logical partitions).
  5. Don't forget to toggle the [partition type] (0x82, 0x83, 0x8E, etc). For [GNU/Linux] this isn't really a concern, but it is a good idea - especially when [dual boot]ing with a [lesser OS].

Note: At home I created 20 partitions for my main 160GB SATA disc... don't do that. Though it'a good idea to have many partitions rather than one big one when using LVM2 (just in case you find at some point that you need to use some non-LVM space), you're probably best to keep it under 16 and certainly under 64. The kernel only supports 15 partitions per SCSI device (and therefore SATA, as it is emulated as SCSI), and a whopping 63 for PATA on IDE. Read up on it if you want to know more: `man mknod && less /usr/src/linux/Documentation/devices.txt`. In my case, it took some data juggling to make the overpartitioned disk fully usable again, but in the reading I did learn much about special files a little better. I highly recommend the reading - just for good times.

Code: Good 'ol Fashioned Partitioning
 # partition your disk
 cfdisk ${DISK}

 # ext2 filesystem (generally under 500MB)
 mke2fs ${DISK}1
 
 # ext3 (ext2/journaling) filesystem (generally over 500MB)
 mke2fs -j ${DISK}2
 
 # ReiserFS filesystem
 mkreiserfs ${DISK}3
 
 # make a swap filesystem
 mkswap ${DISK}4

 # This is the fdisk way to view your partition tables
 fdisk -l ${DISK}
 # This is the cfdisk way to view your partition tables
 cfdisk -Ps ${DISK}
#               First       Last
# Type       Sector      Sector   Offset    Length   Filesystem Type (ID) Flag
#-- ------- ----------- ----------- ------ ----------- -------------------- ----
# 1 Primary           0       62495     63       62496 Linux (83)           None
# 2 Primary       62496     1039247      0      976752 Linux (83)           None
# 3 Primary     1039248    18614735      0    17575488 Extended (05)        None
# 5 Logical     1039248     3968495     63     2929248 Linux LVM (8E)       None
# 6 Logical     3968496     6897743     63     2929248 Linux LVM (8E)       None
# 7 Logical     6897744     9826991     63     2929248 Linux LVM (8E)       None
# 8 Logical     9826992    12756239     63     2929248 Linux LVM (8E)       None
# 9 Logical    12756240    15685487     63     2929248 Linux LVM (8E)       None
#10 Logical    15685488    18614735     63     2929248 Linux LVM (8E)       None
# 4 Primary    18614736    19541087      0      926352 Linux swap / So (82) None

Notice that I didn't follow my own advice about the swap being first. My Mistake.

The New Fashioned Way (LVM2)

LVM2 allows for a much easier way to change filesystem sizes on the fly. It's pretty much the 1337est way to make an admin's life easier since the pocket protector. Since it is so fresh and there isn't a handy-dandy hold-your-hand utility, like cfdisk, for it (AFAIK), I will give you some further insight on the matter.

To come up with my partition sizes I ran `du -ch ${FILESYSTEM} | grep total` and considered a little room for growth.

  1. All of the remaining space (partitions from ${DISK}5 on) are to be made 'physical volumes' for lvm2.
    • We'll pretend that each partiton is 10GB (even though in the example above it's only 1.5GB, hehe).
    • We won't use all of the partitions right away and if they are needed later, it's easy to release them with pvremove.
  2. A few of the pvs will be assigned to at least one 'volume group' (vg0)
    • A vg is, more or less, a pool of storage capacity.
  3. A quantity of storage capacity is assigned to each 'logical volumes' (arbitrarily called usr, opt, home, ...).
  4. A file system is created on the logical volume
    • ReiserFS is great because it comes with tools to easily shrink and grow the filesystem size
Code: New Fashioned Partitioning
 modprobe dm-mod
 echo "avoid scanning cdrom"
 mkdir -p /etc/lvm 
 echo 'devices { filter=["r/cdrom/"] }' >/etc/lvm/lvm.conf 
 echo "If you reboot before completing the install and /dev/vg0 doesn't exist, rerun `vgchange -a y`"
 vgchange -a y
 pvcreate /dev/${DISK}5 /dev/${DISK}6 /dev/${DISK}7 /dev/${DISK}8 
 pvcreate /dev/${DISK}9 /dev/${DISK}10
 vgcreate vg0 /dev/${DISK}5 /dev/${DISK}6
 vgextend vg0 /dev/${DISK}7 /dev/${DISK}8 /dev/${DISK}9
 vgreduce vg0 /dev/${DISK}9
 echo 'Just to give you an example of how cool LVM is I'll play around a bit'
 lvcreate -L500M -nvar  vg0; echo "creating /dev/vg0/var as 500MB"; sleep 3
 lvresize -L400M /dev/vg0/var; echo "Now only 400MB"; sleep 3
 lvextend -L+1G /dev/vg0/var; echo "400MB+1GB"; sleep 3
 lvresize -l+22 /dev/vg0/var; echo "add 22 more logical extents (4MB each default) 1.4GB+88MB"; sleep 3
 lvresize -L3G /dev/vg0/var; echo "Don't do math, just make it 3GB"; sleep 3
 lvcreate -L2G -ntmp  vg0
 lvcreate -L2G -nopt  vg0
 lvcreate -L7G -nusr  vg0
 lvcreate -L7G -nhome vg0
 clear; echo "FYI: I did consider reiser4, but at the time of this writing it wasn't stable."; sleep 3
 mkreiserfs /dev/vg0/home
 mkreiserfs /dev/vg0/opt
 mkfs -t reiserfs /dev/vg0/tmp
 mkfs -t reiserfs /dev/vg0/usr
 mkfs -t reiserfs /dev/vg0/var

A few notes to help you out with LVM2:

Now is the time to make good use of these partitions.

Code: Mounting New and 'ol Partitions
swapon ${DISK}4
mkdir -p /mnt/gentoo
mount ${DISK}2 /mnt/gentoo
mkdir /mnt/gentoo/boot
mkdir /mnt/gentoo/home
mkdir /mnt/gentoo/mnt
mkdir /mnt/gentoo/opt
mkdir /mnt/gentoo/proc
mkdir /mnt/gentoo/tmp
mkdir /mnt/gentoo/usr
mkdir /mnt/gentoo/var
mount ${DISK}1 /mnt/gentoo/boot/
mount -t proc none /mnt/gentoo/proc
mount /dev/vg0/home /mnt/gentoo/home
mount /dev/vg0/opt /mnt/gentoo/opt
mount /dev/vg0/tmp /mnt/gentoo/tmp
chmod 1777 /mnt/gentoo/tmp
mount /dev/vg0/usr /mnt/gentoo/usr
mount /dev/vg0/var /mnt/gentoo/var
cp /root/config.vars /mnt/gentoo/root/config.vars

With all of that exampleage, it shouldn't be too difficult to understand the advantages of lvm2. You could add a new hard drive to your system, add a partition from it (or the whole thing) to a physical volume, add that pv to a volume group pool, add divide that capacity among several different filesytems and safely grow filesystems while mounted. Keep in mind that the names used above (such as /dev/vg0 and /dev/vg1/backup) are completely arbitrary.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Install_Gentoo_Linux:_Partitioning"

Last modified: Fri, 05 Sep 2008 22:52:00 +0000 Hits: 13,280