<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2020W_Lecture_10</id>
	<title>Operating Systems 2020W Lecture 10 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2020W_Lecture_10"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_10&amp;action=history"/>
	<updated>2026-06-02T22:26:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_10&amp;diff=22575&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video from the lecture given on February 7, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec10-20200207.m4v is now available...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_10&amp;diff=22575&amp;oldid=prev"/>
		<updated>2020-03-20T02:34:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video from the lecture given on February 7, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec10-20200207.m4v is now available...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on February 7, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec10-20200207.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 10&lt;br /&gt;
----------&lt;br /&gt;
Topics:&lt;br /&gt;
 - VM issues&lt;br /&gt;
 - signals and sleep&lt;br /&gt;
 - filesystems&lt;br /&gt;
 - mount&lt;br /&gt;
 - dd&lt;br /&gt;
 - superblocks, inode blocks, data blocks&lt;br /&gt;
 - fsck&lt;br /&gt;
 - sshfs&lt;br /&gt;
&lt;br /&gt;
On the VMs, the root filesystem is on /dev/mapper/COMPbase--vg-root,&lt;br /&gt;
this is an LVM volume.  LVM is the Logical Volume Manager&lt;br /&gt;
 - allows you to combine multiple disks and partitions into one&lt;br /&gt;
   virtual device&lt;br /&gt;
 - really not needed for a simple VM, but ubuntu defaults to using one&lt;br /&gt;
&lt;br /&gt;
We want to play with filesystems&lt;br /&gt;
 - but we don&amp;#039;t have external devices we can add easily&lt;br /&gt;
   (at least on openstack currently)&lt;br /&gt;
 - so we want to make filesystems in files&lt;br /&gt;
   - treat a file like a block device&lt;br /&gt;
 - normally you don&amp;#039;t do this, but it can be useful&lt;br /&gt;
   - this is how virtual machine disks are implmented&lt;br /&gt;
&lt;br /&gt;
To use a new filesystem:&lt;br /&gt;
 - prepare the block device (plug in USB stick, or make an empty file)&lt;br /&gt;
 - create a filesystem on the block device&lt;br /&gt;
 - mount the new filesystem on a chosen mount point (an empty directory)&lt;br /&gt;
&lt;br /&gt;
The dd command:&lt;br /&gt;
 - allows you to copy from an input file to an output file&lt;br /&gt;
 - key feature is it allows you to specify the number of &amp;quot;blocks&amp;quot;&lt;br /&gt;
   to copy and how big they should be&lt;br /&gt;
 - a block to dd is just the size of the buffer to use when reading&lt;br /&gt;
   and writing&lt;br /&gt;
 - so if bs=4096 and count=10, then dd will issue 10 reads and 10 writes,&lt;br /&gt;
   each reading or writing with a 4096 byte buffer (asking to read 4096 bytes&lt;br /&gt;
   and writing up to 4096 bytes depending on how many were read)&lt;br /&gt;
&lt;br /&gt;
Why can&amp;#039;t we just do &amp;quot;cp /dev/zero newfile&amp;quot; rather than&lt;br /&gt;
  dd if=/dev/zero of=newfile bs=4096 count=10000&lt;br /&gt;
&lt;br /&gt;
We can&amp;#039;t use cp because you can&amp;#039;t copy a character device.  It will potentially&lt;br /&gt;
provide an infinite amount of data.  So we use dd to control how much&lt;br /&gt;
we read and how those reads are done.&lt;br /&gt;
&lt;br /&gt;
Yes there are other ways to make a file with zeros, but dd is generally useful&lt;br /&gt;
  - can fill a file with random bytes by reading from /dev/urandom&lt;br /&gt;
  - can manipulate arbitrary portions of large files (copy, erase)&lt;br /&gt;
  - very useful for directly reading from and writing to actual devices&lt;br /&gt;
    (hard disks, etc)&lt;br /&gt;
