Installing Gentoo: Difference between revisions

From BitFolk
Jump to navigation Jump to search
(initial version)
 
m (→‎Installation: links/formatting)
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Very lightly-edited copy-paste from an emailed guide that a customer supplied:
{{warning|This guide assumes that you’re already comfortable with Linux in general and Gentoo in particular.}}


OK, my guide to running gentoo on bitfolk.
==Installation==


It presumes you know a fair bit about linux in general. including using bash, fdisk, making a kernel, etc.
First thing is to boot in [[rescue]] mode from the [[Xen Shell]] and to create <code>/mnt/gentoo/</code>. Partition and then mount your virtual disk over this, then download your desired stage3 tarball into this location.


I've got a single core machine, 20GB disk, with 500MB RAM VMS. This will work fine on the smallest package of a 10GB disk too. I've done most of my install now, and sitting < 3GB.
Then, you can follow the [https://wiki.gentoo.org/wiki/Handbook:AMD64 official handbook] with those modifications:
 
<ul>
I'm also going for a 64 bit OS, feel free to change the various bits to make a 32 bit OS.
<li><code>/dev/sda</code> is <code>/dev/xvda</code></li>
 
<ul>
A lot of this is a summary of http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml, so if you've done Gentoo installs before, you need to know 4 things:
  <li>You do not require additional partitions unless your bootloader has no native way of reading your root filesystem (for example, full disk encryption)</li>
 
</ul>
<ol>
<li>The IP to configure on eth0 is ${prefix}::2/64 and the gateway is ${prefix}::1. For example, this is my configuration:
<li>Your disks are /dev/xvda (main disk) and /dev/xvdb (swap
<pre>config_eth0="85.119.83.7/21 2001:ba8:1f1:f0af::2/64"
disk)</li>
routes_eth0="default via 85.119.80.1
<li>You need to enable the following kernel modules (in addition to your normal stuff):
default via 2001:ba8:1f1:f0af::1"</pre>
<pre>
</li>
<li>For IPv4, pick the configuration from the live system</li>
<li>In <code>/etc/portage/make.conf</code>, it's recommended to set a <code>PORTAGE_NICENESS</code> setting so installing/updating things does not impact the running services</li>
<li>In <code>/etc/portage/repos.conf/gentoo.conf</code>, you can set the <code>sync-uri</code> to the [[Local software mirrors]]
<pre>sync-uri = rsync://mirror.bitfolk.com/gentoo-portage</pre></li>
<li>The binary [https://wiki.gentoo.org/wiki/Project:Distribution_Kernel distribution kernel] just works for Xen</li>
<li>However, should you wish to compile your own kernel - for the kernel configuration, you have to enable the Xen support. Those options worked for me:
<pre>rr2 ~ # grep -i xen /usr/src/linux-4.19.97-gentoo/.config
CONFIG_XEN=y
CONFIG_XEN=y
CONFIG_XEN_MAX_DOMAIN_MEMORY=500
CONFIG_XEN_PV=y
CONFIG_XEN_PV_SMP=y
CONFIG_XEN_512GB=y
CONFIG_XEN_SAVE_RESTORE=y
CONFIG_XEN_SAVE_RESTORE=y
# CONFIG_XEN_DEBUG_FS is not set
CONFIG_XEN_BLKDEV_FRONTEND=y
CONFIG_XEN_BLKDEV_FRONTEND=y
# CONFIG_XEN_SCSI_FRONTEND is not set
CONFIG_XEN_NETDEV_FRONTEND=y
CONFIG_XEN_NETDEV_FRONTEND=y
CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y
CONFIG_HVC_XEN=y
CONFIG_HVC_XEN=y
CONFIG_HVC_XEN_FRONTEND=y
CONFIG_HVC_XEN_FRONTEND=y
# CONFIG_XEN_WDT is not set
CONFIG_DRM_XEN=y
CONFIG_DRM_XEN_FRONTEND=m
CONFIG_XEN_FBDEV_FRONTEND=y
CONFIG_XEN_FBDEV_FRONTEND=y
# Xen driver support
CONFIG_XEN_BALLOON=y
CONFIG_XEN_BALLOON=y
CONFIG_XEN_BALLOON_MEMORY_HOTPLUG=y
CONFIG_XEN_SCRUB_PAGES_DEFAULT=y
CONFIG_XEN_SCRUB_PAGES=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XENFS=y
CONFIG_XENFS=y
Line 34: Line 49:
CONFIG_XEN_GNTDEV=m
CONFIG_XEN_GNTDEV=m
CONFIG_XEN_GRANT_DEV_ALLOC=m
CONFIG_XEN_GRANT_DEV_ALLOC=m
# CONFIG_XEN_GRANT_DMA_ALLOC is not set
CONFIG_SWIOTLB_XEN=y
# CONFIG_XEN_PVCALLS_FRONTEND is not set
CONFIG_XEN_PRIVCMD=y
CONFIG_XEN_PRIVCMD=y
CONFIG_XEN_HAVE_PVMMU=y
CONFIG_XEN_HAVE_PVMMU=y
</pre>
CONFIG_XEN_HAVE_VPMU=y</pre>
<p>It's possible you can trim this little lot down, but that's
</li>
working</p>
<li>In <code>/etc/inittab</code>, add <code>hvc0:2345:respawn:/sbin/agetty -L 9600 hvc0</code> for the Xen console and set it to run on startup:
<p>You can also trim away a lot of stuff from a standard kernel,
<pre>
like PCI, power management etc.</p></li>
# cd /etc/init.d/
<li>In /etc/rc.conf, set rc_sys="xenU"</li>
# ln -sv agetty agetty.hvc0
<li>Xen and grub didn't play well for me. Create some hda symlinks and then it's happy:
# rc-update add agetty.hvc0 default</pre></li>
<syntaxhighlight>
<li>In <code>/etc/securetty</code>, add <code>hvc0</code></li>
ln -s /dev/xvda /dev/hda
<li>In <code>/etc/default/grub</code>, set:
ln -s /dev/xvda1 /dev/hda1
<pre>GRUB_CMDLINE_LINUX="console=hvc0 xencons=tty"
ln -s /dev/xvda2 /dev/hda2
...
</syntaxhighlight></li>
GRUB_TERMINAL=console</pre></li>
</ol>
</ul>
 
Finally, YMMV. Don't blame me if this goes wrong!
 
==Pre install work==
# Copy the PASSWORDS file somewhere, so that you have it.
# Change the root password (we'll be binning the install soon, but in the interests of security whilst we work)
# Change your domain DNS to point to the right IP.
 
# Log into the console, look in your PASSWORDS file
# Run the [[rescue]] environment.
# You'll need the password for the user "user", which is displayed on screen.
# You can either work off the terminal you are in, or you can now ssh in.
 
==Layout==
'''YOU ARE ABOUT THE DELETE EVERYTHING ON YOUR BITFOLK DISKS. STOP UNLESS YOU WANT TO LOSE EVERYTHING!'''
 
<ol>
<li>Disks are located at /dev/xvda and /dev/xvdb (swap disk) (run fdisk -l to be sure)</li>
<li>fdisk /dev/xvda, and partition accordingly.
<p>I created a 50MB /boot partition (short on space) and the rest for /</p>
<p>For completness, I toggled the boot flag on the /boot partition.</p></li>
<li>Because I like things to be correct, I fdisk'd the swap disk to change the type to 82,
<p>"Linux swap / Solaris"</p></li>
<li>Filesystem types - I'm going with ext4. Change to suit.
<syntaxhighlight>
mkfs.ext4 -L boot /dev/xvda1
mkfs.ext4 -L root /dev/xvdb2
</syntaxhighlight></li>
<li>
<syntaxhighlight>
mkswap -L swap /dev/xvdb1
LABEL=swap, UUID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
</syntaxhighlight></li>
<li>A summary of commands to run, with comments on decisions I made. Best advice is to use the gentoo handbook, so that you can make informed decisions yourself, and also have up to date information! Current on 2013-11-07. This is provided just to give some insight.</li>
</ol>
 
<syntaxhighlight>
mkdir /mnt/gentoo
mount /dev/xvda2 /mnt/gentoo/                                             
mkdir /mnt/gentoo/boot
mount /dev/xvda1 /mnt/gentoo/boot
# Change the URL to match current version and arch
wget http://www.mirrorservice.org/sites/distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-20131031.tar.bz2
tar xvjpf stage3-*.tar.bz2
# Make the appropriate edits.
# Again for some seinsible defaults, I've got:
# CFLAGS="-march=native -O2 -pipe -fomit-frame-pointer"
# CXXFLAGS="${CFLAGS}"
# CHOST="x86_64-pc-linux-gnu"
# MAKEOPTS="-j2"
nano /mnt/gentoo/etc/portage/make.conf
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
mirrorselect -i -r -o >> /mnt/gentoo/etc/portage/make.conf
cp -L /etc/resolv.conf /mnt/gentoo/etc/
mount -t proc none /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
emerge-webrsync
emerge --sync
# Read the news. This stuff is useful, and should be read.
eselect news read
# Look at the profile list. I'm sticking with a "server" install, the default.
eselect profile list
# Make any changes to the USE variable. I chose to leave it as is for now.
nano -w /etc/portage/make.conf
# I'm in the UK. Change accordingly.
cp /usr/share/zoneinfo/Europe/London /etc/localtime
echo "Europe/London" > /etc/timezone
# I like gentoo-sources. You can go with vanilla-sources if you wish, there are others too.
emerge gentoo-sources
cd /usr/src/linux
# Configure your kernel. See my stuff at the top for essential enables, then the rest is up to you.
# Probably should look at http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml if you're new to Gentoo.
make menuconfig
make && make modules_install
cp arch/x86_64/boot/bzImage /boot/vmlinuz
# Edit your fstab. Mine is below:
nano -w /etc/fstab
#/dev/xvda1              /boot          ext4            noatime        1 2
#/dev/xvda2              /              ext4            noatime        1 1
#/dev/xvdb1              none            swap            sw              0 0
# Edit your hostname.
nano -w /etc/conf.d/hostname
# Edit your network settings. Mine is below (change your numbers! run ifconfig -a to get them):
nano -w /etc/conf.d/net
#config_eth0="XXX.XXX.XXX.XXX netmask XXX.XXX.XXX.XXX brd XXX.XXX.XXX"
#routes_eth0="default via XXX.XXX.XXX.XXX"
# Add hosts for your hostname.
nano -w /etc/hosts
# Change the root password
passwd
# Modify your RC to suite. Set rc_sys="xenU"
nano -w /etc/rc.conf
# Modify your keymap (for completeness, you'll never be at the actual keyboard)
nano -w /etc/conf.d/keymaps
# I didn't change the clock settings, but have a look
nano -w /etc/conf.d/hwclock
# If you only want a certain language, you can configure it in /etc/locale.gen.
nano -w /etc/locale.gen
locale-gen
# Setup your env language:
nano -w /etc/env.d/02locale
# Load the languages
env-update && source /etc/profile
 
# Optional choices here. I went with the gentoo choices of syslog-ng for syslog,
#      vixie-cron for cron and installing mlocate.
emerge syslog-ng
rc-update add syslog-ng default
emerge vixie-cron
rc-update add vixie-cron default
emerge mlocate
# Guess we want ssh on startup.....
rc-update add sshd default
 
# Bootloader. I tried grub2, but it wasn't happy. So I went with grub-legacy,
# and even that was tricky.
emerge sys-boot/grub:0
nano -w /boot/grub/grub.conf
# Here's mine. I'm not too worried about backup kernels, because we have the rescue environment.
#default 0
#timeout 0
#
#title Gentoo Linux
#root (hd0,0)
#kernel /boot/vmlinuz root=/dev/xvda2
# To get grub to play ball with Xen, you have to create a symlink from /dev/xvda > /dev/hda
ln -s /dev/xvda /dev/hda
ln -s /dev/xvda1 /dev/hda1
ln -s /dev/xvda2 /dev/hda2
grep -v rootfs /proc/mounts > /etc/mtab
 
grub --no-floppy
grub> root (hd0,0)    (Specify where your /boot partition resides)
grub> setup (hd0)    (Install GRUB in the MBR)
grub> quit            (Exit the GRUB shell)
 
# All done! Unmount and reboot, and cross fingers! Give it a minute to boot, and then you should
be able to ssh in!


exit
==Misc==
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -l /mnt/gentoo{/boot,/proc,}
reboot
# Don't panic if it doesn't work. You can start the rescue environment again,
# mount the disks, and work out what went wrong.


# GOOD LUCK!
If you have questions, I’m on the [https://panel.bitfolk.com/fun/ IRC channel] as alarig.


</syntaxhighlight>
I used https://www.mad-hacking.net/documentation/linux/deployment/xen/pv-guest-basics.xml to know what the Xen options are for.

Latest revision as of 02:57, 3 February 2021

Warning Warning: This guide assumes that you’re already comfortable with Linux in general and Gentoo in particular.

Installation

First thing is to boot in rescue mode from the Xen Shell and to create /mnt/gentoo/. Partition and then mount your virtual disk over this, then download your desired stage3 tarball into this location.

Then, you can follow the official handbook with those modifications:

  • /dev/sda is /dev/xvda
    • You do not require additional partitions unless your bootloader has no native way of reading your root filesystem (for example, full disk encryption)
  • The IP to configure on eth0 is ${prefix}::2/64 and the gateway is ${prefix}::1. For example, this is my configuration:
    config_eth0="85.119.83.7/21 2001:ba8:1f1:f0af::2/64"
    routes_eth0="default via 85.119.80.1
    default via 2001:ba8:1f1:f0af::1"
  • For IPv4, pick the configuration from the live system
  • In /etc/portage/make.conf, it's recommended to set a PORTAGE_NICENESS setting so installing/updating things does not impact the running services
  • In /etc/portage/repos.conf/gentoo.conf, you can set the sync-uri to the Local software mirrors
    sync-uri = rsync://mirror.bitfolk.com/gentoo-portage
  • The binary distribution kernel just works for Xen
  • However, should you wish to compile your own kernel - for the kernel configuration, you have to enable the Xen support. Those options worked for me:
    rr2 ~ # grep -i xen /usr/src/linux-4.19.97-gentoo/.config
    CONFIG_XEN=y
    CONFIG_XEN_PV=y
    CONFIG_XEN_PV_SMP=y
    CONFIG_XEN_512GB=y
    CONFIG_XEN_SAVE_RESTORE=y
    # CONFIG_XEN_DEBUG_FS is not set
    CONFIG_XEN_BLKDEV_FRONTEND=y
    # CONFIG_XEN_SCSI_FRONTEND is not set
    CONFIG_XEN_NETDEV_FRONTEND=y
    CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y
    CONFIG_HVC_XEN=y
    CONFIG_HVC_XEN_FRONTEND=y
    # CONFIG_XEN_WDT is not set
    CONFIG_DRM_XEN=y
    CONFIG_DRM_XEN_FRONTEND=m
    CONFIG_XEN_FBDEV_FRONTEND=y
    # Xen driver support
    CONFIG_XEN_BALLOON=y
    CONFIG_XEN_SCRUB_PAGES_DEFAULT=y
    CONFIG_XEN_DEV_EVTCHN=y
    CONFIG_XENFS=y
    CONFIG_XEN_COMPAT_XENFS=y
    CONFIG_XEN_SYS_HYPERVISOR=y
    CONFIG_XEN_XENBUS_FRONTEND=y
    CONFIG_XEN_GNTDEV=m
    CONFIG_XEN_GRANT_DEV_ALLOC=m
    # CONFIG_XEN_GRANT_DMA_ALLOC is not set
    CONFIG_SWIOTLB_XEN=y
    # CONFIG_XEN_PVCALLS_FRONTEND is not set
    CONFIG_XEN_PRIVCMD=y
    CONFIG_XEN_HAVE_PVMMU=y
    CONFIG_XEN_HAVE_VPMU=y
  • In /etc/inittab, add hvc0:2345:respawn:/sbin/agetty -L 9600 hvc0 for the Xen console and set it to run on startup:
    # cd /etc/init.d/
    # ln -sv agetty agetty.hvc0
    # rc-update add agetty.hvc0 default
  • In /etc/securetty, add hvc0
  • In /etc/default/grub, set:
    GRUB_CMDLINE_LINUX="console=hvc0 xencons=tty"
    ...
    GRUB_TERMINAL=console

Misc

If you have questions, I’m on the IRC channel as alarig.

I used https://www.mad-hacking.net/documentation/linux/deployment/xen/pv-guest-basics.xml to know what the Xen options are for.