Home Tutorials Mount or Unmount Drives

Mount or Unmount Drives

Last updated on Aug 01, 2024

Mount/Unmount

List All Partitions

Running the lsblk the available drives will be provided

lsblk

Once command is ran a read-out will be provided showing available drives similar to below. In this example the volume vdb size 50G is block-storage_1 inside the American Cloud CMP. Additionally, below we can see vdb is not mounted.

cloud@Compute-1:~$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0     7:0    0 63.3M  1 loop /snap/core20/1822
loop1     7:1    0 91.9M  1 loop /snap/lxd/24061
loop2     7:2    0 49.9M  1 loop /snap/snapd/18357
loop3     7:3    0 63.3M  1 loop /snap/core20/1852
sr0      11:0    1 1024M  0 rom
vda     252:0    0   25G  0 disk
├─vda1  252:1    0 24.9G  0 part /
├─vda14 252:14   0    4M  0 part
└─vda15 252:15   0  106M  0 part /boot/efi
vdb     252:16   0   50G  0 disk

Partition Drive

  • Partitioning a drive involves dividing it into one or more logical sections, each of which acts as a separate drive with its own file system. This can be useful for various reasons, such as isolating data for backup or security purposes, installing multiple operating systems on a single drive, or organizing files and folders more efficiently. Partitioning can be done using various tools, such as Disk Management in Windows, Disk Utility in macOS, or fdisk in Linux. - In this example fdisk command will be utilized
  1. Identify the drive to partition using fdisk -l

    
    sudo fdisk -l
    Disk /dev/loop0: 49.84 MiB, 52260864 bytes, 102072 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/loop1: 111.95 MiB, 117387264 bytes, 229272 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
  2. Use fdisk command to partition the drive.

  • Identify the drives path. For this example /dev/vdb1 will be placed in fdisk command. This information was retrieved running fdisk -l above
sudo fdisk /dev/vdb1
  • A readout similar to the below will be displayed confirming drive is open using fdisk command
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

The device contains 'ext4' signature and it will be removed by a write command. See fdisk(8) man page and --wipe option for more details.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x11b600de.

Command (m for help):
  • fdisk command is a letter based operation where a letter is assigned to a command. Notice (m for help). Press 'm' and enter to enter help mode and print command layout. The first couple of columns are printed below
Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition
  • Create new partition using 'n' command
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
  • In the about command once the 'n' command has been given fdisk command request information on the partition type. Here a primary partition will be built identified by the 'p' command. Next we'll be asked the sector in which to build the new partition. The first (1) sector will be selected
Partition number (1-4, default 1): 1
  • Following the above we'll determine the size of the sector/partition.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10000-97654783, default 97654783): +10G
  • The new partition of 10G has been built by fdisk command
Created a new partition 1 of type 'Linux' and of size 10 GiB.
  • Notice partition type defaulted to 'Linux in the above read out. fdisk will automatically defualt to 'Linux' In order to change this use the 't' command. Following the 't' command a 'L' command can be given to list all available types
1 EFI System                     C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  2 MBR partition scheme           024DEE41-33E7-11D3-9D69-0008C781F39F
  3 Intel Fast Flash               D3BFE2DE-3DAF-11DF-BA40-E3A556D89593
  4 BIOS boot                      21686148-6449-6E6F-744E-656564454649
  5 Sony boot partition            F4019732-066E-4E12-8273-346C5641494F
  6 Lenovo boot partition          BFBFAFE7-A34F-448A-9A5B-6213EB736C22
  7 PowerPC PReP boot              9E1A2D38-C612-4316-AA26-8B49521E5A8B
  8 ONIE boot                      7412F7D5-A156-4B13-81DC-867174929325
  9 ONIE config                    D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149
 10 Microsoft reserved             E3C9E316-0B5C-4DB8-817D-F92DF00215AE
 11 Microsoft basic data           EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
 12 Microsoft LDM metadata         5808C8AA-7E8F-42E0-85D2-E1E90434CFB3
 13 Microsoft LDM data             AF9B60A0-1431-4F62-BC68-3311714A69AD
 14 Windows recovery environment   DE94BBA4-06D1-4D40-A16A-BFD50179D6AC
 15 IBM General Parallel Fs        37AFFC90-EF7D-4E96-91C3-2D7AE055B174
 16 Microsoft Storage Spaces       E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D
 17 HP-UX data                     75894C1E-3AEB-11D3-B7C1-7B03A0000000
 18 HP-UX service                  E2A1E728-32E3-11D6-A682-7B03A0000000
 19 Linux swap                     0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
 20 Linux filesystem               0FC63DAF-8483-4772-8E79-3D69D8477DE4
 21 Linux server data              3B8F8425-20E0-4F3B-907F-1A25A76F98E8
 22 Linux root (x86)               44479540-F297-41B2-9AF7-D131D5F0458A
 23 Linux root (x86-64)            4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
 24 Linux root (ARM)               69DAD710-2CE4-4E3C-B16C-21A1D49ABED3
:
  • Now the new partition is saved in memory and waiting to be written to disk. To review the newly built partition use the 'p' command