&lt;br /&gt;
(We will be making our own character devices later in this term)&lt;br /&gt;
&lt;br /&gt;
Remember that device files have their own implementation of read,&lt;br /&gt;
write, etc.  They can do anything, including return random bytes or&lt;br /&gt;
zeros (or digits of pi).&lt;br /&gt;
&lt;br /&gt;
mount: add filesystem to filesystem hierarchy&lt;br /&gt;
&amp;quot;mount fs dir&amp;quot; means make the files in filesystem fs appear under directory dir&lt;br /&gt;
&lt;br /&gt;
dir was an empty directory before, but after this command all the files in fs&lt;br /&gt;
will appear in it&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 - if you insert a USB stick on an ubuntu system, you&amp;#039;ll see its files&lt;br /&gt;
   appear in /media/&amp;lt;user&amp;gt;/&amp;lt;device name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
mass storage devices have &amp;quot;less&amp;quot; storage than advertised because they&lt;br /&gt;
advertise storage in base-10 units but we use base-2 in practice&lt;br /&gt;
e.g., difference between 1000 (10^3) versus 1024 (2^10).  Difference&lt;br /&gt;
gets really big when we talk about gigabytes and up!&lt;br /&gt;
&lt;br /&gt;
(But we also lose some space due to filesystem overhead, by default ext4&lt;br /&gt;
reduces available space by 5% so it always has some extra space to play with.  The root user can use this reserved space and you can change it.)&lt;br /&gt;
&lt;br /&gt;
When we treat a file as a block device, we do this by associating it with&lt;br /&gt;
a &amp;quot;loopback&amp;quot; block device, e.g. /dev/loop0.  You don&amp;#039;t have to play with this&lt;br /&gt;
device directly, normally it is allocated for us automatically (but&lt;br /&gt;
shows up when we do df).&lt;br /&gt;
&lt;br /&gt;
one key reason we make filesystems is to provide isolation&lt;br /&gt;
 - when you fill up a USB stick you don&amp;#039;t fill up your main filesystem&lt;br /&gt;
 - similarly, when you fill up a virtual disk, it won&amp;#039;t fill up the rest&lt;br /&gt;
   of the system, it will just use up the maximum space the virtual disk could&lt;br /&gt;
&lt;br /&gt;
Imagine running a program so it only had access to the files in a special&lt;br /&gt;
virtual filesystem&lt;br /&gt;
 - it literally couldn&amp;#039;t see anything else, let alone mess with anything else&lt;br /&gt;
 - snaps, containers are built around this idea&lt;br /&gt;
&lt;br /&gt;
You can manipulate the parameters of a filesystem with utilities&lt;br /&gt;
 - for ext4, you can use e2label (to give/change its name) or other&lt;br /&gt;
   parameters using tune2fs (e.g., how much space is reserved for the root user)&lt;br /&gt;
&lt;br /&gt;
In a UNIX filesystem, the blocks are divided between three types&lt;br /&gt;
 - data blocks (contents of files)&lt;br /&gt;
 - inode blocks (file metadata)&lt;br /&gt;
    - directory blocks are normally a kind of inode block&lt;br /&gt;
 - superblocks&lt;br /&gt;
&lt;br /&gt;
Superblocks have metadata about whole filesystems (rather than individual files)&lt;br /&gt;
 - what type of filesystem (ext4? vfat?)&lt;br /&gt;
 - what are the parameters of the fs (how big?  block size?  how many inodes?)&lt;br /&gt;
 - if you lose the superblock you lose the filesystem&lt;br /&gt;
   - which is why you normally have backup superblocks&lt;br /&gt;
&lt;br /&gt;
Normally a filesystem will take up an entire device (so mkfs.ext4 asks&lt;br /&gt;
the kernel how big the device is and adjusts accordingly).  We control&lt;br /&gt;
it for virtual filesystems by controlling how big of a file we&lt;br /&gt;
allocate (with dd or similar).&lt;br /&gt;
&lt;br /&gt;
losing a superblock means erase or corrupt.  It isn&amp;#039;t quite delete&lt;br /&gt;
because you can&amp;#039;t add or remove blocks from a device once created (how do you &amp;quot;grow&amp;quot; a USB stick?)&lt;br /&gt;
&lt;br /&gt;
Note that filesystems are complex data structures.  If you look up a&lt;br /&gt;
filesystem&amp;#039;s superblock and low-level format, expect to find way more&lt;br /&gt;
info than you might otherwise expect!&lt;br /&gt;
&lt;br /&gt;
Note that a filesystem&amp;#039;s blocksize might not match the block size of&lt;br /&gt;
the underlying device&lt;br /&gt;
 - but normally it will be a multiple of it, e.g.&lt;br /&gt;
   the device has a block size of 1024 but the filesystem&amp;#039;s block size is&lt;br /&gt;
   4096&lt;br /&gt;
 - need to be able to easily translate between device blocks and&lt;br /&gt;
   filesystem blocks&lt;br /&gt;
&lt;br /&gt;
If you delete the primary superblock (which is either block 0 or 1 of most filesystems), you&amp;#039;ll make the filesystem unmountable.&lt;br /&gt;
 - but you can recover by repairing the filesystem using a backup superblock&lt;br /&gt;
 - fsck can normally do it, but you may have to tell it where to find&lt;br /&gt;
   the backup superblock&lt;br /&gt;
&lt;br /&gt;
Superblocks don&amp;#039;t change often (and what changes is not too important), so they don&amp;#039;t have to be update all the time.  They are there for disasters&lt;br /&gt;
&lt;br /&gt;
Filesystems should be recoverable, a feature that isn&amp;#039;t needed of most data&lt;br /&gt;
structures&lt;br /&gt;
 - the data structures you&amp;#039;ve studied, how well do they deal with&lt;br /&gt;
   corrupted or deleted pointers?  generally not well!&lt;br /&gt;
 - filesystems are tolerant of such problems because storage can go bad&lt;br /&gt;
&lt;br /&gt;
Note that tools like fsck *are not* data recovery tools&lt;br /&gt;
 - they try to save the filesystem, not files&lt;br /&gt;
 - they can delete files in order to restore integrity to a filesystem&lt;br /&gt;
&lt;br /&gt;
If a filesystem is corrupted, *never* write to it.  Instead,&lt;br /&gt;
 - get your data off the filesystem&lt;br /&gt;
 - THEN try to repair it&lt;br /&gt;
&lt;br /&gt;
A great tool for copying data off a failing disk is dd&lt;br /&gt;
 - can get a raw filesystem image that can later be examined using&lt;br /&gt;
   advanced tools&lt;br /&gt;
 - there are fancy versions of dd that can get data even when&lt;br /&gt;
   reads fail on parts of the disk&lt;br /&gt;
&lt;br /&gt;
Most of the time nowadays, if a device has errors, the device should&lt;br /&gt;
be thrown away (recycled)&lt;br /&gt;
 - there are low-level errors all the time on modern storage devices&lt;br /&gt;
 - these errors are hidden by the device controllers&lt;br /&gt;
 - when they can no longer hide the errors, that means there are too many&lt;br /&gt;
   to hide, so the device is going bad fast -&lt;br /&gt;
   GET YOUR DATA OUT ASAP and replace!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Professional data recovery people can recover data when drives have been damaged in all kinds of ways&lt;br /&gt;
 - they charge for this&lt;br /&gt;
 - and they have real limits&lt;br /&gt;
 - HAVE BACKUPS&lt;br /&gt;
&lt;br /&gt;
When you run fsck, it may find inodes that are allocated but have no&lt;br /&gt;
hard links to them&lt;br /&gt;
 - file contents without a filename&lt;br /&gt;
&lt;br /&gt;
fsck will gives these inodes a name, e.g. for inode 5200 it will create&lt;br /&gt;
/lost+found/#5200&lt;br /&gt;
&lt;br /&gt;
If you find files in lost and found, it means fsck put them there&lt;br /&gt;
 - which means your filesystem was corrupted, but maybe is okay now?&lt;br /&gt;
 - hope you had backups!&lt;br /&gt;
&lt;br /&gt;
A filesystem are a set of files that are accessed using common code, with&lt;br /&gt;
all the files under a mountpoint&lt;br /&gt;
 - most commonly on a device (e.g. hard drive)&lt;br /&gt;
 - but can be virtual (/proc)&lt;br /&gt;
 - and can be remote (nfs, samba/cifs, ceph, sshfs)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>