A friend asked me how to resize a disk partition ( virtual disk ) in an Ubuntu VM on VMware.
This is what I did: -
Look at the existing disk layout
df -kmh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 3.6G 15G 20% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 478M 4.0K 478M 1% /dev
tmpfs 98M 1.5M 97M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 489M 216K 489M 1% /run/shm
none 100M 32K 100M 1% /run/user
/dev/sdb1 4.8G 10M 4.6G 1% /installs
Look at the underlying disk "drive"
fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
181 heads, 40 sectors/track, 1448 cylinders, total 10485760 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: 0x9844eb8f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10485759 5241856 83 Linux
In VMware Fusion, I have TWO virtual disks
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 3.6G 15G 20% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 478M 4.0K 478M 1% /dev
tmpfs 98M 1.5M 97M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 489M 216K 489M 1% /run/shm
none 100M 32K 100M 1% /run/user
/dev/sdb1 4.8G 10M 4.6G 1% /installs
Look at the underlying disk "drive"
fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
181 heads, 40 sectors/track, 1448 cylinders, total 10485760 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: 0x9844eb8f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10485759 5241856 83 Linux
In VMware Fusion, I have TWO virtual disks
Increase it from 5 GB to 10 GB, with the Linux VM shutdown
With this result
Now check the file-system in Linux
df -kmh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 3.6G 15G 21% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 478M 4.0K 478M 1% /dev
tmpfs 98M 1.5M 97M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 489M 144K 489M 1% /run/shm
none 100M 28K 100M 1% /run/user
/dev/sdb1 4.8G 10M 4.6G 1% /installs
/dev/sda1 19G 3.6G 15G 21% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 478M 4.0K 478M 1% /dev
tmpfs 98M 1.5M 97M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 489M 144K 489M 1% /run/shm
none 100M 28K 100M 1% /run/user
/dev/sdb1 4.8G 10M 4.6G 1% /installs
fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
181 heads, 40 sectors/track, 2896 cylinders, total 20971520 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: 0x9844eb8f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10485759 5241856 83 Linux
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
181 heads, 40 sectors/track, 2896 cylinders, total 20971520 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: 0x9844eb8f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10485759 5241856 83 Linux
Nothing has changed, you cry
Now we delete the old partition :-)
Command (m for help): d
Selected partition 1
and then create a new one
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-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Note that we start with the same block - 2048 - but that the end block is ~2x ( increased from 10,485,759 to 20,971,519 )
Write the new partition table
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.
Selected partition 1
and then create a new one
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-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Note that we start with the same block - 2048 - but that the end block is ~2x ( increased from 10,485,759 to 20,971,519 )
Write the new partition table
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.
Error-check the virtual disk
e2fsck -f /dev/sdb1
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 11/327680 files (0.0% non-contiguous), 55902/1310464 blocks
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 11/327680 files (0.0% non-contiguous), 55902/1310464 blocks
Resize the virtual disk
resize2fs /dev/sdb1
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/sdb1 to 2621184 (4k) blocks.
The filesystem on /dev/sdb1 is now 2621184 blocks long.
Resizing the filesystem on /dev/sdb1 to 2621184 (4k) blocks.
The filesystem on /dev/sdb1 is now 2621184 blocks long.
Mount the file-system
mount -a
Look at the new disk layout
df -kmh
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 3.7G 15G 21% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 478M 4.0K 478M 1% /dev
tmpfs 98M 1.5M 97M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 489M 144K 489M 1% /run/shm
none 100M 28K 100M 1% /run/user
/dev/sdb1 9.8G 12M 9.2G 1% /installs
/dev/sda1 19G 3.7G 15G 21% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 478M 4.0K 478M 1% /dev
tmpfs 98M 1.5M 97M 2% /run
none 5.0M 0 5.0M 0% /run/lock
none 489M 144K 489M 1% /run/shm
none 100M 28K 100M 1% /run/user
/dev/sdb1 9.8G 12M 9.2G 1% /installs
Job, as they say, is a good 'un
With thanks to this: -
No comments:
Post a Comment