You are on page 1of 30

Please sit at a desktop and

find a partner

(2 people per desktop)


Setting Up a Linux
System
Part 1 - Base Installation
Overview

● Booting into an installation media


● Verifying the new system
● Install the OS

● Hope it all works


Overview

● Install the OS
a. Partition disks
b. Choose filesystems
c. Install base system
d. chroot, initial system configuration
i. root password, /etc/network/interfaces
Installation Media
● CD/DVD
○ Old school: burn an ISO with a full system on it, set BIOS to boot from the disk, then run scripts
that basically copy the CD’s contents to your HDD and set up the new system
● USB live media
○ Same as above, but on a flash drive (most common at home)
● PXE
○ Pre-boot eXecution Environment
○ Retrieve an executable environment using DHCP and TFTP, boot that, and use that to
bootstrap the rest of the booting process.
● Netboot
○ Don’t install anything, don’t use a disk. Load kernel into memory over the network, everything
happens in memory. All state is volatile.
Live Activity:

PXE Boot Your Desktop


How does booting actually work?
1. MB signals PSU to supply power, which triggers MB to start CPU
2. CPU resets, performs Power-On Self Test, loads BIOS into memory
3. BIOS selects boot method, e.g. block storage, network
a. Block: BIOS reads first sectors of disk which contain MBR/GPT metadata, executes data from
here to load into 2nd-stage bootloader
b. Network: BIOS has NIC gain network access (DHCP) and requests netboot, then uses TFTP
to download/unpack kernel and initrd directly into memory, uses this as 2nd-stage bootloader
4. 2nd-stage bootloader (e.g. GRUB) takes over, reads config for OS location,
loads kernel into memory and jumps to kernel init
a. e.g. drivers for encryption, LVM, different filesystems, peripherals
Verifying the new system
Want to make sure you’re doing the right thing before you
accidentally (permanently) screw something up or waste a lot
of time

● Examples:
○ making sure you’re on the right machine
○ making sure you’re on the right drive or partition
○ making sure your hardware works, like memory, NIC, etc.
Install Process
1. Optionally configure language and keyboard right now
2. Navigate to “Configure Network”
3. Select “yes” when asked to autoconfigure network
a. This is DHCP - the NIC will make an L2 request for IP address, netmask, DNS server and set
this for you.
b. Look at the config files before clicking through - they should be:
i. IP Address, Hostname
ii. Domain - this is the default DNS search domain
4. Choose mirror: select “mirrors.ocf.berkeley.edu”
5. Download installer components: look through the options but don’t select
anything before clicking through. Ask questions if you’re curious.
6. Configure the clock: put “ntp1.ocf.berkeley.edu”
Complete Install Steps
Until

“Partition Disks”
Partitioning
● Each storage device on your computer is divided into “partitions”
○ Fixed-size subset of disk treated by OS as a single unit
● This happens below the filesystem level
● Ex.
○ GUID Partition Table
○ Master Boot Record
● Disks need to be partitioned before you can install a FS on a partition

● This is necessary because the partition map tells the bootloader where to find
the boot/root partitions/filesystems
Example: dkessler’s laptop, SSD
Example: dkessler’s laptop, HDD
OCF Hypervisor (jaws)
Explanation

/dev/mdxxx - mdadm raid array virtual device

● /dev/md0p1 - root partition (where OS is installed)

● /dev/md0p2 - swap partition (recall 61C, CS162)

● /dev/md0p3 - Linux LVM volume group - virtual partitioning


Partition Disks

(guided)
Filesystems (Old, Inferior, Inferior)
● FAT32: ubiquitous, probably used on your flash drive/SD card
○ File Allocation Table
○ Very old, with a simple implementation; understood by almost any
computer made since 1996
○ Max file size of 2GB
○ Take CS162 to learn how it works

● NTFS: used on Windows computers (New Technology File System)

● APFS: introduced in 2017, used by many Apple products


○ Has special optimizations for solid-state drives and encryption
Linux Filesystems

