Mike Lab 11: Difference between revisions

From ITCwiki
Jump to navigation Jump to search
(Created page with "=Introduction= =Lab Procedure= == Prerequisites == # Open an SSH console to your Linux system using the PuTTY software, login with your standard user account == Exploring /pr...")
 
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Introduction=
=Introduction=
Welcome to Lab 11. This lab will focus on hard disk prep, partitioning, mounting/unmounting partitions, and disk & file usage.
The commands you will be using and exploring include:
lsmod
mount
uname
lsusb
lspci
dmesg
cfdisk
You will also be exploring the /proc directory, /dev directory, and the fstab file.
=Lab Procedure=
=Lab Procedure=
== Prerequisites ==
== Prerequisites ==
Line 5: Line 26:


== Exploring /proc ==
== Exploring /proc ==
# Enter the ''/proc'' directory on your VM. ''/proc'' is a very special folder is its a virtual filesystem. Its sometimes referred to as a process information pseudo-filesystem. The reason for calling it a pseudo-file system is that all of the "files" in ''/proc'' are not really files at all, but kernel runtime configuration and system information.
<ol>
# For example, use '''cat cpuinfo''' to view the contents of the ''/proc/cpuinfo'' "file". Notice how the output tells your information about the CPU that is running the VM. This isn't actually a file at all you are essentially asking the kernel to provide information about the CPU it's running on which it gathers in realtime. ''/proc'' is used not only to get hardware and kernel information, but it can also be used to tweak kernel settings while the system is running in a way similar to some Windows Registry edits. Look back on Lab 10 and notice how we echoed a "1" to a "file" in ''/proc'' to enable packet forwarding without rebooting the system.
<li>Enter the ''/proc'' directory on your VM. ''/proc'' is a very special folder is its a virtual filesystem. Its sometimes referred to as a process information pseudo-filesystem. The reason for calling it a pseudo-file system is that all of the "files" in ''/proc'' are not really files at all, but kernel runtime configuration and system information.</li>
# There are a few files in ''/proc'' you should get to know:
<li>For example, use '''cat cpuinfo''' to view the contents of the ''/proc/cpuinfo'' "file". Notice how the output tells your information about the CPU that is running the VM. This isn't actually a file at all you are essentially asking the kernel to provide information about the CPU it's running on which it gathers in realtime. ''/proc'' is used not only to get hardware and kernel information, but it can also be used to tweak kernel settings while the system is running in a way similar to some Windows Registry edits. Look back on Lab 10 and notice how we echoed a "1" to a "file" in ''/proc'' to enable packet forwarding without rebooting the system.</li>
#* '''/proc/cpuinfo''' = Shows you the CPU info for your machine.
<li>There are a few files in ''/proc'' you should get to know:</li>
#* '''/proc/modules''' = Shows you the currently enabled kernel modules that are active on your kernel.
* '''/proc/cpuinfo''' = Shows you the CPU info for your machine.
#* '''/proc/cmdline''' = Shows you the boot arguments used to boot your kernel.
* '''/proc/modules''' = Shows you the currently enabled kernel modules that are active on your kernel.
#* '''/proc/version''' = Shows you your kernel version.
* '''/proc/cmdline''' = Shows you the boot arguments used to boot your kernel.
# It is important to note that some of these files have commands tied to them that can give you similar information but often formatted in a different way, for example.
* '''/proc/version''' = Shows you your kernel version.
#* '''/proc/modules''' = '''lsmod'''
<li>It is important to note that some of these files have commands tied to them that can give you similar information but often formatted in a different way, for example.</li>
#* '''/proc/mounts''' = '''mount'''
* '''/proc/modules''' = '''lsmod'''
#* '''/proc/version''' = '''uname -a'''
* '''/proc/mounts''' = '''mount'''
# Normally it is best to use the command version to lookup the information as it is normally formatted to be easier to read and understand.
* '''/proc/version''' = '''uname -a'''
# Explore all of these files and commands and find the differences between the command line and file output versions as well as what types of information are available.
<li>Normally it is best to use the command version to lookup the information as it is normally formatted to be easier to read and understand.</li>
<li>Explore all of these files and commands and find the differences between the command line and file output versions as well as what types of information are available.</li>
</ol>
== Exploring /dev ==
== Exploring /dev ==
# Change directories to ''/dev'' and list the "files". Notice there are A LOT, but don't worry, there is organization in the mess. Each "file", like in ''/proc'', is actually a device or interface on the machine so ''/dev'' is actually another pseudo-filesystem. Here is a list of the most common interfaces you will see:
# Change directories to ''/dev'' and list the "files". Notice there are A LOT, but don't worry, there is organization in the mess. Each "file", like in ''/proc'', is actually a device or interface on the machine so ''/dev'' is actually another pseudo-filesystem. Here is a list of the most common interfaces you will see:
Line 30: Line 53:
#* '''lspci''' = List PCI Devices (Bus, Type, Advertised Name, Revision)
#* '''lspci''' = List PCI Devices (Bus, Type, Advertised Name, Revision)
#* '''dmesg''' = Display or Driver Message. This shows kernel messages that are normally linked to adding, or removing devices.
#* '''dmesg''' = Display or Driver Message. This shows kernel messages that are normally linked to adding, or removing devices.


== Adding a 2nd disk ==
== Adding a 2nd disk ==
# As you may have noticed when exploring ''/dev'', our VM setup uses ''sd'' devices for hard drives. Drives are identified by a letter such as ''sda'', ''sdb'', ''sdc'', etc. for the first, second, and third SATA drives on a system (including HDDs, CD/DVDs, SSDs, etc.). Each partition on the drive is then given a number starting with 0 for the first partition. So the first partition on the first disk, the full identifier for the partition would be ''/dev/sda0''.
# As you may have noticed when exploring ''/dev'', our VM setup uses ''sd'' devices for hard drives. Drives are identified by a letter such as ''sda'', ''sdb'', ''sdc'', etc. for the first, second, and third SATA drives on a system (including HDDs, CD/DVDs, SSDs, etc.). Each partition on the drive is then given a number starting with 0 for the first partition. So the first partition on the first disk, the full identifier for the partition would be ''/dev/sda0''.
# You may also have noticed there is an ''sdb'' that currently has no partitions. We are going to format this drive into 2 partitions, format them, and then setup automatic mounting of the partitions.
# You may also have noticed there is an ''sdb'' that currently has no partitions. We are going to format this drive into 2 partitions, format them, and then setup automatic mounting of the partitions.
# To start, run '''cfdisk /dev/sdb''' as root. ''cfdisk'' is a graphical version of ''fdisk'', which is a tool used to setup disk partitioning. Note that ''fdisk'' or any other partitioning software only sets up the MBR, and does not actually format the drive even though you can set a partition type identifier such as '''fat32''', '''Linux''', etc. Also notice how we tell ''cfdisk'' what drive we want to edit the partition on by appending the drive device "file" to the end of the command.
# To start, run the following command as root:
<pre>cfdisk /dev/sdb</pre>
''cfdisk'' is a graphical version of ''fdisk'', which is a tool used to setup disk partitioning. Note that ''fdisk'' or any other partitioning software only sets up the MBR, and does not actually format the drive even though you can set a partition type identifier such as '''fat32''', '''Linux''', etc. Also notice how we tell ''cfdisk'' what drive we want to edit the partition on by appending the drive device "file" to the end of the command.
 
[[File:Linuxpenguin.jpg | 300px]]
 
# Because our new drives contain no existing partitions we are asked what type of partition table to create. Choose to create a ''dos'' (aka ''MBR'') style partition table. Although this is an older style partition table it is well supported by many operating systems and BIOSes. The primary benefit of the newer ''GPT'' style tables is their ability to work with very large drives.
# Because our new drives contain no existing partitions we are asked what type of partition table to create. Choose to create a ''dos'' (aka ''MBR'') style partition table. Although this is an older style partition table it is well supported by many operating systems and BIOSes. The primary benefit of the newer ''GPT'' style tables is their ability to work with very large drives.
# Once in ''cfdisk'', Select the ''New'' option. Now select ''primary'' as we are making a primary MBR partition, then set the size close to ''5GB'' (it doesn't need to be exact).  
# Once in ''cfdisk'', Select the ''New'' option. Now select ''primary'' as we are making a primary MBR partition, then set the size close to ''5GB'' (it doesn't need to be exact).  
Line 40: Line 69:
# At this point we should have two partitions, one named ''sdb1'' with a size of about 5GB (the program will round down to the closest boundary), and ''sdb2'' which takes up the next 2GB or so of the drive. Use the arrow keys to select the ''Write'' option, and press ''enter''. You will be warned that this will write the table to the disk. enter ''yes'', and press ''enter'' again to confirm.
# At this point we should have two partitions, one named ''sdb1'' with a size of about 5GB (the program will round down to the closest boundary), and ''sdb2'' which takes up the next 2GB or so of the drive. Use the arrow keys to select the ''Write'' option, and press ''enter''. You will be warned that this will write the table to the disk. enter ''yes'', and press ''enter'' again to confirm.
# If, on the bottom of the screen, you see "The partition table has been altered", you have successfully written the MBR to the drive. Now you can navigate to ''Quit'' to exit the program.
# If, on the bottom of the screen, you see "The partition table has been altered", you have successfully written the MBR to the drive. Now you can navigate to ''Quit'' to exit the program.
# From the command line run '''ls -al /dev/sd*'''. Notice how you can now see both of the new partitions, ''sdb1'' and ''sdb2'' in the listing. This means the partition device "files" have been created and you are ready to format the partitions with a filesystem.
# From the command line run the following command:
<pre>ls -al /dev/sd*</pre>
Notice how you can now see both of the new partitions, ''sdb1'' and ''sdb2'' in the listing. This means the partition device "files" have been created and you are ready to format the partitions with a filesystem.
# The first partition will be formatted as ''ext4'', and the second partition will be formatted as ''btrfs''. Both filesystems (as well as many others) are commonly used on Linux systems. For more information on the differences and similarities between ''btrfs'' and ''ext4'', refer to your book or Google.
# The first partition will be formatted as ''ext4'', and the second partition will be formatted as ''btrfs''. Both filesystems (as well as many others) are commonly used on Linux systems. For more information on the differences and similarities between ''btrfs'' and ''ext4'', refer to your book or Google.
# To create the ''ext4'' partition, we will use the ''mkfs.ext4'' command. So as root, run the command ''mkfs.ext4 /dev/sdb1''. This will partition the drive as ''ext4'' with no label. If you would like to label the partition, look into the options of ''mkfs.ext4'' using ''man mkfs.ext4''.
# To create the ''ext4'' partition, we will use the ''mkfs.ext4'' command. So as root, run the command
<pre>mkfs.ext4 /dev/sdb1</pre>
This will partition the drive as ''ext4'' with no label. If you would like to label the partition, look into the options of ''mkfs.ext4'' using ''man mkfs.ext4''.
# Before formatting the other partition as ''btrfs'' we need to install some tools. The required tools are part of the ''btrfs-tools'' software package so install that package at this time.
# Before formatting the other partition as ''btrfs'' we need to install some tools. The required tools are part of the ''btrfs-tools'' software package so install that package at this time.
#* Note if you have issues with installing packages, check your firewall rules you created in a previous lab and ensure your Internet access is working properly from the VM.
#* Note if you have issues with installing packages, check your firewall rules you created in a previous lab and ensure your Internet access is working properly from the VM.
# To format the second partition as a ''btrfs'' filesystem partition we will run ''mkfs.btrfs /dev/sdb2''. Just like before, we need to tell the ''mkfs.btrfs'' package what partition to format by including that on the command line.
# To format the second partition as a ''btrfs'' filesystem partition we will run the command:
<pre>mkfs.btrfs /dev/sdb2</pre>
Just like before, we need to tell the ''mkfs.btrfs'' package what partition to format by including that on the command line.
# There are many other options that can be set for specific filesystems during the formatting process. For example, many newer large drives use 4096 byte "Advanced Format" sectors instead of the traditional 512 byte hard drive sectors. Using these disks most efficiently requires adjusting the sector size during the format process to match the physical sector size on the disk. Other features and filesystems include the ability to take snapshots of the drive for backups. The full details of all the options, settings, and filesystems available in Linux is beyond the scope of this course. Suffice it to say that Linux systems with a need for high speed I/O from disks or other specialized features are finely tuned.
# There are many other options that can be set for specific filesystems during the formatting process. For example, many newer large drives use 4096 byte "Advanced Format" sectors instead of the traditional 512 byte hard drive sectors. Using these disks most efficiently requires adjusting the sector size during the format process to match the physical sector size on the disk. Other features and filesystems include the ability to take snapshots of the drive for backups. The full details of all the options, settings, and filesystems available in Linux is beyond the scope of this course. Suffice it to say that Linux systems with a need for high speed I/O from disks or other specialized features are finely tuned.
# As a Linux system administrator at a minimum you should be familiar with the basic formatting of drives in the most common ''ext3'', ''ext4'', ''btrfs'', and ''fat'' (32) filesystems. Even though the FAT filesystem is not native to Linux (it doesn't have important features like user and group ownership) it is important as it is a cross platform filesystem commonly used to share files on thumb drives, external hard drives, or dual boot systems with MacOS or Windows users.
# As a Linux system administrator at a minimum you should be familiar with the basic formatting of drives in the most common ''ext3'', ''ext4'', ''btrfs'', and ''fat'' (32) filesystems. Even though the FAT filesystem is not native to Linux (it doesn't have important features like user and group ownership) it is important as it is a cross platform filesystem commonly used to share files on thumb drives, external hard drives, or dual boot systems with MacOS or Windows users.
Line 55: Line 90:
<li> To start, we will learn how to manually mount a partition. change into the ''/mnt'' directory and then create a new directory named ''part1''. This will become the location where we will mount our ''/dev/sdb1'' partition and be able to save files to it.</li>
<li> To start, we will learn how to manually mount a partition. change into the ''/mnt'' directory and then create a new directory named ''part1''. This will become the location where we will mount our ''/dev/sdb1'' partition and be able to save files to it.</li>
<li> Enter the ''part1'' directory and create a new empty file (remember the '''touch''' command?) named ''unmounted''. Because we have not yet mounted ''/dev/sdb1'' this file will be stored on our existing partition (''/dev/sda1'').</li>
<li> Enter the ''part1'' directory and create a new empty file (remember the '''touch''' command?) named ''unmounted''. Because we have not yet mounted ''/dev/sdb1'' this file will be stored on our existing partition (''/dev/sda1'').</li>
<li> Go back to the ''/mnt'' parent directory. Run the ''mount /dev/sdb1 /mnt/part1'' command as root. This command will mount, or attach, ''/dev/sdb1'' to the filesystem location ''/mnt/part1'' and everything stored in that "directory" from this point on will actually be saved onto the first partition of the second SATA drive.</li>
<li> Go back to the ''/mnt'' parent directory. Run the following command as root:
<pre>mount /dev/sdb1 /mnt/part1</pre>
This command will mount, or attach, ''/dev/sdb1'' to the filesystem location ''/mnt/part1'' and everything stored in that "directory" from this point on will actually be saved onto the first partition of the second SATA drive.</li>
<li> Go back into the ''part1'' directory and try listing the files. Notice how the ''unmounted ''file you made appears to no longer exist. This is because the ''part1'' "directory is now being used as the mount point for the first partition on ''sdb'' and we haven't yet saved any files onto ''sdb1''.</li>
<li> Go back into the ''part1'' directory and try listing the files. Notice how the ''unmounted ''file you made appears to no longer exist. This is because the ''part1'' "directory is now being used as the mount point for the first partition on ''sdb'' and we haven't yet saved any files onto ''sdb1''.</li>
[[File:Linuxpenguin.jpg | 300px]]
<li> You can see a list of all storage devices currently mounted on the system by simply running the command '''mount''' without any options. Try doing this and verify that the newly mounted partition is showing in the list.</li>
<li> You can see a list of all storage devices currently mounted on the system by simply running the command '''mount''' without any options. Try doing this and verify that the newly mounted partition is showing in the list.</li>
<li> Change back to the ''/mnt'' directory and unmount the partition by running the command ''umount /mnt/part1''.</li>
<li> Change back to the ''/mnt'' directory and unmount the partition by running the following command
<pre>umount /mnt/part1</pre></li>
<li> Again list the contents of the ''part1'' directory. Notice how the ''unmounted'' file is back. The file didn't every really go away but it was not accessible while the other partition was mounted on the ''part1'' directory. When a drive is mounted on a directory, it overlays on top of any files in the directory, but it does not delete or touch the files on the original disk.</li>
<li> Again list the contents of the ''part1'' directory. Notice how the ''unmounted'' file is back. The file didn't every really go away but it was not accessible while the other partition was mounted on the ''part1'' directory. When a drive is mounted on a directory, it overlays on top of any files in the directory, but it does not delete or touch the files on the original disk.</li>
<li> Make a directory named ''btrfs'' in ''/mnt''. Once created, using the file editor of your choice, open the ''/etc/fstab'' file.</li>
<li> Make a directory named ''btrfs'' in ''/mnt''. Once created, using the file editor of your choice, open the ''/etc/fstab'' file.</li>
Line 64: Line 105:
<pre>/dev/sdb1      /mnt/part1      ext4    defaults        0      0
<pre>/dev/sdb1      /mnt/part1      ext4    defaults        0      0
/dev/sdb2      /mnt/btrfs      btrfs  defaults        0      0</pre> </li>
/dev/sdb2      /mnt/btrfs      btrfs  defaults        0      0</pre> </li>
<li> Adding these lines will indicate both partitions should be mounted at boot to the directories we created. To mount the partitions without rebooting or entering individual mount commands, we can just run '''mount -a''' which will load and mount all partitions in the ''fstab'' file. Run the '''mount -a''' command now and verify both partitions are mounted.</li>
 
