CREATING THE FILESYSTEM INSIDE A REGULAR FILE
Follow the next steps to create a regular file that contains a filesystem (also know as RAW DISC, IMG DISC or IMAGE DISC).
This kind of filesystem inside a file is used in Virtualization like XEN or when you copy a harddisk from /dev/hdxx or /dev/sdxx to a regular file.
1) Create an empty file (filled with zeros) with 100Mbytes size:
# dd if=/dev/zero of=fakedisk bs=1M count=100
Change the "count" value to the desired space.
2) Create the partitions with fdisk:
# fdisk fakedisk
Command (m for help): n (create a new partition)
Command (m for help): p (create a primary partition)
Command (m for help): 1 (create the first partition of the disk)
Command (m for help): enter (use default values)
Command (m for help): enter (use default values)
Command (m for help): t -> 83 (use 83 for linux filesystems like ext2,ext3,ext4)
Command (m for help): w (write changes to disk)
3) Using fdisk, note the "Start" number of the partition, in this case is 2048.
# fdisk -l fakedisk
Disk fakedisk: 104 MB, 104857600 bytes
191 heads, 50 sectors/track, 21 cylinders, total 204800 sectors
Units = setores of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb5cd89fb
Dispositivo Boot Start End Blocks Id System
fakedisk1 2048 204799 101376 83 Linux
# losetup /dev/loop0 fakedisk -o $((2048 * 512))
5) Format the partition with the filesystem
# mkfs.ext3 /dev/loop0
6) Verify if the partition is recognized as ext3:
# file -s /dev/loop0
/dev/loop0: sticky Linux rev 1.0 ext3 filesystem data, UUID=c52cc60c-9419-4906-95a7-c742937b7769
7) Mount the partition
# mkdir /mnt/partition1
# mount /dev/loop0 /mnt/partition1
Case loop0 is already used, you can use loop1, loop2, ...
Now you can use the /mnt/partition directory like any other mounted point.
RESIZING YOUR PARTITION INSIDE REGULAR FILE
Now if you want to increase your partition/filesystem inside a regular file, follow the steps:
1) Unmount the partition
# umount /mnt/partition1
2) Increase the regular file that contains the filesystem with zeroes at the end.
In this example we'll increase the file that holds the filesystem to more 100MB.
In this example we'll increase the file that holds the filesystem to more 100MB.
# dd if=/dev/zero bs=1M count=100 >> fakedisk
3) Reload the loop device mapping to recognize the new free space:
# losetup -d /dev/loop0
# losetup /dev/loop0 fakedisk -o $((2048 * 512))
4) Check the Filesystem Integrity
# fsck -f /dev/loop0
fsck de util-linux 2.20.1
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 11/25376 files (0.0% non-contiguous), 8874/101376 blocks
5) Resize the filesystem
# resize2fs /dev/loop0
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/loop0 to 203776 (1k) blocks.
The filesystem on /dev/loop0 is now 203776 blocks long.
7) Mount the loop0 device:
# mount /dev/loop0 /mnt/partition1
8) Verify the partition with the new size:
# df -h
Sist. Arq. Tam Usad Dispon. Uso% Montado em
rootfs 19G 13G 4.9G 73% /
/dev/loop0 193M 5.6M 178M 4% /mnt/partition1
# df -h
Sist. Arq. Tam Usad Dispon. Uso% Montado em
rootfs 19G 13G 4.9G 73% /
/dev/loop0 193M 5.6M 178M 4% /mnt/partition1
Done.
Now you have the partition with more space.
Nenhum comentário:
Postar um comentário