Difference between revisions of "Install Linux in a virtual machine"

From Computer Science
Jump to navigationJump to search
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
------------------------------------------------------------------
+
[[Guides]]> [[Linux Guide|linux]] > [[Install Linux in a virtual machine]]
  
 
NOTE: These instructions are not canonical.  There are many ways of installing
 
NOTE: These instructions are not canonical.  There are many ways of installing
 
Linux, but this will get you a running system that you can play with.
 
Linux, but this will get you a running system that you can play with.
  
Download the install media [here](middlinux-2020.01.05-x86_64.iso).
+
Download the install media [https://www.cs.middlebury.edu/~rlichenstein/Files/middlinux-2020.08.20-x86_64.iso here].
  
  
Line 49: Line 49:
 
root@archiso ~ # fdisk /dev/sda
 
root@archiso ~ # fdisk /dev/sda
 
</pre>
 
</pre>
 
 
You'll see some mildly informative messages and then a different prompt
 
You'll see some mildly informative messages and then a different prompt
 
indicating that `fdisk` (rather than the shell) is awaiting input.  Like the
 
indicating that `fdisk` (rather than the shell) is awaiting input.  Like the
Line 66: Line 65:
  
 
<pre style="color: silver; background: black;">
 
<pre style="color: silver; background: black;">
 +
Command (m for help): n
 
Partition type
 
Partition type
 
   p  primary (0 primary, 0 extended, 4 free)
 
   p  primary (0 primary, 0 extended, 4 free)
Line 76: Line 76:
 
Created a new partition 1 of type 'Linux' and of size 16 GiB.
 
Created a new partition 1 of type 'Linux' and of size 16 GiB.
 
</pre>
 
</pre>
 
 
Note that for first sector and last sector I just hit enter to pick the
 
Note that for first sector and last sector I just hit enter to pick the
 
default.  Some of the exact numbers might be different depending on the size
 
default.  Some of the exact numbers might be different depending on the size
Line 84: Line 83:
 
partition table; the list of partitions at the end should look very similar to
 
partition table; the list of partitions at the end should look very similar to
 
this:
 
this:
 +
 
<pre style="color: silver; background: black;">
 
<pre style="color: silver; background: black;">
 
Device    Boot Start      End  Sectors Size Id Type
 
Device    Boot Start      End  Sectors Size Id Type
 
/dev/sda1        2048 33554431 33552384  16G 83 Linux
 
/dev/sda1        2048 33554431 33552384  16G 83 Linux
 
</pre>
 
</pre>
 
 
If it doesn't, enter the command "d" to delete the partition and re-create it
 
If it doesn't, enter the command "d" to delete the partition and re-create it
 
according to the instructions in the previous pair of paragraphs.
 
according to the instructions in the previous pair of paragraphs.
Line 102: Line 101:
  
 
And then make that formatted partition available to the running system:
 
And then make that formatted partition available to the running system:
 +
 
<pre style="color: silver; background: black;">
 
<pre style="color: silver; background: black;">
 
root@archiso ~ # mount /dev/sda1 /mnt
 
root@archiso ~ # mount /dev/sda1 /mnt
Line 115: Line 115:
 
privileges (sudo).
 
privileges (sudo).
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
root@archiso ~ # pacstrap -c /mnt base xfce4 xorg-server virtualbox-guest-modules-arch virtualbox-guest-utils ttf-dejavu dhcpcd grub sudo man man-pages
+
root@archiso ~ # pacstrap -c /mnt base xfce4 xorg-server virtualbox-guest-utils ttf-dejavu dhcpcd grub sudo man man-pages
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
The preceding command will produce an error if you mistype any of the package
 
The preceding command will produce an error if you mistype any of the package
 
names.  For instance, if I misspell "sudo" as "sud" it will complain at me
 
names.  For instance, if I misspell "sudo" as "sud" it will complain at me
 
like so:
 
like so:
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]])
+
<pre style="color: silver; background: black;">
 
error: target not found: sud
 
error: target not found: sud
 
==> ERROR: Failed to install packages to new root
 
==> ERROR: Failed to install packages to new root
 
1 root@archiso # _
 
