Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shrink ext3 filesystem using e2fsprogs and fdisk

42 views
Skip to first unread message

Martin T

unread,
Mar 25, 2012, 7:00:02 PM3/25/12
to
I have a 500GB((131072000*4096)/1024^3) ext3 filesystem:

root@debian:~#dumpe2fs /dev/sda9 | egrep "Block count|Block size"
dumpe2fs 1.41.12 (17-May-2010)
Block count: 131072000
Block size: 4096
root@debian:~#

..on a 904GB((1953523711-56924160)*512)/(1024^3) partition(sda9):

root@debian:~#fdisk -cul /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062a0f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 684031 340992 83 Linux
/dev/sda2 686078 1953523711 976418817 5 Extended
/dev/sda5 686080 18262015 8787968 83 Linux
/dev/sda6 18264064 24121343 2928640 83 Linux
/dev/sda7 24123392 56141823 16009216 82 Linux swap / Solaris
/dev/sda8 56143872 56922111 389120 83 Linux
/dev/sda9 56924160 1953523711 948299776 83 Linux
root@debian:~#


At the moment everything works, but if I shrink the size of the
/dev/sda9 partition from the beginning of the partition like this(sda9
is now 693GB which is more than enough to hold the 500GB file system):

root@debian:~#fdisk -cul /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00062a0f

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 684031 340992 83 Linux
/dev/sda2 686078 1953523711 976418817 5 Extended
/dev/sda5 686080 18262015 8787968 83 Linux
/dev/sda6 18264064 24121343 2928640 83 Linux
/dev/sda7 24123392 56141823 16009216 82 Linux swap / Solaris
/dev/sda8 56143872 56922111 389120 83 Linux
/dev/sda9 500000000 1953523711 726761856 83 Linux
root@debian:~#

..then file system is broken:

root@debian:~#dumpe2fs /dev/sda9
dumpe2fs 1.41.12 (17-May-2010)
dumpe2fs: Bad magic number in super-block while trying to open /dev/sda9
Couldn't find valid filesystem superblock.
root@debian:~#

Is it possible to make partition smaller starting from the beginning?
If yes, do I need to somehow start file system from the end of the
partition?


regards,
martin


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CAJx5YvHKWV_b5X_G=j4dG7F=aV8TK-CWDrQET...@mail.gmail.com

Jochen Spieker

unread,
Mar 26, 2012, 4:10:03 AM3/26/12
to
Martin T:
>
> Is it possible to make partition smaller starting from the beginning?

No.

> If yes, do I need to somehow start file system from the end of the
> partition?

AFAIK that's not possible. The solution for your problem (which involves
initial reformatting) is LVM.

J.
--
There is no justice in road accidents.
[Agree] [Disagree]
<http://www.slowlydownward.com/NODATA/data_enter2.html>
signature.asc

Darac Marjal

unread,
Mar 26, 2012, 10:30:03 AM3/26/12
to
On Sun, Mar 25, 2012 at 10:50:27PM +0000, Martin T wrote:
> I have a 500GB((131072000*4096)/1024^3) ext3 filesystem:
>
[cut]
>
> Is it possible to make partition smaller starting from the beginning?
> If yes, do I need to somehow start file system from the end of the
> partition?

Not directly. Try installing gparted (package: gparted). This will give
you a graphical interface which will allow you to resize the partition
as you're wanting. You will probably become aware that, no, taking space
off the beginning of the partition is not possible, but it IS possible
to take space off the END of the partition and then "slide" the
partition towards the end of the space.

The same is possible (I think) using the CLI parted, if you don't have
X. Note also that ext3 does NOT support online shrinking (you can make
it larger, but to make it smaller you MUST umount it).


--
Darac Marjal


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/20120326142...@darac.org.uk

Martin T

unread,
Mar 26, 2012, 7:20:01 PM3/26/12
to
Jochen, Darac:

