2

I have a bootable 32 GB Ubuntu USB stick with persistent storage.

The 32 GB USB stick is getting full, so I want to clone it into a 64 GB USB stick and increase both the casper-rw and the usbdata partition.

How can I do it without losing any data?

Here is how I cloned the 32 GB USB stick into the 64 GB USB stick. First, I issued the following command:

lsblk

and got this result: lsblk result on terminal

Second, I used the DD command:

sudo dd if=/dev/sdb of=/dev/sde status=progress

Third, I powered-off the computer, removed the 32 GB stick and powered on the computer. The system booted correctly from the new USB stick and it seems that all the files are there.

Forth, I loaded the GParted utility and here is the snapshot: GParted snapshot

Now back to my original question: How do I proceed in order to increase the casper-rw and usbdata partitions using the free/unallocated space without losing any data?

Melebius
  • 11,431
  • 9
  • 52
  • 78
BlueSkies
  • 2,145

3 Answers3

1

Clone with mkusb

You can clone from a drive to another drive with mkusb. Start via the graphical interface or with

dus /dev/sdx

where x is the device letter or the source in the cloning operation. The target will be selected in a safe way via menus.

  • mkusb wraps a safety belt around dd
  • if there is a GUID partition table, GPT, mkusb fixes the backup partition table at the tail end of the drive. (Otherwise you must do that manually for example with gdisk.)

After the cloning you can edit the partitions with gparted. If you touch only the casper-rw partition and the usbdata partition (amd if an MSDOS partition table the extended partition), booting will not be affected.

