Table of Contents
Thorough the guide we'll assume that the drive you'll be installing to is
/dev/sda. Please replace this device with the one you will be using.
In order to install Gentoo stand-alone we'll need a GPT partitioned drive with
an EFI boot partition. This is a small FAT32-formatted partition that will
contain the EFI executables needed to boot the system (namely GRUB plus the
SecureBoot shim). Run
# parted -a minimal /dev/sda GNU Parted 3.4 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands.
parted prompt switch the default unit to use MiBs:
(parted) unit MiB
Now create the GPT partition table by executing this command in
(parted) mklabel gpt
If the disk already contains a partition table parted will prompt you about it.
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes
Once the partition table has been created, create a new EFI boot partition.
We'll make it 128MiB in size, and set the appropriate flags for it to be
recognized, type the following in the
(parted) mkpart efi fat32 1 129 (parted) set 1 boot on (parted) set 1 esp on
We can now close
(parted) quit Information: You may need to update /etc/fstab.
Format the newly created EFI boot partition. It needs to use the FAT32 filesystem:
# mkfs.vfat -F32 /dev/sda1
Finally we'll label the EFI partition so that it will be easier to find later:
# fatlabel /dev/sda1 EFI
To install Gentoo on the same drive on which Windows is installed you'll first need to make sure that the drive is using the proper partition format and that all required partitions are present. We'll then make room for Gentoo's partitions and proceed with the installation.
First of all let's make sure that the disk partition table uses the GUID
Partition format. You can do so by printing out the drive's information using
# parted /dev/sda print Model: ATA INTEL SSDSC2BX01 (scsi) Disk /dev/sda: 1200GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 274MB 273MB fat32 EFI System Partition boot, hidden, esp 2 274MB 60.6GB 60.3GB ntfs Windows msftdata 3 60.6GB 61.2GB 628MB ntfs WinRE msftres
The partition table format is visible in the
Partition Table line and it
must be gpt.
If the format is msdos then your disk is using the legacy master boot record (MBR) partition scheme. It is possible to convert your disk to GPT using Microsoft's MBR2GPT.EXE tool and switch your machine to use UEFI but the procedure is beyond the scope of this tutorial.
Once you've verified that you're using the GPT partition format make sure that the first partition in the drive is a FAT32 partition called EFI System Partition. This is the partition that contains Windows' boot loader and kernel, and which we'll use for Gentoo's boot loader and kernel too.
Now that you've verified that your disk is properly formatted it's time to make room for Gentoo's partitions. Launch gparted and inspect your Windows drive, this is what you'll likely find:
Your disk will have between two and four partition, one of which is an NTFS partition likely labeled Windows and possibly another smaller one afterwards often called WinRE or something along the lines. The large partition is your main Windows partition and the following one is a recovery partition. The latter might not be present at all so don't worry if it's not there.
Let's start by shrinking Windows' main partition. Select it, right-click on it and select the Resize/Move option from the context menu, you will be presented with the following dialog:
Make room after this partition by acting on the Free space following (MIB): option. In this case I'm freeing 60GB of space after it:
Once this is done click on the Resize/Move button. gparted will now display the change that you requested but not execute it right away.
If you have a recovery partition after the Windows partition we'll need to move it. If the Windows partition was the last one on the drive skip this step.
Select the recovery partition, right click on it and select the Resize/Move option. Now set the Free space preceding (MIB): value to 0, like so:
This will move the partition all the way behind the resized Windows one.
Click on the Resize/Move button. gparted will inform you that moving a partition might make your drive unbootable, this won't be an issue in this particular case so click OK. The layout will now look like this:
Now press the Apply All Operations button, the green mark in the toolbar. This will execute all the operations that we queued. Be patient and when everything's done close gparted.
Now from the terminal label the EFI boot partition, this will be useful later when we will mount the partitions:
# fatlabel /dev/sda1 EFI
Before we can continue with the installation we'll have to reboot into Windows. This step is required for the resize to take effect. Windows will check the NTFS file system upon reboot and flag it as clean. Once this is done reboot with your live CD and we'll resume Gentoo's installation.
At this point your destination disk should be ready for hosting the partition where Gentoo will be installed. We will use a single partition for Gentoo with the BTRFS file system.
BTRFS is a modern and stable file system with a few important features:
It supports snapshotting which allows us to create copies of the contents of the filesystem at a certain point in time. This is extremely useful when experimenting as one can roll back changes easily.
It supports checksums on the data stored on disk, which makes it easy to detect data corruption. This is critical to preserve your data over long spans of time.
It supports carving a single partition into multiple subvolumes, this allows for proper separation of the various parts of the installation without having to pre-allocate a certain amount of space to each partition.
parted and print out the current partition layout. Check where the last
partition ends. In this case it's at
# parted -a minimal /dev/sda GNU Parted 3.4 Using /dev/sdc Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) unit MiB (parted) print Model: Hitachi HTS543232A7A (scsi) Disk /dev/sdc: 305245MiB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1,00MiB 129MiB 128MiB fat32 efi boot, esp
Now create the root partition, starting at the end of the last partition on the
disk and ending at
-1s. This will create a partition that spans all the
remaining space on the drive. If the partition cannot be created at the
exact boundaries we have specified parted will prompt us about it. Check that
the suggested values are fine and confirm the operation, you can then quit:
(parted) mkpart rootfs btrfs 129MiB -1s Warning: You requested a partition from 129MiB to 305245MiB (sectors 264192..625142443). The closest location we can manage is 129MiB to 305245MiB (sectors 264192..625142410). Is this still acceptable to you? Yes/No? Yes (parted) quit Information: You may need to update /etc/fstab.
It's now time to create the BTRFS filesystem. From now on we don't need to
refer to the root filesystem via its raw device link (like
because we have labelled it. It will now be reachable at:
/dev/disk/by-partlabel/rootfs. If you chose a different name for the
partition in the previous step replace
rootfs with the name of your
# mkfs.btrfs /dev/disk/by-partlabel/rootfs btrfs-progs v5.10.1 See http://btrfs.wiki.kernel.org for more information. Label: (null) UUID: 6440dea2-ece0-429b-a60c-d887a47dcab1 Node size: 16384 Sector size: 4096 Filesystem size: 297.96GiB Block group profiles: Data: single 8.00MiB Metadata: DUP 1.00GiB System: DUP 8.00MiB SSD detected: no Incompat features: extref, skinny-metadata Runtime features: Checksum: crc32c Number of devices: 1 Devices: ID SIZE PATH 1 297.96GiB /dev/disk/by-partlabel/rootfs
# mkdir /mnt/gentoo # mount /dev/disk/by-partlabel/rootfs /mnt/gentoo # btrfs subvolume create /mnt/gentoo/@ Create subvolume '/mnt/gentoo/@' # btrfs subvolume create /mnt/gentoo/@/home Create subvolume '/mnt/gentoo/@/home' # btrfs subvolume create /mnt/gentoo/@/root Create subvolume '/mnt/gentoo/@/root' # mkdir /mnt/gentoo/@/usr # btrfs subvolume create /mnt/gentoo/@/swap Create subvolume '/mnt/gentoo/@/swap' # btrfs subvolume create /mnt/gentoo/@/usr/local Create subvolume '/mnt/gentoo/@/usr/local' # btrfs subvolume create /mnt/gentoo/@/var Create subvolume '/mnt/gentoo/@/var' # umount /mnt/gentoo
# touch /mnt/gentoo/swap/swapfile # chmod 600 /mnt/gentoo/swap/swapfile
# chattr +C /mnt/gentoo/swap/swapfile
# fallocate /mnt/gentoo/swap/swapfile -l4g
# mkswap /mnt/gentoo/swap/swapfile
LABEL=EFI /boot/efi vfat defaults 0 0 LABEL=rootfs / btrfs subvol=/@ 0 0 LABEL=rootfs /home btrfs subvol=/@/home 0 0 LABEL=rootfs /root btrfs subvol=/@/root 0 0 LABEL=rootfs /swap btrfs subvol=/@/swap 0 0 LABEL=rootfs /usr/local btrfs subvol=/@/usr/local 0 0 LABEL=rootfs /var btrfs subvol=/@/var 0 0 /swap/swapfile none swap sw 0 0