Install Gentoo on Laptop with rsync

Original link: http://weepingdogel.github.io/posts/%E5%88%A9%E7%94%A8rsync%E7%BB%99%E7%AC%94%E8%AE%B0%E6%9C% AC%E5%AE%89%E8%A3%85gentoo/

wallhaven-955vx1.jpg

sequence

I haven’t seen you for half a year, I miss you

I have an underwhelming ChromeBook

2GB of RAM and an old dual-core low-voltage U with only 2.6 GHz are not enough for current popular distributions. Currently running Mint is also 100% of the CPU’s regular occupancy.

So I wondered if I could put a Gentoo on him.

However, this turtle U is estimated to have to be turned on for a week before it can be compiled…

Hmm, but I want to see if I can compile Gentoo on the desktop and transfer it to the ChromeBook via rsync.

On the compilation, I feel that even in E3 2022, the Church will not let me down.

At least much faster than this little Celeron.

Preparation

Don’t talk nonsense and start directly.

But we have to prepare these things

  • Gentoo Wiki
    • Official guidelines and documentation are required during the installation process
  • Translation tools
    • Due to the small user group of Gentoo, the localization of documents may not be very comprehensive, so you can use translation tools to recommend deepl here
  • a USB stick
    • Used to install a temporary Linux as the rsync receiver for the notebook.
    • This one has nothing to say, it’s better to support USB 3.0
  • Download the stage package officially provided by Gentoo
    • This will be written down below the process
  • A working Linux terminal

Download the stage tarball

Since our installation method is special, we can skip directly to this step of the official wiki

According to the documentation given by the official wiki, we do the following:

First enable root

 1
 weepingdogel $ sudo -i

Next, you can mount a partition to mnt , or you can directly create a folder. I have enough space here, so I can directly operate it without loading.

As for how to mount, you can refer to the Arch Wiki.

 1
 root # cd /mnt/gentoo

Then we need to download the stage package with wget to open this page here we choose stage3

Because I am lazy and like to use systemd, I can choose according to my needs.

Note right-click stage3 systemd copy link

Paste the link on the terminal

 1
 root # wget https://bouncer.gentoo.org/fetch/root/all/releases/amd64/autobuilds/20220605T170549Z/stage3-amd64-systemd-20220605T170549Z.tar.xz

Waiting to download.

After the download is complete, you can check the file. You can refer to this official entry .

Under normal circumstances, my side will not be damaged, so I will not write it here. Next, we will go directly to the step of decompressing the stage file.

Unzip the stage archive

We use tar to decompress this is the command given by the official wiki

 1
 root #tar xpvf stage3-*.tar.bz2 --xattrs-include='*.*' --numeric-owner

Some readers may not understand that the string in the middle is actually a wildcard, but this wildcard may not be the same as the file you downloaded, so we will change the middle section to an accurate file name.

This step is as simple as pressing the Tab key.

 1
 root # tar xpvf stage3-amd64-systemd-20220102T170545Z.tar.xz --xattrs-include='*.*' --numeric-owner

Just wait for a while to decompress unless you use an IDE hard drive .

Configure compile options

This step is officially explained as follows

To optimize Gentoo you can set some variables that affect Portage. Gentoo officially supports the package manager. All these variables can be set as environment variables using export but this is not permanent. To preserve settings Portage reads /etc/portage/make.conf a configuration file for Portage.

Notes

A commented list of all possible variables can be found in /mnt/gentoo/usr/share/portage/config/make.conf.example. To successfully install Gentoo you just need to set the variables mentioned below.

Start the editor In this guide we use nano to change the optimization variables we will discuss below.

 1
 root #nano -w /mnt/gentoo/etc/portage/make.conf

It is obvious from the make.conf.example file that the structure of the file. Comment lines start with “#” and other lines use the VARIABLE=”content syntax to define variables. Next, select a few of them for discussion.

Here we use vim to write

 1
 root # vim /mnt/gentoo/etc/portage/make.conf

Add COMMON_FLAGS= to the -march=silvermont option so that the compiler can optimize the garbage CPU of the silvermont architecture.

The complete file is as follows

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 # These settings were set by the catalyst build script that automatically # built this stage. # Please consult /usr/share/portage/config/make.conf.example for a more # detailed example. COMMON_FLAGS="-march=silvermont -O2 -pipe" CFLAGS="${COMMON_FLAGS}" CXXFLAGS="${COMMON_FLAGS}" FCFLAGS="${COMMON_FLAGS}" FFLAGS="${COMMON_FLAGS}" # NOTE: This stage was built with the bindist Use flag enabled PORTDIR="/var/db/repos/gentoo" DISTDIR="/var/cache/distfiles" PKGDIR="/var/cache/binpkgs" # This sets the language of build output to English. # Please keep this setting intact when reporting bugs. LC_MESSAGES=C

Install Gentoo base system

The operation of the first stage has been completed above, and the basic system can be installed, hehe.

The next thing to do is to select the mirror source. We can refer to the help document given by ustc mirror

Just follow the help given by ustc to set these two source addresses.

Then copy the DNS information

 1
 root # cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

Mount the necessary filesystems

Pay attention here. I have to type several commands here.

Why

official explanation

After a few moments the root directory of Linux will change to the new location. To make sure the new environment works properly requires making sure that some filesystems are available.

The file system that needs to be provided is

  • /proc/ A pseudo file system looks like a regular file but is actually generated in real time and exposed by the Linux kernel with some environmental information
  • /sys/ A pseudo filesystem like /proc/ to be replaced is more structured than /proc/
  • /dev/ is a regular filesystem part containing all device files managed by the Linux device manager usually udev

