The following 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
Growing Partitions and file systems
From Transwiki
Contents |
[edit] Live Replacing a Mirrored Raid System with Larger Drives
- Install new drive (assuming a 2 drive mirrored RAID with no spare, SATA and squeeze or later OS)
- Detect drive name
tail /var/log/syslog
look for "sd " some number "[sdx]"
- make drive bootable by copying the MBR and existing partition table
dd if=/dev/old of=/dev/new bs=512 count=1
- Tell the kernel to re-read the partition table
echo "- - -" > /sys/class/scsi_host/host0/scan # force kernel to reread drive
- Enlarge partition size
cfdisk /dev/new - Delete and recreate as needed - new partitions must be at least as big as the old. - Verify and write - exit fdisk
- (Use parted instead if over 2TB - you will need a motherboard that supports Extensible Firmware Interface (EFI) and the Unified EFI (UEFI)!
parted -a optimal /dev/new (parted) mklabel gpt ; We need this for big partitions (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
- Observe mdstat
cat /proc/mdstat
[edit] 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 )
- repeat for each partition
- wait for the raid to sync by observing mdstat
cat /proc/mdstat
- Observe mdstat - you should see new drive appear as spare (noted by (S))
[edit] Removing Drives
- Hot Remove first old Drives
- you should observe recovery on spare
- track via mdstat until complete
- Remove second old drive
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
[edit] Grow
- grow the raid partition
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.
- Grow LVM
- grow the physical volume
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
- Grow file system
mount -o remount,resize /mountpoint ; works for jfs - YMMV with other systems
- file system check
touch /forcefsck ; force a full check next boot
- Make sure drives are bootable
grub-install /dev/sdz ; We want all drives bootable
- A good idea to test a reboot
[edit] Variations - Notes
- Edit the partitions on the new drive, making sure you leave any boot partitions alone, and increase the size of any partition(s) you want to grow.
cfdisk /dev/new (or partition editor of choice) <edit as required>
- WARNING: If you need to alter your boot partition, or you only have one big root partition, you need to make sure the new larger partition starts in EXACTLY the same location as the previous one. The best way to check this is to verify the starting sector using the following
sfdisk -d /dev/(old|new1)
- Zero if needed so raid won't try to use old data
mdadm --zero-superblock /dev/sd??
[edit] 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
- /dev/sd[ab]1 = /boot
- /dev/sd[ab]5 = /root
- /dev/sd[ab]6 = <swap>
- /dev/sd[ab]7 = LVM partition
- LVM contains /home, /tmp, /usr, & /var volumes.
- NOTE: Putting swap on LVM is a *BAD* idea, but swap on RAID1 has generally been OK.
- notes on hidden drive data http://www.berghel.net/publications/data_hiding/data_hiding.php
