Using linux you can pull this off pretty easily with dd. dd is a Linux command line utility that allows you to mirror/copy a drive or a partition from a drive to either a file or another drive. It copies the partitions byte for byte, including any unused space on the filesystem.
Can I assume from your username and icon that you're using Ubuntu? :-) I'm assuming some knowledge here, so feel free to ask in the comments if you have any questions.
Note: If you're not using Linux and are on Windows, you have a few options. You can use dd for windows or boot from an Ubuntu disc/USB drive. You can then mount the file in Windows using one of the tools linked in the comments below.
Determine which partition you want to clone
So let's say the drive you want to copy is /dev/sda. (If it is an external drive, it might be /dev/sdb, /dev/sdc, etc...) For you to be able to mount it (the partition you're interested in) later, you'll want to copy the individual partitions, not the full drive image. If you already know which partition you want (ie. the 3rd partition, /dev/sda3), you can go ahead and skip this part. If you're not sure or want to check, use the fdisk tool to list out your partitions:
$ sudo fdisk -l /dev/sda
You're probably interested in the largest one, measured in blocks. Let's say it's /dev/sda3
Copy the partition to a file
Let's assume that you want to copy that drive's contents to /media/thumbdrive/backup.img
Check out the man dd
manpage for details on what all the arguments to dd mean. I'll provide a working example here:
dd if=/dev/sda3 of=/mount/thumbdrive/backup.img bs=1M
Showing progress
dd does not normally give any output while it works, and it can take a long time. You can get dd to show its progress by sending it a USR1 signal. You do this with the kill command.
Open another terminal, and run
killall dd -USR1
dd will then output its progress in the other terminal.
Mounting the partition later
After the copy is done, you can mount that backup.img file as if it were a device, using the -o loop
option to the mount command. Let's say you want to mount it onto /media/backup:
sudo mkdir -p /media/backup # create a directory for it to mount onto
sudo mount -o loop /media/thumbdrive/backup.img /media/backup
ls /media/backup # you will see the files that are on the drive you copied
You can unmount the file later:
sudo umount /media/backup
Note that you can edit or add files inside backup.img while it's mounted. Changes will be persisted as long as you unmount properly.