1 root@archiso # _
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]])
+
</pre>
  
 
If you see such an error, press the up arrow to bring up the previous command,
 
If you see such an error, press the up arrow to bring up the previous command,
Line 133: Line 132:
 
print a message telling you how long it took, followed by a new prompt, e.g.:
 
print a message telling you how long it took, followed by a new prompt, e.g.:
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]])
+
<pre style="color: silver; background: black;">
pacstrap -c /mnt base xfce4 xorg-server virtualbox-guest-modules-arch  grub  38.73s user 16.03s system 80% cpu 1:07.99 total
+
pacstrap -c /mnt base xfce4 xorg-server grub  38.73s user 16.03s system 80% cpu 1:07.99 total
 
root@archiso # _
 
root@archiso # _
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]])
+
</pre>
  
 
Now you're ready to make sure the partition you've just created gets mounted
 
Now you're ready to make sure the partition you've just created gets mounted
 
at runtime:
 
at runtime:
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
root@archiso ~ # genfstab -p /mnt >> /mnt/etc/fstab
 
root@archiso ~ # genfstab -p /mnt >> /mnt/etc/fstab
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Your new installation is located at /mnt.  Start up a new shell that thinks
 
Your new installation is located at /mnt.  Start up a new shell that thinks
 
its whole world is the collection of files under /mnt, called a *chroot*.
 
its whole world is the collection of files under /mnt, called a *chroot*.
Line 152: Line 150:
 
be running.)
 
be running.)
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
root@archiso ~ # arch-chroot /mnt
 
root@archiso ~ # arch-chroot /mnt
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
On success, your prompt should change to a stripped-down version (because this
 
On success, your prompt should change to a stripped-down version (because this
 
is a shell running in a stripped-down environment, and thus hasn't been
 
is a shell running in a stripped-down environment, and thus hasn't been
Line 161: Line 158:
 
directory):
 
directory):
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]#
 
[root@archiso /]#
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Replace "middlinux" in the following command to set the computer name to
 
Replace "middlinux" in the following command to set the computer name to
 
anything you like (though limit yourself to lowercase letters, numbers, and
 
anything you like (though limit yourself to lowercase letters, numbers, and
 
underscore).
 
underscore).
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# echo middlinux > /etc/hostname
 
[root@archiso /]# echo middlinux > /etc/hostname
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Set the timezone.  (This assumes the hardware clock on the host machine is set
 
Set the timezone.  (This assumes the hardware clock on the host machine is set
 
to UTC rather than localtime.  It's entirely probable this assumption is
 
to UTC rather than localtime.  It's entirely probable this assumption is
Line 178: Line 173:
 
fixed.)  The `date` command should show the correct timezone.
 
fixed.)  The `date` command should show the correct timezone.
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# ln -snf /usr/share/zoneinfo/US/Eastern /etc/localtime
 
[root@archiso /]# ln -snf /usr/share/zoneinfo/US/Eastern /etc/localtime
 
[root@archiso /]# date
 
[root@archiso /]# date
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Set up localization.  The sed command uncomments all lines that contain the
 
Set up localization.  The sed command uncomments all lines that contain the
 
string "en_US", thus enabling US-centric English-language localization, as
 
string "en_US", thus enabling US-centric English-language localization, as
Line 189: Line 183:
 
etc).
 
etc).
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# mv /etc/locale.gen /etc/locale.gen.pacnew
 
[root@archiso /]# mv /etc/locale.gen /etc/locale.gen.pacnew
 
[root@archiso /]# sed -ne '/^#en_US/ s/^#//p' /etc/locale.gen.pacnew > /etc/locale.gen
 
[root@archiso /]# sed -ne '/^#en_US/ s/^#//p' /etc/locale.gen.pacnew > /etc/locale.gen
Line 198: Line 192:
 
Generation complete.
 
Generation complete.
 
[root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf
 
[root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 +
 
 +
 
 +
Edit our boot environment creation script, to avoid unruly bugs.
 +
 
 +
<pre style="color: silver; background: black;">
 +
[root@archiso /]# sed -i -e '/^MODULES=/ s/()/(i915)/' /etc/mkinitcpio.conf
 +
</pre>
 +
 
  
 
Create the initial boot environment, customized to your particular system.
 
Create the initial boot environment, customized to your particular system.
Line 204: Line 206:
 
can ignore these.)
 
can ignore these.)
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# mkinitcpio -p linux
 
