Tag Archives: install

Gentoo Install with LVM/EFI via Ansible

Assumptions: You have a host with Ansible and a network.

Download the Gentoo iso from here.
Download the role from here.

You will need to edit:
gentoobase/vars/main.yml - encrypt password

Boot with the ISO (cached), ensuring that networking is present.

Once booted, set a password and start the ssh daemon.

Unmount the ISO.

SSH as the root user to the target server.
mkdir .ssh
Copy the pubkey of the user executing the playbook into /root/.ssh/authorized_keys

CD to your playbook role directory.
Unpack the role tarball
Create the playbook below.

Playbook

---
- name: Base Gentoo Installation
gather_subset: min
hosts: vms
tasks:
- import_role:
name: gentoobase
...
 ansible-playbook -u root gentoo_install_base.yml

This will take ~3 hours to complete the base system.

Timings are based on a VM (i7 6700K x4, 16Gb RAM)

If you wish to change any settings, edit:
roles/gentoobase/vars/main.yml

Now go outside and get some fresh air.

The below is to understand the build process.

Manual Steps

Partition the HDD:
gdisk /dev/Xda
part1 = 512M 8300 [boot]
part2 = 100M ef00 efi [efi]
part3 = LVM 8e00 [LVM]
part4 = 4G 8200 [swap]

Create LVMs:

pvcreate /dev/Xda2
vgcreate vg00 /dev/Xda2
lvcreate -L 20G -n root vg00
lvcreate -L 10G -n home vg00

Format FileSystems:

mke2fs -t ext4 -L BOOT /dev/Xda1
mkfs.vfat -F 32 -n EFI /dev/Xda2
mke2fs -t ext4 -L ROOT /dev/mapper/vg00-root
mke2fs -t ext4 -L HOME /dev/mapper/vg00-home

Mount FileSystems:

mount -t ext4 /dev/mapper/vg00-root /mnt/gentoo
mkdir -p /mnt/gentoo/boot/EFI
mount -t ext4 /dev/vda1 /mnt/gentoo/boot
mount -t vfat /dev/vda2 /mnt/gentoo/boot/EFI
mount swap if configured

SCP the stage3 and portage files to the VM

Download Tarballs:

wget https://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64-systemd/stage3-amd64-systemd-20240616T153408Z.tar.xz

wget https://gentoo.osuosl.org/snapshots/portage-latest.tar.xz

Unpack files:

tar xpf stage3...xz -C /mnt/gentoo
tar xpf portage-latest...xz -C /mnt/gentoo/usr/

Mount Some More FileSystems:

mount -t proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
mount --rbind /run /mnt/gentoo/run
mount --make-rslave /mnt/gentoo/run
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm

Setup Rsync Mirror:

mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

DNS:
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

Setup Portage:

mkdir /mnt/gentoo/var/db/repos/gentoo
mkdir /mnt/gentoo/etc/portage/repos.conf
nano -w /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
[DEFAULT]
main-repo = gentoo
[gentoo]
location = /usr/portage
sync-type = rsync
sync-uri = rsync://rsync.europe.gentoo.org/gentoo-portage

Chroot into the VM:

chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile

Set Locale:

ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
nano -w /etc/locale.gen
    en_GB.UTF-8 UTF-8
Execute locale-gen

Set Profile:

eselect profile list (choose the number in brackets)
"[30]  default/linux/amd64/23.0/no-multilib/systemd (stable)"
eselect profile set 30

Let's Start Building:

emerge -av gentoo-sources
ln -s /usr/src/linux-<version>-gentoo /usr/src/linux
cd /usr/src/linux
make defconfig && make && make modules_install
cp arch/x86_64/boot/bzImage /boot/kernel-<version>
cp .config /boot/config-<version>-gentoo (optional)
cpan Locale::gettext
emerge -q vim genkernel grub lvm2 gptfdisk efibootmgr

Setup Grub:

grub-install --target=x86_64-efi --efi-directory=/boot/EFI /dev/Xda
vi /etc/default/grub
    GRUB_CMDLINE_LINUX="rootfstype=ext4 init=/usr/lib/systemd/systemd dolvm"

