Saturday, July 28, 2012

Linux 17 - Create Partitions and Filesystems

partition
create filesystems
make swap space

Debian 6 64-bit-2012-03-15-00-35-02 

There are two types of partitions on a block device

- primary

- extended

fdisk

Partition table manipulator for Linux

fdisk -l
List  the  partition tables for the specified devices and then exit.  If no devices are given, those mentioned in /proc/partitions (if that exists) are used.


To work on a specific partition the command fdisk /dev/xxx would be used.

Here the command is fdisk /dev/sda

Debian 6 64-bit-2012-03-15-00-35-44

To print all partitions press “p”

Debian 6 64-bit-2012-03-15-00-37-54

To add a new partition press “n”

image

We will create a simple partition scheme so select “p” for primary

image

Which partition umber we want : 1

First cylinder is ok as 1 since there are no other partitions

The last cylinder can be entered also as how many kilobytes, megabytes or gigabytes would we want, for this 8 GB disk I entered a value of +7G

Debian 6 64-bit-2012-03-15-00-56-07

Next we need to create a partition table ID, this is not a format command but instead a way to help the system understand how it should read the information off the disk

Debian 6 64-bit-2012-03-15-00-59-17

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

Calling ioctl() to re-read partition table.
Syncing disks.
root@debian:~#
root@debian:~# fdisk /dev/sdb

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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (916-1044, default 916):
Using default value 916
Last cylinder, +cylinders or +size{K,M,G} (916-1044, default 1044):
Using default value 1044

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x9abe0188

Device Boot Start End Blocks Id System
/dev/sdb1 1 915 7349706 83 Linux
/dev/sdb2 916 1044 1036192+ 83 Linux

Command (m for help): T
Partition number (1-4): 2
Hex code (type L to list codes): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1

Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)

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

Calling ioctl() to re-read partition table.
Syncing disks.
root@debian:~#

Now there are two partitions created.

root@debian:~# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x0003806e

Device Boot Start End Blocks Id System
/dev/sda1 * 1 996 7993344 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 996 1045 392193 5 Extended
/dev/sda5 996 1045 392192 82 Linux swap / Solaris

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x9abe0188

Device Boot Start End Blocks Id System
/dev/sdb1 1 915 7349706 83 Linux
/dev/sdb2 916 1044 1036192+ 82 Linux swap / Solaris
root@debian:~#

Create the swapspace

mkswap
sets up a Linux swap area on a device or in a file.
root@debian:~# mkswap /dev/sdb2 
Setting up swapspace version 1, size = 1036188 KiB
no label, UUID=2e0358bf-469e-4823-a0b0-c6435f8f41bc
root@debian:~#

Swap is created, next is actually telling the system to use it


root@debian:~# swapon /dev/sdb2
root@debian:~#

Check

root@debian:~# swapon  -s
Filename Type Size Used Priority
/dev/sda5 partition 392184 0 -1
/dev/sdb2 partition 1036184 0 -2
root@debian:~#

Make /dev/sdb1 an ext2 formatted partition:

 

Format as EXT3

Format as reiserFS

Format as XFS

Format as FAT32

No comments:

Post a Comment