might be in an unstable condition. LVM can also make snapshots of the logical volume that can then be mounted and backed up.

For more information on LVM under Linux, read the LVM HOWTO at http://tldp.org/HOWTO/LVM-HOWTO/, which explains the terminology and provides a guide to setting up and using LVM on a Linux system.

File System Manipulation

Different people have various learning styles. For those of you who prefer examples rather than lectures, here are a few practical examples in which you learn how to create a file system within a file and mount it using the loopback file system — a special file system that enables you to accomplish this useful feat. You can use the file system you create to experiment with and practice almost all the commands found in this chapter with no fear of damaging your system.

Creating a File System for Testing

Because most of us do not have a spare computer or hard drive on which to experiment and practice, you can make one of your own by creating an image file containing the file system of your choice and using the loopback file system to mount it. That way, you do not run the risk of accidentally wreaking havoc on the system itself. Although you could also use a floppy drive for these same exercises, their small size limits your flexibility.

Step 1 — Make a Blank Image File

Use the dd command to create a file with a block size of 1,024 bytes (a megabyte) and create a file that is 10MB in size. (You need to have enough free space on your hard drive to hold a file this big, so adjust the size accordingly.) You need 10,000 1KB (1,024-byte) blocks, so select a count of 10000.

If you wanted a floppy-sized image, you would have selected a block size (bs) of 512 and a count of 2880 for a 1.4MB floppy or 5760 for a 2.88MB floppy. Here's how to do that:

# dd if=/dev/zero of=/tmp/fedoratest.img bs=1024 count=10000

You can see the computer respond with the following:

10000+0 records in

10000+0 records out

If you check your new file command, you see this:

# file /tmp/fedoratest.img /tmp/fedoratest.img: data

Step 2 — Make a File System

Now you need to make the system think that the file is a block device instead of an ASCII file, so you use losetup, a utility that associates loop devices with regular files or block devices; you will be using the loopback device, /dev/loop0.

# losetup /dev/loop0 /tmp/fedoratest.img

Now you can format the file as an ext2 file system:

# mke2fs /dev/loop0

You can see the computer respond as follows:

mke2fs 1.27 (8-Mar-2003)

File System label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

2512 inodes, 10000 blocks

500 blocks (5.00%) reserved for the super user

First data block=1

2 block groups

8192 blocks per group, 8192 fragments per group

1256 inodes per group

Superblock backups stored on blocks: 8193

Writing inode tables: done

Writing superblocks and file system accounting information: done

This file system will be automatically checked every 21 mounts or 180 days,

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

Step 3 — Mount the Test File System

After your test file system has been created, you can experiment with the different options for the formatting commands you will be using. It will be useful to make a mount point for your image file:

# mkdir /mnt/image

and then mount it:

# mount /dev/loop0 /mnt/image

You can do this now because you already have the loopback file system associated with the image file. Later on, if you remount it, you must use the following format to use the loopback option:

# mount -o loop /tmp/fedoratest.img /mnt/image

After mounting the new file system, you can look at it and see that the /lost+found directory has been created on it and that the df command returns:

# df -h /mnt/image

File System Size Used Avail Use% Mounted on/dev/loop0

9.5M 13k 8.9M 1% /mnt/image

To unmount it, use this:

# umount /mnt/image

Make a backup of the image just in case you break the original:

# cp /tmp/fedoratest.img fedoratest.bak

After the test file system is created, you can create directories, copy files to it, delete files, attempt to recover them, and, in general, create controlled chaos on your computer while you are learning and practicing valuable skills. If you damage the file system on the image beyond repair, unmount it, delete it, and create a new one (or copy a new one from that backup).

Mounting a Partition as Read-Only on a Running System

Remember that to do almost any kind of file system manipulation (formatting, checking, and so on), you should unmount the file system; by doing so, you avoid having any writes made to the file system, which would corrupt it.

How do you remount partitions on a running system? For example, to remount the /home partition (assuming that it is on a separate physical partition from root) as read-only to run fsck on it and then remount it as read-write, use the remount option for mount:

# mount -o ro,remount /home

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату