469 lines
8.1 KiB
HTML
469 lines
8.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Appendix</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="Linux Partition HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Setting Up Swap Space"
|
|
HREF="setting_up_swap.html"></HEAD
|
|
><BODY
|
|
CLASS="sect1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Linux Partition HOWTO</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="setting_up_swap.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
></TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
> </TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="appendix"
|
|
></A
|
|
>10. Appendix</H1
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="formating"
|
|
></A
|
|
>10.1. Formating Partitions</H2
|
|
><P
|
|
> At the shell prompt, I begin making the file systems on my
|
|
partitions. Continuing with the example in (see <A
|
|
HREF="fdisk_partitioning.html#mixed"
|
|
>Section 5.3</A
|
|
>),
|
|
this is:
|
|
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="programlisting"
|
|
> # mke2fs /dev/sda1
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
> I need to do this for each of my partitions, but not for <TT
|
|
CLASS="filename"
|
|
>/dev/sda4</TT
|
|
> (my extended partition).
|
|
|
|
Linux supports types of file systems other than ext2. You can find out
|
|
what kinds your kernel supports by looking in:
|
|
<TT
|
|
CLASS="filename"
|
|
>/usr/src/linux/include/linux/fs.h</TT
|
|
>
|
|
</P
|
|
><P
|
|
> The most common file systems can be made with programs in <TT
|
|
CLASS="filename"
|
|
>/sbin</TT
|
|
> that start with "mk" like
|
|
<B
|
|
CLASS="command"
|
|
>mkfs.msdos</B
|
|
> and <B
|
|
CLASS="command"
|
|
>mke2fs</B
|
|
>.
|
|
</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="swap"
|
|
></A
|
|
>10.2. Activating Swap Space</H2
|
|
><P
|
|
>
|
|
To set up a swap partition:
|
|
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="programlisting"
|
|
> # mkswap -f /dev/hda5
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
To activate the swap area:
|
|
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="programlisting"
|
|
> # swapon /dev/hda5
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
Normally, the swap area is activated by the initialization scripts at
|
|
boot time.
|
|
</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="mounting"
|
|
></A
|
|
>10.3. Mounting Partitions</H2
|
|
><P
|
|
>
|
|
Mounting a partition means attaching it to the linux file system. To
|
|
mount a linux partition:
|
|
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="programlisting"
|
|
> # mount -t ext2 /dev/sda1 /opt
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
<P
|
|
></P
|
|
><DIV
|
|
CLASS="variablelist"
|
|
><DL
|
|
><DT
|
|
>-t ext2</DT
|
|
><DD
|
|
><P
|
|
> File system type. Other types you are likely to use are:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
>ext3 (journaling sile system based on ext2)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>msdos (DOS)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>hfs (mac)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>iso9660 (CDROM)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>nfs (network file system)</P
|
|
></LI
|
|
></UL
|
|
>
|
|
</P
|
|
></DD
|
|
><DT
|
|
>/dev/sda1</DT
|
|
><DD
|
|
><P
|
|
> Device name. Other device names you are likely to use:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
><TT
|
|
CLASS="filename"
|
|
>/dev/hdb2</TT
|
|
> (second partition in second IDE drive)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
><TT
|
|
CLASS="filename"
|
|
>/dev/fd0</TT
|
|
> (floppy drive A)</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
><TT
|
|
CLASS="filename"
|
|
>/dev/cdrom</TT
|
|
> (CDROM)</P
|
|
></LI
|
|
></UL
|
|
>
|
|
</P
|
|
></DD
|
|
><DT
|
|
>/opt</DT
|
|
><DD
|
|
><P
|
|
> mount point. This is where you want to "see" your partition.
|
|
When you type <TT
|
|
CLASS="userinput"
|
|
><B
|
|
>ls /opt</B
|
|
></TT
|
|
>, you can see what
|
|
is in <TT
|
|
CLASS="filename"
|
|
>/dev/sda1</TT
|
|
>. If there
|
|
are already some directories and/or files under <TT
|
|
CLASS="filename"
|
|
>/opt</TT
|
|
>, they will be invisible after
|
|
this mount command.
|
|
</P
|
|
></DD
|
|
></DL
|
|
></DIV
|
|
>
|
|
</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="fragmentation"
|
|
></A
|
|
>10.4. Some facts about file systems and fragmentation</H2
|
|
><P
|
|
> Disk space is administered by the operating system in units of
|
|
blocks and fragments of blocks. In ext2, fragments and blocks
|
|
have to be of the same size, so we can limit our discussion to
|
|
blocks.
|
|
</P
|
|
><P
|
|
> Files come in any size. They don't end on block boundaries. So
|
|
with every file a part of the last block of every file is
|
|
wasted. Assuming that file sizes are random, there is
|
|
approximately a half block of waste for each file on your disk.
|
|
Tanenbaum calls this "internal fragmentation" in his book
|
|
"Operating Systems".
|
|
</P
|
|
><P
|
|
> You can guess the number of files on your disk by the number of
|
|
allocated inodes on a disk. On my disk
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="programlisting"
|
|
> # df -i
|
|
Filesystem Inodes IUsed IFree %IUsed Mounted on
|
|
/dev/hda3 64256 12234 52022 19% /
|
|
/dev/hda5 96000 43058 52942 45% /var
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
|
|
there are about 12000 files on <TT
|
|
CLASS="filename"
|
|
>/</TT
|
|
> and about 44000 files on <TT
|
|
CLASS="filename"
|
|
>/var</TT
|
|
>. At a block size of 1 KB, about
|
|
6+22 = 28 MB of disk space are lost in the tail blocks of files. Had
|
|
I chosen a block size of 4 KB, I had lost 4 times this space.
|
|
</P
|
|
><P
|
|
> Data transfer is faster for large contiguous chunks of data, though.
|
|
That's why ext2 tries to preallocate space in units of 8 contigous
|
|
blocks for growing files. Unused preallocation is released when the
|
|
file is closed, so no space is wasted.
|
|
</P
|
|
><P
|
|
> Noncontiguous placement of blocks in a file is bad for performance,
|
|
since files are often accessed in a sequential manner. It forces the
|
|
operating system to split a disk access and the disk to move the
|
|
head. This is called "external fragmentation" or simply
|
|
"fragmentation" and is a common problem with MS-DOS file systems. In
|
|
conjunction with the abysmal buffer cache used by MS-DOS, the
|
|
effects of file fragmentation on performance are very noticeable.
|
|
DOS users are accustomed to defragging their disks every few weeks
|
|
and some have even developed some ritualistic beliefs regarding
|
|
defragmentation.
|
|
</P
|
|
><P
|
|
> None of these habits should be carried over to Linux and ext2. Linux
|
|
native file systems do not need defragmentation under normal use and
|
|
this includes any condition with at least 5% of free space on a
|
|
disk. There is a defragmentation tool for ext2 called defrag, but
|
|
users are cautioned against casual use. A power outage during such
|
|
an operation can trash your file system. Since you need to back up
|
|
your data anyway, simply writing back from your copy will do the
|
|
job.
|
|
</P
|
|
><P
|
|
> The MS-DOS file system is also known to lose large amounts of disk
|
|
space due to internal fragmentation. For partitions larger than 256
|
|
MB, DOS block sizes grow so large that they are no longer useful
|
|
(This has been corrected to some extent with FAT32). Ext2 does not
|
|
force you to choose large blocks for large file systems, except for
|
|
very large file systems in the 0.5 TB range (that's terabytes with 1
|
|
TB equaling 1024 GB) and above, where small block sizes become
|
|
inefficient. So unlike DOS there is no need to split up large disks
|
|
into multiple partitions to keep block size down.
|
|
</P
|
|
><P
|
|
> Use a 1Kb block size if you have many small files. For large
|
|
partitions, 4Kb blocks are fine.
|
|
</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="setting_up_swap.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
> </TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Setting Up Swap Space</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
> </TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
> </TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |