In the Linux world, there are two types of distributions.
First the monolithic ones, such as Ubuntu, where you don't have to set anything before using it.
Everything (or almost) is included to begin.
Second, the specific ones, that on calls meta-distributions, where you have to select only packages and options you want to have.
Of course, the first is easier to use for a current usage but there is no optimization at all.
With the second, optimization and selecting packages are the key, but they are very complicated for beginners.
Let's try to deep inside the second one in this Gentoo installation tutorial for beginners.
We are going to use VirtualBox and Gentoo.
So let's download the VirtualBox virtual machine manager and the Gentoo distribution:
To be exact, we will use:
It's essential to set up a new virtual machine, because it's likely that a kernel panic will occur in the current process.
So don't be afraid, with a fresh new virtual machine, you won't lose anything because it's always possible to erase it and start again from the beginning.
From VirtualBox > New:
Next > 1024 MB > Next > Create a virtual hard disk now > Create > VDI (VirtualBox Disk Image) > Next > Fixed size > select 8 GB as file size > Create.
It should take 1 minute to create.
Space for your virtual machine is created.
Let's now add the Gentoo distribution to this virtual machine.
From VirtualBox > select the new VM just created > Right click > Settings > Storage > on the Storage Tree, select Empty under the Controller: IDE.
On the right there is CD-ROM icon, click it.
Choose Virtual Optical Disk File... > select your Gentoo distribution downloaded > OK.
From VirtualBox > select your VM in the list > right click > Start > You are now able to start Gentoo by clicking on the Green arrow > Start > Normal Start.
You have now 15 seconds to press any key when the message will request it.
At this moment, if your mouse cursor has disappeared, don't worry, just click your OS Home key from your computer.
In a moment we will see how to configure your network with VirtualBox, in the SSH server part.
Stay tuned!
Once the Gentoo OS started, it's time to set it up.
The first screen that should appear is a choice to boot from the kernels or options, respectively by pressing F1 or F2 keys.
Press F1 and type the following command for the boot:
gentoo
Press ENTER.
You'll have to choose which keyboard country you depend on.
Then a new prompt will appear after few seconds:
livecd ~ #
This is your new prompt and you can try to list the current directory with a classic:
livecd ~ # ls -la
In order to control your Gentoo directly from another shell (Putty for example) you have to start the SSH server from your Gentoo distribution.
First, it necessary to shutdown your VM to change the network settings, you can do directly from your Gentoo prompt like that:
livecd ~ # shutdown -h now
Now that your VM is powered off, you can change your network settings.
From VirtualBox > right click your Gentoo VM > Network > in the Adapter 1 tab, check the Enable Network Adapter > Attached to: Bridge Adapter > just below you should see your network card appear > OK.
Start again your VM.
When you see the livecd prompt, you can type the following command:
livecd ~ # ifconfig
You should see two IPs, the first is the lo (for loopback system), the second enp0s4 (for example, it changes from a computer to another).
So with the second, in our case enp0s4, you can read the IP just after the inet word:
This IP is then: 192.168.0.9
Still from your Gentoo distribution, type the following command in your prompt:
livecd ~ # /etc/init.d/sshd start
Your SSH server is now started.
Let's change the password by something easy to remember.
Still from your Gentoo VM prompt:
livecd ~ # passwd
Enter the new password "root" and retype it when asked:
livecd ~ # root
Even with the message saying that the password is too short or too simple, it's not important for this tutorial.
Your password is now updated succesfully.
Open Putty > Session > on the right, in the Host Name (or IP adress), type 192.168.0.9 > just below, select SSH as Connection type > Open.
You should see a PuTTY security alert telling you that the server's host key is not cached in the registry.
Don't worry with that and click Yes.
Instantly from your Putty console, you should see a message asking you to enter the login and then the password.
Enter the default login and password (they are the same by default):
login as: root Password: root
Done!
You can see now the same prompt as in your Gentoo from VirtualBox.
I think it's quite easiest to use Putty in this case.
But of course, it's up to you to continue this tutorial with either your VM or Putty.
Before going further, it's time to partitioning our hard drive.
On Linux, the system is divided in block devices.
They are on the /dev/ directory.
Here /dev/ stands for device.
So all files in /dev/ directory are devices.
You can see for example, in the /dev/ directory, something like this:
brw-rw---- 1 root disk 8, 0 Nov 21 21:21 sda
The first letter, on the left, is a "b" meaning block.
The letters "sda" stand for Sata Device A.
Here the "a" means the first Sata Device.
The second device (second hard drive for example) would be "sdb", the third "sdc", etc.
But if we have sda with some numbers, such as sda1, sda2 it's because the number represents the partition number.
Consequently we can assume:
So we are going now to create partitions on your hard drive.
The main tool for that is fdisk.
So to activate it just type in your prompt:
livecd ~ # fdisk /dev/sda
To show your partitions just write "p" for print:
p
You should see something like this:
Command (m for help): p Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 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: 0x0ab1508c Command (m for help):
The main option is of course the help that you can open with the letter "m" for manual:
Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table Misc m print this menu u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table
So we are going to use some of these options throw this tutorial.
Let's start by create the boot partition by typing the following command:
n (NEW) p (PRIMARY) 1 (PARTITION 1) ENTER (2048 MiB by default for the FIRST SECTOR ADRESS) +100M (LAST SECTOR SIZE)
Indeed when you type "ENTER" without any number, the default value is applied.
Here the result step by step:
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): 1 First sector (2048-16777215, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-16777215, default 16777215): +100M Created a new partition 1 of type 'Linux' and of size 100 MiB.
By typing "p" again, you'll see the new partition created:
Command (m for help): p Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 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: 0x0ab6506b Device Boot Start End Sectors Size Id Type /dev/sda1 2048 206847 204800 100M 83 Linux
This partition will be used by the system when you'll run out of memory (RAM).
So to help it, we create this swap partition in order to help the processor to write data on your hard drive when it needs it.
So it's like the RAM but slower.
Let's create it almost like the boot partition but with a size of 1 GiB this time:
Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (206848-16777215, default 206848): Last sector, +sectors or +size{K,M,G,T,P} (206848-16777215, default 16777215): +1G Created a new partition 2 of type 'Linux' and of size 1 GiB.
You are of course free to specify the amount you want but dont' forget that this will be taken from the 8 GiB space allowed at the beginning.
It's of course necessary to select the type with the "t" letter by typing the corresponding value in the list.
To open up the list, type "L" for list then in our case "82" for Linux swap / So (Solaris):
Command (m for help): t Partition number (1,2, default 2): 2 Partition type (type L to list all types): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L ff BBT 1e Hidden W95 FAT1 80 Old Minix be Solaris boot Partition type (type L to list all types): 82 Changed type of partition 'Linux swap / Solaris' to 'Linux swap / Solaris'.
Command (m for help): p Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 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: 0x0ab6506b Device Boot Start End Sectors Size Id Type /dev/sda1 2048 206847 204800 100M 83 Linux /dev/sda2 * 206848 2303999 2097152 1G 82 Linux swap / Solaris
You can notice the asterisk (*) on the second partition.
This asterisk means that the current partition is the bootable partition.
So in our example we need that this bootable partition is the partition 1 (sda1).
In order to change it, let's type the "a" letter and select the partition 1.
It'll add it as the partition bootable.
But we've to remove the partition 2 as bootable by simply selecting it:
Command (m for help): a Partition number (1,2, default 2): 1 The bootable flag on partition 1 is enabled now. Command (m for help): p Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 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: 0x0ab6506b Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 206847 204800 100M 83 Linux /dev/sda2 * 206848 2303999 2097152 1G 82 Linux swap / Solaris Command (m for help): a Partition number (1,2, default 2): 2 The bootable flag on partition 2 is disabled now. Command (m for help): p Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 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: 0x0ab6506b Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 206847 204800 100M 83 Linux /dev/sda2 206848 2303999 2097152 1G 82 Linux swap / Solaris
Now the sda1 partition is the only bootable partition.
The root partition
Now that we have the boot and the swap partition, it's time to create our root partition.
It's quite easy because there is nothing special here.
As we already used 100 MiB + 1 GiB = 1.1 GiB, we still have 8 - 1.1 = 6.9 GiB.
So let's take 6 GiB as our root partition and let 900 MiB free to use later (if you want):
Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): 3 First sector (2304000-16777215, default 2304000): Last sector, +sectors or +size{K,M,G,T,P} (2304000-16777215, default 16777215): +6G Created a new partition 3 of type 'Linux' and of size 6 GiB.
Here we are, our 3 partitions are created, to be sure, let's print them all:
Command (m for help): p Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 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: 0x0ab6506b Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 206847 204800 100M 83 Linux /dev/sda2 206848 2303999 2097152 1G 82 Linux swap / Solaris /dev/sda3 2304000 14886911 12582912 6G 83 Linux
Saving the partitions
These partitions aren't in memory yet.
It means that if you quit the fdisk tool and restart it again, these partitions won't be there.
To save it, just type the letter "w" for write:
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
You can now quit the fdisk tool by using the "q" letter.
In order to have a filesystem on our partitions, we have to use the mkfs.ext and the mkswap tool.
To set our partition 1 to ext2, let's do from the livecd Gentoo prompt:
livecd ~ # mkfs.ext2 /dev/sda1 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 102400 1k blocks and 25688 inodes Filesystem UUID: 9809c750-2a6f-46f1-a101-c1060a5e4986 Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done
For the partition 2, we need to use the mkswap tool:
livecd ~ # mkswap /dev/sda2 Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=29c5442a-8bc9-4140-9bbe-76821790f2a1
livecd ~ # swapon /dev/sda2
livecd ~ # free
livecd src # free total used free shared buff/cache available Mem: 900636 23344 42564 64036 834728 787372 Swap: 0 0 0
livecd src # free total used free shared buff/cache available Mem: 900636 23248 42316 64036 835072 787540 Swap: 1048572 0 1048572
livecd ~ # mkfs.ext4 /dev/sda3 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 1572864 4k blocks and 393216 inodes Filesystem UUID: 75351d27-20bd-416b-9530-0956fd95fa05 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
To verify that everything is OK, we can use the parted tool and use the print command:
livecd ~ # parted GNU Parted 3.2 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 8590MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 106MB 105MB primary ext2 boot 2 106MB 1180MB 1074MB primary linux-swap(v1) 3 1180MB 7622MB 6442MB primary ext4
Everything is OK!
After formated the partitions and set the filesystem, we are going to mount these partitions to real directories in our Gentoo.
First, we can check with the df tool that our partitions aren't mounted yet:
livecd ~ # df -h Filesystem Size Used Avail Use% Mounted on udev 10M 4.0K 10M 1% /dev tmpfs 440M 63M 378M 15% / /dev/sr0 255M 255M 0 100% /mnt/cdrom /dev/loop0 227M 227M 0 100% /mnt/livecd tmpfs 88M 412K 88M 1% /run shm 440M 0 440M 0% /dev/shm cgroup_root 10M 0 10M 0% /sys/fs/cgroup tmpfs 440M 0 440M 0% /mnt/livecd/usr/portage
We use the -h option to display sizes into readable numbers.
So our partitions aren't here.
Let's mount them:
livecd ~ # mount /dev/sda3 /mnt/gentoo/ livecd ~ # mkdir /mnt/gentoo/boot livecd ~ # mount /dev/sda1 /mnt/gentoo/boot
Let's use again the df tool to see that this time our partitions are mounted:
livecd ~ # df -h Filesystem Size Used Avail Use% Mounted on udev 10M 4.0K 10M 1% /dev tmpfs 440M 63M 378M 15% / /dev/sr0 255M 255M 0 100% /mnt/cdrom /dev/loop0 227M 227M 0 100% /mnt/livecd tmpfs 88M 412K 88M 1% /run shm 440M 0 440M 0% /dev/shm cgroup_root 10M 0 10M 0% /sys/fs/cgroup tmpfs 440M 0 440M 0% /mnt/livecd/usr/portage /dev/sda3 5.8G 12M 5.5G 1% /mnt/gentoo /dev/sda1 97M 1.6M 91M 2% /mnt/gentoo/boot
We can see that we have our 2 partitions sda1 (boot) and sda3 (filesystem) mounted to respectively /mnt/gentoo/boot and /mnt/gentoo directories.
To be prepared for next section, let's go into this last directory:
livecd / # cd /mnt/gentoo/
This stage tarball is an archive containing basic files for the Gentoo installation.
But first we need to know which kind of computer you have, for that just type uname -m from your prompt:
livecd gentoo # uname -m
The result should be something like:
i686
So we know that our system is a i686.
First, we need to find this stage tarball on the Gentto official website:
Select the mirror of your choice and navigate through this directory (assuming your computer is a i686 one):
Then copy the whole link of this tarball, you should have something like this:
Come back to your Gentoo.
We assume that we are still in the /mnt/gentoo/ directory.
With the wget tool we are going to download this tarball:
livecd gentoo # wget ftp://ftp.gtlib.gatech.edu/pub/gentoo/releases/x86/autobuilds/current-stage3-i686/stage3-i686-20161122.tar.bz2 ... stage3-i686-20161122.tar.bz2. 100%[===============================================>] 226.82M 1.75MB/s in 2m 22s 2016-11-29 10:04:02 (1.59 MB/s) - 'stage3-i686-20161122.tar.bz2.2' saved [237841553] FINISHED --2016-11-29 10:04:02-- Total wall clock time: 2m 24s Downloaded: 1 files, 227M in 2m 22s (1.59 MB/s)
Once the Stage tarball downloaded, it's time to extract its content with the tar tool:
livecd gentoo # tar xvjpf stage3-i686-20161122.tar.bz2
The xvjpf letters are options for the tar tool.
Have a look to the manual if you want to learn more.
Before using the file system, it has to be mounted.
This is the only purpose of mounting a file system.
For example when you plug an SD card into your computer a file system is mounted for this SD card.
And when you decide to unmount it, the SD card won't appear anymore as a folder.
Well, this said, let's continue.
With the following commands we are going to mount the /proc directory (of type proc) to another folder then bind the /sys and /dev directories.
livecd mnt # mount -t proc /proc /mnt/gentoo/proc livecd mnt # mount --rbind /sys /mnt/gentoo/sys livecd mnt # mount --rbind /dev /mnt/gentoo/dev
We use a bind for the /dev and /sys directories because we want to be sure to be able to unmount them if needed.
So in our situtation the new /proc directory becomes /mnt/gentoo/proc whereas the /dev and /sys directories stay the same.
The rbind keyword means that we want the exact same copy of a directory, the "r" in rbind standing for recursion.
It's time to change the root directory from our medium (here the livecd) to the hard drive.
Currently we have created the new partitions on /mnt/gentoo.
So we are going to use this directory as the new root one.
livecd / # chroot /mnt/gentoo
You can now try to go inside the root directory, for example:
livecd / # cd /
And if you do a simple ls -la, you should see that the root directory is the new one:
livecd / # ls -la
If you wanted to come back to the old directory, you could do that, by typing exit:
livecd / # exit
The Gentoo basis have been seen.
That's an important step before going further.
The next stage is indeed to configure the Linux kernel, that will certainly see in a future tutorial.
Anyway, well done if you finished it and see you later!
Add new comment