Franske ITC-2480 Lab 11: Difference between revisions

From ITCwiki
Jump to navigation Jump to search
Line 33: Line 33:
# 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.
# 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.
# 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.
# 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.  
# 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.
# 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.

Revision as of 20:14, 6 April 2016

Introduction

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. 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.
  2. 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.
  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 arguements 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, 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 around with these commands and find the differences between the command line and file output versions.

Exploring /dev

  1. 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.
  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)
    • 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. 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
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Press enter to mark the first partition bootable.
  7. 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.
  8. 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.
  9. Now run ls -l /dev | grep sdb. Notice how the two partitions, sdb1 and sdb2 show up.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. Now that we are done, we are ready to move onto mounting the partitions.

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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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
  1. 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

  1. 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
  1. 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.
  2. Now, cd into /mnt/part1 so you are on the ext4 partition you created. Then as root, run the command cp -r /var/log ./
  3. 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.
  4. Mess around with using this across the file system. How much data is the /etc/ folder taking up on your linux system?
  5. This concludes the Chapter 11 Lab.