Edit: How to edit the partitions to fill the drive.

  • Be sure you have a backup (for example the original drive).
  • Read how to use gparted.
  • Boot from another drive
  • Unmount all partitions on the target drive
  • Start gparted and check that there are no lock symbols on /dev/sdb1 and /dev/sdb5.
  • Move /dev/sdb1 to the tail end (to the right)
  • Drag its left border of /dev/sdb1 to the left until the size is what you want
  • Drag the right border of /dev/sdb5` to the right to use all remaining unallocated drive space. The two partitions should 'touch each other'.
  • Check that things are as you want them.
  • Click on the tick icon to start the actions.
  • Please wait ... it will take a long time. Be sure there is enough power (do not run on battery).

If you cloned with dd you need to repair the backup partition table at the tail end of the drive with gdisk or maybe use gpt-fix.

Edit: gdisk command options cut from gpt-fix

echo \
"v
x
e
r
d
w
y" \
| gdisk "$1"

where "$1" should be replaced by the target device /dev/sdx, if run directly (not within the shellscript).

These command letters are explained in

man gdisk

The crucial commands are

in the expert's menu

   e      Move backup GPT data structures to the end of the disk. Use this
          command if you've added disks to a RAID array, thus  creating  a
          virtual  disk with space that follows the backup GPT data struc‐
          tures. This command moves the backup GPT data structures to  the
          end of the disk, where they belong.

and in the the recovery & transformation menu

   d      Use  main  GPT  header  and  rebuild  the backup. This option is
          likely to be useful if the backup GPT header has been damaged or
          destroyed.

The other commands are verifying, moving between menus and writing.

Links added by the OP, @BlueSkies:

Unable to unmount a partition with GParted - is this a problem?

GParted cannot finish step 1

GParted showing now

After cloning with mkusb, copying partitions from the original USB stick and booting from the new-larger stick, I'm unable to access the usbdata.

Access to usbdata partition blocked

Please advice. Thanks!


Advice: Please post the output of the following command lines (when booted from the new-larger stick),

sudo lsblk -f
sudo lsblk -m
sudo ls -l /mountpoint-to-usbdata
sudo ls -l /mountpoint-to-casper-rw

where you enter the actual mountpoints to see usbdata and casper-rw.

This will help me understand what is the problem, so that I can suggest what to do next.

Please edit your original question to enter these output texts instead of here in my answer. Indent each line 4 characters in order to render the output as code. You can mark (high-light) the text and click on the {} icon at the head of the editing window to make those indentations quickly.

Outputs of the four above-mentioned commands:

The command sudo lsblk -f gives the following results

enter image description here

The other one (sudo lsblk -m) outputs the following info:

sudo lsblk -m results

The last two commands and results:

result1

enter image description here

BlueSkies
  • 2,145
sudodus
  • 46,324
  • 5
  • 88
  • 152
  • After cloning a 32 GB USB stick into a 64 GB USB stick using the dd command (or mkusb) I'll have about 32 GB of unallocated space. How do I use GParted to split it, so half of that will be added to the casper-rw partition and half to the usbdata partition - without loosing any data? As far as I understand, a partition can safely be increased only into unallocated space. – BlueSkies Oct 06 '19 at 14:00
  • Please show the 64 GB USB stick in gparted, take a screenshot, and edit it into your original question, or run sudo parted -ls and edit the output text into your original question (and render it as 'code' by indenting each line 4 spaces). This way it will be possible to see what you have and give more detailed advice. General advice: you can move partitions (not only expand them). See also this link – sudodus Oct 06 '19 at 15:33
  • @BlueSkies, I saw your screenshot and edited my answer: How to edit the partitions to fill the drive. Good luck :-) – sudodus Oct 08 '19 at 20:13
  • is this still necessary: If you cloned with dd you need to repair the backup partition table at the tail end of the drive with gdisk or maybe use gpt-fix.

    Also, what is backup partition table?

    – BlueSkies Oct 10 '19 at 11:41
  • @BlueSkies, Yes, if you have a GUID partition table, GPT, it is necessary. Otherwise the partition and the file system will not work correctly. And I think you have a GPT in your persistent live drive (it is the modern partition table, default by mkusb). The backup partition table is at the tail end of the drive, a backup copy of the main table at the head end of the drive. You can look at gpt-fix and read about those options (command letters) in man gdisk, where it is explained what happens when you repair (or create new) backup partition table using a good main partition table. – sudodus Oct 10 '19 at 12:53
  • Do I need to unmount all partitions before editing them with GParted to fill the drive? I was able to unmount all partitions using GParted, except for one - the sde4 partition with iso9660 file system on it. – BlueSkies Oct 11 '19 at 16:16
  • 1
    It is enough to unmount the partitions that are involved in the editing (and you will not touch the sde4 partition with iso9660). – sudodus Oct 11 '19 at 16:32
  • the GParted was unable to finish the first step (move dev/sde1 to the tail & increase it's size by dragging its left border). I have the GParted log. Here is what it says at the end of the log: – BlueSkies Oct 11 '19 at 21:11
  • grow partition from 13.22 GiB to 25.45 GiB 00:00:01 ( ERROR )

    old start: 66756608 old end: 94482431 old size: 27725824 (13.22 GiB) requested start: 66756608 requested end: 120127487 requested size: 53370880 (25.45 GiB) libparted messages ( INFO )

    Unable to satisfy all constraints on the partition.

    – BlueSkies Oct 11 '19 at 21:13
  • 1
    You had bad luck :-( This is what happens sometimes. Editing partitions is risky. But I think you have still got the original 32 GB USB stick with the correct data. Now I suggest that you use mkusb and create a fresh persistent live system (with exactly the same system (from the same iso file) in the new 64 GB USB stick. Then you can use sudo rsync to copy the directory trees in the original casper-rw and usbdata partitions to the corresponding partitions in the new drive. – sudodus Oct 11 '19 at 21:52
  • 1
    sudo rsync -Havn /mountpoint-of-original-usbdata/ /mountpoint-of-new-usbdata/; (one line); Check that the output looks good, and then remove the option n and do the real thing. – sudodus Oct 11 '19 at 21:55
  • 1
    sudo rsync -Havn /mountpoint-of-original-casper-rw/ /mountpoint-of-new-casper-rw/; (one line); Check that the output looks good, and then remove the option n and do the real thing. -- Read man rsync in order to understand the details, for example the trailing slash after the source: source/ – sudodus Oct 11 '19 at 21:56
  • 1
    It should be possible to read and write in /media/ubuntu/usbdata. You need elevated permisisons to read and write directly into '/media/ubuntu/casper-rwbecause its first level of directories is owned byroot.But it should be overlayed with the system partition **/**. and you should be able to read and write as usual into your home directory, which should be saved automatically in thecasper-rwpartition (at/media/ubuntu/casper-rw/upper/home/ubuntu` – sudodus Oct 13 '19 at 13:34
  • Is it possible to chanage ownership of /media/ubuntu/usbdata and /media/ubuntu/casper-rw from root to ubuntu? Then, the Files application would be able to access both partitions, right? – BlueSkies Oct 13 '19 at 16:54
  • 1
    Yes it is possible, but not a good idea. The usbdata ownership and permissions should be easy for you already. If you mess with the ownership and permissions in casper-rw, you will probably get big problems, because these files are overlayed with important system files. – sudodus Oct 13 '19 at 16:57
  • So, how do I change the permissions to read and write into '/media/ubuntu/casper-rw'? – BlueSkies Oct 13 '19 at 17:00
  • 1
    Why do you want this? It is a system partition for persistence, and except for backup and restore, it should only be written indirectly by your usual commands (installing new programs, running programs, saving files etc). – sudodus Oct 13 '19 at 17:03
  • OK, agreed - no need to access the casper-rw storage. But I want to access the usbdata storage (to share data). – BlueSkies Oct 13 '19 at 17:07
  • 1
0

You could try ddrescue or gddrescue.

sudo apt-get install gddrescue ddrescue
ddrescue /dev/sda /dev/sdb -v
Eliah Kagan
  • 117,780
0

Just open ubuntu and install gparted, umount all partitions that you want to clone. Select partition from usb A in Gparted and copy >> paste to another usb B.enter image description here

nobjta_9x_tq
  • 121
  • 4