Add, partition, format and mount hard disks on linux. Fast and simple step by step guideBy neokrates, written on November 12, 2011
New hard disk was attached to the Linux PC. Now it is time to find it, add partitions, format and make available for the system.Here is a simple step by step guide with some explanation of the process.
✔ newer Debian, Ubuntu, CentOS distros
Should work for:
✔ most other common newer Linux distros
You will need super user privileges, do and enter authorize as needed
Where on Linux is my new hard disk?
One way to find new, avalaible but not partitioned device, is to use
[root@thinkplexx ~]# ls /dev/s* /dev/sda /dev/sda2 /dev/sdb1 /dev/sg1 /dev/snapshot /dev/stdin /dev/systty /dev/sda1 /dev/sdb /dev/sdc /dev/sg0 /dev/sg2 /dev/stderr /dev/stdout
Here, we can see that
/dev/sda, /dev/sdb etc all have been partitioned:
/dev/sda /dev/sda1 ... /dev/sdb /dev/sdb1 ...
/dev/sdc is available as a phisical device but has no partitions like
/dev/sdc1, /dev/sdc2 etc.
Use fdisk to make partitions
fdisk /dev/sdc :
[root@thinkplexx ~]# fdisk /dev/sdc The number of cylinders for this disk is set to 33418. 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)
Message is common for newer disks and selfexplaining. Says that you might have problems with older LILO’s and double booting systems.
Get disk info
You are inside fdisk now
Command (m for help): [type p] Disk /dev/sdc: 274.8 GB, 274877906944 bytes 255 heads, 63 sectors/track, 33418 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Yep, disk is there, but no partitions.
Add a primary partition
We just take all space for one partition:
Command (m for help): [type n] Command action e extended p primary partition (1-4) [type p] Partition number (1-4): [type 1] First cylinder (1-621, default 1): [type RETURN] Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-33418, default 33418): [type RETURN] Using default value 33418
Verify new partition table, in my case it would be:
Command (m for help): p ... Device Boot Start End Blocks Id System /dev/sdc1 1 33418 268430053+ 83 Linux
Write table to disk and exit
After you verified that your changes are ok, use
w to write new partition table.
If you don’t use “w”, no changes will happen, no new partitions will be creted.
now, if you try
ls /dev/s* , there will be /dev/sdc1 partition available:
[root@thinkplexx ~]# ls /dev/s* /dev/sda /dev/sda2 /dev/sdb1 /dev/sdc1 /dev/sg1 /dev/snapshot /dev/stdin /dev/systty /dev/sda1 /dev/sdb /dev/sdc /dev/sg0 /dev/sg2 /dev/stderr /dev/stdout
mkfs.ext3 to format using
[root@thinkplexx ~]# mkfs.ext3 /dev/sdc1 mke2fs 1.39 (8-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) ... Writing inode tables: done Creating journal (268430053 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Create a new mount point
fstab so that mounted device will be available after reboot and
mount command may be applied on mount point.
You are in vim, type [e].
/dev/sdc1 partition should be mounted to
/dev/sdc1 /mnt/storage ext3 defaults 1 2
After line is added, use key combination [esc][:wq!]. Vim saves new fstab.
Done, new hard disk partition can be used
[root@thinkplexx ~]# cd / [root@thinkplexx ~]# df -k Filesystem 1K-blocks Used Available Use% Mounted on ... /dev/sdc1 264218344 0 89411780 0% /mnt/storage ...
device is ready to be used.