How to move partition linux

How to move a partition in GNU/Linux?

How to move a partition to the beginning of the disk a bit? Parted wants a filesystem for some reason (I don’t know why), I want just to shift all sectors left.

r@l:15:32:45:~# parted /dev/sdb GNU Parted 2.3 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: HGST HTS 541010A9E680 (scsi) Disk /dev/sdb: 1000GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 32.2GB 32.2GB primary fat32 2 32.2GB 37.6GB 5360MB primary 3 37.6GB 1000GB 963GB primary (parted) move 3 WARNING: you are attempting to use parted to operate on (move) a file system. parted's file system manipulation code is not as robust as what you'll find in dedicated, file-system-specific packages like e2fsprogs. We recommend you use parted only to manipulate partition tables, whenever possible. Support for performing most operations on most types of file systems will be removed in an upcoming release. Error: Could not detect file system. 

Are you using the partitions without FS? You can just set the FS to anyone with fdisk and then move them.

Thus is actually a LUKS container. But I don’t think a partition mover should ever look inside the filesystem.

3 Answers 3

sfdisk , which intents to be a scriptable fdisk, has since some version the —move-data option. Example from their man page:

echo '+100M,' | sfdisk --move-data /dev/sdc -N 1 

Manual way with dd and fdisk:

# fdisk -l /dev/sdb | grep sdb3 /dev/sdb3 73402368 1953525167 940061400 83 Linux # fdisk /dev/sdb Command (m for help): d Partition number (1-4): 3 Command (m for help): n Partition number (1-4, default 3): 3 First sector (73385984-1953525167, default 73385984): Using default value 73385984 Last sector, +sectors or +size (73385984-1953525167, default 1953525167): Using default value 1953525167 Command (m for help): w The partition table has been altered! # fdisk -l /dev/sdb | grep sdb3 /dev/sdb3 73385984 1953525167 940069592 83 Linux # dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 count=100 skip=$((73402368-73385984)) seek=0 2> /dev/null | file -s - /dev/stdin: LUKS encrypted file, ver 1 [aes, cbc-essiv:sha256, sha1] UUID: af1c47f0-4ca5-4ea7-a091-065bd263653f # dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 skip=$((73402368-73385984)) seek=0 of=/dev/sdb3 # file -s /dev/sdb3 /dev/sdb3: sticky LUKS encrypted file, ver 1 [aes, cbc-essiv:sha256, sha1] UUID: af1c47f0-4ca5-4ea7-a091-065bd263653f 

Now waiting for about 2h. (more looks more like 18h. )

Читайте также:  Рейтинг оконных менеджеров linux

Note: this only moves data back, not forward.

# pidof dd 907 # kill -STOP 907 # cat /proc/907/fdinfo/1 pos: 586921398272 flags: 0100001 # kill -9 907 remember 586921398272/512 = 1146330856 
dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 skip=$((1146330856+73402368-73385984)) seek=1146330856 of=/dev/sdb3 

Источник

How to move a partition in gnu linux

but probably more common way — would be move data with dd chunk by chunk also there dd moving in opposite direction, interesting in handling dd command and determining offsets Solution 2: dd_rescue has option for reversing the direction. I did not, moving of partitions in that way, but it may work, so proof of concept on test file: just making test file, for experiments We need also pv command , which able act like buffer for our data in form : default dd block size is 512 bytes — we shift data by 2 dd blocks, so buffer in 1024 bytes is enough.

How to move a partition in GNU/Linux?

sfdisk , which intents to be a scriptable fdisk, has since some version the —move-data option. Example from their man page:

echo '+100M,' | sfdisk --move-data /dev/sdc -N 1 

Manual way with dd and fdisk:

# fdisk -l /dev/sdb | grep sdb3 /dev/sdb3 73402368 1953525167 940061400 83 Linux # fdisk /dev/sdb Command (m for help): d Partition number (1-4): 3 Command (m for help): n Partition number (1-4, default 3): 3 First sector (73385984-1953525167, default 73385984): Using default value 73385984 Last sector, +sectors or +size (73385984-1953525167, default 1953525167): Using default value 1953525167 Command (m for help): w The partition table has been altered! # fdisk -l /dev/sdb | grep sdb3 /dev/sdb3 73385984 1953525167 940069592 83 Linux # dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 count=100 skip=$((73402368-73385984)) seek=0 2> /dev/null | file -s - /dev/stdin: LUKS encrypted file, ver 1 [aes, cbc-essiv:sha256, sha1] UUID: af1c47f0-4ca5-4ea7-a091-065bd263653f # dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 skip=$((73402368-73385984)) seek=0 of=/dev/sdb3 # file -s /dev/sdb3 /dev/sdb3: sticky LUKS encrypted file, ver 1 [aes, cbc-essiv:sha256, sha1] UUID: af1c47f0-4ca5-4ea7-a091-065bd263653f 

