Growing Partitions and file systems


Live Replacing a Mirrored Raid System with Larger Drives

tail /var/log/syslog

look for "sd " some number "[sdx]"

dd if=/dev/old of=/dev/new bs=512 count=1
echo "- - -" > /sys/class/scsi_host/host0/scan # force kernel to reread drive
cfdisk  /dev/new
- Delete and recreate as needed - new partitions must be at least as big as the old.
- Verify and write 
- exit fdisk

using parted

parted -a optimal /dev/new
(parted) mklabel gpt ; We need this for big partitions - label in this case means a new partition table of the gpt type
(parted) mkpart primary 8192S  23447039S ; make an aligned 12 GB partition 
(parted) mkpart primary 23453696s -1 ; use the rest of the drive for the second partition
(parted) set 1 raid on
(parted) set 2 raid on
(parted) q
sfdisk -R /dev/new
sfdisk -V /dev/new ; make sure it is valid
echo "- - -" > /sys/class/scsi_host/host0/scan # force kernel to reread drive again
sync


Use parted to do an optimal alignment of the entire disk

$  parted --align optimal /dev/new
 GNU Parted 3.2
 Using /dev/sde
 Welcome to GNU Parted! Type 'help' to view a list of commands.
 (parted) mklabel gpt 
 Warning: The existing disk label on /dev/sde will be destroyed and all data on this disk will be lost. Do you want to continue?
 Yes/No? yes 
 (parted) mkpart primary 0% 100% 
 (parted) q

checking raid status

cat /proc/mdstat

Add the drives to the raid

mdadm -a /dev/md0 /dev/new1 

(new in the form sdxd where x is the drive letter and d is the partition number - needs to rhyme with what was in mdstat )

cat /proc/mdstat

Removing Drives

mdadm -f /dev/mdz /dev/sdxd ; fails the unit where 'z' is the raid and x is the drive and d is the partition number
mdadm -r /dev/mdz /dev/sdxd ; removes the unit
echo "- - -" > /sys/class/scsi_host/host0/scan # force kernel to reread drive
sync

Grow

mdadm --grow -z max /dev/md0 ; You could use some size in kB if you don't want the whole drive
/usr/share/mdadm/checkarry /dev/mdx ; This is not needed, but might be a good check.
vgdisplay ; See where we start
pvresize /dev/md0
vgdisplay ; should now show the new size
lvdisplay ; find the logical volume you want to expand
lvresize -l +100%FREE /dev/vgname/lvname ; to use max size - other options available
mount -o remount,resize /mountpoint ; works for jfs - YMMV with other systems
touch /forcefsck ; force a full check next boot
grub-install /dev/sdz ; We want all drives bootable

Variations - Notes

cfdisk /dev/new (or partition editor of choice) <edit as required>
sfdisk -d /dev/(old|new1)


mdadm --zero-superblock /dev/sd??

Partition Notes

Regarding the partitioning...beware of the tools you use. In general, the partitions created by fdisk/sfdisk/cfdisk are not all happily compatible with each other, and may or may not be compatible with Windows (particularly Windows 7/Vista).

Try them in the order cfdisk, fdisk, sfdisk. (Indeed, cfdisk is a beautiful program that has strict requirements on the partition tables it accepts, and produces high quality partition tables. Use it if you can. fdisk is a buggy program that does fuzzy things - usually it happens to produce reasonable results. Its single advantage is that it has some support for BSD disk labels and other non-DOS partition tables. Avoid it if you can. sfdisk is for hackers only - the user interface is terrible, but it is more correct than fdisk and more powerful than both fdisk and cfdisk. Moreover, it can be used noninteractively.)

That's why I put boot on primary partition one, and clone the first sector (and partition table) so there are no surprises with a non-booting system. I typically just blow away the extended partition table which (for me) contains root, swap, and a partition for LVM:

Device Boot Start End Blocks Id  System
/dev/sda1 * 1 31 248976 fd  Linux raid autodetect
/dev/sda4 32 121601 976511025 5  Extended
/dev/sda5 32 156 1004031 fd  Linux raid autodetect
/dev/sda6 157 405 2000061 fd  Linux raid autodetect
/dev/sda7 406 121601 973506838+  fd  Linux raid autodetect

Top Page wiki Index

Disclaimer

This information may have errors; It is not permissible to be read by anyone who has ever met a lawyer.
Use is confined to Engineers with more than 370 course hours of electronic engineering for theoretical studies.
ph +1(785) 841-3089

Email inform@xtronics.com

(C) Copyright 1994-2017, Transtronics, Inc. All rights reserved
TranstronicsĀ® is a registered trademark of Transtronics, Inc.
All trademarks are the property of their respective owners.