- You added a disk and need linux to recognize it
- You need to resize a disk on a Linux system
- You asked me about it, and I sent you this link or
- you are me, and I forgot how to resize a disk because despite having done this a billion times, I can never remember all the steps.
I’ve adjusted this note several times over the years for a wide range of users with a wide range of experience. So I will assume basic Linux background and explain this procedure as much as possible.
I will first assume that you’ve already determined that you are working with LVM. If you aren’t sure, here is how you can check:
- check fstab ` cat /etc/fstab `
fstab is the Linux ‘file system table’. It tells the system what to mount at boot, and chances are the disk you are working with should be here.
if you see
UUID=[some long string]or
/dev/sda[some letter], then you have a physical partition. What you are looking for is
Check if there are already any logical volumes
lvdisplaywill display any logical volumes as well as their path, name, group name, and size.
The following assumption I am going to make is that you have either physically installed another disk or added one in ESXi or whichever VM manager you are using.
So now you have an unpartitioned disk. You need to first get the disk ready by creating a partition.
fdisk -l to confirm and identify that disk. You will see the existing disk (probably
/dev/sda/, but your mileage may vary as your system may be set up differently) with its partitions and a new disk
/dev/sdb without any partitions. This is the one you’ve added. Use cfdisk to add a partition:
Or whichever is the new disk you’ve added. It may be something different such as sdc; make sure you are working with the correct one matching the disk size you added.
select the options
primary -> [
default partition] ->
fdisk -l again to confirm the new disk now has a workable partition.
Create physical volumes
Use the pvcreate command to create physical volumes.
pvcreate /dev/sdb1 # then check again with pvdisplay pvdisplay
Despite the name “physical volume, “ these lvm objects are logical ‘containers’ for one another. The physical disk contains partions that contain the physical volumes which will belong to a virtual group. Virtual groups can ‘own’ multiple physical volumes. Virtual groups contain logical volumes. Logical volumes are what we will ultimately mount.
Create Virtual Group
You need to create a virtual group that will contain your new physical volumes.
vgcreate new_vg /dev/sdb1
Create Virtual Group Add any new physical volumes to a virtual group with
vgextend new_vg /dev/sdb1
This will extend the virtual group to use the rest of the new disk.
Create Logical Volumes
You will create logical volumes from this virtual group, which will be mounted as before.
lvcreate -L 5000 -n vol01 new_vg
This will create a 5GB “partition”.
Now just like an actual physical disk, this just needs a file system.
# mkfs.ext3 -m 0 /dev/new_vg/vol01
Note that this command will use the entire logical volume partition. In your case you may want something more specific.
Add a new line in your fstab with
vim /etc/fstab for the new logical partition.
This mount will need a directory as a mount point.
This may be determined by the disk you were resizing to begin with. Now that you have a mount point, you can mount the new partition with `mount -a’
- validate the new disk space with
dfand see that you may still need to extend to use all this new space.
Extend logical volume
Along this procedure, I usually run
fdisk -l over and over and over to make sure I am copypasta the correct names and paths.
These notes are from my scratchpad that I’ve accumulated hacks and tricks over the years. Most of them are incoherent, incomplete thoughts and incredibly biased to my workspace, my workstyle, locally set aliases, and whatever I was doing when I scribbled them. I am sharing them here for my personal posterity, and they won’t likely age well either. If they happen to help you, excellent - pay it forward. If they are wrong, or there is a mistake or anything that can be improved, please tell me. I shouldn’t have to say this, but never run a command without being sure what it does, and don’t blindly copy-paste commands from the internet.