Tuesday, December 25, 2012

Archlinux VM Installation + LVM

Setup the disks

# fdisk /dev/sda
-> n
[enter] x3 
[enter] x1

-> n
[enter] x4

-> a
-> 1
-> t
-> 2
-> 8e
-> w

Explanation: /dev/sda means device scsi disk a. The 'a' is just a military numbering (alpha, bravo, charlie, etc). A second hard disk would be /dev/sdb, a third /dev/sdc. etc.

fdisk is a tool that is used to partition the hard disk. Using fdisk we created two Linux partitions, /dev/sda1 & /dev/sda2. We assigned /dev/sda1 as the boot partition and labelled /dev/sda2 as Linux LVM. The boot partition is where the boot loader checks for the operating systems boot files, without it your OS would never start.

Make the filesystems & build directories

# mkfs.ext4 /dev/sda1
# pvcreate /dev/sda2
# vgcreate rootvg /dev/sda2
# lvcreate -C y -L 1G rootvg -n swaplv00
# mkswap /dev/mapper/rootvg-swaplv00
# swapon /dev/mapper/rootvg-swaplv00
# lvcreate -l +100%FREE rootvg -n rootlv00
# mkfs.ext4 /dev/mapper/rootvg-rootlv00 
# mount /dev/mapper/rootvg-rootlv00 /mnt
# mkdir /mnt/boot
# mount /dev/sda1 /mnt/boot

Explanation: mkfs is building ext4 filesystems on sda1. Since we want to use LVM we have to setup our lvm physical volumes, volume groups and logical volumes before creating the filesystem. First we create a 1G swap LV. Arch has a small footprint, my default VM has 256MB of RAM. A 1G swap is more than enough (Usually Size=Ramx2).

The remaining free space is used for the root logical volume. The swap and mkfs commands for the lvm drives are ran on the lvm devices (/dev/mapper...) not the physical (/dev/sda2) device.

When finished, the rootlv will be mounted /mnt and the boot partition mounted to /mnt/boot.

Install the base operating system

# pacstrap /mnt base base-devel

Explanation: base is the base OS package, base-devel are the development packages. I install the devel package because it suits my needs afterwards. base-devel is optional. 

Go make some popcorn =)

Install the bootloader

# arch-chroot /mnt pacman -S grub-bios

Explanation: Change root grub install

Configure the Operating System

# genfstab -p /mnt >> /mnt/etc/fstab

in /etc/fstab change /dev/dm-3 to /dev/mapper/rootvg-swaplv00
Edit* This has been corrected in the 2012.12 release of arch (https://github.com/falconindy/arch-install-scripts/commit/3a7eb157d11cd822)

# arch-chroot /mnt
# echo "hostname" >> /etc/hostname
# ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

Delete the # in front of en_US in /etc/locale.gen
# locale-gen

In /etc/mkinitcpio.conf add "dm_mod" to MODULES="..." and "lvm2" to HOOKS="base udev ... filesystem" where the "..." is located (Anywhere in MODULES, between base udev and filesystem in HOOKS). 

# mkinitcpio -p linux

Explanation: Generate an fstab, the lvm swap lv won't generate properly in fstab. Arch will still start if this isn't correct but will take significantly longer to load. Change root to /mnt and save our hostname. Then we add the hooks and module for loading lvm at boot. Then we create the initial ramdisk.

Configure the Boot Loader

# modprobe dm-mod
# grub-install /dev/sda
# cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo
# grub-mkconfig -o /boot/grub/grub.cfg
# passwd 

Set a root password

Ctrl+D to go back to the Live CD. 

# umount /mnt/boot
# umount /mnt
# reboot

Explanation: This sets up grub. When I started with Arch I would skip this part and be stuck scratching my head. Afterwards set a new root password, exit back to the Live CD, unmount and reboot in to a brand new Arch install.

No comments:

Post a Comment