[[File:Linuxpenguin.jpg | 300px]]
 
<li> Adding these lines will indicate both partitions should be mounted at boot to the directories we created. To mount the partitions without rebooting or entering individual mount commands, we can just run '''mount -a''' which will load and mount all partitions in the ''fstab'' file. To verify both partitions are mounted run the following command:
<pre>mount -a</pre> </li>
</ol>
</ol>


Line 73: Line 118:
/dev/sdb2                26995912    120  24870016  1% /mnt/btrfs</pre></li>
/dev/sdb2                26995912    120  24870016  1% /mnt/btrfs</pre></li>
<li> This indicates that the two partitions are mounted properly to the folders we created earlier. ''df'' is a powerful command as not only will it show you what is mounted where, but it also shows you how much disk space is used and how much space is left.</li>
<li> This indicates that the two partitions are mounted properly to the folders we created earlier. ''df'' is a powerful command as not only will it show you what is mounted where, but it also shows you how much disk space is used and how much space is left.</li>
<li> The '''df''' command doesn't give the most easily readable disk or usage sizes by default. Try adding the ''-h'' option to the command like '''df -h''' to change the output to a "human readable" format and see what it looks like.</li>
<li> The '''df''' command doesn't give the most easily readable disk or usage sizes by default. Try adding the ''-h'' option to the command
<li> Now, '''cd''' into ''/mnt/part1'' so you are on the ext4 partition you created. Then as root, run the command '''cp -r /var/log ./'''</li>
<pre>df -h</pre>
<li> '''cd''' into the ''log'' folder, and run '''du -h'''. '''du''' is a command that allows you to view file usage in a tree format. Just like with '''df''' the ''-h'' flag tells '''du''' to output the usage in a "human readable" format, while the ''-a'' flag tells it to show you the results for all files, and not just for folders.</li>
This changes the output to a "human readable" format.</li>
 
[[File:Linuxpenguin.jpg | 300px]]
 
<li> Now, '''cd''' into ''/mnt/part1'' so you are on the ext4 partition you created. Then as root, run the following command:
<pre>cp -r /var/log ./</pre></li>
<li> '''cd''' into the ''log'' folder, and run the following command:
<pre>du -h</pre>
'''du''' is a command that allows you to view file usage in a tree format. Just like with '''df''' the ''-h'' flag tells '''du''' to output the usage in a "human readable" format, while the ''-a'' flag tells it to show you the results for all files, and not just for folders.</li>
<li> Read the '''man du''' page and play around with using the '''du''' command across the file system. How much data is the /etc/ folder taking up on your Linux system? What directories are the biggest?</li>
<li> Read the '''man du''' page and play around with using the '''du''' command across the file system. How much data is the /etc/ folder taking up on your Linux system? What directories are the biggest?</li>
</ol>
</ol>

Latest revision as of 23:49, 26 January 2021

Introduction

Welcome to Lab 11. This lab will focus on hard disk prep, partitioning, mounting/unmounting partitions, and disk & file usage.

The commands you will be using and exploring include:

lsmod

mount

uname

lsusb

lspci

dmesg

cfdisk

You will also be exploring the /proc directory, /dev directory, and the fstab file.

Lab Procedure

Prerequisites

  1. Open an SSH console to your Linux system using the PuTTY software, login with your standard user account

Exploring /proc

  1. Enter the /proc directory on your VM. /proc is a very special folder is its a virtual filesystem. Its sometimes referred to as a process information pseudo-filesystem. The reason for calling it a pseudo-file system is that all of the "files" in /proc are not really files at all, but kernel runtime configuration and system information.
  2. For example, use cat cpuinfo to view the contents of the /proc/cpuinfo "file". Notice how the output tells your information about the CPU that is running the VM. This isn't actually a file at all you are essentially asking the kernel to provide information about the CPU it's running on which it gathers in realtime. /proc is used not only to get hardware and kernel information, but it can also be used to tweak kernel settings while the system is running in a way similar to some Windows Registry edits. Look back on Lab 10 and notice how we echoed a "1" to a "file" in /proc to enable packet forwarding without rebooting the system.
  3. There are a few files in /proc you should get to know:
    • /proc/cpuinfo = Shows you the CPU info for your machine.
    • /proc/modules = Shows you the currently enabled kernel modules that are active on your kernel.
    • /proc/cmdline = Shows you the boot arguments used to boot your kernel.
    • /proc/version = Shows you your kernel version.
  4. It is important to note that some of these files have commands tied to them that can give you similar information but often formatted in a different way, for example.
    • /proc/modules = lsmod
    • /proc/mounts = mount
    • /proc/version = uname -a
  5. Normally it is best to use the command version to lookup the information as it is normally formatted to be easier to read and understand.
  6. Explore all of these files and commands and find the differences between the command line and file output versions as well as what types of information are available.

Exploring /dev

  1. Change directories to /dev and list the "files". Notice there are A LOT, but don't worry, there is organization in the mess. Each "file", like in /proc, is actually a device or interface on the machine so /dev is actually another pseudo-filesystem. Here is a list of the most common interfaces you will see:
    • /dev/sd* = SATA Hard Drives
    • /dev/hd* = IDE Hard Drives
    • /dev/vd* = VirtIO (Virtualized) Hard Drives
    • /dev/ttyS* = Serial Interfaces on your PC.
    • /dev/tty* = Virtual Consoles, similar to the one you are using to enter commands. Mostly used by background programs or services.
  2. There are also some commands you should learn that will help you with detecting, and looking up devices:
    • lsusb = List USB Devices (Bus, Device, ID, and advertised vendor)
      • Note: Many virtual machines do not include a virtual USB controller which means the USB drivers and software including lsusb are not installed.
    • lspci = List PCI Devices (Bus, Type, Advertised Name, Revision)
    • dmesg = Display or Driver Message. This shows kernel messages that are normally linked to adding, or removing devices.


Adding a 2nd disk

  1. As you may have noticed when exploring /dev, our VM setup uses sd devices for hard drives. Drives are identified by a letter such as sda, sdb, sdc, etc. for the first, second, and third SATA drives on a system (including HDDs, CD/DVDs, SSDs, etc.). Each partition on the drive is then given a number starting with 0 for the first partition. So the first partition on the first disk, the full identifier for the partition would be /dev/sda0.
  2. You may also have noticed there is an sdb that currently has no partitions. We are going to format this drive into 2 partitions, format them, and then setup automatic mounting of the partitions.
  3. To start, run the following command as root:
cfdisk /dev/sdb

cfdisk is a graphical version of fdisk, which is a tool used to setup disk partitioning. Note that fdisk or any other partitioning software only sets up the MBR, and does not actually format the drive even though you can set a partition type identifier such as fat32, Linux, etc. Also notice how we tell cfdisk what drive we want to edit the partition on by appending the drive device "file" to the end of the command.

Linuxpenguin.jpg

  1. Because our new drives contain no existing partitions we are asked what type of partition table to create. Choose to create a dos (aka MBR) style partition table. Although this is an older style partition table it is well supported by many operating systems and BIOSes. The primary benefit of the newer GPT style tables is their ability to work with very large drives.
  2. Once in cfdisk, Select the New option. Now select primary as we are making a primary MBR partition, then set the size close to 5GB (it doesn't need to be exact).
  3. Using the arrow keys to go down to the remaining Free Space on the drive, and press enter to again select New. Create another primary partition, and set the size to about 2GB.
  4. At this point we should have two partitions, one named sdb1 with a size of about 5GB (the program will round down to the closest boundary), and sdb2 which takes up the next 2GB or so of the drive. Use the arrow keys to select the Write option, and press enter. You will be warned that this will write the table to the disk. enter yes, and press enter again to confirm.
  5. If, on the bottom of the screen, you see "The partition table has been altered", you have successfully written the MBR to the drive. Now you can navigate to Quit to exit the program.
  6. From the command line run the following command:
ls -al /dev/sd*

Notice how you can now see both of the new partitions, sdb1 and sdb2 in the listing. This means the partition device "files" have been created and you are ready to format the partitions with a filesystem.

  1. The first partition will be formatted as ext4, and the second partition will be formatted as btrfs. Both filesystems (as well as many others) are commonly used on Linux systems. For more information on the differences and similarities between btrfs and ext4, refer to your book or Google.
  2. To create the ext4 partition, we will use the mkfs.ext4 command. So as root, run the command
mkfs.ext4 /dev/sdb1

This will partition the drive as ext4 with no label. If you would like to label the partition, look into the options of mkfs.ext4 using man mkfs.ext4.

  1. Before formatting the other partition as btrfs we need to install some tools. The required tools are part of the btrfs-tools software package so install that package at this time.
    • Note if you have issues with installing packages, check your firewall rules you created in a previous lab and ensure your Internet access is working properly from the VM.
  2. To format the second partition as a btrfs filesystem partition we will run the command:
mkfs.btrfs /dev/sdb2

Just like before, we need to tell the mkfs.btrfs package what partition to format by including that on the command line.

  1. There are many other options that can be set for specific filesystems during the formatting process. For example, many newer large drives use 4096 byte "Advanced Format" sectors instead of the traditional 512 byte hard drive sectors. Using these disks most efficiently requires adjusting the sector size during the format process to match the physical sector size on the disk. Other features and filesystems include the ability to take snapshots of the drive for backups. The full details of all the options, settings, and filesystems available in Linux is beyond the scope of this course. Suffice it to say that Linux systems with a need for high speed I/O from disks or other specialized features are finely tuned.
  2. As a Linux system administrator at a minimum you should be familiar with the basic formatting of drives in the most common ext3, ext4, btrfs, and fat (32) filesystems. Even though the FAT filesystem is not native to Linux (it doesn't have important features like user and group ownership) it is important as it is a cross platform filesystem commonly used to share files on thumb drives, external hard drives, or dual boot systems with MacOS or Windows users.
  3. Once your two partitions are formatted they need to be mounted to the filesystem structure so that we can begin using them for file storage.

Mounting Partitions

  1. There are two main ways to mount disks in Linux. One is done manually, and the other is to setup mounting at boot. Manual mounting is typically done for either temporary access to drives such as CD/DVDs, thumb drives, external hard drives, or to access a newly created partition before rebooting the system. Automatic mounting is done during the boot process so that you have immediate access to he drive once the system is booted.
  2. To start, we will learn how to manually mount a partition. change into the /mnt directory and then create a new directory named part1. This will become the location where we will mount our /dev/sdb1 partition and be able to save files to it.
  3. Enter the part1 directory and create a new empty file (remember the touch command?) named unmounted. Because we have not yet mounted /dev/sdb1 this file will be stored on our existing partition (/dev/sda1).
  4. Go back to the /mnt parent directory. Run the following command as root:
    mount /dev/sdb1 /mnt/part1
    This command will mount, or attach, /dev/sdb1 to the filesystem location /mnt/part1 and everything stored in that "directory" from this point on will actually be saved onto the first partition of the second SATA drive.
  5. Go back into the part1 directory and try listing the files. Notice how the unmounted file you made appears to no longer exist. This is because the part1 "directory is now being used as the mount point for the first partition on sdb and we haven't yet saved any files onto sdb1.
  6. Linuxpenguin.jpg
  7. You can see a list of all storage devices currently mounted on the system by simply running the command mount without any options. Try doing this and verify that the newly mounted partition is showing in the list.
  8. Change back to the /mnt directory and unmount the partition by running the following command
    umount /mnt/part1
  9. Again list the contents of the part1 directory. Notice how the unmounted file is back. The file didn't every really go away but it was not accessible while the other partition was mounted on the part1 directory. When a drive is mounted on a directory, it overlays on top of any files in the directory, but it does not delete or touch the files on the original disk.
  10. Make a directory named btrfs in /mnt. Once created, using the file editor of your choice, open the /etc/fstab file.
  11. The fstab file is used to tell a Linux system what drives and partitions is should mount at boot, as well as any mount options and where to mount the partitions. On the bottom of the file, add the following:
    /dev/sdb1       /mnt/part1      ext4    defaults        0       0
    /dev/sdb2       /mnt/btrfs      btrfs   defaults        0       0
  12. Linuxpenguin.jpg

  13. Adding these lines will indicate both partitions should be mounted at boot to the directories we created. To mount the partitions without rebooting or entering individual mount commands, we can just run mount -a which will load and mount all partitions in the fstab file. To verify both partitions are mounted run the following command:
    mount -a

Disk and File Usage

  1. Another way to verify the partitions which are mounted and to see how much disk space is used on each is to use the df command. When you run df, you should see something similar to this at the bottom of the output:
    /dev/sdb1                 14712416  167576  13797488   2% /mnt/part1
    /dev/sdb2                 26995912     120  24870016   1% /mnt/btrfs
  2. This indicates that the two partitions are mounted properly to the folders we created earlier. df is a powerful command as not only will it show you what is mounted where, but it also shows you how much disk space is used and how much space is left.
  3. The df command doesn't give the most easily readable disk or usage sizes by default. Try adding the -h option to the command
    df -h
    This changes the output to a "human readable" format.
  4. Linuxpenguin.jpg
  5. Now, cd into /mnt/part1 so you are on the ext4 partition you created. Then as root, run the following command:
    cp -r /var/log ./
  6. cd into the log folder, and run the following command:
    du -h
    du is a command that allows you to view file usage in a tree format. Just like with df the -h flag tells du to output the usage in a "human readable" format, while the -a flag tells it to show you the results for all files, and not just for folders.
  7. Read the man du page and play around with using the du command across the file system. How much data is the /etc/ folder taking up on your Linux system? What directories are the biggest?