Work with File Systems on Oracle Linux

3
0
Send lab feedback

Work with File Systems on Oracle Linux

Introduction

In the following tutorial, you list the mounted file systems. In addition, you partition disk devices and mount file systems. Then, you add entries in the file system table to mount file systems on reboots, and increase swap space. Lastly, you remove partitions and additional swap space.

Objectives

  • Display the current partition table
  • List mounted file systems
  • Partition disk devices
  • Create and mount file systems on partitions
  • Modify the file system table to mount the file systems on reboots
  • Increase the amount of swap space
  • Remove partitions and additional swap space

What Do You Need?

  • A system with Oracle Linux 8 or later installed
  • Two or more block devices attached to the system.

Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.

Task 1: Prepare Block Volumes

In this task, you run iscsiadm commands to prepare two block volumes for use in this tutorial.

Note: The iscsiadm utility is a command-line tool allowing discovery and login to iSCSI targets.

  1. Use the sudo command to switch user to the root user.

    sudo -i
  2. Open the Oracle Cloud Console.

  3. If necessary, click Compute and then Instances.

  4. Click the instance name link in the table to display its details page. The following image shows the instance name is ol-server.

    copy public IP

  5. Scroll down the details page and select Attached Block Volumes under Resources to display the attached block volumes. The following image lists the block volumes attached to the instance.

    copy attached

  6. For each block volume, click the three dots menu (on the right side) and select iSCSI Commands & Information from the list. The following image shows the iSCSI Commands & Information window and the three iscsiadm commands to copy:

    copy iscsiadm

    1. Copy and paste the three commands for connecting the block volume into a terminal window.

    2. Press Enter after the third (last) iscsiadm command.

    3. Repeat step 5 for the other block volumes in the list.

  7. Use the lsblk command to verify the block volumes are available on the system.

    lsblk

    Note: The command output shows three block devices: sda, sdb, and sdc.

Task 2: List the Current Disk Partitions

  1. As the root user, run the fdisk -l command to display the current partition table. Pipe the output to grep and list all /dev/sd disk devices.

    fdisk -l | grep /dev/sd

    Note: The lab system has three disk devices, /dev/sda, /dev/sdb, /dev/sdc.

    • The device /dev/sda is a 46.6 GB disk containing three partitions of various types and sizes: /dev/sda1 is a 100 MB Extensible Firmware Interface (EFI partition), /dev/sda2 is a 1 GB Linux file system, with /dev/sda3 being a 45.5 GB Linux Logical Volume Manager (LVM).
    • Partitions /dev/sda1 and /dev/sda2 are the primary boot devices.
    • Partition /dev/sda3 is mapped to the root file system.
    • Disk device, /dev/sdb, is a 50 GB disk without any partitions.
    • Disk device, /dev/sdc, is a 50 GB disk without any partitions.
  2. Use the df command to list the mounted partitions. The order of the devices might be different, and some numbers might vary.

    df -h
    • The first partition, sda1, on the hard drive contains the Unified Extensible Firmware Interface (UEFI) boot loader files and is mounted on /boot/efi.
    • The second partition, sda2, is mounted on /boot.
    • The file systems mounted on / and /var/oled are logical volumes.

Task 3: Create an MBR Partition

In this section, use the fdisk utility to create a Master Boot Record (MBR) partition.

