How to mount and configure a storage unit in VirtualBox?
Managing storage drives is crucial for any Linux system administrator. In this module, we will learn how to create partitions and manage file systems in a practical and easy way. From setting up a hard disk in VirtualBox to mounting a file system, this process is fundamental and useful for frequent administration tasks, especially in on-site environments such as data centers.
How to add a hard disk in VirtualBox?
Adding a new disk to a server in VirtualBox is a simple and essential process for storage activities.
- Make sure your server is turned off.
- Open the VirtualBox configuration and add a new disk.
- Navigate to the SATA controller section.
- Click "Add" and then "Create" a new disk if necessary.
- Assign a relevant name (e.g.
backup.vdl
).
- Define the size of the disk, such as 10 GB.
- Verify the addition of the disk.
- The disk should appear in the storage section, as
backup.vdl
on the SATA1 port.
How to create partitions on a new drive?
The fdisk
tool allows you to easily create partitions in Linux. Here is the procedure:
Preparations and disk identification
- Start your virtual machine and log in via SSH.
- Clear the screen and verify the presence of the new disk with
sblk
.
- Confirm the location of the disk with
fdisk -l.
Creating partitions
To manage partitions, we will use fdisk
, a versatile but powerful tool.
-
Access fdisk
with administrator permissions:
sudo fdisk /dev/sdb
-
Create two partitions:
- Use the
N
option to create a new primary partition.
- Define the size of the first partition as 3 GB:
+3G
- Repeat for the second 7GB partition, using the remaining space.
-
Print the partition table before finishing:
p
-
Save the changes by writing the partition table:
w
How to format and use a partition?
Formatting a partition with ext4
- Use the
mkfs
command to format the partition:sudo mkfs.ext4 /dev/sdb1
Mount the partition
-
Create a mount point:
sudo mkdir /mnt/scripts
-
Mount the partition in the directory:
sudo mount /dev/sdb1 /mnt/scripts
Test the mount by creating a file
How to mount automatically at startup?
To ensure that the partition is automatically mounted at system boot:
-
Edit the fstab
file:
sudo vim /etc/fstab
-
Add the following line:
/dev/sdb1 /mnt/scripts ext4 defaults 0 0
-
Reboot the system to apply the changes:
sudo reboot
Verify the mount again at logon, checking that the mount point contains the expected files.
The correct management of file systems and storage is essential in Linux system administration, ensuring efficiency and organization of your computing resources. Keep practicing and go further!
Want to see more contributions, questions and answers from the community?