Attach Disk
First of all attach a disk to the Linux Box by following Attach Disk to Live Linux
Create new partition
- As root user run fdisk on new disk, this tutorial will use /dev/sdd as example. Output will look like
$ fdisk /dev/sdd Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x925579ba. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): - Create a new partition by typing letter ‘n‘ and hit enter, to create a primary partition type ‘p‘, followed by partition number e.g. ‘1‘ and then accept default cylinder numbers by hitting enter to use the maximum space on the disk,
Output would like likeCommand (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2088, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088): Using default value 2088 Command (m for help): - Change the type of the partition to Linux LVM by hitting ‘t’ followed by ’8e’
Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help):
- to see the result hit ‘p’, please note the device path in the output, in this example “/dev/sdd1″
Command (m for help): p Disk /dev/sdd: 17.2 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x925579ba Device Boot Start End Blocks Id System /dev/sdd1 1 2088 16771828+ 8e Linux LVM Command (m for help):
- to write changes and exit hit ‘w’
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
- use pvcreate to setup the newly created partition
pvcreate /dev/sdd1
Extend existing volume group on to new partition
- Run vgdisplay to get list of volume groups
$ vgdisplay --- Volume group --- VG Name ubuntu-template System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.76 GiB PE Size 4.00 MiB Total PE 5058 Alloc PE / Size 5054 / 19.74 GiB Free PE / Size 4 / 16.00 MiB VG UUID RIgBdX-r2aN-s0Dn-kkkh-ZkVr-rHDM-AycDtH --- Volume group --- VG Name ubuntuserver System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size 43.82 GiB PE Size 4.00 MiB Total PE 11218 Alloc PE / Size 5537 / 21.63 GiB Free PE / Size 5681 / 22.19 GiB VG UUID ZoXbMV-LtZL-TRT1-MIFi-04xr-CFB3-rYTKxs
- in above output we will be extending “ubuntuserver” volume group by running
vgextended ubuntuserver /dev/sdd1
Extend existing logical volume onto new space
- Get the file path for the logical volume
$ ls -la /dev/ubuntuserver total 0 drwxr-xr-x 2 root root 80 2012-10-11 10:57 . drwxr-xr-x 15 root root 3940 2012-10-11 13:00 .. lrwxrwxrwx 1 root root 27 2012-10-11 10:59 root -> ../mapper/ubuntuserver-root lrwxrwxrwx 1 root root 29 2012-10-09 12:51 swap_1 -> ../mapper/ubuntuserver-swap_1
- use lvextend
- to use all of the new space
lvextend /dev/ubuntuserver/root /dev/sdd1
- to increase by by 20GB, provided that /dev/sdd1 has the free space available
lvextend -L +20G /dev/ubuntuserver/root /dev/sdd1
- to use all of the new space
Extend Filesystem
The command to use depends on the file system that is currently in use.
- For ext3/4
ext2online /dev/ubuntuserver/root
OR
resize2fs /dev/ubuntuserver/root
- For reiserfs
resize_reiserfs /dev/ubuntuserver/root
Finally, check disk space to see the expanded disk space
df -h