Building an Android custom ROM in the one of the most customizable Linux Distribution in the planet (Arch Linux)? Here’s my take on how to do it.
If you read my post on building Resurrection Remix for Zuk Z1, I mentioned about building an Arch based Android Development machine. I was struggling to do it before but after some research, I managed to create one.
In this post, we will take a look on how to create an Android Development environment for the use of custom ROM compilation using Arch Linux as the OS. We won’t be touching on the syncing the sources part as it was pretty much detailed in Part 2 of my post on how to build Resurrection Remix for Zuk Z1.
This will be a command-line heavy tutorial so make sure you are comfortable in handling the terminal.
Prepare the Virtual Machine
This part is pretty much the same with the Part 1 of building Resurrection Remix. However, this time we won’t be using easy install for the creation of the virtual machine.
Basically we will have to load the live USB and install the operating system manually on the first boot of our newly created virtual machine. You can check this post as a guide but make sure to modify the options as shown below.
After completing the settings for the virtual machine, we can now start and run the VM and proceed with the installation.
Installing Arch Linux
Power on the virtual machine and it will greet you with this.
Select the 1st option Boot Arch Linux to continue. After a series wall of texts flashing on the screen, it will bring you to the Arch terminal (see below).
There will be no Graphical User Interface (GUI) from this point until we get the chance to install one (Part 2), so make sure that you are comfortable dealing with terminal. If you are not, you can always opt for Ubuntu as your build machine OS and follow this guide instead.
Check for connectivity
Firs, let us make sure that we have a working internet connection. Type:
If you see something like the one below, you have a working internet connection.
Hit CTRL+C to stop the command.
Next is we prepare the disks that we are going to use. Type
in the terminal to run partition manager program and type help for more info.
Then afterwards, enter these commands:
mkpart primary ext4 0% 100%
set 1 boot on
These commands will make a primary partition using your VM’s full disk which we will be formatting as ext4 type.
Double check partition
After running and quitting parted, type
in order to list partitions found in the machine. If it lists /dev/sda1, you have successfully executed the partitioning instructions.
Now lets format the disk. Type
to start formatting.
After formatting the disk, we can now mount the partition for use of our installation medium. To do this, type
mount /dev/sda1 /mnt
Select mirrors (optional)
After we have successfully mounted the newly formatted disk, we can now go ahead and download Arch packages and install it in the disk drive. However, you might want to change your download mirrors for faster package download.
To do this, type
From this list, select a line which is geographically near in your location and put it on top in order to gain faster downloads. You can use CTRL+W to find a country, CTRL+K to cut a specific line and CTRL+U to paste the line. Remember to paste the one starting with “Server” and not the line starting with “##”.
After pasting the line in the top of the list, press CTRL+C and type Y and ENTER to save changes.
Pactrapping. Installing the base packages
Now we are ready to download the base packages in our machine. To do this type
pacstrap /mnt base
This will download the base packages and install in our disk drive mounted in /mnt.
Generating the fstab
Next is we need to generate the fstab file. This file is used by the mnt command which mounts file systems at boot. If we don’t do this, Arch won’t know which disk to use upon boot up.
To generate fstab, type
genfstab -U /mnt >> /mnt/etc/fstab
Chroot to our disk installation
Currently, we are running Arch using our live disc and preparing the system somewhat remotely. We are not yet booted into our Arch instance inside the VMware disk yet. Therefore by default, all package installation done in this environment will affect the live disc and will be installed temporarily only. In order to fix that, let us chroot to our Arch installation. To do it, type
After doing this, you will notice the change in an indicator in our terminal. This means that we successfully chrooted to our /mnt. As you may remember, /mnt is the location of the folder where we mounted our /dev/sda1.
Configuring the installation
Now that we are inside the VMware disk, we can now configure some of its parts.
To do this, we need to type
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
where Region and City is your region and city. To find the list of valid items for Region and City, you can go and type
to see the list of region and
to see the list of cities; where Region is set to your selected region.
After setting the timezone, run
to complete setting the timezone into the machine.
Setting the locale
After configuring the timezone we will now configure the locale which will control the language of the machine. Type
and uncomment (delete the # in front of a text line) any needed localization. If you are in US, you will need to uncomment
Then, press CTRL+X and Y to save the file. Afterwards, run
in the terminal to finish the configuration. Then create a locale.conf file by typing
and add the uncommented locale found in the locale.gen to the file. If you selected en_US.UTF-8 UTF-8, put
in the file. Press CTRL+X and Y to save file.
Modifying the hostname and hosts file
In this section, we will set our own hostname for our machine and subsequently add it in the hosts files which controls the local nameserver of our installation.
To do this, type
and add you hostname in the file (avoid spaces ” “). Think of this as the name of your computer. You can set it to any value such as “mycomputer”, “JohnComputer” etc.
Then after editing the file, hit CTRL+X and Y to save it.
Then, edit the hosts file by typing
127.0.1.1 myhostname.localdomain myhostname
where myhostname is the hostname you set in the /etc/hostname. Subsequently, the hosts file will now look like this after the edit:
127.0.0.1 localhost.localdomain localhost ::1 localhost.localdomain localhost 127.0.1.1 myhostname.localdomain myhostname
Configure the network
Then, we should now configure the network so that after a reboot, we will have a working network connection. To do this, type
systemctl enable dhcpcd.service
This command will enabled the dhcpcd.service which is responsible in resolving us a valid IP address for the network. Without it, we will have to configure the network manually everytime we boot up the machine.
Configure the root password
Now we will configure the root or administrator password. To do this simply type,
and type your desired password. Take note that the characters you are typing will not appear in the screen. Not even the * which hides the characters in most password input fields.
Configure the boot loader
Then we now configure the boot loader. The boot loader is the first piece of software that runs before your OS starts. It is responsible for a lot of things and one of which is starting the OS itself. If we do not configure the boot loader, our Arch installation won’t even boot.
To configure the boot loader, type
pacman -S grub
This will install the boot loader named grub. Then type
grub-install –target=i386-pc /dev/sda
to install the bootloader in /dev/sda. Finally, type
grub-mkconfig -o /boot/grub/grub.cfg
to generate configuration settings to our machine.
umount -R /mnt
to unmount the local disk. Afterwards, type
to reboot the VM.
Congratulations! You now have Arch Linux installed. But we are not yet finished. We only have the base installation. We still need to add and configure the user interface.
Stay tuned for Part 2!
Special thanks to these sources in making this post a reality: