Franske ITC-2480 Lab 11: Difference between revisions
Jump to navigation
Jump to search
BenFranske (talk | contribs) |
BenFranske (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
== 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. | ||
# For example, | # 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. | ||
# There are a few files in /proc you should get to know: | # There are a few files in ''/proc'' you should get to know: | ||
#* '''/proc/cpuinfo''' = Shows you the CPU info for your machine. | #* '''/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/modules''' = Shows you the currently enabled kernel modules that are active on your kernel. | ||
#* '''/proc/cmdline''' = Shows you the boot | #* '''/proc/cmdline''' = Shows you the boot arguments used to boot your kernel. | ||
#* '''/proc/version''' = Shows you your kernel version. | #* '''/proc/version''' = Shows you your kernel version. | ||
# It is important to note that some of these files have commands tied to them, for example. | # 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/modules''' = '''lsmod''' | ||
#* '''/proc/mounts''' = mount | #* '''/proc/mounts''' = '''mount''' | ||
#* '''/proc/version''' = uname -a | #* '''/proc/version''' = '''uname -a''' | ||
# 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. | # 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. | ||
# Explore | # 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 == | == 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: | ||
#* '''/dev/sd*''' = SATA Hard Drives | #* '''/dev/sd*''' = SATA Hard Drives | ||
#* '''/dev/hd*''' = IDE Hard Drives | #* '''/dev/hd*''' = IDE Hard Drives | ||
Line 27: | Line 27: | ||
# There are also some commands you should learn that will help you with detecting, and looking up devices: | # 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) | #* '''lsusb''' = List USB Devices (Bus, Device, ID, and advertised vendor) | ||
#** Note: Many virtual machines do not include a virtual | #** 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) | #* '''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. |
Revision as of 17:03, 21 March 2018
Introduction
Lab Procedure
Prerequisites
- Open an SSH console to your Linux system using the PuTTY software, login with your standard user account
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.
- 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.
- 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.
- 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
- 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.
- 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
- 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.
- 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.
- lsusb = List USB Devices (Bus, Device, ID, and advertised vendor)
Adding a 2nd disk
- If you noticed when exploring /dev, our VM setup uses sd devices for our hard drives. If you remember from the reading, the * in the name is a letter standing for which device is on the first sata interface, and the number after that, ex 0, marks the first partition. So for the first partition on the first disk, the drive would be /dev/sda0
- Now if you noticed there is a sdb that has no partitions. We are going to format this drive into 2 partitions, and then later setup automatic mounting.
- 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 only sets up the MBR, and does not actually format the drive. Also notice how we tell cfdisk what drive we want to format by appending the drive file to the end of the command.
- Note: some very large drives can no longer use MBR partition tables and there are other reasons to switch to the newer standard for partitioning, GPT partition tables. In order to do that you would use different tools such as gdisk and cgdisk instead of fdisk and cfdisk. Note that there are several other differences in the way GPT partitions work so you'll want to do some research about them before you try using them.
- If you are asked what type of partition table to use for the drive select "dos" which uses the MBR type. Once in cfdisk, Press the New option. Now select Primary as we are making a Primary partition, then for the size set it to 5GB.
- Now, use the arrow keys to go down to the Free Space, and press enter to Select New. Again, set it to Primary, and set it to 2GB. Then press Enter.
- 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. At this point, use the arrow keys to select Write, and press enter. You will be warned that this will write the table to the disk. enter "yes", and press enter to confirm.
- If on the bottom you see "The partition table has been altered", then you have successfully written the MBR to the drive. Now you can navigate to quit to exit the program.
- Now run ls -l /dev | grep sdb. Notice how the two partitions, sdb1 and sdb2 show up.
- Now we are going to format our two partitions. The first one we will format to ext4, and the second partition will be formatted to btrfs. 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 to ext4 with no label. If you would like to label the partition, look into the options of mkfs.ext4 using man mkfs.ext4.
- Now, before we format the other partition to btrfs we need to install some tools. As root, use your favorite package manager to download the btrfs-tools package.
- Note if you have issues with installing packages, check your firewall rules you created in the last lab.
- Now we will format the btrfs partition. To do this, we will run mkfs.btrfs /dev/sdb2 as root. Just like before, we need to tell the mkfs.btrfs package what partition to format.
- Now that we are done, we are ready to move onto mounting the partitions.
Mounting Partitions
- There are two main ways to mount disks in linux. One is done manually, and the other is to setup mounting at boot.
- To start, we will learn how to manually mount a partition. change into the /mnt directory and then create a folder called part1. Now cd into the part1 folder and create a empty file called unmounted.
- Now, go back to the mnt directory. We are now going to use the mount command to mount the first partition we created to the part1 folder. To do this, we will run mount /dev/sdb1 /mnt/part1 as root. Now, go back into the part1 folder and list files. Notice how the file you made called unmounted no longer exists. This is because the folder is being used as the mount point for the partition. Now change back to the /mnt folder.
- To unmount the partition, run the command umount /mnt/part1. Now list the contents of the folder part1 again. Notice how the unmounted file is now back. This is because when a drive is mounted to the file, it overlays on top of any files in the folder, but it does not delete or touch the files.
- Now we are going to make a folder called btrfs in /mnt. Once created, using the file editor of your choice, open up the file /etc/fstab.
- The fstab file is used to tell a linux system what drives and partitions is should mount as boot, as well as 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
- Adding these lines will tell the fstab file to mount both partitions at boot to the folders we created. To mount the partitions without rebooting or using the full mount command syntax, we can just run mount -a which will load and mount all partitions in the fstab file.
- At this point we can now use the df command to verify that our new partitions are properly mounted. When you run df, you should see something similar to this at the bottom of the output:
- This means that your 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, as well as how much space is left.
- Now, cd into /mnt/part1 so you are on the ext4 partition you created. Then as root, run the command cp -r /var/log ./
- Now cd into the log folder, and run du -h. du is a command that allows you to view file usage in a tree format. 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 folders.
- Mess around with using this across the file system. How much data is the /etc/ folder taking up on your linux system?
- This concludes the Chapter 11 Lab.
Disk and File Usage
/dev/sdb1 14712416 167576 13797488 2% /mnt/part1 /dev/sdb2 26995912 120 24870016 1% /mnt/btrfs