Gentoo Installation Step by Step

1. Boot the system with Gentoo-minimal ISO CD.

Download Gentoo ISO (Minimal) from https://www.gentoo.org/downloads/ site.

Burn the CD and boot the system.

2. Determine interface name using ifconfig command.

In my case, it is “eno16777728”. Configure the network interface. IP will change according to your network.

# ifconfig eth0 192.168.1.109 broadcast 192.168.1.255 netmask 255.255.255.0 up
# route add default gw 192.168.1.1

Add the following entry in resolve.conf file.

# nano /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8


3. Start sshd service.

To do the installation over ssh, start the sshd service and provide the root password.

#/etc/init.d/sshd start
# passwd


4. Create partitions as per the requirement.
In my case, I am going to create following partitions as on my virtual machine I am having only 20 GB of /dev/sda disk size.
Partitions and its size will vary depending on your system.

1. /boot -- 500M
2. /          -- 18G
3. swap   --  1024M


5. Formatting partitions.

Now Format created partitions with the supported filesystem(here formatted with ext4 filesystem).

#mkfs.ext4 /dev/sda1


#mkfs.ext4 /dev/sda2


Activate the swap partition.

#mkswap /dev/sda3
#swapon /dev/sda3


6. Setting date.

Check date and time of the system. In case of time desynchronization use following command to set time.

#date MMDDhhmmYYYY

7. Mounting root partition.

Mount the root and boot partition under /mnt/gentoo.

#mount /dev/sda2 /mnt/gentoo
#mkdir /mnt/gentoo/boot
#mount /dev/sda1 /mnt/gentoo/boot




8. Downloading stage3 tarball.

Download stage3 tar from https://www.gentoo.org/downloads/
Once downloaded dump it into /mnt/gentoo. 


Now unpack the tar ball under /mnt/gentoo directory.

#tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner
After extracting stage3 tar ball it will look like in below image.



9. Copy dns info.

Before entering the new environment copy the DNS information in /etc/resolv.conf.

#cp -L /etc/resolv.conf /mnt/gentoo/etc/

10. Mounting the necessary filesystems.

Mount the /proc, /sys and /dev directories to /mnt/gentoo installation system path, as this contains all the important hardware information of your system gathered by the kernel when the live CD is booted.

#mount -t proc /proc /mnt/gentoo/proc
#mount --rbind /sys /mnt/gentoo/sys

#mount --rbind /dev /mnt/gentoo/dev



11. Entering the new environment

Now go to the chroot environment, load previous system settings provided by /etc/profile file and change $PS1 Command Prompt.

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



12. Install ebuild repository snapshot from the web.

#emerge-webrsync


13. Choosing the right profile.

After Portage finishes synchronization select a profile for your future system destination.

#eselect profile list

I am going to select default profile i.e. 1

#eselect profile set 1

14. Setting time zone.
Next, configure your system Time Zone.

# ls /usr/share/zoneinfo
# cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
# echo " Asia/Kolkata " > /etc/timezone


15. Configuring locales.

Configure Locales by uncommenting your preferred language from /etc/locale.gen file using the following series of commands.

#nano  /etc/locale.gen

Uncomment your system locale, I have uncommented below one.

en_US.UTF-8 UTF-8

run locale-gen command to generate all the locale specified in /etc/locale.gen

#locale-gen


Now reload the environment.

#env-update && source /etc/profile


16. Installing the sources.

#emerge --ask sys-kernel/gentoo-sources

17. Installing pciutils.
#emerge --ask sys-apps/pciutils


18. Configuring Linux kernel.

Go to the kernel source directory and execute make menuconfig.

#cd /usr/src/linux
#make menuconfig


Now configuration screen will appear on the terminal. The Linux kernel configuration has many, many sections. Select/Verify appropriate modules has been selected or not. Select if not and finally save the configuration.


Exit the configuration and start the compilation process

#make && make modules_install
#make install



Copy the kernel image file to the boot directory.

#cp arch/x86_64/boot/bzImage /boot/kernel-4.12.5-gentoo


19. Open /etc/fstab file and add the following content.

Next step is to configure fstab file to automatically mount system partitions during the boot process.


20. Installing system bootloader.

To make Gentoo start after reboot install GRUB Boot Loader on your first hard disk and generate its configuration file by running the following commands.

#emerge sys-boot/grub


#grub-install /dev/sda
#grub-mkconfig -o /boot/grub/grub.cfg


21. Set the hostname.


Set a hostname for your system by editing /etc/conf.d/hostname file.  



22. Install DHCP client.

Configure your network settings with DHCP install dhcpcd Client.
rc-update will add it in system startup process.

#emerge net-misc/dhcpcd

#rc-update add dhcpcd default


23. Install other important packages.

#emerge virtual/ssh
#emerge syslog-ng
#emerge cronie
#emerge mlocate
#rc-update add sshd default
#rc-update add syslog-ng default
#rc-update add cronie default
#emerge sudo
#emerge net-misc/netkit-telnetd
#emerge tcpdump

24. Provide root password in chroot environment.

#passwd


25. Rebooting the system

Exit the chrooted environment and unmount all mounted partitions.

#exit
#cd
#umount -l /mnt/gentoo/dev{/shm,/pts,}
#umount -R /mnt/gentoo
#reboot




Reference Link: https://wiki.gentoo.org/ and https://www.tecmint.com/

Find out Memory Usage of each process in Linux

In this post, I have listed out some commands to show the Memory Usage of each process running.
Hope this will help you out to know memory utilization per process.
Also shared reference links where I found this commands.


1. Show the processes memory in megabytes and the process path.
Reference Link: https://superuser.com/

#ps aux  | awk '{print $6/1024 " MB\t\t" $11}'  | sort -n

2. Total memory consumption by the current user.
Reference Link: https://superuser.com/

#echo "------------------------------------" && mem=0 && while read -r rss comm ; do mbs=$((rss/1024)); mem=$((mbs + mem)); echo $mbs"MB - $comm"; done <<< "$(ps -u $USER -wo rss=,comm= --sort -rss)" && echo "------------------------------------" && echo $mem"MB: Memory used by user '$USER'"

All user processes sorted by the highest memory usage in MB.

#ps -u $USER -wo rss=,comm= --sort -rss | while read -r rss comm ; do echo $((rss/1024))"MB -" $comm; done


3. Display Processes Sorted By Memory Usage in Linux.
Reference Link:https://www.shellhacks.com

#ps axo rss,comm,pid \
| awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } \
END { for (proc in proc_list) { printf("%d\t%s\n", \
proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10 | sort -rn \
| awk '{$1/=1024;printf "%.0fMB\t",$1}{print $2}'

4. Top 10 processes sorted by memory usage.
Reference Link: https://www.linuxquestions.org/

#ps -eo rss,pid,user,comm | sort -rn | head -10 | awk '{ hr[1024**2]="GB"; hr[1024]="MB";
 for (x=1024**3; x>=1024; x/=1024) {
 if ($1>=x) { printf ("%-6.2f %s ", $1/x, hr[x]); break }
 } } { printf ("%-6s %-10s ", $2, $3) }
 { for ( x=4 ; x<=NF ; x++ ) { printf ("%s ",$x) } print ("\n") }'