Friday, July 26, 2013

Create an EXT2 FS in Linux via CLI (CentOs 6.3 64bit)

1. Open a terminal (Applications > System Tools > Terminal)

2. Within that terminal, type   fdisk -l     this will list all the disks that the system currently sees. For ease of use, make sure your system doesn't have any additional external drive connected other than the one you want to format and setup. See below for an example fdisk -l output

root@localhost:~ [root@localhost ~]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 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: 0x000c8ffe

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       60802   487873536   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 7834 MB, 7834959872 bytes
255 heads, 63 sectors/track, 952 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: 0x00000000


Disk /dev/mapper/VolGroup-lv_home: 438.1 GB, 438057304064 bytes
255 heads, 63 sectors/track, 53257 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: 0x00000000


Disk /dev/sdb: 16.0 GB, 16013852672 bytes
64 heads, 32 sectors/track, 15272 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x42c383bf

In this case, the bolded and italicized section at the bottom is the disk I want. And that disk is showing as /dev/sdb

3. You can also verify this is the correct disk by checking the /var/log/messages right after you plug in the drive (after boot, and right before formatting)

command is tail /var/log/messages The output will look something like this:

root@localhost:~ [root@localhost ~]# tail /var/log/messages 
Jun 26 14:26:17 localhost kernel: scsi7 : SCSI emulation for USB Mass Storage devices
Jun 26 14:26:18 localhost kernel: scsi 7:0:0:0: Direct-Access              Patriot Memory   PMAP PQ: 0 ANSI: 0 CCS
Jun 26 14:26:18 localhost kernel: sd 7:0:0:0: Attached scsi generic sg2 type 0
Jun 26 14:26:19 localhost kernel: sd 7:0:0:0: [sdb] 31277056 512-byte logical blocks: (16.0 GB/14.9 GiB)
Jun 26 14:26:19 localhost kernel: sd 7:0:0:0: [sdb] Write Protect is off
Jun 26 14:26:19 localhost kernel: sd 7:0:0:0: [sdb] Assuming drive cache: write through
Jun 26 14:26:19 localhost kernel: sd 7:0:0:0: [sdb] Assuming drive cache: write through
Jun 26 14:26:19 localhost kernel: sdb:
Jun 26 14:26:19 localhost kernel: sd 7:0:0:0: [sdb] Assuming drive cache: write through
Jun 26 14:26:19 localhost kernel: sd 7:0:0:0: [sdb] Attached SCSI removable disk

The bolded and italicized portions tell you what the drive is, and the [sdb] tells you the drive is located at /dev/sdb

4. Once you have verified where the drive is (/dev/XXX) now you need to format it. The base command is mke2fs, and there are a ton of options you can use. Here is an example:

mke2fs -b 4096 -L New-Volume /dev/XXX

The -b creates a filesystem with a blocksize of 4k and the -L labels the volume as New-Volume.

Verify with your customer if they want any special parameters (like blocksize, Inode size, etc) set on the deliverable drive. Then include the options wanted when running this command. Type man mke2fs for the additional options and brief description of what they do.

No comments:

Post a Comment