Bookmark this page

Guided Exercise: Add Partitions, File Systems, and Persistent Mounts

In this exercise, you create a partition on a new storage device, format it with an XFS file system, configure it to mount at boot, and mount it for use.

Outcomes

  • Use the parted, mkfs.xfs, and other commands to create a partition on a new disk, format it, and persistently mount it.

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-partitions

Instructions

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

    student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Create an msdos disk label on the /dev/vdb device.

    [root@servera ~]# parted /dev/vdb mklabel msdos
    Information: You may need to update /etc/fstab.
  3. Add a 1 GB primary partition. For correct alignment, start the partition at the 2048 sector. Set the partition file-system type to XFS.

    1. Use parted interactive mode to create the partition.

      [root@servera ~]# parted /dev/vdb
      GNU Parted 3.4
      Using /dev/vdb
      Welcome to GNU Parted! Type 'help' to view a list of commands.
      (parted) mkpart
      Partition type?  primary/extended? primary
      File system type?  [ext2]? xfs
      Start? 2048s
      End? 1001MB
      (parted) quit
      Information: You may need to update /etc/fstab.

      Because the partition starts at the 2048 sector, the previous command sets the end position to 1001 MB to get a partition size of 1000 MB (1 GB).

      Alternatively, you can perform the same operation with the following non-interactive command: parted /dev/vdb mkpart primary xfs 2048s 1001 MB

    2. Verify your work by listing the partitions on the /dev/vdb device.

      [root@servera ~]# parted /dev/vdb print
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 5369MB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      Disk Flags:
      
      Number  Start   End     Size    Type     File system  Flags
       1      1049kB  1001MB  1000MB  primary
    3. Run the udevadm settle command. This command waits for the system to register the new partition, and returns when it is done.

      [root@servera ~]# udevadm settle
  4. Format the new partition with the XFS file system.

    [root@servera ~]# mkfs.xfs /dev/vdb1
    meta-data=/dev/vdb1              isize=512    agcount=4, agsize=61056 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=244224, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
    log      =internal log           bsize=4096   blocks=1566, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
  5. Configure the new file system to mount to the /archive directory persistently.

    1. Create the /archive directory.

      [root@servera ~]# mkdir /archive
    2. Discover the UUID of the /dev/vdb1 device. The UUID in the output is probably different on your system.

      [root@servera ~]# lsblk --fs /dev/vdb
      NAME   FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
      vdb
      └─vdb1 xfs                881e856c-37b1-41e3-b009-ad526e46d987
    3. Add an entry to the /etc/fstab file. Replace the UUID with the one that you discovered from the previous step.

      ...output omitted...
      UUID=881e856c-37b1-41e3-b009-ad526e46d987 /archive xfs defaults  0 0
    4. Update the systemd daemon for the system to register the new /etc/fstab file configuration.

      [root@servera ~]# systemctl daemon-reload
    5. Mount the new file system with the new entry in the /etc/fstab file.

      [root@servera ~]# mount /archive
    6. Verify that the new file system is mounted on the /archive directory.

      [root@servera ~]# mount | grep /archive
      /dev/vdb1 on /archive type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
  6. Reboot servera. After the server rebooted, log in and verify that the /dev/vdb1 device is mounted on the /archive directory. When done, log out from servera.

    1. Reboot servera.

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

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera ~]$
    3. Verify that the /dev/vdb1 device is mounted on the /archive directory.

      [student@servera ~]$ mount | grep /archive
      /dev/vdb1 on /archive type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
    4. Return to the workstation machine as the student user.

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

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-partitions

This concludes the section.

Revision: rh134-9.0-fa57cbe