Вы находитесь на странице: 1из 6

Disk /dev/sdb: 74.3 GB, 74355769344 bytes

255 heads, 63 sectors/track, 9039 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

and here's an example of a disk with valid partition table

# fdisk -l /dev/sda

Disk /dev/sda: 299.9 GB, 299974524928 bytes

255 heads, 63 sectors/track, 36469 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

268

2048287+

82

Linux swap

/dev/sda3

 

269

36469

290784532+

83

Linux

to change the partitions on a drive without partition table, such as a new drive, use fdisk

eg. fdisk /dev/sdb

# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.

The number of cylinders for this disk is set to 9039. 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):

m will list the options available.

eg. p will print the partition table, n is for adding new partition table; and after the changes are done, w will commit the changes, and exit the program.

e2label

Usage of e2label is simple. manpage for e2label shows following command line options,

e2label device [ new-label ]

device can be the entire drive or a partition. eg. /dev/sda is the entire drive /dev/sda1 is the first partition of device /dev/sda /dev/sda2 is the second partition of device /dev/sda

eg. to show the label of /dev/sda1 and /dev/sda3

# e2label /dev/sda1

/boot

#

e2label /dev/sda3

/

To change the label for /dev/sda3, do as follows,

# e2label /dev/sda3 changed-label

and to confirm the change was done sucessfully,

# e2label /dev/sda3

changed-label

if you want a / in front of the label,

# e2label /dev/sda3 /changed-label

to verify that the change was done,

# e2label /dev/sda3

/changed-label

if you want the server to be able to boot next time round, ensure changes are made to

/etc/fstab as well. Otherwise, on the next boot, you may be prompted with errors, eg.

fsck.ext3: Unable to resolve 'LABEL=/boot' fsck.ext3: Unable to resolve 'LABEL=/'

in which case, you can boot up with a rescue disk, eg. CentOS installation disk, enter "linux rescue" at prompt; chroot /mnt/sysimage and edit /etc/fstab accordingly. Alternatively, if you are prompted for root password, and gets a shell, you may be able to edit /etc/fstab. If the filesystem is readonly, remount the filesytem readwrite. eg. mount -o remount,rw /

mount, umount

# mount /dev/sdb5 /tmp/mnt

will mount /dev/sdb5 on the /tmp/mnt directory

if /tmp/mnt does not exist, it needs to be created, using mkdir

to unmount the device, use umount /dev/sdb5 or umount /tmp/mnt

Example of partitioning, formatting and labelling of a new drive

2 partitions to be created 100MB and rest of the drive

# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable.

The number of cylinders for this disk is set to 9039. 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): n Command action

e extended

p

primary partition (1-4)

p

Partition number (1-4): 1 First cylinder (1-9039, default 1):

Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-9039, default 9039): +100M

Command (m for help): n Command action

e

extended

p

primary partition (1-4)

p

Partition number (1-4): 2 First cylinder (14-9039, default 14):

Using default value 14 Last cylinder or +size or +sizeM or +sizeK (14-9039, default 9039):

Using default value 9039

Command (m for help): p

Disk /dev/sdb: 74.3 GB, 74355769344 bytes

255 heads, 63 sectors/track, 9039 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

9039

72501345

83

Linux

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

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

Next: format both partitions as ext3 filesystems

# mkfs.ext3 /dev/sdb1

mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0)

26104 inodes, 104388 blocks

5219 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67371008 13 block groups

8192

blocks per group, 8192 fragments per group

2008

inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729

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

This filesystem will be automatically checked every 22 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

# mkfs.ext3 /dev/sdb2

mke2fs 1.39 (29-May-2006)

Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 9076736 inodes, 18125336 blocks 906266 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296

554 block groups

32768

blocks per group, 32768 fragments per group

16384

inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424

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

This filesystem will be automatically checked every 33 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

next: use e2label to label the volumes. Although both mkfs3.ext and tune2fs is capable of labelling, with the -L option, I am deliberately using e2label in this example to demonstrate the use of e2label.