[root@archiso /]# mkinitcpio -p linux
 
(lots of messages)
 
(lots of messages)
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Install and configure the bootloader.
 
Install and configure the bootloader.
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# grub-install /dev/sda
 
[root@archiso /]# grub-install /dev/sda
 
Installing for i386-pc platform.
 
Installing for i386-pc platform.
Line 221: Line 222:
 
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
 
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
 
done
 
done
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Make sure networking starts at boot.  (The last letter of the first word is
 
Make sure networking starts at boot.  (The last letter of the first word is
 
the letter ell, *not* the number one.)
 
the letter ell, *not* the number one.)
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# systemctl enable dhcpcd@enp0s3
 
[root@archiso /]# systemctl enable dhcpcd@enp0s3
 
Created symlink
 
Created symlink
 
/etc/systemd/system/multi-user.target.wants/dhcpcd@enp0s3.service -> /usr/lib/systemd/system/dhcpcd@.service
 
/etc/systemd/system/multi-user.target.wants/dhcpcd@enp0s3.service -> /usr/lib/systemd/system/dhcpcd@.service
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Enable some VirtualBox-specific services.
 
Enable some VirtualBox-specific services.
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# systemctl enable vboxservice
 
[root@archiso /]# systemctl enable vboxservice
 
/etc/systemd/system/multi-user.target.wants/vboxservice.service -> /usr/lib/systemd/system/vboxservice.service
 
/etc/systemd/system/multi-user.target.wants/vboxservice.service -> /usr/lib/systemd/system/vboxservice.service
 
[root@archiso /]# echo vboxsf > /etc/modules-load.d/vbox.conf
 
[root@archiso /]# echo vboxsf > /etc/modules-load.d/vbox.conf
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Configure sudo, which allows one user to run a program using the privileges of
 
Configure sudo, which allows one user to run a program using the privileges of
 
another.  (Usually used to perform administrative activities without having to
 
another.  (Usually used to perform administrative activities without having to
Line 247: Line 245:
 
lines.
 
lines.
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# sed -i -e '/wheel ALL=(ALL) ALL$/ s/^# //' /etc/sudoers
 
[root@archiso /]# sed -i -e '/wheel ALL=(ALL) ALL$/ s/^# //' /etc/sudoers
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Set the root (superuser, administrator) password and exit from the chroot.
 
Set the root (superuser, administrator) password and exit from the chroot.
 
(Note that it won't even print asterisks to let you know you're typing.)
 
(Note that it won't even print asterisks to let you know you're typing.)
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
[root@archiso /]# passwd
 
[root@archiso /]# passwd
 
Enter new UNIX password:
 
Enter new UNIX password:
Line 260: Line 257:
 
passwd: password updated successfully
 
passwd: password updated successfully
 
[root@archiso /]# exit
 
[root@archiso /]# exit
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
It should print an account of the time you spent in the chroot and then the
 
It should print an account of the time you spent in the chroot and then the
 
prompt should now revert to what it was before:
 
prompt should now revert to what it was before:
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
exit
 
exit
 
arch-chroot /mnt  10.96s user 2.74s system 5% cpu 4:26.84 total
 
arch-chroot /mnt  10.96s user 2.74s system 5% cpu 4:26.84 total
 
root@archiso ~ #
 
root@archiso ~ #
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
  
 
=== Remove the virtual install media from the virtual drive ===
 
=== Remove the virtual install media from the virtual drive ===
Line 276: Line 271:
 
Shut down the system:
 
Shut down the system:
  
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
<pre style="color: silver; background: black;">
 
root@archiso ~ # halt -p
 
root@archiso ~ # halt -p
[[User:Robert Lichenstein|Robert Lichenstein]] ([[User talk:Robert Lichenstein|talk]]) 15:56, 9 February 2020 (EST)
+
</pre>
 
 
 
Now, in the VirtualBox UI, select your virtual machine from the list.  Click
 
Now, in the VirtualBox UI, select your virtual machine from the list.  Click
 
"Settings".  Select "Storage".  Under the "Controller: IDE" heading, select
 
"Settings".  Select "Storage".  Under the "Controller: IDE" heading, select
Line 289: Line 283:
 
=== Congratulations ===
 
=== Congratulations ===
  
Proceed to [[Your First Boot]].
+
Proceed to [[your first boot]].
 +
 
 +
 
 +
=== Commands Only ===
 +
The below commands are just the instructions from above, without any annotation.
 +
<pre style="color: silver; background: black;">
 +
root@archiso ~ # fdisk /dev/sda
 +
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):
 +
First sector (2048-33554431, default 2048):
 +
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-33554431, default 33554431):
 +
 
 +
