- First, use LVM; it makes resizing filesystems nearly trivial, robust, without any real downsides. Just another way that Ubuntu is not enterprise-worthy. But, we don’t have LVM on these systems’s as they are….
- Second, before doing any operations on your partitions, always perform and test a backup (to a separate system!) of your data. You may make your system unbootable and/or nuke all of your data!
- The system I performed these steps on was partitioned thus:
- /dev/sda – 7GB – /
- /dev/sda2 – remainder – Extended partition
- /dev/sda5 – swap – partition within the extended partition.
- So, to grow “/”, we will become root, delete the swap partition and the extended partition, grow /, and then re-create the swap partition. Adjust the steps below according to the partition numbers and layout of your particular system:
- Disable swap:
- swapoff /dev/sda5
- Delete and re-create partitions as appropriate.
- fdisk /dev/sda
- print out partition information (p)
- Delete partition 5 (d – 5)
- Delete partition 2 (d – 2)
- Delete partition 1 (d)
- Create partition 1 (n – p – 1)
- It must start on the exact same sector as before (as seen in the print command)
- It must end on a sector higher than it did before. Num_GB*1024*1024*2 = ending sector
- Create partition 2 (n – p – 2)
- Change partition 2 to type “Linux Swap” (t – 2 – 82 )
- Activate partition 1 to make it bootable (a - 1)
- Double-check everything.
- Exit (w)
- recreate the swap partition, using a label:
- mkswap -L swap /dev/sda2
- add a label to the root filesystem
- e2label /dev/sda1 / (in centos, it’s e4label)
- Fix up /etc/fstab
- Fix the “swap” line to use LABEL=swap instead of UUID=
- Fix the “/” line to use LABEL=/ instead of UUID=
- swapon /dev/sda2
- Fix up /boot/grub/grub.cfg
- Either: Find the “linux” line for the menu option you will boot, change UUID= to LABEL=/
- Or: update-grub
- Re-create the initrd
- update-initramfs -u -k 3.2.0-38-generic
- Reboot the VM. *Cross your fingers!* This is your moment of truth.
- Grow the root filesystem
- resize2fs /dev/sda1 (resize4fs on CentOS, I believe).
- If it didn't boot, then that's what you get for biting off more than you could chew, and for choosing a distro that doesn't leverage LVM. Boot off your Ubuntu/Mint install disk, and copy off your data to a USB disk, and start over. (...but you DID back up your data anyway, right?)
2013/12/06
Grow root partition and filesystem in Ubuntu and Linux Mint
Here are the steps to grow the root filesystem on an existing system that does NOT use LVM:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment