Linux - How to Expand a Partition
The basic idea is that you will delete the old partition and create a new one that is larger. It will start at the same place on the disk but the last sector will be larger. Here are some key points:
- You are going to need to make sure that the starting sector is the same on the new partition otherwise you will almost certainly lose your filesystem.
- The new partition should be larger than the old partition. To do this specify a last sector that is beyond what you are currently using or just specify a larger size.
- Watch out for partitions that are defined after the partition that you are expanding. Make sure you have enough space to expand.
You will want to run most or all of these commands as root. You can also use sudo if you like.
WARNING - Make sure you understand what you are doing. Things could still go wrong. Back up your data first. Don’t blindly rely on these instructions without understanding what you are doing.
Steps - How to Expand a Partition on Linux
WARNING - Make sure you get the first sector right or you could ( probably will ) lose data. Also pay attention to the last sector or the size that you want to expand to. Back your data up before doing this!
- Backup your data first
- Unmount
umount /dev/sdb2
- Edit partitions with fdisk
fdisk /dev/sdb
p print existing partitions ( note start and end sectors )
d delete partition
2 enter partition number to delete
n create new partition
p create primary partition
[enter] to accept default first sector or enter a value (enter the value if this is not correct)
+50G Enter the new size or just specify the last sector if you want
p show the partition table to make sure everything is as expected
w write changes to disk
- Check the disk for errors:
e2fsck /dev/sdb2
- Increase the actual filesystem size
resize2fs /dev/sdb2
- Mount the disk
mount /dev/sdb2
- Verify that your data is still there
Expand LVM Volumes On Linux
- Backup your data first
- Unmount
umount /dev/sdb2
- Edit partitions with fdisk ( use fdisk options from the section above )
fdisk /dev/sdb
- Expand the physical volume to the size of the new partition:
pvresize /dev/sdb2
- Show the available logical volumes:
lvdisplay -v
- Expand the logical volume:
lvextend -l +100%FREE /dev/vg/lv_root
- Extend the filesystem:
resize2fs /dev/vg/lv_root
- Mount the disk
mount /dev/vg/lv_root
- Verify that your data is still there
Helpful Info
If you want to see what disks are available on your system you can use any of the following commands:
lsblk
df -h
fdisk -l