Update fstab:

blkid
Copy the UUID for /boot and /
UUID1=$(blkid | grep Xda1 | grep -Po "(UUID.*?)\"\s")
UUID2=$(blkid | grep Xda2 | grep -Po "(UUID.*?)\"\s")
echo -e "${UUID1}\t/boot\text4\tdefaults\t1 2" >> /etc/fstab
echo -e "${UUID2}\t/\text4\tdefaults\t1 1" >> /etc/fstab
cd /etc/
cp -p genkernel.conf genkernel.conf.orig
vi genkernel.conf

uncomment:
MAKEOPTS="$(portageq envvar MAKEOPTS)"
LVM="yes"

genkernel initramfs --lvm (this does not overwrite the kernel above)
grub-mkconfig -o /boot/grub/grub.cfg

passwd

emerge -q networkmanager gentoolkit gpm
systemctl enable sshd NetworkManager

Create Bootable Windows Installation USB

So, a situation may arise where you are required to install Windows where the only media you have is a USB drive. Now if you're already running Windows, you can do this with the media creation tool.
You can download a Windows 10 image direct from M$ here.

Obviously, we're running Linux ;) So download the ISO image and let's get cracking ;)

USB Prepare

You will need a drive >4Gb (I used a 2Gb :\)

Insert your USB and execute (where 'X' is the drive eg /dev/sda):

fdisk /dev/sdX

I'm assuming there are no partitions defined. So we'll start from scratch.

# fdisk /dev/sdj

Welcome to fdisk (util-linux 2.30.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdj: 1.9 GiB, 2058354688 bytes, 4020224 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0003dd8d
-------------------------------------------------------------------------------
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4020223, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-4020223, default 4020223): 

Created a new partition 1 of type 'Linux' and of size 1.9 GiB.
-------------------------------------------------------------------------------
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 7
Changed type of partition 'Linux' to 'HPFS/NTFS/exFAT'.
-------------------------------------------------------------------------------
Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.
-------------------------------------------------------------------------------
Command (m for help): p
Disk /dev/sdj: 1.9 GiB, 2058354688 bytes, 4020224 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0003dd8d

Device     Boot Start     End Sectors  Size Id Type
/dev/sdj1  *     2048 4020223 4018176  1.9G  7 HPFS/NTFS/exFAT
-------------------------------------------------------------------------------
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Make sure you have sys-fs/ntfs3g installed.

Execute

mkntfs -Q /dev/sdj1
# mkntfs -Q /dev/sdj1
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
Install boot sector

Make sure you have ms-sys installed.

Execute ms-sys -n /dev/sdj1

# ms-sys -n /dev/sdj1
NTFS Windows 7 boot record successfully written to /dev/sdj1

Now for the installation files.

Mount the downloaded ISO and the USB drive.

mount -o loop /$HOME/Downloads/Win10_1709_English_x64.iso /mnt/THIS
mount /dev/sdj1 /mnt/THIS

Now copy the files.