Created a new partition 1 of type 'Linux' and of size 16 GiB.
 +
 
 +
Command (m for help: w
 +
root@archiso ~ # mkfs.ext4 /dev/sda1
 +
root@archiso ~ # mount /dev/sda1 /mnt
 +
[root@archiso /]# pacstrap -c /mnt base xfce4 xorg-server virtualbox-guest-utils ttf-dejavu dhcpcd grub sudo man man-pages
 +
[root@archiso /]# genfstab -p /mnt >> /mnt/etc/fstab
 +
[root@archiso /]# arch-chroot /mnt
 +
[root@archiso /]# echo middlinux > /etc/hostname
 +
[root@archiso /]# ln -snf /usr/share/zoneinfo/US/Eastern /etc/localtime
 +
[root@archiso /]# date
 +
[root@archiso /]# mv /etc/locale.gen /etc/locale.gen.pacnew
 +
[root@archiso /]# sed -ne '/^#en_US/ s/^#//p' /etc/locale.gen.pacnew > /etc/locale.gen
 +
[root@archiso /]# locale-gen
 +
[root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf
 +
[root@archiso /]# sed -i -e '/^MODULES=/ s/()/(i915)/' /etc/mkinitcpio.conf
 +
[root@archiso /]# mkinitcpio -p linux
 +
[root@archiso /]# grub-install /dev/sda
 +
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg
 +
[root@archiso /]# systemctl enable dhcpcd@enp0s3
 +
[root@archiso /]# echo vboxsf > /etc/modules-load.d/vbox.conf
 +
[root@archiso /]# sed -i -e '/wheel ALL=(ALL) ALL$/ s/^# //' /etc/sudoers
 +
[root@archiso /]# passwd
 +
[root@archiso /]# exit
 +
root@archiso ~ # halt -p
 +
</pre>

Latest revision as of 14:03, 19 April 2021

Guides> linux > Install Linux in a virtual machine

NOTE: These instructions are not canonical. There are many ways of installing Linux, but this will get you a running system that you can play with.

Download the install media here.


Boot the virtual install media

Select your virtual machine from the list. Click "Settings". Select "Storage". Under the "Controller: IDE" heading, select the stylized DVD labeled "Empty". In the right pane (labeled Attributes), on the line labeled "Optical Drive", click the button with the stylized DVD. Select "Choose Virtual Optical Disk File..." Navigate to and select the install media you just downloaded. Click Ok.

Click the big green arrow labeled "Start".

You'll see a menu show up: hit Enter to select the default option, "Boot Arch Linux (x86_64)".

A bunch of opaque nonsense will fly by and eventually you'll be presented with a prompt that looks something like this:

Arch Linux 5.4.8-arch1-1-ARCH (tty1)

archiso login: root (automatic login)

root@archiso ~ # _

This tells you that you've been automatically logged in as the user "root" on the machine called "archiso" and that your current working directory is "~" (i.e., root's home directory). The "#" is the prompt awaiting input. The "\_" is the cursor. (The name of the program awaiting input is not Linux itself, but rather a program Linux has started for you, precisely to accept your input and do your bidding. This program is called the *shell*.)

Prepare disk

Before you can install anything on the virtual disk inside your virtual machine, you need to partition it and format the partition.

Use the `fdisk` program to partition the disk, referred to as `/dev/sda`.

root@archiso ~ # fdisk /dev/sda

You'll see some mildly informative messages and then a different prompt indicating that `fdisk` (rather than the shell) is awaiting input. Like the shell, `fdisk` expects you to enter a command (most are one letter) followed by Enter.

Command (m for help): _

Enter the command "n" to create a new partition; select "p" to make it a primary partition; with the partition number "1"; the default first sector and the default last sector. (For any of these, you can press enter to pick the default instead of actually typing the option explicitly.) Here's a transcript from my run through these steps:

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):
First sector (2048-33554431, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-33554431, default 33554431):

