Bookmark this page

Lab: Manage Basic Storage

In this lab, you create several partitions on a new disk, and format some with file systems and mount them, and activate others as swap spaces.

Outcomes

  • Display and create partitions with the parted command.

  • Create file systems on partitions and persistently mount them.

  • Create swap spaces and activate them at boot.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start storage-review

Instructions

  1. The serverb machine has several unused disks. On the first unused disk, create a GPT partition label and a 2 GB GPT partition named backup.

    Because it is difficult to set an exact size, a size between 1.8 GB and 2.2 GB is acceptable.

    Configure the backup partition to host an XFS file system.

    1. Log in to serverb as the student user and switch to the root user.

      [student@workstation ~]$ ssh student@serverb
      ...output omitted...
      [student@serverb ~]$ sudo -i
      [sudo] password for student: student
      [root@serverb ~]#
    2. Identify the unused disks. The first unused disk, /dev/vdb, does not have any partitions.

      [root@serverb ~]# lsblk
      NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
      vda    252:0    0   10G  0 disk
      ├─vda1 252:1    0    1M  0 part
      ├─vda2 252:2    0  200M  0 part /boot/efi
      ├─vda3 252:3    0  500M  0 part /boot
      └─vda4 252:4    0  9.3G  0 part /
      vdb    252:16   0    5G  0 disk
      vdc    252:32   0    5G  0 disk
      vdd    252:48   0    5G  0 disk
    3. Confirm that the /dev/vdb disk has no label.

      [root@serverb ~]# parted /dev/vdb print
      Error: /dev/vdb: unrecognised disk label
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 5369MB
      Sector size (logical/physical): 512B/512B
      Partition Table: unknown
      Disk Flags:
    4. Define the GPT partitioning scheme.

      [root@serverb ~]# parted /dev/vdb mklabel gpt
      Information: You may need to update /etc/fstab.
    5. Create the 2 GB backup partition with an xfs file-system type. Start the partition at sector 2048.

      [root@serverb ~]# parted /dev/vdb mkpart backup xfs 2048s 2GB
      Information: You may need to update /etc/fstab.
    6. Confirm the creation of the backup partition.

      [root@serverb ~]# parted /dev/vdb print
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 5369MB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:
      
      Number  Start   End     Size    File system  Name    Flags
       1      1049kB  2000MB  1999MB               backup
    7. Run the udevadm settle command. This command waits for the system to detect the new partition and to create the /dev/vdb1 device file.

      [root@serverb ~]# udevadm settle
  2. Format the 2 GB backup partition with an XFS file system and persistently mount it to the /backup directory.

    1. Format the /dev/vbd1 partition.

      [root@serverb ~]# mkfs.xfs /dev/vdb1
      meta-data=/dev/vdb1              isize=512    agcount=4, agsize=121984 blks
               =                       sectsz=512   attr=2, projid32bit=1
               =                       crc=1        finobt=1, sparse=1, rmapbt=0
               =                       reflink=1    bigtime=1 inobtcount=1
      data     =                       bsize=4096   blocks=487936, imaxpct=25
               =                       sunit=0      swidth=0 blks
      naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
      log      =internal log           bsize=4096   blocks=2560, version=2
               =                       sectsz=512   sunit=0 blks, lazy-count=1
      realtime =none                   extsz=4096   blocks=0, rtextents=0
    2. Create the /backup mount point.

      [root@serverb ~]# mkdir /backup
    3. Before adding the new file system to the /etc/fstab file, retrieve its UUID. The UUID on your system might be different.

      [root@serverb ~]# lsblk --fs /dev/vdb1
      NAME FSTYPE FSVER LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
      vdb1 xfs                f74ed805-b1fc-401a-a5ee-140f97c6757d
    4. Edit the /etc/fstab file and define the new file system.

      [root@serverb ~]# vim /etc/fstab
      ...output omitted...
      UUID=f74ed805-b1fc-401a-a5ee-140f97c6757d   /backup   xfs   defaults   0 0
    5. Force the systemd daemon to reread the /etc/fstab file.

      [root@serverb ~]# systemctl daemon-reload
    6. Manually mount the /backup directory to verify your work. Confirm that the mount is successful.

      [root@serverb ~]# mount /backup
      [root@serverb ~]# mount | grep /backup
      /dev/vdb1 on /backup type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
  3. On the same disk, create two 512 MB GPT partitions with the swap1 and swap2 names.

    A size between 460 MB and 564 MB is acceptable.

    Configure the file-system types of the partitions to host swap spaces.

    1. Retrieve the end position of the first partition by displaying the current partition table on the /dev/vdb disk. In the next step, you use that value as the start of the swap1 partition.

      [root@serverb ~]# parted /dev/vdb print
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 5369MB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:
      
      Number  Start   End     Size    File system  Name    Flags
       1      1049kB  2000MB  1999MB  xfs          backup
    2. Create the first 512 MB GPT partition named swap1. Set its type to linux-swap. Use the end position of the first partition as the starting point. The end position is 2000 MB + 512 MB = 2512 MB.

      [root@serverb ~]# parted /dev/vdb mkpart swap1 linux-swap 2000M 2512M
      Information: You may need to update /etc/fstab.
    3. Create the second 512 MB GPT partition named swap2. Set its type to linux-swap. Use the end position of the previous partition as the starting point: 2512M. The end position is 2512 MB + 512 MB = 3024 MB.

      [root@serverb ~]# parted /dev/vdb mkpart swap2 linux-swap 2512M 3024M
      Information: You may need to update /etc/fstab.
    4. Display the partition table to verify your work.

      [root@serverb ~]# parted /dev/vdb print
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 5369MB
      Sector size (logical/physical): 512B/512B
      Partition Table: gpt
      Disk Flags:
      
      Number  Start   End     Size    File system  Name    Flags
       1      1049kB  2000MB  1999MB  xfs          backup
       2      2000MB  2512MB  513MB                swap1   swap
       3      2512MB  3024MB  512MB                swap2   swap
    5. Run the udevadm settle command. The command waits for the system to register the new partitions and to create the device files.

      [root@serverb ~]# udevadm settle
  4. Initialize the two 512 MB partitions as swap spaces, and configure them to activate at boot. Set the swap space on the swap2 partition to be preferred over the other. Note that 512 MB is approximately equivalent to 488 MiB.

    1. Use the mkswap command to initialize the swap partitions. Note the UUIDs of the two swap spaces, because you use that information in the next step. If you clear the mkswap output, then use the lsblk --fs command to retrieve the UUIDs.

      [root@serverb ~]# mkswap /dev/vdb2
      Setting up swapspace version 1, size = 489 MiB (512749568 bytes)
      no label, UUID=87976166-4697-47b7-86d1-73a02f0fc803
      [root@serverb ~]# mkswap /dev/vdb3
      Setting up swapspace version 1, size = 488 MiB (511700992 bytes)
      no label, UUID=4d9b847b-98e0-4d4e-9ef7-dfaaf736b942
    2. Edit the /etc/fstab file and define the new swap spaces. To set the swap space on the swap2 partition to be preferred over the swap1 partition, give the swap2 partition a higher priority with the pri option.

      [root@serverb ~]# vim /etc/fstab
      ...output omitted...
      UUID=a3665c6b-4bfb-49b6-a528-74e268b058dd   /backup xfs   defaults  0 0
      UUID=87976166-4697-47b7-86d1-73a02f0fc803   swap    swap  pri=10    0 0
      UUID=4d9b847b-98e0-4d4e-9ef7-dfaaf736b942   swap    swap  pri=20    0 0
    3. Force the systemd daemon to reread the /etc/fstab file.

      [root@serverb ~]# systemctl daemon-reload
    4. Activate the new swap spaces. Verify the correct activation of the swap spaces.

      [root@serverb ~]# swapon -a
      [root@serverb ~]# swapon --show
      NAME      TYPE      SIZE USED PRIO
      /dev/vdb2 partition 489M   0B   10
      /dev/vdb3 partition 488M   0B   20
  5. To verify your work, reboot the serverb machine. Confirm that the system automatically mounts the first partition to the /backup directory. Also, confirm that the system activates the two swap spaces.

    1. Reboot serverb.

      [root@serverb ~]# systemctl reboot
      Connection to serverb closed by remote host.
      Connection to serverb closed.
      [student@workstation ~]$
    2. Wait for serverb to boot, and then log in as the student user.

      [student@workstation ~]$ ssh student@serverb
      ...output omitted...
      [student@serverb ~]$
    3. Verify that the system automatically mounts the /dev/vdb1 partition to the /backup directory.

      [student@serverb ~]$ mount | grep /backup
      /dev/vdb1 on /backup type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
    4. Verify that the system activates both swap spaces.

      [student@serverb ~]$ swapon --show
      NAME      TYPE      SIZE USED PRIO
      /dev/vdb2 partition 489M   0B   10
      /dev/vdb3 partition 488M   0B   20
    5. Return to the workstation machine as the student user.

      [student@serverb ~]$ exit
      logout
      Connection to serverb closed.
      [student@workstation ~]$

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade storage-review

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish storage-review

This concludes the section.

Revision: rh199-9.0-4fecb06