Using a new empty volume on a Linux VM
Jump to navigation
Jump to search
On most Linux distributions the following steps can be used to partition, format, and mount the newly created volume. NOTE: If this is not a newly created volume the partition and format steps should be skipped as they will result in loss of data on that volume, and only the steps to mount the volume should be followed.
- Create a partition on the volume with
[name@server ~]$ sudo fdisk /dev/vdb
fdisk
will prompt you to enter a command. Use this sequence of single-character commands to create a new partition on your volume.
n => new partition
p => primary, only one partition on disk
1 => partition number 1
<return> => first sector (use default)
<return> => last sector (use default)
w => write partition table to disk and exit
- Format the newly created partition with
[name@server ~]$ sudo mkfs -t ext4 /dev/vdb1
- Create a place to mount the device with
[name@server ~]$ sudo mkdir /media/data
- Finally, mount the volume with
[name@server ~]$ sudo mount /dev/vdb1 /media/data
If the VM is rebooted for some reason the volume will need to be remounted. To cause the VM to mount the volume automatically at boot time, edit /etc/fstab
and add a line like
/dev/vdb1 /media/data ext4 defaults 0 2
For more details about the fstab file see this wikipedia article. If you are not rebooting, you can mount the device just added to /etc/fstab
with
[name@server ~]$ sudo mount -a