ext4
● ext3, ext4: most common Linux filesystem family, ext4 stable in ‘08
● Workhorse, general-purpose filesystem with support for
○ Journaling - action log that helps prevent corruption from crashes
○ Extents - range of blocks, take 162
○ Checksumming
○ Nanosecond timestamps
● Solid choice if you don’t have more specific needs
○ Google uses ext4 as the on-disk FS below Colossus/GFS
More filesystems - btrfs (B-Tree FS)
● Dev. by Oracle, stable but relatively experimental
● Fancy tech: copy-on-write, compression, online expansion (!), in-place
upgrade from ext4
● “subvolumes”: ~lightweight partitions/block devices
● Snapshots: CoW = lightweight backups of only deltas between files
● Copy-on-write can be dangerous though -- has bad performance for
certain types of files, like VM disks, where lots of things are changed
all over
● Generally used by adventurous Linux users on their personal
machines
More filesystems
● ReiserFS
○ Invented by Hans Reiser, a co-founder of the OCF!
○ Efficiently handles small files - can be 10-15x faster than ext3
○ Sometimes used for the /var folder

● XFS
○ High-performance 64-bit parallel FS designed by SGI, designed for “extreme scalability”
○ Extents, journaling, guaranteed-rate I/O in special cases (!)
○ NASA uses it
○ Red Hat recommends it for 100TB+ clusters
ZFS - The Final Word in File Systems
● “Zettabyte” filesystem - 128 bit addressing = max size of 2 ZB

● Developed by Sun Microsystems in ‘01, bought by Oracle


○ Initially open-source (CDDL). Now closed source, but forks (OpenZFS) exist
○ Binary cannot be distributed in the Linux kernel due to licensing issues
○ ZoL (“ZFS on Linux”) development headed by our own at LBNL

● Integrated filesystem, volume manager, RAID, etc.

● Many of the benefits of btrfs: checksumming, CoW, snapshots, first class block
devices (ZVOLs), FS-managed RAID (raidz), online expansion in the works
Special Filesystems
● Swap
○ Special partition/FS used for virtual memory management and paging
○ Take CS 162
● Tmpfs
○ Looks like a mounted directory but data is only in RAM. Lost on reboot.
○ Used on OCF desktops for home directories
● /proc
○ Special filesystem giving a file-like object view into processes on UNIX-like systems
○ This is where `ps` etc. get their data from
● /sys
○ pseudo-FS provided by Linux that gives information about the kernel and subsystems,
hardware devices, drivers, etc.
● /dev
○ devfs provides a file-like view of block devices, generated by udev from sysfs
Install!
Installing the Base System
Time to install the OS!
Critical Locations:

● / (root partition, contains directories for the FS hierarchy)


● /boot (where kernel, initrd, GRUB modules are stored)
● /bin, /sbin, /usr/bin, /usr/sbin: (static/superuser) binaries)
● /etc - configuration info
● /var - runtime info, -> /var/lib, /var/cache, /var/run
● /proc, /sys, /dev already explained
Installing the Base System
What happens when you click “Install System?”

1. Underneath, “debootstrap” - copies contents of a Debian root into your newly


provisioned storage, all binaries and base configs
2. Installs a
a. kernel - (/boot/vmlinuz*)
b. initrd (/boot/initrd.img*)
c. init system (systemd)
d. package manager (dpkg, apt)
e. minimal set of useful packages (base-files, etc.)
3. `chroot` into the new root FS, mount /proc, /sys, /dev, initial config
a. Network config, set hostname, etc.
b. Initial users - set root password, make users, etc.
Final Install Notes
● NTP?
○ Network Time Protocol helps deal with “clock skew” - result of internal clocks slowly getting out
of sync due to random fluctuation, load, etc.

○ Accurate time is critical for many things - databases, synchronous networked tasks (distributed
computing), encryption, etc.

● Locales?
○ America is #1, but other countries insist on doing things the non-freedom way

○ Locales configure location-specific settings like number/date formats, currency, paper size,
keyboard layout,
Further reading for the curious
● For uses of swap besides “what happens when RAM runs out”:
https://chrisdown.name/2018/01/02/in-defence-of-swap.html

You might also like