Using a new empty volume on a Linux VM

From CC Doc
Jump to: navigation, search
Other languages:
English • ‎français

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.

  1. Create a partition on the volume with
    Question.png
    [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.
  2. 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
    
  3. Format the newly created partition with
    Question.png
    [name@server ~]$ sudo mkfs -t ext4 /dev/vdb1
  4. Create a place to mount the device with
    Question.png
    [name@server ~]$ sudo mkdir /media/data
  5. Finally, mount the volume with
    Question.png
    [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

Question.png
[name@server ~]$ sudo mount -a