Watch the video below for an overview on disk partitioning.

  1. Use the fdisk command to partition /dev/sdb.

    fdisk /dev/sdb

    The interactive program opens with a short statement on its use, information about the device selected, and a command prompt.

  2. Enter m at the prompt to display the fdisk menu.

    Note: The menu groups the available options by their function.

  3. Enter n to add a new MBR primary partition.

    • The MBR stores partition information at the beginning of a disk and is limited to four primary partitions.
    • One of the four partitions can be designated as an extended partition. This partition can then be subdivided into multiple logical partitions.
  4. Enter p, followed by the number 1 for the first primary partition.

  5. Press Enter to accept the default (2048) as the start of the first sector.

  6. Enter +500M to set the last sector using the size notation.

    fdisk returns a message telling you that the new partition is of the type 'Linux' with a size of 500 MiB.

  7. Enter p to print the new partition.

    Some of the information the print option displays is:

    • The disk device name: /dev/sdb1.
    • The disk label type: dos, which indicates an MBR partition table.
    • The partition type: Linux.
  8. Enter w to save the new partition.

    fdisk notes that the partition has changed, is being re-read by ioctl(), and that the disk is synchronizing.

  9. Use the fdisk -l command to list the partition table on /dev/sdb. The fdisk -l command uses the lowercase letter l option, and not the numeral 1.

    fdisk -l /dev/sdb

Task 4: Create a GPT Partition

  1. Use the fdisk -l command to list the current partitions on /dev/sdc.

    fdisk -l /dev/sdc

    Note: The disk does not have any partitions.

  2. Use the fdisk command to create a GUID Partition Table (GPT) partition on /dev/sdc.

    fdisk /dev/sdc
    • fdisk outputs the summary as it did before about the disk.
    • GPT partitions are ideal for disks larger than 2 TB.
    • In this lab, you use a 50 GB disk.
    • If this disk was larger than 2 TB, a warning displays affirming the size of the disk and indicating that it cannot be used as a DOS partition table.
  3. Enter g to add a new GPT partition.

    The output confirms the creation of a new GPT disk label.

  4. Enter n, followed by the number 1 for the first sector partition.

  5. Press Enter to accept the default (2048) as the start of the first sector.

  6. Enter Enter to set the last sector using the default size of 104857566.

    fdisk returns a message telling you of the new partition of the type 'Linux' with a size of 50 GiB.

  7. Enter p to print the new partition.

    Some of the information the print option displays is:

    • The disk device name: /dev/sdc1.
    • The disk label type: gpt, which indicates an GPT partition table.
    • The partition type: Linux.
  8. Enter w to save the new partition.

    fdisk notes that the partition changed, being re-read by ioctl(), and the disks are synchronizing.

Task 5: Create an ext4 File System on the MBR Partition

In this section, you create a file system on /dev/sdb1.

Watch the video below for an overview on creating file systems.

  1. Use the mkfs command to make an ext4 file system on the disk and assign it the label of Test.

    mkfs -t ext4 -L Test /dev/sdb1
  2. Use the blkid command to display the attributes of the /dev/sdb1 block device.

    blkid /dev/sdb1

Task 6: Create a xfs File System on the GPT Partition

In this section, you create an xfs file system on /dev/sdc1.

  1. Use the mkfs command to make an xfs file system on the disk and assign it the label of Dev.

    mkfs -t xfs -L Dev /dev/sdc1
  2. Use the blkid command to display the attributes of the /dev/sdc1 block device.

    blkid /dev/sdc1

Task 7: Mount the File Systems

In this section, you create mount points and mount the file systems to the mount points.

Watch the videos below for an overview on mounting file systems.

  1. Use the mkdir command to create the mount points.

    mkdir /Test
    mkdir /Dev
  2. Use the mount command to mount /dev/sdb1 to /Test, and /dev/sdc1 to /Dev.

    mount /dev/sdb1 /Test
    mount /dev/sdc1 /Dev
  3. Use the df command to display the mounted file systems.

    df -h
  4. Use the mount command and pipe the output to grep to display the /Test file system.

    mount | grep /Test

    Note:

    • Notice that the output shows the default mount options on /Test.
    • Refer to the man mount page for more information on these and other mount options.
  5. Use the mount command and pipe the output to grep to display the /Dev file system.

    mount | grep /Dev

    Note: Refer to the man mount page for more information on these and other mount options.

  6. Use the command cat /proc/mounts to view the status of all mounted file systems. Pipe the output to tail and display the last six lines.

    cat /proc/mounts | tail -6

    The mounts file is part of the proc virtual file system. The mounts file, like other files in the /proc directory, does not exist. It is a representation of file system status in file form.