Created a new partition 1 of type 'Linux' and of size 16 GiB.

Note that for first sector and last sector I just hit enter to pick the default. Some of the exact numbers might be different depending on the size of the virtual hard drive you created previously.

You should now be back at the `fdisk` prompt. Enter "p" to print the partition table; the list of partitions at the end should look very similar to this:

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1        2048 33554431 33552384  16G 83 Linux

If it doesn't, enter the command "d" to delete the partition and re-create it according to the instructions in the previous pair of paragraphs.

Once all is well, enter the command "w" to write the partition table to disk and exit `fdisk`. Upon doing so, you should once again see the shell prompt.

Now format the partition you just created:

root@archiso ~ # mkfs.ext4 /dev/sda1

And then make that formatted partition available to the running system:

root@archiso ~ # mount /dev/sda1 /mnt

Install and configure

Install the base set of packages into the virtual drive. This is the bare minimum of software required for a running system (base), along with the graphical environment (XFCE), some tools to make running inside VirtualBox easier (virtualbox-guest-utils), code that gets the system up and running (grub), and the program that lets you run *other* programs with elevated privileges (sudo).

root@archiso ~ # pacstrap -c /mnt base xfce4 xorg-server virtualbox-guest-utils ttf-dejavu dhcpcd grub sudo man man-pages

The preceding command will produce an error if you mistype any of the package names. For instance, if I misspell "sudo" as "sud" it will complain at me like so:

error: target not found: sud
==> ERROR: Failed to install packages to new root
1 root@archiso # _

If you see such an error, press the up arrow to bring up the previous command, fix the typo, and re-run the command. When successfully complete, it will print a message telling you how long it took, followed by a new prompt, e.g.:

pacstrap -c /mnt base xfce4 xorg-server grub   38.73s user 16.03s system 80% cpu 1:07.99 total
root@archiso # _

Now you're ready to make sure the partition you've just created gets mounted at runtime:

root@archiso ~ # genfstab -p /mnt >> /mnt/etc/fstab

Your new installation is located at /mnt. Start up a new shell that thinks its whole world is the collection of files under /mnt, called a *chroot*. (Normally you'd just use the `chroot` program, but for this particular purpose, there are some other things that need to happen, so the Arch Linux maintainers have wrapped the raw chroot command up in the bigger script you'll be running.)

root@archiso ~ # arch-chroot /mnt

