0

I would like to know how to copy a Linux partition (example: /dev/sda1) on a USB stick, and then boot on the USB stick. I tried to just copy it with the command cp but when I tried to boot on it, it booted on the partition I copied (/dev/sda1) and not the usb. In short what I want to do is create a USB stick with my Linux partition on it that I can boot on with any computer.

Thank you.

jybateman
  • 303
  • 1
  • 3
  • 11

2 Answers2

0

Please change your bios setting so that the first boot device is USB.

Sayu Sekhar
  • 169
  • 5
  • No, because when I know how to boot on the usb, but when i boot on it, it boots on the partition I copied. And if I try booting on the usb on another pc it can't. – jybateman Oct 09 '14 at 22:39
0

cp is great for copying files, but you should consider it too high-level for copying partitions. When you copy a partition, you read from a device file and write to another device file, or normal file, or what ever. With cp, many file attributes might be changed: modification time, owner, permissions, etc. This isn't great for partition copies, e.g. files owned by root should still be owned by root, or ~/.ssh/config should still have permissions 600.

The program for this task is dd, which copies bit-by-bit. You specify an input file and an output file:

dd if=/dev/sda of=/dev/sdf bs=512

This copies contents of /dev/sda to /dev/sdf while reading 512 bytes at a time (bs=blocksize). After some time, it will finish and report some statstics. To get statistics during copying, you must send SIGUSR1 signal to the dd process.

Please beware that dd is a dangerous tool, if incorrectly used: For example, it won't ask you for permission to overwrite your 10000 picture vacation album. It simply does. Make sure to specify the correct device files! You also have to take care that sizes of source and destination fit: destination needs to be at least the size as the source. If you have a 500GB hard disk it won't work to copy to a 4GB USB stick.

Copying whole hard disks also copies the boot loader. An issue with this might be, that the entries in boot loader configuration reference wrong disks. However, starting the boot loader should be no problem (provided architecture matches). If you use GRUB, you even get a command line, which you can use to boot the system manually.

Ali Ben
  • 86
  • 3