Lesson 6: Boot and the Filesystem Hierarchy
Note
- grub, filesystem stuff based roughly on Frostsnow's talk
- basics of kernel and differences between virtualization/physical (the picture that kevin draws)
Note
Note
Based on Wade's talk https://github.com/clinew/presentation_filesystems/blob/master/presentation.tex
What's a filesystem?
In computing, a file system is used to control how information is stored and retrieved. Without a file system, information placed in a storage area would be one large body of information with no way to tell where one piece of information stops and the next begins.
Note
Moving from Windows?
$ ls
bin etc initrd.img.old lost+found opt run srv usr
boot home lib media proc sbin sys var
dev initrd.img lib64 mnt root selinux tmp vmlinuz
/bin /usr/sbin
/sbin /usr/local/bin
/usr/bin /usr/local/sbin
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ which bash
/bin/bash
Configurations in dotfiles within home (/.)
$ dmesg | tail
[260930.208715] sdb: sdb1
[260930.320756] sd 6:0:0:0: >[sdb] Asking for cache data failed
[260930.320765] sd 6:0:0:0: >[sdb] Assuming drive cache: write through
[260930.320771] sd 6:0:0:0: >[sdb] Attached SCSI removable disk
USB filesystem under /media, main disk /
/etc/fstab tells things where to mount
/etc/mtab shows where things are currently mounted
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda8 73G 29G 41G 42% /
$ du -sh /home/
21G /home/
/, essential for system booting and mounting /usr.
/usr, read-only system data for normal system operation.
Directory | Contents |
---|---|
/bin | Binary files |
/include | Header files for C/C++ programs |
/lib | Libraries |
/sbin | Binary files for root (superuser) |
/boot | Files essential for booting kernel, initramfs |
/dev | Virtual filesystem, exports hardware devices |
/etc | System-wide configurations |
/home | Individual users' data |
/media | Removable storage devices |
/mnt | Like media -- place to mount disks and things |
Directory | Contents |
---|---|
/opt | "Add-on application software packages" |
/proc | Virtual filesystem exporting system data |
/root | homedir for root |
/run | Volatile information accumulated since boot |
/sys | Virtual filesystem exporting kernel objects |
/tmp | Temporary files |
/var | Data which varies -- logs, mail, etc. |
/usr/share | Architecture-independent, read-only data |
/usr/src | Kernel source code |
Which Linux kernel version are you running?
$ cat /proc/version
Linux version 3.5.0-17-generic (buildd@allspice) (gcc version 4.7.2
(Ubuntu/Linaro 4.7.2-2ubuntu1) ) #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012
Learn about system's hardware
$ less /proc/cpuinfo
$ less /proc/meminfo
Some parts of /proc can be written as well as read...
$ echo 3 > /proc/sys/vm/drop_caches # drop caches
Creating filesystems
$ mkfs
Mounting filesystems
$ mount
# -t for type
# -o for options
# requires device path and mount point
Loopback devices
$ losetup
$ /dev/loop*
# makes it look like a device instead of a file
sd*
sr*
/dev/null
/dev/random
/dev/urandom
/dev/zero
Block size is the size of chunks allocated for files
$ dd if=/dev/random of=/dev/sda
# What will this do?
Filesystem consistency tool; protections against system freezes, power outages, etc.
Replaying the journal.
ext3’s three modes of journaling:
journal: | Data and metadata to journal. |
---|
ordered: | Data updates to filesystem, then metadata committed to journal. |
---|
writeback: | Metadata comitted to journal, possibly before data updates. |
---|
Note
kernel loaded into memory, initialization tasks, and available to users
Note
Note
Note
grub> root (hd0,0) (Specify where your /boot partition resides)
grub> setup (hd0) (Install GRUB in the MBR)
grub> quit (Exit the GRUB shell)
grub-install
Note
Typically ask for root password
- Troubleshoot problems
- Manual Filesystem Checks
- Booting with bare services
- Fix boot problems
- Add “single” to kernel option
Note
Verbose and print out description of what its doing.
Old days were to manually adjust scripts, not anymore. Most are configurable now.
Note
Run levels:
level 0 | sys is completely down (halt) |
level 1 or S | single-user mode |
level 2 through 5 | multi-user levels |
level 6 | reboot level |
Note
Look at inittab
# The default runlevel.
id:2:initdefault:
# What to do in single-user mode.
~~:S:wait:/sbin/sulogin
# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
# terminals
1:2345:respawn:/sbin/getty 38400 tty1
T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
Note
$ service sshd status
openssh-daemon (pid 1186) is running...
$ service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
Note
Show sshd script show list, adding, removing, enabling, disabling
$ chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ chkconfig sshd off
$ chkconfig --list sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Note
show sendmail & network config examples for CentOS
/etc/defaults seems to be more common between UNIX's
$ cat /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
Note
Modern systems are less touchy with hard resets, but still need to be careful. Only for emergencies.
Shutdown -h
$ wall hello world
Broadcast message from root@devops-bootcamp (pts/0) (Fri Jan 31 00:40:29 2014):
hello world