On success, your prompt should change to a stripped-down version (because this is a shell running in a stripped-down environment, and thus hasn't been customized to show things like username, hostname, and current working directory):

[root@archiso /]#

Replace "middlinux" in the following command to set the computer name to anything you like (though limit yourself to lowercase letters, numbers, and underscore).

[root@archiso /]# echo middlinux > /etc/hostname

Set the timezone. (This assumes the hardware clock on the host machine is set to UTC rather than localtime. It's entirely probable this assumption is invalid; we can deal with it later, it's not a big deal even if it's never fixed.) The `date` command should show the correct timezone.

[root@archiso /]# ln -snf /usr/share/zoneinfo/US/Eastern /etc/localtime
[root@archiso /]# date

Set up localization. The sed command uncomments all lines that contain the string "en_US", thus enabling US-centric English-language localization, as opposed to British (en_UK), Australian (en_AU), or Canadian (en_CA); or, alternatively, completely different locales like China (zh_CN, zh_HK, zh_TW, etc).

[root@archiso /]# mv /etc/locale.gen /etc/locale.gen.pacnew
[root@archiso /]# sed -ne '/^#en_US/ s/^#//p' /etc/locale.gen.pacnew > /etc/locale.gen
[root@archiso /]# locale-gen
Generating locales...
  en_US.UTF-8... done
  en_US.IDO-8859-1... done
Generation complete.
[root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf


Edit our boot environment creation script, to avoid unruly bugs.

[root@archiso /]# sed -i -e '/^MODULES=/ s/()/(i915)/' /etc/mkinitcpio.conf


Create the initial boot environment, customized to your particular system. (You will probably see a couple warnings about possibly missing firmware: you can ignore these.)

[root@archiso /]# mkinitcpio -p linux
(lots of messages)

Install and configure the bootloader.

[root@archiso /]# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux
Found initrd image(s) in /boot: initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
done

Make sure networking starts at boot. (The last letter of the first word is the letter ell, *not* the number one.)

[root@archiso /]# systemctl enable dhcpcd@enp0s3
Created symlink
/etc/systemd/system/multi-user.target.wants/dhcpcd@enp0s3.service -> /usr/lib/systemd/system/dhcpcd@.service

Enable some VirtualBox-specific services.

[root@archiso /]# systemctl enable vboxservice
/etc/systemd/system/multi-user.target.wants/vboxservice.service -> /usr/lib/systemd/system/vboxservice.service
[root@archiso /]# echo vboxsf > /etc/modules-load.d/vbox.conf

Configure sudo, which allows one user to run a program using the privileges of another. (Usually used to perform administrative activities without having to log out and log back in as root.) The following `sed` command reads the file `/etc/sudoers`, searches for all lines that contain the string within the first pair of forward slashes, and removes the leading # and space from those lines.

[root@archiso /]# sed -i -e '/wheel ALL=(ALL) ALL$/ s/^# //' /etc/sudoers

Set the root (superuser, administrator) password and exit from the chroot. (Note that it won't even print asterisks to let you know you're typing.)

[root@archiso /]# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
[root@archiso /]# exit

It should print an account of the time you spent in the chroot and then the prompt should now revert to what it was before:

exit
arch-chroot /mnt  10.96s user 2.74s system 5% cpu 4:26.84 total
root@archiso ~ #

Remove the virtual install media from the virtual drive

Shut down the system:

root@archiso ~ # halt -p

Now, in the VirtualBox UI, select your virtual machine from the list. Click "Settings". Select "Storage". Under the "Controller: IDE" heading, select the stylized DVD labeled with the name of the install media. To the right, click the stylized DVD with the little down-arrow. Select "Remove Disk from Virtual Drive". Click Ok.


Congratulations

Proceed to your first boot.


Commands Only

The below commands are just the instructions from above, without any annotation.

root@archiso ~ # fdisk /dev/sda
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):
First sector (2048-33554431, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-33554431, default 33554431):

Created a new partition 1 of type 'Linux' and of size 16 GiB.

Command (m for help: w
root@archiso ~ # mkfs.ext4 /dev/sda1
root@archiso ~ # mount /dev/sda1 /mnt
[root@archiso /]# pacstrap -c /mnt base xfce4 xorg-server virtualbox-guest-utils ttf-dejavu dhcpcd grub sudo man man-pages
[root@archiso /]# genfstab -p /mnt >> /mnt/etc/fstab
[root@archiso /]# arch-chroot /mnt
[root@archiso /]# echo middlinux > /etc/hostname
[root@archiso /]# ln -snf /usr/share/zoneinfo/US/Eastern /etc/localtime
[root@archiso /]# date
[root@archiso /]# mv /etc/locale.gen /etc/locale.gen.pacnew
[root@archiso /]# sed -ne '/^#en_US/ s/^#//p' /etc/locale.gen.pacnew > /etc/locale.gen
[root@archiso /]# locale-gen
[root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf
[root@archiso /]# sed -i -e '/^MODULES=/ s/()/(i915)/' /etc/mkinitcpio.conf
[root@archiso /]# mkinitcpio -p linux
[root@archiso /]# grub-install /dev/sda
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg
[root@archiso /]# systemctl enable dhcpcd@enp0s3
[root@archiso /]# echo vboxsf > /etc/modules-load.d/vbox.conf
[root@archiso /]# sed -i -e '/wheel ALL=(ALL) ALL$/ s/^# //' /etc/sudoers
[root@archiso /]# passwd
[root@archiso /]# exit
root@archiso ~ # halt -p