次のリビジョン | 前のリビジョン |
linux:dd [2025/05/17 14:08] – 作成 ともやん | linux:dd [2025/06/28 20:34] (現在) – [loop デバイスのセットアップとマウント] ともやん |
---|
====== dd - USB フラッシュ、SD カードのバックアップ/復元 ====== | ====== dd - USB フラッシュ、SD カードのバックアップ/復元 ====== |
| |
| ===== バックアップ ===== |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
| |
| ===== 復元 ===== |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">dd</font> if=~/dietpi-sd-backup_20250517.img of=/dev/sdc bs=16M status=progress |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| 124939927552 bytes (125 GB, 116 GiB) copied, 3069 s, 40.7 MB/s |
| 7447+0 records in |
| 7447+0 records out |
| 124939927552 bytes (125 GB, 116 GiB) copied, 3070.18 s, 40.7 MB/s |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ===== Raw Image のマウント ===== |
| 参考: [[https://unix.stackexchange.com/questions/753538/mount-img-file-to-extract-data|mount .img file to extract data - Unix & Linux Stack Exchange]]\\ |
| |
| ==== losetup の使い方 ==== |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">losetup</font> <font color="#A347BA">-h</font> |
| </pre></html></WRAP> |
| <WRAP color_result_hlong><html><pre> |
| Usage: |
| losetup [options] [<loopdev>] |
| losetup [options] -f | <loopdev> <file> |
| |
| Set up and control loop devices. |
| |
| Options: |
| -a, --all list all used devices |
| -d, --detach <loopdev>... detach one or more devices |
| -D, --detach-all detach all used devices |
| -f, --find find first unused device |
| -c, --set-capacity <loopdev> resize the device |
| -j, --associated <file> list all devices associated with <file> |
| -L, --nooverlap avoid possible conflict between devices |
| |
| -o, --offset <num> start at offset <num> into file |
| --sizelimit <num> device is limited to <num> bytes of the file |
| -b, --sector-size <num> set the logical sector size to <num> |
| -P, --partscan create a partitioned loop device |
| -r, --read-only set up a read-only loop device |
| --direct-io[=<on|off>] open backing file with O_DIRECT |
| --loop-ref <string> loop device reference |
| --show print device name after setup (with -f) |
| -v, --verbose verbose mode |
| |
| -J, --json use JSON --list output format |
| -l, --list list info about all or specified (default) |
| -n, --noheadings don't print headings for --list output |
| -O, --output <cols> specify columns to output for --list |
| --output-all output all columns |
| --raw use raw --list output format |
| |
| -h, --help display this help |
| -V, --version display version |
| |
| Available output columns: |
| NAME loop device name |
| AUTOCLEAR autoclear flag set |
| BACK-FILE device backing file |
| BACK-INO backing file inode number |
| BACK-MAJ:MIN backing file major:minor device number |
| BACK-MAJ backing file major device number |
| BACK-MIN backing file minor device number |
| MAJ:MIN loop device major:minor number |
| MAJ loop device major number |
| MIN loop device minor number |
| OFFSET offset from the beginning |
| PARTSCAN partscan flag set |
| REF loop device reference string |
| RO read-only device |
| SIZELIMIT size limit of the file in bytes |
| DIO access backing file with direct-io |
| LOG-SEC logical sector size in bytes |
| |
| For more details see losetup(8). |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ==== loop デバイスのセットアップとマウント ==== |
| 参考: [[https://askubuntu.com/questions/483009/mounting-disk-image-in-raw-format|command line - Mounting Disk Image in Raw format - Ask Ubuntu]]\\ |
| [[https://askubuntu.com/questions/1243020/losetup-raspbian-20200505-img-failed-to-set-up-loop-device-device-or-resource|losetup: raspbian-20200505.img: failed to set up loop device: Device or resource busy - Ask Ubuntu]]\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">losetup</font> <font color="#A347BA">-f</font> <font color="#A347BA">-P</font> <u style="text-decoration-style:solid">aiy-vk-001-backup_20250517.img</u> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">losetup</font><font color="#999999"> </font><font color="#A347BA">-l</font> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC |
| /dev/loop0 0 0 0 0 /home/tomoyan/aiy-vk-001-backup_20250517.img 0 512 |
| </pre></html></WRAP> |
| </WRAP> |
| |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">parted</font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:solid">/dev/loop0</u></font><font color="#999999"> print</font> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| モデル: Loopback デバイス (loopback) |
| ディスク /dev/loop0: 126GB |
| セクタサイズ (論理/物理): 512B/512B |
| パーティションテーブル: msdos |
| ディスクフラグ: |
| |
| 番号 開始 終了 サイズ タイプ ファイルシステム フラグ |
| 1 4194kB 273MB 268MB primary fat32 lba |
| 2 273MB 126GB 126GB primary ext4 |
| </pre></html></WRAP> |
| </WRAP> |
| |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">mkdir</font> /run/media/tomoyan/boot |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">mount</font> <u style="text-decoration-style:solid">/dev/loop0p1</u> <u style="text-decoration-style:solid">/run/media/tomoyan/boot</u> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">ls</font> <u style="text-decoration-style:solid">/run/media/tomoyan/boot</u> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| <font color="#26A269"><b>COPYING.linux</b></font> <font color="#26A269"><b>bcm2709-rpi-2-b.dtb</b></font> <font color="#26A269"><b>bcm2711-rpi-cm4.dtb</b></font> <font color="#26A269"><b>fixup_cd.dat</b></font> <font color="#26A269"><b>start.elf</b></font> |
| <font color="#26A269"><b>LICENCE.broadcom</b></font> <font color="#26A269"><b>bcm2710-rpi-2-b.dtb</b></font> <font color="#26A269"><b>bootcode.bin</b></font> <font color="#26A269"><b>fixup_db.dat</b></font> <font color="#26A269"><b>start4.elf</b></font> |
| <font color="#12488B"><b>'System Volume Information'</b></font> <font color="#26A269"><b>bcm2710-rpi-3-b-plus.dtb</b></font> <font color="#26A269"><b>cmdline.txt</b></font> <font color="#26A269"><b>fixup_x.dat</b></font> <font color="#26A269"><b>start4cd.elf</b></font> |
| <font color="#26A269"><b>bcm2708-rpi-b-plus.dtb</b></font> <font color="#26A269"><b>bcm2710-rpi-3-b.dtb</b></font> <font color="#26A269"><b>config.txt</b></font> <font color="#26A269"><b>issue.txt</b></font> <font color="#26A269"><b>start4db.elf</b></font> |
| <font color="#26A269"><b>bcm2708-rpi-b-rev1.dtb</b></font> <font color="#26A269"><b>bcm2710-rpi-cm3.dtb</b></font> <font color="#26A269"><b>fixup.dat</b></font> <font color="#26A269"><b>kernel.img</b></font> <font color="#26A269"><b>start4x.elf</b></font> |
| <font color="#26A269"><b>bcm2708-rpi-b.dtb</b></font> <font color="#26A269"><b>bcm2710-rpi-zero-2-w.dtb</b></font> <font color="#26A269"><b>fixup4.dat</b></font> <font color="#26A269"><b>kernel7.img</b></font> <font color="#26A269"><b>start_cd.elf</b></font> |
| <font color="#26A269"><b>bcm2708-rpi-cm.dtb</b></font> <font color="#26A269"><b>bcm2710-rpi-zero-2.dtb</b></font> <font color="#26A269"><b>fixup4cd.dat</b></font> <font color="#26A269"><b>kernel7l.img</b></font> <font color="#26A269"><b>start_db.elf</b></font> |
| <font color="#26A269"><b>bcm2708-rpi-zero-w.dtb</b></font> <font color="#26A269"><b>bcm2711-rpi-4-b.dtb</b></font> <font color="#26A269"><b>fixup4db.dat</b></font> <font color="#26A269"><b>kernel8.img</b></font> <font color="#26A269"><b>start_x.elf</b></font> |
| <font color="#26A269"><b>bcm2708-rpi-zero.dtb</b></font> <font color="#26A269"><b>bcm2711-rpi-400.dtb</b></font> <font color="#26A269"><b>fixup4x.dat</b></font> <font color="#12488B"><b>overlays</b></font> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ==== アンマウント ==== |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">umount</font> <u style="text-decoration-style:solid">/run/media/tomoyan/boot</u> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269"><u style="text-decoration-style:solid">sudo</u></font> <font color="#26A269">rm</font> <font color="#A347BA">-r</font> <u style="text-decoration-style:solid">/run/media/tomoyan/boot</u> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ===== 参考文献 ===== |
| [[linux:knoppix|KNOPPIX]]\\ |
| |