Pertama, Anda harus membuat file gambar:
# dd if=/dev/zero of=./binary.img bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 10.3739 s, 101 MB/s
Kemudian, Anda harus membuat partisi pada itu - Anda dapat menggunakan alat apa pun yang Anda inginkan, fdisk
, parted
, gparted
, saya lebih memilih parted
, sehingga:
# parted binary.img
Anda harus membuat tabel partisi terlebih dahulu dan kemudian satu partisi besar:
(parted) mktable
New disk label type? msdos
(parted) mkpartfs
WARNING: you are attempting to use parted to operate on (mkpartfs) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition type? primary/extended? primary
File system type? [ext2]? fat32
Start? 1
End? 1049M
Sekarang mari kita lihat:
(parted) print
Model: (file)
Disk /media/binary.img: 1049MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 1049MB 1048MB primary fat32 lba
Itu terlihat bagus,
Anda ingin memperbesarnya, jadi tinju menambahkan beberapa nol ke gambar menggunakan dd:
# dd if=/dev/zero bs=1M count=400 >> ./binary.img
400+0 records in
400+0 records out
419430400 bytes (419 MB) copied, 2.54333 s, 165 MB/s
root:/media# ls -al binary.img
-rw-r--r-- 1 root root 1.4G Dec 26 06:47 binary.img
Itu menambahkan 400 juta gambar:
# parted binary.img
GNU Parted 2.3
Using /media/binary.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: (file)
Disk /media/binary.img: 1468MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 1049MB 1048MB primary fat32 lba
Seperti yang Anda lihat, ukuran gambar berbeda (1468MB). Parted juga dapat menunjukkan ruang kosong pada gambar. Jika Anda ingin melihatnya, ketikkan print free
saja print
. Sekarang Anda harus menambahkan ruang ekstra ke sistem file:
(parted) resize 1
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Start? [1049kB]?
End? [1049MB]? 1468M
dan periksa:
(parted) print
Model: (file)
Disk /media/binary.img: 1468MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 1468MB 1467MB primary fat32 lba
Cukup bagus. Jika Anda ingin mengecilkannya, lakukan saja hal serupa:
(parted) resize 1
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Start? [1049kB]?
End? [1468MB]? 500M
Sekarang Anda dapat memeriksa apakah partisi tersebut lebih kecil:
(parted) print
Model: (file)
Disk /media/binary.img: 1468MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 500MB 499MB primary fat32 lba
Ya itu.
Jika Anda mencoba mengubah ukuran partisi ketika data ada, Anda harus memperhatikan ukuran data karena ketika Anda menyusut terlalu banyak, Anda akan mendapatkan kesalahan:
Error: Unable to satisfy all constraints on the partition
Setelah menyusutkan sistem file, Anda juga harus memotong beberapa file. Tapi ini rumit. Anda bisa mengambil nilai dari parted 500M (END):
# dd if=./binary.img of=./binary.img.new bs=1M count=500
Tapi ini menyisakan ruang di akhir file. Saya tidak yakin mengapa, tetapi gambar itu berfungsi.
Dan ada satu hal tentang pemasangan gambar seperti itu - Anda harus tahu offset untuk lolos ke perintah mount. Anda dapat memperoleh offset dari, misalnya, fdisk:
# fdisk -l binary.img
Disk binary.img: 1468 MB, 1468006400 bytes
4 heads, 32 sectors/track, 22400 cylinders, total 2867200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f0321
Device Boot Start End Blocks Id System
binary.img1 2048 2867198 1432575+ c W95 FAT32 (LBA)
2048 (mulai) x 512 (ukuran sektor) = 1048576, jadi Anda harus menggunakan perintah berikut untuk memasang gambar:
# mount -o loop,offset=1048576 binary.img /mnt