# e2label /dev/sdb1 /drive2-100MB

confirm its done.

# e2label /dev/sdb1

/drive2-100MB

label sdb2 next,

# e2label /dev/sdb2 /drive2-restofdrive

Warning: label too long, truncating.

# e2label /dev/sdb2

/drive2-restofdr

the description used was too long, and got truncated. maximum for label is 16 characters.

next, we try to mount and unmount the 2 filesystems created,

mount shows what has already been mounted. in addition, the -l option shows the filesystem label

# mount -l

/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/sda1 on /boot type ext3 (rw) [/boot] 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)

We are mainly concerned with the drives, so let's grep for the relevent entries

#mount -l | grep /dev/sd /dev/sda3 on / type ext3 (rw) [/]

/dev/sda1 on /boot type ext3 (rw) [/boot]

We need mount points; the following mount points are created,

# mkdir /mountpt1

# mkdir /mountpt2

to manually mount the drives,

# mount /dev/sdb1 /mountpt1

check that it is mounted,

# mount -l|grep /dev/sd

/dev/sda3 on / type ext3 (rw) [/] /dev/sda1 on /boot type ext3 (rw) [/boot] /dev/sdb1 on /mountpt1 type ext3 (rw) [/drive2-100MB]

# mount /dev/sdb2 /mountpt2

# mount -l|grep /dev/sd

/dev/sda3 on / type ext3 (rw) [/] /dev/sda1 on /boot type ext3 (rw) [/boot] /dev/sdb1 on /mountpt1 type ext3 (rw) [/drive2-100MB] /dev/sdb2 on /mountpt2 type ext3 (rw) [/drive2-restofdr]

to unmount, use umount

# umount /dev/sdb1

# umount /dev/sdb2

# mount -l|grep /dev/sd

/dev/sda3 on / type ext3 (rw) [/] /dev/sda1 on /boot type ext3 (rw) [/boot]

we can also mount the filesystems using the filesystem labels,

# mount -L /drive2-100MB /mountpt1/

# mount -L /drive2-restofdr /mountpt2/

# mount -l |grep /dev/sd

/dev/sda3 on / type ext3 (rw) [/] /dev/sda1 on /boot type ext3 (rw) [/boot] /dev/sdb1 on /mountpt1 type ext3 (rw) [/drive2-100MB] /dev/sdb2 on /mountpt2 type ext3 (rw) [/drive2-restofdr]

unmount can also use the mount point instead of the device, eg.

# umount /mountpt1

# umount /mountpt2

# mount -l |grep /dev/sd

/dev/sda3 on / type ext3 (rw) [/] /dev/sda1 on /boot type ext3 (rw) [/boot]

next: edit /etc/fstab, add in entries for the new drive if we want it to be mounted at boot up.

following is existing /etc/fstab for the server, which was installed for purpose of this tutorial,

LABEL=/

/

ext3

defaults

1

1

LABEL=/boot

/boot

ext3

defaults

1

2

tmpfs

/dev/shm

tmpfs

defaults

0

0

devpts

/dev/pts

devpts

gid=5,mode=620

0

0

sysfs

/sys

sysfs

defaults

0

0

proc

/proc

proc

defaults

0

0

LABEL=SWAP-sda2

swap

swap

defaults

0

0

add the following entries,

LABEL=/drive2-100MB

/mountpt1

ext3

defaults

1 1

LABEL=/drive2-restofdr

/mountpt2

ext3

defaults

1 2

mount has a -a option which reads /etc/fstab and mounts all filesystems mentioned in the file,

# mount -a

# mount -l |grep /dev/sd

/dev/sda3 on / type ext3 (rw) [/] /dev/sda1 on /boot type ext3 (rw) [/boot] /dev/sdb1 on /mountpt1 type ext3 (rw) [/drive2-100MB] /dev/sdb2 on /mountpt2 type ext3 (rw) [/drive2-restofdr]

next, reboot, and ensure the new drive is mounted automatically, and accessible via the mount points, /mountpt1, /mountpt2