Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a local file on my disk which contains a msdos partition table and some linux-partitions. I use this as a virtual raw disk with qemu.

klm@lato:~/images/disk$ parted arch-linux2 p
WARNING: You are not superuser.  Watch out for permissions.
Model:  (file)
Disk /home/klm/images/disk/arch-linux2: 4339MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
1      32,3kB  107MB   107MB   primary  ext2            boot
2      107MB   378MB   271MB   primary  linux-swap(v1)
3      378MB   4100MB  3722MB  primary  ext4
4      4100MB  4331MB  231MB   primary  ext4

I want to resize a partition on this file, and GParted is normally really easy to use for this. However, when i run

$ gparted arch-linux2

Most of my partitions give me a warning:

e2label: No such file or directory while trying to open 
/home/klm/images/disk/arch-linux2. 
Couldn't find valid filesystem superblock.

Why can't gparted edit my partitions inside the file?

share|improve this question
    
i found the answer ... but I need to wait 8 hrs before I can post. thanks anyway, guys :) –  kristianlm Aug 4 '11 at 13:42

1 Answer 1

All right, kpartx and symbolic links to the rescue!

Use KPartX to create virtual block-devices for each partition:

klm@lato:~/images/disk$ sudo kpartx -a arch-linux2
klm@lato:~/images/disk$ ls /dev/mapper/
control  cryptswap1  loop0p1  loop0p2  loop0p3  loop0p4

Now you can point your gparted to your individual partitions:

klm@lato:~/images/disk$ sudo gparted /dev/mapper/loop0p1

But that won't help much since gparted needs the whole partition-table in order to resize a partition on it. Symbolic links solves this:

klm@lato:~/images/disk$ ln -s /dev/mapper/loop0p1 arch-linux2p1
klm@lato:~/images/disk$ ln -s /dev/mapper/loop0p2 arch-linux2p2
klm@lato:~/images/disk$ ln -s /dev/mapper/loop0p3 arch-linux2p3
klm@lato:~/images/disk$ ln -s /dev/mapper/loop0p4 arch-linux2p4

This is the structure that gparted wants:

klm@lato:~/images/disk$ ls -l
total 6275112
-rw-r--r-- 1 klm klm  4339007488 2011-07-22 15:47 arch-linux2
lrwxrwxrwx 1 klm klm          19 2011-08-04 15:23 arch-linux2p1 -> /dev/mapper/loop0p1
lrwxrwxrwx 1 klm klm          19 2011-08-04 15:23 arch-linux2p2 -> /dev/mapper/loop0p2
lrwxrwxrwx 1 klm klm          19 2011-08-04 15:23 arch-linux2p3 -> /dev/mapper/loop0p3
lrwxrwxrwx 1 klm klm          19 2011-08-04 15:23 arch-linux2p4 -> /dev/mapper/loop0p4

Now, I run gparted normally and without warnings, and I can resize stuff!

klm@lato:~/images/disk$ sudo gparted arch-linux2
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.