LVM – Resizing a Linux partition

LVM Resizing a Linux partition

I’m sure at some point you will need to resize a partition, particularly if you aren’t using LVM (Logical Volume Manager), to create and manage your disks. **** This will only work for non-root partitions *****

# Drop to single user mode
init 1

# Umount the partition
umount /var

# Create a temporary directory
mkdir /backup-var

# Remount the disk under the temporary directory
mount /dev/sdb1 /backup-var

# Copy all data from the disk
cd /backup-var
cp -R * /var
cd /
umount /backup-var

# Update /etc/fstab comment out the path this partition / disk maps to

(optional)
# Resize the disk in VMWare
# Using vSphere, right click the VM and edit settings
# Increase the storage allocation for the relevant disk

# Remove the current partitions on the disk
fdisk /dev/sdb

# Create a new physical volume
pvcreate /dev/sdb1

# Confirm the PV exists
pvdisplay

# Create a new volume group
vgcreate vg-name /dev/sdb1

# Confirm the VG exists
vgdisplay

# Create a new logical volume
lvcreate vg-name -L size in GB G

# Prepare the volume by creating the filesystem
mkfs.ext3 /dev/mapper/vg-name-lv-name

# Copy the data back
mount /dev/mapper/vg-name-lv-name /backup-var
cd /var
cp -R * /backup-var

# Update /etc/fstab
/dev/mapper/vg-name-lv-name /var ext3 errors=remount-ro 0 1

# Reboot
Enhanced by Zemanta
Posted in IT, Linux, Open Source and tagged , , , , , , , . Bookmark the permalink. RSS feed for this post. Leave a trackback.

Leave a Reply

  • Who is Gareth?

    Established in the mid eighties, Gareth took to computers at an early age. Growing to lead a career in IT, now spanning over a decade. His big passion is fitness, and studying the impact it has on a persons life. As a regular at the gym he uses his workouts to push his body beyond the limit. When not working, Gareth spends his evenings developing ideas to generate viable business solutions encompassing his passions, IT + Fitness.

Swedish Greys - a WordPress theme from Nordic Themepark.