Task 8: Update the fstab File

In this section, you update the /etc/fstab file to mount the new file systems on reboots.

Watch the video below for an overview on updating the file system table.

  1. Use the blkid command to obtain the UUID values for /dev/sdb1 and /dev/sdc1 to use in the next step.

    blkid /dev/sdb1
    blikd /dev/sdc1

    Note: Small computer system interface (SCSI) device names are not stable across reboots. Oracle recommends using the device universally unique identifier (UUID) instead of /dev path names.

  2. Use the command vi /etc/fstab and add the following entries to /etc/fstab:

    UUID="<UUID_VALUE_OF_SDB1_FROM_PREVIOUS_STEP>" /Test ext4  defaults,_netdev  0 0
    UUID="<UUID_VALUE_OF_SDC1_FROM_PREVIOUS_STEP>" /Dev xfs  defaults,_netdev  0 0
    • When you add an iSCSI remote block volume, you must include the _netdev mount option or your instance will become unavailable after the next reboot.

    • Updating the /etc/fstab automatically mounts your file systems after the system reboots.

  3. Use the umount command to unmount the file systems.

    umount /Dev /Test
  4. Use the mount –a command to mount all file systems in /etc/fstab file.

    mount -a
  5. Use the command df -h to verify your new file systems are mounted.

    df -h

Task 9: Increase Swap Space

In this section, you increase the amount of swap space by creating, initializing, and enabling a swap file.

Watch the video below for an overview on increasing swap space.

  1. Use the swapon command to display the current amount of swap space.

    swapon -s
  2. Use the command grep -i swap /proc/meminfo to display the amount of swap space.

    grep -i swap /proc/meminfo
  3. Use the free command to display the amount of swap space.

    free -h
  4. Use the dd command to create a swap file.

    dd if=/dev/zero of=/.swapfile2 bs=1024 count=1048576
  5. Use the mkswap command to initialize the swap file.

    mkswap /.swapfile2
  6. Use the swapon command to enable swapping on the swap file.

    swapon /.swapfile2

    Note: Notice the suggestion to change permissions on the file.

  7. Use the following commands to display the updated swap space.

    swapon -s
    grep -i swap /proc/meminfo
    free -h

If you need the additional swap space after a reboot, add the new swap file to the /etc/fstab file.

Task 10: Remove Partitions and Additional Swap Space

In this section, you remove your partitions, remove the entries in the file system table, and remove the additional swap space.

  1. Use the umount command to unmount the file systems.

    umount /Dev /Test
  2. Use the fdisk command to delete the partition on /dev/sdb.

    fdisk /dev/sdb
    1. Enter d to delete partition 1.

    2. Enter p to print the partition table and confirm there are no partitions.

    3. Enter w to save the partition table and exit the fdisk utility.

  3. Use the fdisk command to delete the partition on /dev/sdc.

    fdisk /dev/sdc
    1. Enter d to delete partition 1.

    2. Enter p to print the partition table and confirm there are no partitions.

    3. Enter w to save the partition table and exit the fdisk utility.

  4. Use the parted command to change the label on /dev/sdc from gpt to msdos

    parted /dev/sdc
    1. Enter mklabel msdos to create an msdos label.

    2. Enter Yes to continue.

    3. Enter print to the partition table to confirm the label change.

    4. Enter quit to exit the parted utility.

  5. Use the vi command to remove the Dev and Test entries from the /etc/fstab file by deleting the appropriate lines.

  6. Use the rmdir command to remove the /Dev and /Test mount point directories.

    rmdir /Dev /Test
  7. Use the swapoff command to disable swapping to /.swapfile2.

    swapoff /.swapfile2
  8. Use the rm command to remove /.swapfile2.

    rm /.swapfile2
SSR