The /proc/ location will be mounted to /mnt/gentoo/proc/ while the other two are bind mounts. Literally for example /mnt/gentoo/sys/ is in fact /sys/ which is just the second entry point of the same filesystem and /mnt/gentoo/proc/ is a new mount of the filesystem so to speak. load.

So execute the following commands in order to mount

 1 2 3 4 5
 root # mount --types proc /proc /mnt/gentoo/proc root # mount --rbind /sys /mnt/gentoo/sys root # mount --make-rslave /mnt/gentoo/sys root # mount --rbind /dev /mnt/gentoo/dev root # mount --make-rslave /mnt/gentoo/dev

But it’s not over

Therefore, we will add these three

 1 2 3
 root # test -L /dev/shm && rm /dev/shm && mkdir /dev/shm root # mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm root # chmod 1777 /dev/shm

Chroot : enter a new environment

Once everything is mounted, you can chroot in

 1
 root # chroot /mnt/gentoo /bin/bash
 1
 root # source /etc/profile
 1
 root # export PS1="(chroot) ${PS1}"

Then the terminal will look like this

mount the boot partition

We skip this step directly because the final installed device is not this machine but another laptop.

After that, we will manually install the boot media.

Install Gentoo ebuild database snapshot from website

Officially, this is equivalent to sudo pacman -Syyu in Arch

Not to mention copy and paste.

 1
 root # emerge-webrsync

Choose a configuration file

How do I feel like I’m copying the content of the wiki…

Configuration files are the building blocks of any Gentoo system. Not only does it specify default values ​​for USE, CFLAGS, and other important variables, it also locks down the system’s range of package versions. These settings are all maintained by the Portage developers at Gentoo.

 1
 # eselect profile list
 1 2 3 4 5
 Available profile symlink targets: [1] default/linux/amd64/17.1 * [2] default/linux/amd64/17.1/desktop [3] default/linux/amd64/17.1/desktop/gnome [4] default/linux/amd64/17.1/desktop/kde

Then enter the following command

 1
 # eselect profile set [对应的数字]

In fact, it will list a lot of options, we need to choose the version with desktop/system

set time zone

Here is the method of Arch directly

 1
 # ln -sf /usr/share/zoneinfo/Region地区名/City城市名/etc/localtime

According to my situation I should write like this

 1
 # ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Then run hwclock to generate /etc/adjtime

 1
 # hwclock --systohc

set USE

For the Gentoo system, the USE flag is necessary, so we need to set the global USE flag before compiling

 1
 # vim /etc/portage/make.conf
 1 2
 USE="alsa udev dbus icu systemd gles2 sound video intel -kde tiff x265" VIDEO_CARDS="intel"

Update @world collection

In fact, it is similar to the “rolling” of Arch, but it will be a relatively long process.

 1
 # emerge --ask --verbose --update --deep --newuse @world

In addition to changing the USE flag this command is also used to dynamically adjust the system functionality.

configure locale

Please refer to this Installation guide (Simplified Chinese) – ArchWiki

configure the kernel

Hmm, you think I’m so stupid and I compile it for eight hours, this time I choose to use the bin kernel

 1
 # emerge --ask sys-kernel/installkernel-systemd-boot

Save a lot of time.

 1
 # emerge --ask sys-kernel/gentoo-kernel-bin

Oops

see for yourself

Install firmware

Some drivers require additional firmware to be installed on the system in order to work. Often network interfaces are used especially wireless network interfaces. Additionally, modern video chips from vendors such as AMD, NVidia, and Intel often require external firmware files when using open source drivers. Most firmware is packaged in sys-kernel/linux-firmware

Most device drivers depend on the linux-firmware package

 1
 # emerge --ask sys-kernel/linux-firmware

configure fstab

This step is to let the kernel know the partition when the system starts.

But Gentoo doesn’t seem to be able to use genfstab

only handwritten

First get the UUID in the notebook

 1
 ls /dev/disk/by-uuid/ -l

Next, write the UUID of the partition corresponding to the / partition in the file /etc/fstab in the following format

 1 2
 # /dev/mmcblk1p2 UUID=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx / xfs default,rw,relatime 0 1

Dump the system to the laptop via rsync

At this time, you need to insert an ArchISO U disk into the notebook, boot to the ISO , connect to WIFI and start the ssh service.

Next, format the original partition

 1
 # mkfs.btrfs /dev/mmcblk1p2 -f

Then mount it and rsync the file you just made into it

 1
 # mount /dev/mmcblk1p2 /mnt

Next, start the ssh service on the notebook side

 1
 # systemctl start sshd

Then use rsync to transfer the compiled file to the notebook’s system partition.

 1
 # rsync -aAXHv -P -vi --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} ./mnt/gentoo/. [email protected]:/mnt

Install bootloader on laptop

This is also a very familiar operation.

 1
 # grub-install --target=x86_64-efi --efi-directory=/dev/mmcblk1p1 --bootloader-id=GRUB
 1
 # grub-mkconfig -o /boot/grub/grub.cfg

Epilogue

After a series of tossing, this old book can finally exert its maximum performance.

From this it seems possible to copy Linux distribution system files to other devices via rsync.

But it took a long time

Reference link

This article is reprinted from: http://weepingdogel.github.io/posts/%E5%88%A9%E7%94%A8rsync%E7%BB%99%E7%AC%94%E8%AE%B0%E6%9C% AC%E5%AE%89%E8%A3%85gentoo/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment