On IDE-based systems there will almost certainly be a primary master, so the example in slide 241 should work on most normal PCs. The slide gives an example output from “fdisk -l /dev/hda” on a system.
The Device column lists the devices each partition links up with.
The Boot column flags which partition a standard bootloader stored in the master boot record (MBR) would boot from. If GRUB is stored in the MBR it will ignore this. The boot loader which comes with DOS or Windows checks for this flag however, which means it is (potentially) useful in multi-boot systems
The Start and End columns show the start and end cylinders for each partition. The size of each cylinder is defined by the number of blocks (which is the number of heads times the number of sectors) and the size of each block. In the example in slide 241 there are 255 heads, 63 sectors and 2434 cylinders. This means that there are 2434 cylinders of 16065 blocks each (63 255). Each block is 512 bytes in size, so there are 2434 cylinders of 8032 kb (16065 512 bytes) which is 19549888 kb (8032 2434).
The Blocks column shows how many 512-byte blocks are used by a partition. The trailing+signs indicate that rounding has taken place, and that the actual value is slightly more. It is possible to get a-sign as well which means that the value is slightly less.
The Id column displays the numerical ID for the filesystem type in that partition. (See the “l” key in slide 242 and slide 243)
The System column gives the name for the ID in the previous column.
#fdisk -l /dev/hda
Disk /dev/hda: 20.0 GB, 20020396032 bytes 255 heads, 63 sectors/track, 2434 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux /dev/hda2 14 523 4096575 83 Linux /dev/hda3 524 778 2048287+ 83 Linux /dev/hda4 779 2434 13301820 5 Extended /dev/hda5 779 905 1020096 83 Linux /dev/hda6 906 1032 1020096 83 Linux /dev/hda7 1033 1097 522081 82 Linux swap
By far the most likely options for you to deal with are shown in slide 243.
# fdisk /dev/hda Command (m for help): m Command action
a toggle a bootable flag b edit bsd disklabel
c toggle the dos compatibility flag d delete a partition
l list known partition types m print this menu
n add a new partition
o create a new empty DOS partition table p print the partition table
q quit without saving changes t change a partition’s system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help):
Slide 242: Options onfdisk
m print the menu of options Effectively the help key.
p print the current partition table So you know where you are at the moment.
d delete a partition This only takes effect when you write out the details.
n create a new partition Also only takes effect when you write out the details.
q quit without saving changes For when you make a mistake, also [Control]+[C]
w write table to disk and exit For when you are sure that you have it right.
a make a partition the bootable Useful for dual booting.
l list known partition types List possible partition types for different filesystems
t change a partition’s system id Select something other than the default ext3 (Linux) partition type
Slide 243:fdiskoptions explained
9.9
Creating a partition
Slide 244 shows a new partition being created on a small blank disk. It sets the first cylinder of the new partition to be the first free one, which in this case is also the first one. Then it sets the size to be a given number of megabytes (alternatively the size could have been specified by giving the last cylinder for the partition). The only step that is not shown is the final one, “w” to write the new partition table out.
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1
First cylinder (1-648, default 1): 1
Last cylinder or +size or +sizeM (1-648, default 648): +48M
And then to check that the partition was created as expected
Command (m for help): p
Disk /dev/hdb: 64 heads, 63 sectors, 648 cylinders Units = cylinders of 4032 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 25 50368+ 83 Linux
Slide 244: Creating a new partition example
Rather than add a new disk to the system we will add a new partition to the disk which is already installed. If you have obeyed the installation instructions carefully thenfdiskon your computer will show that there is some spare space on your system which can be used to create a new partition. So usefdiskon the right device, and have a look at the options using the “m” key as in slide 242. A later exercise in this section will get you to move/varinto there, so the partition should be bigger than the current/var. There should currently be plenty of space spare on the disk.
Experiment withfdisk
do not write anything out unless you are sure that it will not delete anything important. [Control]+[C] is your friend.
When you are happy with the options available underfdiskcreate a spare partition which is larger than the current/var.
Note: Because this exercise uses a partition on an active disk a reboot is needed to make this take effect.
Slide 245: Exercise: Create a new partition
9.10
Filesystems
Now you have a blank partition on which you need a filesystem. There are large numbers of filesystems which Linux recognises and can manipulate. The (current) standard for Red Hat Linux is the “ext3” filesystems, and that is what this section concentrates on. “ext3” is the “third extended filesystem”. This has one major enhancement over “ext2”, namely it is a logging filesystem. This means that it will write changes to a log before writing to the filesystem itself. The significance is that it is easy to maintain a consistant filesystem, of which more in section 9.17. “ext2” itself which has several enhancements over the original “extended filesystem” which in turn had large improvements over the Minix filesystem that Linus Torvalds used in the original release. Section 9.16 looks in more detail at filesystem concepts, and section 9.18 looks at even more advanced filesystems. “ext3” is
such a small internal change over “ext2” that many of the tools you will use still have ’e2’ included within the name. This is merely an accident of history.
9.11
Creating a filesystem
Filesystems are created with themkfscommand, although this is really just a front end for programs likemkfs.ext3,
mkfs.minixandmkfs.msdos. The manual pages list the options as-V,-tfstype and fs-options. The-Voption will show what commands are being executed, and if given twice will not execute the commands, but only print them. The-toption takes a parameter which indicates which filesystem type is to be used, this results in the right version ofmkfsbeing called. The fs-options are passed onto whatever program is executed. The manual page for
mkfs.ext3(8) lists all the option that it takes, most of which you are unlikely to ever need to use. If you want to know more details then read the manual page, however some features that you should be aware of options to are:
Check the partition for bad blocks Set the volume label for the partition.
Change the total number of inodes or the percentage of inodes. Change the percentage of reserved blocks.
Normallymkfs /dev/partitionwill suffice to create a sensible filesystem, and unless you are sure that you wish to stray from the norm you are advised not to change the default options.
Usefdisk -landdfto check which partition to create the filesystem on. Usemkfsto create a filesystem on the partition that you created
MS-DOS calls thisformattinga partition.
If you choose a partition that is currently mounted and in use then you will be warned. Warning: It is possible to destroy data if the partition table has overlaps.
Slide 246: Exercise: Create a filesystem
9.12
Mounting filesystems
Now you have a filesystem which is on a partition, but you cannot access it. The filesystem needs to be mounted somewhere so that it can be accessed. The standard form of the mount command is
#mount -t vfstype device dir
The vfstype is one of the supported filesystems. These include, but are not limited, to ext2 ext3 iso9660 msdos vfat. More details can be found inmount(8) and in/usr/src/redhat/BUILD/linux/fs/filesystems.cif you have the sources installed.
The device is the entry in/dev refering to the relevant partition. The dir is the directory which will have the filesystem mounted onto it. It should be noted that under Linux any existing contents of the underlying directory tree are hidden from view when something is mounted on a directory.
The manual page formount(8) gives a long, if not comprehensive, list of options to mount. Some of the more interesting options are detailed in slide 247
Option Effect and use of option
async All I/O is done asynchronously. This is fast, but slightly increases the chances of a filesystem corruption in the case of a system crash.
auto Makemount -amount this filesystem. Only really useful in/etc/fstab(see section 9.13)
defaults Sets all the defaults (rw,suid,dev,exec,auto,nouser,async)
noexec Do not allow execution of any binaries on the mounted filesystem.
nosuid Do not allow set-user-ID or set-group-ID bits to take effect.
remount Re-mount a filesystem which is already mounted. Allows changes in mount flags without un- mounting a filesystem, which may not be possible at this time.
ro Make the filesystem read only.
user Allow a normal user to mount the specified filesystem, only really useful in /etc/fstab (see section 9.13)
owner Allow a normal user who owns a device to mount that filesystem. Particularly useful with CD- ROMs and floppies. Only really relevant in/etc/fstab(see section 9.13)
noload ext3 specific option to prevent the journal being played when mounting an ext3 filesystem.
Slide 247: Interesting mount options
Mount the newly created filesystem on/mnt(a traditional location).
Slide 248: Exercise: Mount the filesystem
It also would be helpful at this point to know how to unmount a filesystem. The command isumount. By and large usingumountwith the mount point or the device name as an argument will do exactly what you would want it to do. The manual page forumount(8) covers what few options it has. When unmounting a filesystem you can get the message that the “device is busy”. This means that something is using a resource on the filesystem. Often this will be an open file, although it can be a working directory, or a number of other possible things. Normallyfuser
andlsofcan be used to track down the offending processes. One hint I will include is that if you have a filesystem mounted under the filesystem that you are trying to unmount then only/etc/mtaband the output frommountwill give you a clue as to why you cannot unmount the filesystem. When the mount table has become corrupted then it is almost impossible to track down the cause of the busy message.
9.13
/etc/fstab
Being able to mount filesystems is all well and good, although naturally it would be useful to be able to have some filesystems mounted at boot time, and to be able to mount things without having to remember the specific options that are needed for that particular device.
Example entries in/etc/fstab
LABEL=/boot /boot ext3 defaults 1 2 /dev/hda7 swap swap defaults 0 0
Field Description Example
1 The block device (or volume label) to be mounted /dev/hda7, a block device.
2 The directory to mount on /boot, a directory
3 The filesystem type ext3,swap,ignore,iso9660,nfs
4 Comma separated list of mount options ro,noauto,user,owner(seemount(8))
5 Number used bydump defaults to 0, meaning do not dump
6 Number in the boot timefsckorder defaults to 0, meaning do not fsck on boot
Slide 249:/etc/fstabexplained
If you look at/etc/fstabyou will see how partitions are arranged on your current system. Included in slide 249 are details extracted fromfstab(5). The file/etc/fstabis used by the mount command to automate aspects of its operation, especially at boot time. The file is also used to declare which partitions are to be used as swap, seeswapon(8). Additionally/etc/fstabis used to control the sequence forfsckat boot time, and potentially
/sbin/dumpis partially controlled by the sixth field. If you need to add a partition to be available for use by the system then this is where you need to add it. Seemount(8) on how to override any options in/etc/fstabon the command line, or how to mount devices which have no entry in/etc/fstabby specifying all the options. Note that you need to be careful with the options, and it is strongly recommended that you check them carefully. Volume labels have existed for some time, but Red Hat have only started using them in recent releases. Unfortu- nately they are unhelpful in most respects. Knowing the volume label gives you no clues as to what the device is. In order to be able to manipulate a partition you need to know what the device is.