Now waiting for about 2h. (more looks more like 18h. )

Note: this only moves data back, not forward.

# pidof dd 907 # kill -STOP 907 # cat /proc/907/fdinfo/1 pos: 586921398272 flags: 0100001 # kill -9 907 remember 586921398272/512 = 1146330856 
dd conv=notrunc bs=512 iflag=fullblock if=/dev/sdb3 skip=$((1146330856+73402368-73385984)) seek=1146330856 of=/dev/sdb3 
  • Boot from a liveCD (or any other way which makes sure the partition is not mounted)
  • dd if=/dev/sdc2 of=somefile bs=1M to create a copy of the partition on a file.
  • fdisk (or whatever you like) to delete the partition
  • fdisk (or whatever you like) to create the partition in your desired place.
  • dd of=/dev/sdc2 if=somefile bs=1M to restore the contents from file.
Читайте также:  How to install plugin in linux

How to move a partition in GNU/Linux? (3 Solutions!!)

How to move a partition in GNU/Linux?Helpful? Please support me on Patreon: https://www Duration: 3:09

Resize or Extend a Linux Partition/Volume/Disk

Can `parted` move a partition like `gparted`?

parted used to be able to move partitions and resize (certain) file systems, but this feature was removed in version 3.0 because it was deemed to difficult to maintain.

How to Use KDE Partition Manager, After installing KDE Partition Manager, you can find it in the list of applications that you have installed on your system. When you open the partition manager,

Move partition data with dd to the right

  • what would be the parameters that archive the copying from right to left so that the data doesn’t get overwritten

Not exists, there is no in one command dd solution

Also I warn you from using dd for moving partition, because if something fails you have no chances to restore data, without backup, which you did before that operation. But if you have backup then operation is trivial. So that was disclaimer .

Now the fun way(I find your question interesting). I did not, moving of partitions in that way, but it may work, so proof of concept on test file:

perl -e 'foreach $i (0..1023) < printf "%0.7i\n", $i; >' >test.dat 

just making test file, for experiments

We need also pv command , which able act like buffer for our data in form : pv -B buffer_size_in_bytes

dd if=test.dat | pv -B 1024 | dd of=test.dat seek=2 

default dd block size is 512 bytes — we shift data by 2 dd blocks, so buffer in 1024 bytes is enough.

dd if=/div/sda bs=512*device block size* skip=111111*much blocks until sda2 begins* | pv -B 90000000 *have_to_fit_shift size+* | dd of=/div/sda seek=(blocks until sda2 begins + amount of blocks we shift that for) 

after that, if everything went ok, needs to fix partition table.

but probably more common way — would be move data with dd chunk by chunk

dd if=/div/sda bs=1M count=100 skip=PosToRead seek=PosToWrite PosToRead -= dd_count PosToWrite -= dd_count repeat if not done 

also there dd moving in opposite direction, interesting in handling dd command and determining offsets

Читайте также:  Все версии fedora linux

dd_rescue has option -r for reversing the direction.

partition=/dev/vdc1 disk=/dev/vdc sector_size=512 new_start_sector=4096 # opos is right after the new partition and given in bytes opos=$(($new_start_sector * $sector_size + `blockdev --getsize64 $partition`)) dd_rescue -v -r -S $opos $partition $disk 

Afterwards don’t forget to update the partition table. Don’t update it before!

How do I resize root partition with UEFI, First, move all the partitions that are located «to the right» of the partition you wish to extend as far towards the right as you can.

Источник

How to move and rearrange partitions in Ubuntu

enter image description here

I have a mess of partitions. This picture pretty much sums it up. I don’t understand why there are small unallocated areas. My goal is to move the whole /dev/sda4 partition to a new hard drive (including swap). Then increase the remaining space in Storage (/dev/sda3). Thank you in advance.

It went perfect I just installed a new ubuntu installation on the new hard drive. I moved the home folder to the new ubuntu installation. I deleted the ubuntu partition (which includes moving the swap) with a live cd. After Being done with ubuntu I booted into Windows and moved all the other partitions up to the beginning. Finally, I extended the Storage partition. This last part took the longest.

2 Answers 2

You’ll want to partition the new drive as you like, then, you can use, for example, a liveUSB or LiveCD to boot the system.

Copy the files using cp -p (preserve permissions) as root (use sudo) from the old drive to the new.

Then you’ll want to sudo chroot into the environment (this is an advanced topic) and run grub install from within the chroot. (this may be easier if you remove the original drive)

Then, if you have not already done so, remove the existing drive and confirm the secondary system boots. It may take several attempts to get grub configured properly to do this. confirm you have no data loss on the transferred system.

Lastly, you may remove the linux system from the old drive. Once done, you can put both drives into the system. Further grub configuration may be required at that time.

Bonus, resizing the NTFS/Window partitions will best be done with windows disk management

Источник

Оцените статью
Adblock
detector