Tuesday, February 2, 2010

Linux: How to create a new Partition on Linux?

Linux Partitioning follows a simple step which can be executed post installation.Below mentioned steps creates a new partition called /u02 and needed to be mounted therein.

Hope it helps understandign clear cut steps to linux partitioning:

[root@ajeet ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 479M 9.1G 5% /
/dev/sda7 4.9G 139M 4.5G 3% /home
/dev/sda6 4.9G 230M 4.4G 5% /var
/dev/sda5 7.6G 2.4G 4.9G 33% /usr
/dev/sda2 11G 155M 9.4G 2% /opt
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 1010M 0 1010M 0% /dev/shm
/dev/sda9 9.2G 150M 8.6G 2% /u01

[root@ajeet ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1364 10851907+ 83 Linux
/dev/sda3 1365 2715 10851907+ 83 Linux
/dev/sda4 2716 9729 56339955 5 Extended
/dev/sda5 2716 3738 8217216 83 Linux
/dev/sda6 3739 4388 5221093+ 83 Linux
/dev/sda7 4389 5038 5221093+ 83 Linux
/dev/sda8 5039 5560 4192933+ 82 Linux swap / Solaris
/dev/sda9 5561 6777 9775521 83 Linux

Command (m for help): n
First cylinder (6778-9729, default 6778):
Using default value 6778
Last cylinder or +size or +sizeM or +sizeK (6778-9729, default 9729): +10000M

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1364 10851907+ 83 Linux
/dev/sda3 1365 2715 10851907+ 83 Linux
/dev/sda4 2716 9729 56339955 5 Extended
/dev/sda5 2716 3738 8217216 83 Linux
/dev/sda6 3739 4388 5221093+ 83 Linux
/dev/sda7 4389 5038 5221093+ 83 Linux
/dev/sda8 5039 5560 4192933+ 82 Linux swap / Solaris
/dev/sda9 5561 6777 9775521 83 Linux
/dev/sda10 6778 7994 9775521 83 Linux

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.
Syncing disks.

[root@ajeet ~]# partprobe

[root@ajeet ~]# mkfs.ext3 /dev/sda10
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1224000 inodes, 2443880 blocks
122194 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2503999488
75 block groups
32768 blocks per group, 32768 fragments per group
16320 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 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@ajeet ~]# e2label /dev/sda10 /u02

[root@ajeet ~]# vi /etc/fstab

[root@ajeet ~]# mkdir /u02

[root@ajeet ~]# mount -a

[root@ajeet ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 479M 9.1G 5% /
/dev/sda7 4.9G 139M 4.5G 3% /home
/dev/sda6 4.9G 230M 4.4G 5% /var
/dev/sda5 7.6G 2.4G 4.9G 33% /usr
/dev/sda2 11G 155M 9.4G 2% /opt
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 1010M 0 1010M 0% /dev/shm
/dev/sda9 9.2G 150M 8.6G 2% /u01
/dev/sda10 9.2G 150M 8.6G 2% /u02

[root@ajeet ~]# mount
/dev/sda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda7 on /home type ext3 (rw)
/dev/sda6 on /var type ext3 (rw)
/dev/sda5 on /usr type ext3 (rw)
/dev/sda2 on /opt type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sda9 on /u01 type ext3 (rw)
/dev/sda10 on /u02 type ext3 (rw)

[root@ajeet ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 479M 9.1G 5% /
/dev/sda7 4.9G 139M 4.5G 3% /home
/dev/sda6 4.9G 230M 4.4G 5% /var
/dev/sda5 7.6G 2.4G 4.9G 33% /usr
/dev/sda2 11G 155M 9.4G 2% /opt
/dev/sda1 99M 24M 71M 25% /boot
tmpfs 1010M 0 1010M 0% /dev/shm
/dev/sda9 9.2G 150M 8.6G 2% /u01
/dev/sda10 9.2G 150M 8.6G 2% /u02
[root@ajeet ~]#