cp -Rv /mnt/THIS/* /run/media///

And that's it. Unmount the ISO/USB and go install.

RAID1 setup

I decided it was about time I actually setup some redundancy for my data.  Having never done a full backup and only storing the odd chunk of data somewhere on a dvd.  Losing the HDD would be a severe PITA!  I purchased a Startech PEXSAT32 and popped it in.  As my current HDD is SATA and is running under AHCI, the card was picked up out of the box.

Before connecting any drives I ran a quick speed check (3 times) with the onboard SATA controller and got the following results.

# hdparm -tT /dev/sda
/dev/sda:
 Timing cached reads:   10954 MB in  2.00 seconds = 5479.70 MB/sec
 Timing buffered disk reads: 264 MB in  3.01 seconds =  87.64 MB/sec

# hdparm -tT /dev/sda
/dev/sda:
Timing cached reads: 11060 MB in 2.00 seconds = 5533.11 MB/sec
Timing buffered disk reads: 264 MB in 3.01 seconds = 87.71 MB/sec

# hdparm -tT /dev/sda
/dev/sda:
Timing cached reads: 10698 MB in 2.00 seconds = 5351.98 MB/sec
Timing buffered disk reads: 262 MB in 3.02 seconds = 86.71 MB/sec

Fairly poor for a SATAII controller and a SATAII drive!!!

Time to connect the drives...

At the risk of not losing any data and the fact that I just didn't have anything big enough to backup to, I just bought 2 x WD 1TB Eco.  The current drive is SATAII one of these :)

Due to the way the RAID is setup, both drives will be erased upon setup.  This rules out cloning the original drive and building the array. The way I had to do this was to setup the RAID1 and then clone the original drive...FAIL!  The original drive was a few blocks larger than the RAID drives :(
The work around was to mirror the partitions of the original.  This doesn't have to be an exact science, but does have to accommodate the data to be copied.  Once the partitions have been setup (done via a Gentoo minimal CD and fdisk) it was time to start migrating data.

I created 2 directories:
/mnt/master
/mnt/raid

/boot /dev/sda1    100M
swap /dev/sda2    2Gb
/ /dev/sda3    5Gb
/dev/sda4    Extended partition
/var /dev/sda5    10Gb
/usr /dev/sda6    20Gb
/tmp /dev/sda7    10Gb
/root /dev/sda8    1Gb
/home /dev/sda9    870Gb

/dev/sda being the original drive, I mounted the in the following order.

mount /dev/sda3 /mnt/master
mount /dev/sda1 /mnt/master/boot
mount /dev/sda5 /mnt/master/var
mount /dev/sda6 /mnt/master/usr
mount /dev/sda7 /mnt/master/tmp
mount /dev/sda8 /mnt/master/root
mount /dev/sda9 /mnt/master/home

I did the same with the raid drive (/dev/sdb) as above but mounted to /mnt/raid.

I then executed the following to copy the data:

cd /mnt/master
tar cf - . | (cd /mnt/raid; tar xfp -)

This took quite a few hours due to the sheer amount of data.  Although the tar command would be a little slower than say dd.  It does allow me to copy *ALL* files from each partition, including hidden files/folders.

Once that completed, I powered off the machine and removed the original drive.  Powered back up and booted into the Gentoo CD again.  I repeated the procedure and mounted the partitions (except sda1 or /boot).
Next we need to chroot into the drive's installed OS.  cd into /mnt/(where you mounted the / partition).
chroot /mnt/(where you mounted the / partition) /bin/bash
env-update
source /etc/profile

This has now put us into the OS installed on the drive.  As we have only copied the OS files, we need to install grub onto the MBR.  If you ignored me and mounted /dev/sda1 then you will fail and grub will complain!!
type "grub" to enter the grub command line interface.
type "root (hd0,0)"  This will return the format of the file system ie 0x83
type "setup (hd0)"  This will return several lines of "stage" files if successful.

That's it.. job done.  Exit the chroot by typing "exit" and "reboot".

Now... the pros and cons for me for this setup is although I now have the redundancy should a drive die, there is *NO* performance boost at all.  Infact, upgrading to SATAIII only gained me approx 10Mb/s increase.

# hdparm -tT /dev/sda

/dev/sda:
Timing cached reads:   11322 MB in  2.00 seconds = 5664.09 MB/sec
Timing buffered disk reads: 286 MB in  3.00 seconds =  95.26 MB/sec

# hdparm -tT /dev/sda

/dev/sda:
Timing cached reads:   10200 MB in  2.00 seconds = 5102.15 MB/sec
Timing buffered disk reads: 272 MB in  3.00 seconds =  90.56 MB/sec

# hdparm -tT /dev/sda

/dev/sda:
Timing cached reads:   10500 MB in  2.00 seconds = 5252.27 MB/sec
Timing buffered disk reads: 276 MB in  3.02 seconds =  91.33 MB/sec

I found the below info on a forum regarding slow performance, but I also read elsewhere that SATAIII is a complete waste of time with mechanical drives.

fdisk -H 224 -S 56 /dev/sdb

running fdisk with these parameters ensures that every partition you create is aligned to 4KiB boundaries.  I have not run the above command, this is something for me to test when I have time.

Jack-3.1.1

Jack (not to be confused with the jackd audio daemon) is a cdripper for Linux written in python.  You can download via your package manager or from the homesite.  I have found on Gentoo and Fedora that jack depends on python-2.4 which is a pain when just about everything else builds against python-2.5 or higher which causes problems.  I was forever getting:

$ jack
Traceback (most recent call last):
 File "/usr/bin/jack", line 42, in <module>
 import jack_argv
 File "/usr/lib/python2.6/site-packages/jack_argv.py", line 22, in <module>
 import jack_utils
 File "/usr/lib/python2.6/site-packages/jack_utils.py", line 26, in <module>
 import jack_functions
 File "/usr/lib/python2.6/site-packages/jack_functions.py", line 222
 def starts_with(str, with):
                         ^
SyntaxError: invalid syntax

I had my fill of fixing this every time I needed to rip a cd, so I fixed it.  All you need to do after it has been installed is run this script jack python-2.6 patch

If you look at the script, you'll see that it just changes any definitions from starts_with to startswith.
Another common problem is a gcc memory leak.  To fix this add MALLOC_CHECK_=1 at the start of your command.  I have added this as an alias in my .bash_profile eg.

alias jackflac='MALLOC_CHECK_=1 jack --device=/dev/sr0 --append-year=yes --dir-template "%a/%l" -C -Q -R --rename-fmt "%n - %a - %l - %t" --workdir /home/cdstealer/Desktop/ -E flac'

alias jackmp3='MALLOC_CHECK_=1 jack --device=/dev/sr0 --append-year=yes --dir-template "%a/%l" -C -Q -R --rename-fmt "%n - %a - %l - %t" --workdir /home/cdstealer/Desktop/ -E lame --vbr=no -b 320 -e 2 --write-id3v2=yes'

Please make sure that jack and its dependencies have been built against python-2.6+.

dev-python/id3-py
dev-python/cddb-py
dev-python/pyogg
media-libs/id3lib
dev-python/pyid3lib
dev-python/pyvorbis
media-sound/jack

I edited the files below to add high quality and forced stereo.  Just add "-q0 -ms" to the end of the 4 line in each file.  eg:

'cmd': "lame --preset cbr %r --strictly-enforce-ISO %i %o -q0 -ms",
'vbr-cmd': "lame -V %q --vbr-new --nohist --strictly-enforce-ISO %i %o -q0 -ms",
'otf-cmd': "lame --preset cbr %r --strictly-enforce-ISO - %o -q0 -ms",
'vbr-otf-cmd': "lame -V %q --vbr-new --nohist --strictly-enforce-ISO - %o -q0 -ms",

/usr/lib/python2.6/site-packages/jack_helpers.py
/usr/lib/python2.6/site-packages/jack_main_loop.py
/usr/lib/python2.6/site-packages/jack_plugin_lame.py

MythTV Installation

I have create this guide based on my experience of Installing and configuring MythTV.  If you're looking for a PVR project, then MythTV is perfect.
This is for a dedicated box so no desktop environment will be installed.

I have compiled this on the assumption that you are competent in Linux so it won't be much use as a beginners guide, though I may turn it into one if I get time.
Obviously this guide is specific to my hardware so please make changes where needed for your setup.

The Hardware:
Samsung Dual Layer SATA DVD-RW
Western Digital 1Tb HDD [System & Storage]
Asus P7H55M PRO Mainboard
4Gb Corsair XMS3 1333Mhz DDR3
Intel 3.2Ghz i5 650 CPU
MCE Remote v2 (Phillips
Leadtek DTV1000 DVB-T PCI x2


Once you have you base Linux system up and running it's time to start installing applications.  The version currently being used at the time of writing this is:

media-tv/mythtv-0.22_p22860
media-plugins/mythgallery-0.22_p22763
media-plugins/mythgame-0.22_p22763
media-plugins/mythvideo-0.22_p22864-r1
media-plugins/mytharchive-0.22_p22763
x11-themes/mythtv-themes-0.22_p22869
media-plugins/mythmusic-0.22_p22763
x11-themes/mythtv-themes-extra-0.22_p22492
www-apps/mythweb-0.22_p22763-r1


So we now have a base Gentoo install and Mythtv.  If you have used the "autostart" flag then follow the steps below:

(you may need to use ALT+F1 to get a terminal) Assuming you have installed mysql and have not yet setup the root account for mysql.. execute:

  • mysqladmin -uroot -p
  • Edit /etc/inittab and add c8:2345:respawn:/sbin/mingetty --autologin mythtv tty8 underneath the #TERMINALS section.
  • Edit /usr/share/mythtv/database/mc.sql and change the username and password entries.
  • Run mysql -uroot -p < /usr/share/mythtv/database/mc.sql to create the Mythtv database with the details used in previous step.
  • Log into mysql as root and run GRANT ALL PRIVILEGES ON `mythconverg`.* TO 'mythtv'@'localhost'; this just gives permissions to the mythtv user for the Mythtv database.
  • Run rc-update add mythbackend default to have Mythtv's brains startup on reboot.
  • Edit /home/mythtv/.xinitrc

# .xinitrc
#[ -x /usr/bin/nvidia-settings ] && /usr/bin/nvidia-settings -l
/usr/bin/killall -9 mythfrontend evilwm
sleep 1
/usr/bin/xset s noblank
/usr/bin/xset s off
/usr/bin/xset -dpms
/uar/bin/xsetroot -cursor_name dot
/usr/bin/evilwm &
exec /usr/bin/mythfrontend -l /var/log/mythtv/mythfrontend.log -v important,general
#exec /usr/bin/mythtv-setup

*TIP* If you need to enter mythtv-setup for whatever reason, comment out exec /usr/bin/mythfrontend -l /var/log/mythtv/mythfrontend.log -v important,general and add exec /usr/bin/mythtv-setup to  your .xinitrc.  Then exit the frontend.  Don't forget to change back when finished.

You can reboot now


If things are working as they should, you will now have a language selection screen.
Hit ALT+F1 and login as root and stop the mythbackend daemon. /etc/init.d/mythbackend stop
SU to mythtv. su - mythtv Execute DISPLAY=":0.0" mythtv-setup and hit ALT-F7.

Now to tell Mythtv where it's brains are.  Most of the screens can be left as the default settings.
If you are only have 1 box leave the IP's as 127.0.0.1, if you are planning remote frontends then change to the IP of the backend (ie this box).

Change this screen to your TV settings.

Click Next

Click Next

Click Next

Click Next

Change the CPU to HIGH and uncheck Allow Advert Detection Jobs.

Click Next

Click Finish


Capture Cards

Highlight (new capture card) and hit enter.

Change the card type for your tuner.

Select Recording options.
If you only have one card, leave the max recordings as 1.
Tick Wait for SEQ start header
Tick Open DVB card on demand
Tick Use DVB card for active EIT scan


Video Sources

Highlight (new video source) and press enter

Enter a name in the Video source name box
Change the Listings Grabber to EIT


Input Connections

Here you should see the card(s) you have just setup in the previous step.
Select your card and press enter.

Change the Video Source (there should only be the one)
Use Quick Tuning should be fine as the default Live TV Only
Click Scan for Channels (you may need to change the country)

Change the Input group 1 to DVB0 if setting up the first card.


Channel Editor (optional)

Click Icon Download


Storage Directories

Highlight default and press enter
Highlight Add New Directory and press enter
Enter the full path to where you want TV streams to be saved.

Exit mythtv-setup by pressing ESC (you may see the language screen again.. do not select anything!
Hit ALT+F1 and reboot.. you should now boot straight into Mythtv.


Mythvideo

Highlight Setup and press enter.
Highlight Video Settings and press enter.
Highlight General Settings and press enter.
Enter the full path to where you want mythtv to find other videos etc that mythtv did not record.
DVD's ripped by Mythtv will be put here.






PLAYER SETTINGS:
The defaults should be ok.

FILE TYPES:
Here you can add files types of videos that are not enabled by default.

RIP SETTINGS:


MythGallery




MythGame







MythArchive







MythWeb

You need apache2 and php5 installed and setup for mythweb to function.  Apache instructions

cp /usr/share/webapps/mythweb/<version>/htdocs/mythweb.conf.apache /etc/apache2/modules.d/mythweb.conf

edit /etc/apache2/modules.d/mythweb.conf and change the directory path to eg /var/www/localhost/htdocs/mythweb

Change the setenv entries to reflect the mythtv mysql account. run

htpasswd2 -c /path/to/your/.htpasswd <username> This will prompt for a username and password.

^ this should be outside the root of mythweb. The -c option creates a new file. If you are adding a second user or more, omit the -c to apend the file.

Restart apache /etc/init.d/apache2 restart

Advanced:  Setup SSL Add the following lines to .htaccess in the root of mythweb to encrypt user details.

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "<domain>"
ErrorDocument 403 https://domain/path/to/403.html
AuthType Basic
AuthUserFile /path/to/your/.htpasswd
AuthName "Please enter your username and password."
require valid-user

You will also need to create SSL keys and tell apache about them.  You will be forced to provide a password.  This will cause apache not to start if not attended.
openssl genrsa -des3 -out server.key 1024

To remove the password:
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

To create the certificate request:
openssl req -new -key server.key -out server.csr

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Now change the perms so only root can read them.

chmod 400 server*

Copy the generated key and crt files to somewhere that apache can read eg /etc/apache2/ssl/. Enter the following into your vhosts:
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown

Restart apache

Trouble Shooting:
I've come across the occasional update where upon restarting mythbackend, the system load would max out for no reason. I found to resolve this I needed to run mythtv-setup and delete the dvb cards, readd them and rescan the channels. Upon restarting mythbackend, load would remain normal.

Gentoo Install

You can download a minimal install iso from here
It is assumed that you have some knowledge of Linux and how hardware is detected.

'#' = Direct command
Tips:* Once booted into the cd, press CTRL, ALT & F2 and enter

# lspci

This lists your hardware, you may need to refer to this later.*

Research... Gentoo has a fantastic user community and documentation.  If you're using the USB install the root is auto mounted under /mnt/cdrom.

Hard drive setup:-
# fdisk /dev/sda

A typical filesystem layout I use is this on an 80Gb drive.

Set partition 1 to +100M (boot)
Set partition 2 to +40G (root)
Set partition 3 to +30G (home)
Set partition 4 to the remainder (swap)

Press "t", select partition 4 then enter code 82.
Press "a", select partition 1 then "w" to write changes.

# mke2fs -L BOOTFS -t ext4 /dev/sda1
# mke2fs -L ROOTFS -t ext4 /dev/sda2
# mke2fs -L HOMEFS -t ext4 /dev/sda3
# mkswap -L SWAPFS /dev/sda4
# swapon /dev/sda4
# mount -t ext4 /dev/sda2 /mnt/gentoo
# mkdir /mnt/gentoo/boot
# mount /dev/sda1 /mnt/gentoo/boot
# cd /mnt/gentoo
Stage & Portage installation:-
# links http://www.gentoo.org/main/en/mirrors.xml
(move the highlight bar to the desired URL and hit enter.)
Move to releases and hit enter.
Select the correct arch (amd64.)
Select releases
Select your arch and hit enter. (amd64)
Select autobuilds hit enter
Select current-stage3-amd64-systemd
Select the stage file. (stage3-amd64-systemd-YYYYMMDD.tar.bz2)
select ok to save.
Go up 4 levels
Select snapshots
Select the most recent file. (portage-YYYYMMDD.tar.bz2)
# tar -xjpf stageXXX
# tar -xjf portage-XXX -C /mnt/gentoo/usr
#nano -w /mnt/gentoo/etc/portage/make.conf
press CTRL+X to exit, Y to accept changes and ENTER to save.
If you wish to define the CPU arch, please refer to this.
Also, please refer to the global useflags that maybe required depending on your end game.
# mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
# mount -t proc none /mnt/gentoo/proc
# mount --types proc /proc /mnt/gentoo/proc
# mount --rbind /sys /mnt/gentoo/sys
# mount --make-rslave /mnt/gentoo/sys
# mount --rbind /dev /mnt/gentoo/dev
# mount --make-rslave /mnt/gentoo/dev
# cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
!!!!NOTE:  Do not be tempted to add customisation at this stage.  It is better to get the base system built, bootable and stable.
Portage rsync configs are now located in /etc/portage/repos.conf/gentoo.conf

Create the directory:

# mkdir /etc/portage/repos.conf

Then create gentoo.conf with the content below.

[DEFAULT]
main-repo = gentoo
[gentoo]
location = /usr/portage
sync-type = rsync
sync-uri = rsync://rsync.europe.gentoo.org/gentoo-portage
Entering the Gentoo Environment:-
# chroot /mnt/gentoo /bin/bash
# env-update
# source /etc/profile
Install the Kernel:-
# emerge -av gentoo-sources
# cd /usr/src/linux

# make menuconfig
(configure the kernel for your system)

# make && make modules_install

# cp arch/x86_64/boot/bzimage /boot/kernel-?.?.?-gentoo-r?

# cp .config /boot/config-?.?.?-gentoo-r?

Note:  If unmasking a kernel, ensure you also unmask the linux-headers of the same version.
Setup root user password:-
# passwd
Setup Localtime:-
# ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
Setup FSTAB:-
# nano -w /etc/fstab

LABEL=BOOTFS    /boot   ext4    noauto,noatime    1 2
LABEL=SWAPFS    none    swap    sw                0 0
LABEL=ROOTFS    /       ext4    noatime           0 1
LABEL=HOMEFS    /home   ext4    noatime           0 1
Setup Grub (boot loader):-
# emerge grub
# grub-install /dev/sda
# grub-mkconfig -o /boot/grub/grub.cfg

!!! NOTE !!!
If grub fails to compile with the error "illegal instruction", as this is the first item you are compiling.  There is a good chance that the stage3 tarball is at fault.  Try using an older archive.It's also worth noting that if you are using systemd instead of initrc you should amend the following line in /etc/default/grub to save any headaches when adding a different kernel. Append parameters to the linux kernel command line for non-recovery entries:

GRUB_CMDLINE_LINUX_DEFAULT="rootfstype=ext4 init=/usr/lib/systemd/systemd"
 install systemd & networkmanager

* you may need to unmerge udev & libudev

# cd
# umount /mnt/gentoo/boot /mnt/gentoo/proc /mnt/gentoo
# reboot
REBOOT!

Login and enable NetworkManager.

systemctl enable NetworkManager

Now we have a bootable system, we can squeeze a little more speed from compiling.
Also, I highly recommend this if you're using an SSD.
Portage TMPFS

Setup hostname:-
# hostnamectl set-hostname <hostname>
Setup keyboard locale:-
# localectl set-keymap uk
Network Time:-
# systemctl enable systemd-timesyncd

Time servers are defined in /etc/systemd/timesyncd.conf.

Setup system log:-
# emerge syslog-ng logrotate
# systemctl enable syslog-ng@default
 YOU NOW HAVE GENTOO INSTALLED BUT NO GUI OR APPZ...
Now REBOOT
Select system profile
Then execute:
# eselect profile list
Available profile symlink targets:
[1] default/linux/amd64/13.0
[2] default/linux/amd64/13.0/selinux
[3] default/linux/amd64/13.0/desktop
[4] default/linux/amd64/13.0/desktop/gnome
[5] default/linux/amd64/13.0/desktop/gnome/systemd
[6] default/linux/amd64/13.0/desktop/kde
[7] default/linux/amd64/13.0/desktop/kde/systemd
[8] default/linux/amd64/13.0/desktop/plasma
[9] default/linux/amd64/13.0/desktop/plasma/systemd
[10] default/linux/amd64/13.0/developer
[11] default/linux/amd64/13.0/no-multilib
[12] default/linux/amd64/13.0/systemd *
[13] default/linux/amd64/13.0/x32
[14] hardened/linux/amd64
[15] hardened/linux/amd64/selinux
[16] hardened/linux/amd64/no-multilib
[17] hardened/linux/amd64/no-multilib/selinux
[18] hardened/linux/amd64/x32
[19] hardened/linux/musl/amd64
[20] hardened/linux/musl/amd64/x32
[21] default/linux/uclibc/amd64
[22] hardened/linux/uclibc/amd64
Then execute:
# eselect profile set 11
executing:
# emerge -uvnD world will install/rebuild the the required packages for that profile. This may take a few hours.
OK.  If everything went to plan you should now have a basic Gentoo installation.  Now for the hard bit :D

These are only my recommendations:-

create /etc/locale.gen and add "en_GB.UTF8 UTF-8"

# emerge ufed

Set any required global use flags via ufed.  Some useful ones are:

X bluetooth branding cacert cairo consolekit corefonts cups dbus egl evdev flac gd gif gles2 gnome gnome-keyring gnutls gpm gtk icu jpeg jpeg2k ibnotify mmx mp3 mpi nautilus networkmanager offensive office ogg opengl png policykit pulseaudio python qt4 smp sse sse2 sse4 sse4_1 ssse3 svg syslog systemd tiff truetype udev disks usb uxa vhosts vim-syntax vorbis xkb -bindist -ipv6 -widevine

If you don't want to set any global flags, you can opt to set these on a per package basis (recommended).

If you do define/remove any global flags, ensure you run an "emerge -puvND world" and rebuild any packages.

Example only:

/etc/portage/package.use/qtwebkit
dev-qt/qtwebkit printsupport

/etc/portage/package.use/iputils
net-misc/iputils -caps -filecaps

/etc/portage/package.use/libpng
media-libs/libpng apng

/etc/portage/package.use/python
dev-lang/python sqlite

/etc/portage/package.use/ffmpeg
media-video/ffmpeg opus vpx aac aacplus bluray cdio faac fdk x264 xvid
virtual/ffmpeg threads -vdpau x264

/etc/portage/package.use/libpcre
dev-libs/libpcre pcre16

/etc/portage/package.use/qtkeychain
dev-libs/qtkeychain qt5

/etc/portage/package.use/zlib
sys-libs/zlib minizip

/etc/portage/package.use/cogl
media-libs/cogl gles2

/etc/portage/package.use/mesa
media-libs/mesa gles2

# emerge -evD system (optional but recommended)
[this will rebuild the install for your architecture. It may take a while]

#emerge gentoolkit
[this will install some handy tools. One is below]

# revdep-rebuild
[this will reinstall any dependencies. Add a "-p" to see what will be done]

Now it's time to get a GUI installed.

Install GDM & Gnome
Install your Desktop Environment.

# emerge av gdm gnome-light

Once complete enable gdm to autostart
# systemctl enable gdm

Caveats and Cleanups
Gnome-terminal may not start

# locale-gen

And then:

# localectl set-locale LANG="en_GB.UTF-8"

And reboot.

Gnome-shell screen cast may not work.

You may get the error:

gnome-session[736]: ** (gnome-shell:805): WARNING **: ShellRecorder: failed to parse pipeline: no element "vp9enc"
gnome-session[736]: ** (gnome-shell:805): CRITICAL **: shell_recorder_close: assertion 'recorder->state != RECORDER_STATE_CLOSED' failed

To fix this, ensure that gst-plugins-good, libvpx & ffmpeg are installed.

There you have it.  A full Gentoo Linux install with a Gnome3 desktop.

Time to spend a few more hours emerging your apps: ;)

A few useful apps are:

extundelete 
app-misc/screen 
libreoffice (take >1 hour)
google-chrome
firefox
app-admin/keepassx 
eog 
gimp 
vim 
corefonts
linux-firmware
dosfstools
chrome-binary-plugins
gnome-tweak-tool