Adventures from Gentoo installation on Intel Atom netbook

Idea

Gentoo can be very lightweight, and very fast, if configured properly. Intel Atom based netbooks are slow as hell. Compiling Gentoo on one is out of the question. My Idea was to build basic rootfs on remote, powerfull server, and simply install this precompiled package on my netbook, in this case Acer Aspire ONE D270 with Intel Atom N2600, 2GB DDR3 and 16GB SSD.

Getting information needed

I had Puppy Linux installed on this netbook previously, so I could check everything I need from running operating system. I needed specifically two things:

Both things are pretty simple to get from live operating system. We can check exactly how much bytes does my SSD have using `lsblk`. (Stack exchange answer)

lsblk -b --output SIZE -n -d /dev/sda
    

This returned exactly 16013942784 bytes in my case. Later I'll use it to create virtual hard-drive on remote machine. Now to unfold the `-march=native` instruction. Once again, Stack exchange comes with help: How to see which flags -march=native will activate?

gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
    

This returned all the flags specific for my CPU:

-march=bonnell -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -mno-aes -mno-sha -mno-pclmul -mno-popcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-sgx -mno-bmi2 -mno-pconfig -mno-wbnoinvd -mno-tbm -mno-avx -mno-avx2 -mno-sse4.2 -mno-sse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mno-xsave -mno-xsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 -mno-clflushopt -mno-xsavec -mno-xsaves -mno-avx512dq -mno-avx512bw -mno-avx512vl -mno-avx512ifma -mno-avx512vbmi -mno-avx5124fmaps -mno-avx5124vnniw -mno-clwb -mno-mwaitx -mno-clzero -mno-pku -mno-rdpid -mno-gfni -mno-shstk -mno-avx512vbmi2 -mno-avx512vnni -mno-vaes -mno-vpclmulqdq -mno-avx512bitalg -mno-avx512vpopcntdq -mno-movdiri -mno-movdir64b -mno-waitpkg -mno-cldemote -mno-ptwrite --param l1-cache-size=24 --param l1-cache-line-size=64 --param l2-cache-size=512 -mtune=generic -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection
  

I'll use that in portage make.conf on remote machine

Remote machine

Build virtual SSD

Since I have exact number of bytes of my SSD, I can build virtual image, which later I could simply dd into my netbook.

fallocate -l 16013942784 ssd.img
losetup -P ssd.img
  

Now comes the part with gentoo handbook in hand. `losetup` will mount our SSD image in loop0 device, it will act same as `/dev/sda` on local machine. We need to setup partitions now. I used cfdisk for simplicity, created MBR (dos) label, first partition with 12GB of space, bootable, Linux filesystem type. Second partition as the whole free space left (2.9GB in this case), to be used as swap. Next I formatted both partitions with mkfs.ext4 and mkswap. FUTURE ME: If You want to use syslinux as bootloader, make sure to format Your root partition with ext4 in 32bit mode! In future You can use resize2fs to convert 64bit ext4 to 32bit. Now we can make our mount directory, and mount root partition.

mkfs.ext4 /dev/loop0p1
mkswap /dev/loop0p2
mkdir /mnt/gentoo
mount /dev/loop0p1 /mnt/gentoo
  

From this point, almost everything goes just like in Gentoo handbook, with some exceptions. Download Your stage 3, untar, mount /dev, /proc, /sys, chroot, set locale, SET CFLAGS IN PORTAGE MAKE.CONF(!), and do not update @world! I broke my first installation this way, because portage uses cflags for different architecture, and updated binaries ended up unusable in current chroot, throwing "Illegal instruction" error. Instead go directly for kernel compilation, and install all the tools You will need (bootloader, genkernel...). Build kernel, initramfs, finish configuring chroot, and unmount everything. Now it's time to dd our image to netbook.

Moving virtual SSD image to physical one

I didn't have any pendrive or other free physical file transfer medium in hand, so I ended up downloading image directly on SSD. Setup any HTTP server on Your remote machine (in my case `python3 -m http.server), and get the link to Your SSD image. Now on local machine:

curl "http://your.server/ssd.img" | dd of=/dev/sda bs=4k
  

This way, curl will directly write SSD image to our SSD. When everything finishes, mount SSD as per handbook, and finish installation. Now You can update @world, and have fun with freshly installed Gentoo.

Summary

Video presentation