Languages/shell/mount-o

From UIT
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{public}} {{TOC right}}")
 
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{public}}
 
{{public}}
 +
Here is some commands for playing with disk and partition images. Feel free to have a look at [http://libguestfs.org/ libguestfs] tools, they are very handy (apt-get install libguestfs-tools).
 +
 
{{TOC right}}
 
{{TOC right}}
 +
= Mounting a filesystem image for editing =
 +
<source lang='bash'>
 +
# Create a destination directory
 +
mkdir /tmp/toto
 +
# Mount your existing filesystem image into it
 +
sudo mount -o loop image.bin /tmp/toto
 +
# Now you can see what is in this filesystem image and change the files ;)
 +
# Don't forget to umount when you're done
 +
</source>
 +
 +
= Unmounting =
 +
<source lang='bash'>
 +
sudo umount /tmp/toto
 +
</source>
 +
 +
= Create an ext4 image from a sdcard =
 +
<source lang='bash'>
 +
sudo dd if=/dev/sdcard of=/tmp/image.bin
 +
</source>
 +
 +
= Restore the sdcard =
 +
<source lang='bash'>
 +
sudo dd if=/tmp/image.bin of=/dev/sdcard
 +
</source>
 +
 +
== <code>dd</code> status ==
 +
Sending the user signal 1 will force <code>dd</code> to output it's progress.
 +
<source lang='bash'>
 +
kill -SIGUSR1 `pidof dd`
 +
</source>
 +
 +
= Creating an empty partition image =
 +
<source lang='bash'>
 +
dd if=/dev/zero of=/tmp/image.bin bs=1M count=512 # a new 512M image
 +
mkfs.ext4 -F /tmp/image.bin # "format" the disk image, works as a normal user !
 +
</source>
 +
 +
= mount a multi-partition disk image =
 +
<source lang='bash'>
 +
modprobe nbd max_part=16 # this module is used to mount image of disks (not only partitions)
 +
mkdir /tmp/toto # create a temporary directory
 +
qemu-nbd -c /dev/nbd0 image.bin # this must be a full disk copy, including partitions
 +
mount /dev/nbd0p1 /tmp/toto # p1 is the first parition and so on
 +
# when done :
 +
umount /tmp/toto
 +
qemu-nbd -d /dev/nbd0
 +
</source>

Latest revision as of 14:01, 24 August 2015

Here is some commands for playing with disk and partition images. Feel free to have a look at libguestfs tools, they are very handy (apt-get install libguestfs-tools).

Contents

Mounting a filesystem image for editing

# Create a destination directory
mkdir /tmp/toto
# Mount your existing filesystem image into it
sudo mount -o loop image.bin /tmp/toto
# Now you can see what is in this filesystem image and change the files ;)
# Don't forget to umount when you're done

Unmounting

sudo umount /tmp/toto

Create an ext4 image from a sdcard

sudo dd if=/dev/sdcard of=/tmp/image.bin

Restore the sdcard

sudo dd if=/tmp/image.bin of=/dev/sdcard

dd status

Sending the user signal 1 will force dd to output it's progress.

kill -SIGUSR1 `pidof dd`

Creating an empty partition image

dd if=/dev/zero of=/tmp/image.bin bs=1M count=512 # a new 512M image
mkfs.ext4 -F /tmp/image.bin # "format" the disk image, works as a normal user !

mount a multi-partition disk image

modprobe nbd max_part=16 # this module is used to mount image of disks (not only partitions)
mkdir /tmp/toto # create a temporary directory
qemu-nbd -c /dev/nbd0 image.bin # this must be a full disk copy, including partitions
mount /dev/nbd0p1 /tmp/toto # p1 is the first parition and so on
# when done :
umount /tmp/toto
qemu-nbd -d /dev/nbd0
Personal tools
Namespaces
Variants
Actions
Navigation
Browse
Toolbox