Franske ITC-2480 Lab 11: Difference between revisions
Jump to navigation
Jump to search
Riptide wave (talk | contribs) (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...") |
Riptide wave (talk | contribs) No edit summary |
||
Line 20: | Line 20: | ||
== Exploring /dev == | == Exploring /dev == | ||
# now change directories to /dev and list the files. Notice that there are ALOT, but don't worry there is organization in the mess. Each file, like in /proc, is actually a device or interface on the machine. Here is a list of the most common interfaces you will see: | # now change directories to /dev and list the files. Notice that there are ALOT, but don't worry there is organization in the mess. Each file, like in /proc, is actually a device or interface on the machine. Here is a list of the most common interfaces you will see: | ||
#* '''/dev/sd*''' = SATA Hard | #* '''/dev/sd*''' = SATA Hard Drives | ||
#* '''/dev/hd*''' = IDE Hard Drives/ | #* '''/dev/hd*''' = IDE Hard Drives | ||
#* '''/dev/vd*''' = VirtIO (Virtualized) Hard Drives | |||
#* '''/dev/ttyS*''' = Serial Interfaces on your PC. | #* '''/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. | #* '''/dev/tty*''' = Virtual Consoles, similar to the one you are using to enter commands. Mostly used by background programs or services. | ||
Line 29: | Line 30: | ||
#* '''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 == | ||
# | # 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. | ||
# Once in ''cfdisk'', Press the New option. Now select Primary as we are making a Primary partition, then for the size set it to 15GB (15306MB) and select Beginning. | |||
# Now, use the arrow keys to go down to the Free Space, and press enter to Select New. Again, set it to Primary, and leave the size that it shows. Then press Enter. | |||
# Press enter to mark the first partition bootable. | |||
# At this point we should have two partitions, one named sdb1 with a size of 15305~ that is set as bootable, and sdb2 which takes up the rest 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 "wrote partition table to disk", then you have successfully wrote 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: | |||
<pre>/dev/vdb1 /mnt/part1 ext4 defaults 0 0 | |||
/dev/sdb2 /mnt/btrfs btrfs defaults 0 0</pre> | |||
# 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. | |||
== Disk and File Usage == | == Disk and File Usage == | ||
# | # 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: | ||
<pre>/dev/sdb1 14712416 167576 13797488 2% /mnt/part1 | |||
/dev/sdb2 26995912 120 24870016 1% /mnt/btrfs</pre> | |||
# 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. |
Revision as of 23:34, 1 April 2014
Introduction
Lab Procedure
Prerequisites
- Open an SSH console to your Linux system using the PuTTY software, login with your standard user account
Exploring /proc
- To start this lab, go to /proc in putty. /proc is a very special folder is its a virtual filesystem. Its sometimes referred to as a process information pseudo-file system. The reason is that all of the files in /proc are not real files, but runtime and system information.
- For example, now that you are in /proc, run cat cpuinfo. Notice how the output tells your information about the CPU that is running the Virtual Machine. /proc is used not only to get hardware and runtime information, but it can also be used to tweak kernel settings. Look back on Lab 10 and notice how we echoed a number to a file in /proc to enable packet forwarding.
- 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 arguements 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, 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 around with these commands and find the differences between the command line and file output versions.
Exploring /dev
- now change directories to /dev and list the files. Notice that there are ALOT, but don't worry there is organization in the mess. Each file, like in /proc, is actually a device or interface on the machine. 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)
- 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
- 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.
- Once in cfdisk, Press the New option. Now select Primary as we are making a Primary partition, then for the size set it to 15GB (15306MB) and select Beginning.
- Now, use the arrow keys to go down to the Free Space, and press enter to Select New. Again, set it to Primary, and leave the size that it shows. Then press Enter.
- Press enter to mark the first partition bootable.
- At this point we should have two partitions, one named sdb1 with a size of 15305~ that is set as bootable, and sdb2 which takes up the rest 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 "wrote partition table to disk", then you have successfully wrote 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/vdb1 /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.
Disk and File Usage
- 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:
/dev/sdb1 14712416 167576 13797488 2% /mnt/part1 /dev/sdb2 26995912 120 24870016 1% /mnt/btrfs
- 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.