If you have ever created a Linux VM guest and made the ext4 root disk too small, there is a pretty simple way to increase the size of the disk. The following will outline those steps. Sections in blue are what you would type:
-
Edit the settings in vSphere for the VM
- increase the size of the disk
- add another disk just for linux swap (same size as memory). I like to separate the swap partition from the root. In VMware, this is very easy and makes this process very simple
- reboot VM.
-
On the VM do the following:
- Delete all the partitions on /dev/sda (1,2,5) and recreate just the root primary partition /dev/sda1
- create swap disk using mkswap command
- edit /etc/fstab and chage UUID of swap disk
- reboot server
- after reboot, resize root partition /dev/sda1
- confirm your work
Delete and Recreate
root@freeradius2:~# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
64 heads, 2 sectors/track, 327680 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000900
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 31457279 15727616 83 Linux
/dev/sda2 31459326 33552383 1046529 5 Extended
/dev/sda5 31459328 33552383 1046528 82 Linux swap / Solaris
Delete All Partitions
Command (m for help): d
Partition number (1-5): 1
Command (m for help): d
Partition number (1-5): 2
Command (m for help): d
Partition number (1-5): 5
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
64 heads, 2 sectors/track, 327680 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000900
Device Boot Start End Blocks Id System
Create New root Partion, use same first sector as previous partition
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
64 heads, 2 sectors/track, 327680 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000900
Device Boot Start End Blocks Id System
/dev/sda1 2048 41943039 20970496 83 Linux
Make Partition Bootable
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
64 heads, 2 sectors/track, 327680 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000900
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 41943039 20970496 83 Linux
Write Label to Disk
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
root@freeradius2:~#
Make Swap Disk, note the UUID which we will add to fstab
root@freeradius2:~# mkswap -f /dev/sdb
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=57938015-46bc-469b-b4bb-f41b4d2f5a30
Edit /etc/fstab, change UUID of swap
root@freeradius2:/etc# vi fstab
Reboot Server
root@freeradius2:~# reboot
After Reboot, Resize root
root@freeradius2:~# resize2fs /dev/sda1
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/sda1 to 5242624 (4k) blocks.
The filesystem on /dev/sda1 is now 5242624 blocks long.
Now Check Your Work
root@freeradius2:~# df -h
root@freeradius2:~# swapon -s
1 comment
thanks for the great post. it reminds me that i have to bring more structure into my blogging. your blog is very interesting. please let me know how to go for your rss blog. lista de email lista de email lista de email lista de email lista de email