2013年7月14日 星期日

add a new volume to an existing instance on AWS EC2

1. create a new volume in the same region. (I think in the same zone as well.)
2. attached that volume to the instance which you want to mount it on.
3. ssh that instance and use fdisk to format it (as EXT4 file system)
4. make a mount point and mount it manually.
5. if OK, make it auto mount permanently.

in step 3. (new volume device name is /dev/sdg for example) (10GB totally.)

$ sudo fdisk /dev/sdg

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xabc1a488.
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): p

Disk /dev/sdg: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xabc1a488

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305

Command (m for help): p

Disk /dev/sdg: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xabc1a488

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1               1        1305    10482381   83  Linux


Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


## format it

$ sudo mkfs.ext4 /dev/sdg1

mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
652800 inodes, 2608554 blocks
130427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2671771648
80 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


## mkdir a mount point and mount it

$ sudo mkdir /tmp3
$ sudo vi /etc/fstab

### add following line

/dev/sdg1 /tmp3 ext4 rw 0 0

$ sudo mount -a
$ df

## df to check whether it's mounted.
$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1              8256952   6425800   1411724  82% /
...
/dev/sdg1             10270304    153992   9594604   2% /tmp3