thanks for replies! Is it possible to "slide" partition using the
tools included with e2fsprogs package as well? Or is the GNU Parted
only option here if I want to make changes over CLI?


regards,
martin
Archive: http://lists.debian.org/CAJx5YvEnEV4+xCPZVLm-oH0Z...@mail.gmail.com

Stefan Monnier

unread,
Mar 28, 2012, 10:00:03 AM3/28/12
to
> thanks for replies! Is it possible to "slide" partition using the
> tools included with e2fsprogs package as well?

The e2fsprogs tools only deal with the needs specific to
ext[234] partitions. Sliding a partition can be done for any partition
you like with `dd'.


Stefan


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/jwvehscdefn.fsf-monnier...@gnu.org

Martin T

unread,
Mar 28, 2012, 8:00:02 PM3/28/12
to
Stefan:

I'm afraid you can't use dd for this because as far as I know dd(1)
reads and writes one block at a time and in case new position for file
system overlaps with the present one, using dd you will start
overwriting the end of the file system with the readings from the
start of the file system. In addition, both parted and Gparted don't
have dd as a dependency. However, it should be doable if current and
new position don't overlap using the "skip=" and "seek=" options of
dd..or how did you think?


Jochen, Darac:

here is what Gparted did:

========================================

GParted 0.6.2

Libparted 2.3
Move /dev/sda9 to the right and shrink it from 904.37 GiB to 611.40
GiB 06:02:27 ( SUCCESS )

calibrate /dev/sda9 00:00:00 ( SUCCESS )

path: /dev/sda9
start: 56924160
end: 1953523711
size: 1896599552 (904.37 GiB)
check file system on /dev/sda9 for errors and (if possible) fix them
00:02:16 ( SUCCESS )

e2fsck -f -y -v /dev/sda9

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

308 inodes used (0.00%)
18 non-contiguous files (5.8%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 20/9/0
3363494 blocks used (2.57%)
0 bad blocks
1 large file

169 regular files
130 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
299 files
e2fsck 1.41.12 (17-May-2010)
shrink file system 00:01:31 ( SUCCESS )

resize2fs /dev/sda9 641099775K

Resizing the filesystem on /dev/sda9 to 160274943 (4k) blocks.
The filesystem on /dev/sda9 is now 160274943 blocks long.

resize2fs 1.41.12 (17-May-2010)
shrink partition from 904.37 GiB to 611.40 GiB 00:00:01 ( SUCCESS )

old start: 56924160
old end: 1953523711
old size: 1896599552 (904.37 GiB)
new start: 56924160
new end: 1339123711
new size: 1282199552 (611.40 GiB)
check file system on /dev/sda9 for errors and (if possible) fix them
00:02:47 ( SUCCESS )

e2fsck -f -y -v /dev/sda9

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

308 inodes used (0.00%)
18 non-contiguous files (5.8%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 20/9/0
3821982 blocks used (2.38%)
0 bad blocks
1 large file

169 regular files
130 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
299 files
e2fsck 1.41.12 (17-May-2010)
grow file system to fill the partition 00:01:03 ( SUCCESS )

resize2fs /dev/sda9

Resizing the filesystem on /dev/sda9 to 160274944 (4k) blocks.
The filesystem on /dev/sda9 is now 160274944 blocks long.

resize2fs 1.41.12 (17-May-2010)
check file system on /dev/sda9 for errors and (if possible) fix them
00:02:46 ( SUCCESS )

e2fsck -f -y -v /dev/sda9

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

308 inodes used (0.00%)
18 non-contiguous files (5.8%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 20/9/0
3821982 blocks used (2.38%)
0 bad blocks
1 large file

169 regular files
130 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
299 files
e2fsck 1.41.12 (17-May-2010)
grow partition from 611.40 GiB to 904.37 GiB 00:00:02 ( SUCCESS )

old start: 56924160
old end: 1339123711
old size: 1282199552 (611.40 GiB)
new start: 56924160
new end: 1953523711
new size: 1896599552 (904.37 GiB)
move file system to the right 05:48:52 ( SUCCESS )

perform read-only test 01:54:58 ( SUCCESS )

using internal algorithm
read 611.40 GiB
finding optimal block size

read 16.00 MiB using a block size of 2.00 MiB 00:00:00 ( SUCCESS )

16.00 MiB of 16.00 MiB read
0.215304 seconds
read 16.00 MiB using a block size of 4.00 MiB 00:00:00 ( SUCCESS )

16.00 MiB of 16.00 MiB read
0.250469 seconds
read 16.00 MiB using a block size of 8.00 MiB 00:00:01 ( SUCCESS )

16.00 MiB of 16.00 MiB read
0.215766 seconds
read 16.00 MiB using a block size of 16.00 MiB 00:00:00 ( SUCCESS )

16.00 MiB of 16.00 MiB read
0.253064 seconds
optimal block size is 2.00 MiB
read 611.34 GiB using a block size of 2.00 MiB 01:54:57 ( SUCCESS )

611.34 GiB of 611.34 GiB read
611.40 GiB (656486170624 B) read
perform real move 03:53:54 ( SUCCESS )

using internal algorithm
copy 611.40 GiB
finding optimal block size

copy 16.00 MiB using a block size of 1.00 MiB 00:00:01 ( SUCCESS )

16.00 MiB of 16.00 MiB copied
0.988301 seconds
copy 16.00 MiB using a block size of 2.00 MiB 00:00:00 ( SUCCESS )

16.00 MiB of 16.00 MiB copied
0.53326 seconds
copy 16.00 MiB using a block size of 4.00 MiB 00:00:01 ( SUCCESS )

16.00 MiB of 16.00 MiB copied
0.598635 seconds
copy 16.00 MiB using a block size of 8.00 MiB 00:00:01 ( SUCCESS )

16.00 MiB of 16.00 MiB copied
0.530564 seconds
copy 16.00 MiB using a block size of 16.00 MiB 00:00:00 ( SUCCESS )

16.00 MiB of 16.00 MiB copied
0.522437 seconds
optimal block size is 16.00 MiB
copy 611.32 GiB using a block size of 16.00 MiB 03:53:51 ( SUCCESS )

611.32 GiB of 611.32 GiB copied
611.40 GiB (656486170624 B) copied
shrink partition from 904.37 GiB to 611.40 GiB 00:00:02 ( SUCCESS )

old start: 56924160
old end: 1953523711
old size: 1896599552 (904.37 GiB)
new start: 671324160
new end: 1953523711
new size: 1282199552 (611.40 GiB)
check file system on /dev/sda9 for errors and (if possible) fix them
00:03:07 ( SUCCESS )

e2fsck -f -y -v /dev/sda9

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

308 inodes used (0.00%)
18 non-contiguous files (5.8%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 20/9/0
3821982 blocks used (2.38%)
0 bad blocks
1 large file

169 regular files
130 directories
0 character device files
0 block device files
0 fifos
0 links
0 symbolic links (0 fast symbolic links)
0 sockets
--------
299 files
e2fsck 1.41.12 (17-May-2010)
grow file system to fill the partition 00:00:00 ( SUCCESS )

resize2fs /dev/sda9

resize2fs 1.41.12 (17-May-2010)
The filesystem is already 160274944 blocks long. Nothing to do!

========================================

So looks like for "sliding" the partition, (G)parted uses some sort of
"internal algorithm"? In other words parted or Gparted is definitely
needed for operation like this?


regards,
martin

Kuupäeval 28. märts 2012 13:49 kirjutas Stefan Monnier
<mon...@iro.umontreal.ca>:
Archive: http://lists.debian.org/CAJx5YvGoG2q5FZeXK8jS8G6F...@mail.gmail.com
0 new messages