Command (m for help): p
Disk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 0831ABEB-082B-4EF1-AA79-E22EE04FFF74

Device     Start      End  Sectors Size Type
/dev/vdb1   2048 20973567 20971520  10G Linux filesystem
  • To write the changes use the 'w' command. This will write the newly developed partition to the disk
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  • Using sudo fdisk -l double check the build of the new partition

Format Drive

There are different types of Linux format like btrfs, ext2, ext4, xfs, cramfs, ext3 and minix that are compatible with the Linux operating system

BTRFS

  • Btrfs: A modern file system for Linux operating systems that provides features such as snapshots, compression, and checksums for data integrity. It is designed to improve performance, scalability, and manageability of file storage on modern systems.

EXT2

  • Ext2: A traditional file system for Linux operating systems that was introduced in the early 1990s. It provides support for basic file and directory operations and has been widely used in Linux distributions. However, it lacks some modern features such as journaling and dynamic resizing.

EXT4

  • Ext4: A modern file system for Linux operating systems that provides features such as journaling, support for large files and directories, and improved performance and scalability. It is the default file system in many Linux distributions and is widely used in production environments.

XFS

  • XFS: A high-performance file system for Linux and other Unix-like operating systems. It was designed for scalability, supporting file systems up to 16 exabytes in size, and is optimized for handling large files and high-volume data throughput. XFS is widely used in enterprise and cloud environments.

CRAMFS

  • Cramfs (Compressed ROM File System): A read-only file system commonly used in embedded systems such as routers, set-top boxes, and smartphones. It is designed to save storage space by compressing the file system and is loaded into memory at boot time for fast access.

EXT3

  • Ext3: A journaled file system for Linux operating systems that was introduced in 2001. It provides support for basic file and directory operations and also includes a journaling system for improved reliability and faster recovery from crashes. Ext3 is widely used in Linux distributions but has been largely replaced by Ext4.

MINIX

  • MINIX: A file systems using a simple structure consisting of a boot block, superblock, and inode block.

  • To format the drive follow the following steps

  1. Identify drive to format. If partitioning occured in the above step select the partition.

  2. Run the below command to format drive. If desired change ext4 to different format.

sudo mkfs.ext4 /dev/vdb1
  • Readout should look similar to:
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 12206848 4k blocks and 3055616 inodes
Filesystem UUID: a86a8d51-0ed0-4818-9c81-b7afb8c77309
Superblock backups stored on blocks:
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done
  • The drive is now formatted to ext4

Create Mount Point

A mount point directory is a directory in a file system that serves as a reference point for accessing a storage device or a partition. When a storage device is connected to a computer or server, it must be mounted to be accessed by the system. Create the directory within /mnt by running the following command.

sudo mkdir /mnt/vdb1
  • To check creation run:
ls /mnt

Mount the Partition

  • Now that the new partition has been built, formatted, and created a mount point. Mount the partition. The below commands will be ran
sudo mount /dev/vdb1 /mnt/vdb1
  • There will not be a readout from this command. To check mounting use command lsblk as described in previous steps
cloud@Compute-AC-9:~$ lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0     7:0    0  49.8M  1 loop /snap/snapd/18357
loop1     7:1    0 111.9M  1 loop /snap/lxd/24322
loop2     7:2    0  63.3M  1 loop /snap/core20/1828
loop3     7:3    0  63.3M  1 loop /snap/core20/1852
loop4     7:4    0  53.2M  1 loop /snap/snapd/18933
sr0      11:0    1  1024M  0 rom
vda     252:0    0    25G  0 disk
├─vda1  252:1    0  24.9G  0 part /
├─vda14 252:14   0     4M  0 part
└─vda15 252:15   0   106M  0 part /boot/efi
vdb     252:16   0    50G  0 disk
└─vdb1  252:17   0    10G  0 part /mnt/vdb1
  • In the above, vdb1 has been mounted to /mnt/vdb1 as depicted in the MOUNTPOINTS column

Note
The example uses partitions and drives on the local machine. Ensure to use accurate [paths] on your local machine.

Unmount Partition

  • A drive can be unmounted using the 'umount' command
sudo umount /dev/vdb1
  • There will be no readout from this command. To check the success of the operation use the 'lsblk' command
lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0     7:0    0  49.8M  1 loop /snap/snapd/18357
loop1     7:1    0 111.9M  1 loop /snap/lxd/24322
loop2     7:2    0  63.3M  1 loop /snap/core20/1828
loop3     7:3    0  63.3M  1 loop /snap/core20/1852
loop4     7:4    0  53.2M  1 loop /snap/snapd/18933
sr0      11:0    1  1024M  0 rom
vda     252:0    0    25G  0 disk
├─vda1  252:1    0  24.9G  0 part /
├─vda14 252:14   0     4M  0 part
└─vda15 252:15   0   106M  0 part /boot/efi
vdb     252:16   0    50G  0 disk
└─vdb1  252:17   0    10G  0 part
  • Notice the mountpoint has been removed from vdb1

Note
If desired use fdisk to remove partition from drive. All the examples have been built on an American Cloud CMP Block Storage drive.