12
About Bash Scripts Categories » Sponsorship Contact Resize Partition and Filesystem with fdisk & resize2fs !  on November 27 | "  in All Posts, CentOS, FileSystem | #  by Mitch | $ with 3 Comments There was a question in my post on “Linux partitioning with fdisk on CentOS 6“. Our reader asked if it is possible to extend an existing linux non LVM partition without loosing it’s data … here is a post on how to resize partition  and filesystem  with fdisk and resize2fs. IMPORTANT: In order to resize partition (extend), enough disk space must be available!  We can not extend a partition if there are no free sectors/cylinders at the end of the partition to extend! PLEASE BACKUP YOUR DATA BEFORE RESIZING ANY PARTITION! GeekPeek.Net is not responsible for any data loss! Search Rss Feed Google+ Stumbleupon Linked In Tumblr Twitter Facebook Latest Popular Random Tags Manage Users and Groups on Linux 2 weeks ago | 2 Comments Build Apache 2.4.9 RPM on CentOS 6 – RPM Download

Resize Partition and FilesysResize Partition and Filesystem with fdisk & resize2fstem With Fdisk & Resize2fs - GeekPeek.net

Embed Size (px)

DESCRIPTION

Resize Partition and Filesystem with fdisk & resize2fs

Citation preview

  • About

    Bash Scripts

    Categories

    Sponsorship

    Contact

    Resize Partition and Filesystem with fdisk &resize2fs

    ! on November 27 | " in All Posts, CentOS, FileSystem | # byMitch | $ with 3 Comments

    There was a question in my post on Linux partitioning with fdisk onCentOS 6. Our reader asked if it is possible to extend an existinglinux non LVM partition without loosing its data here is a post onhow to resize partition and filesystem with fdisk and resize2fs.

    IMPORTANT: In order to resize partition (extend), enough diskspace must be available! We can not extend a partition if there are nofree sectors/cylinders at the end of the partition to extend!

    PLEASE BACKUP YOUR DATA BEFORE RESIZING ANYPARTITION! GeekPeek.Net is not responsible for any data loss!

    Search

    Rss FeedGoogle+StumbleuponLinked InTumblrTwitterFacebook

    LatestPopularRandomTags

    Manage Users andGroups on Linux

    2 weeks ago | 2 Comments

    Build Apache 2.4.9RPM on CentOS 6 RPM Download

  • Resize Partition and Filesystem with fdiskand resize2fs

    Lets Resize Partition and Filesystemwith fdisk and resize2fs!

    Our system has two disks:

    /dev/sda 16GB system disk with LVM partitions (root andswap)/dev/sdb 1GB clean disk for tutorial purpose

    For the start of this tutorial tutorial we have created one partition on/dev/sdb disk. Partition size (/dev/sdb1) is 500MB. We created anext4 filesystem on this partition and put some dummy data on it. Wewill be modifying our partitions with fdisk and filesystem withresize2fs.

    For more information on how to create and modify partitions withfdisk read Linux partitioning with fdisk on CentOS 6.

    Extend Partition and Filesystem

    Before we start, lets check the current disk configuration. Geekpeekmount point is the partition we want to extend. We can see that thepartition has 494MB of available space and 401MB is already used bydummy data. We want to extend the partition to 1GB:

    [root@foo1 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_foo-LogVol01

    13G 4.6G 7.7G 38% /

    tmpfs 376M 0 376M 0% /dev/shm

    /dev/sda1 485M 105M 355M 23% /boot

    /dev/sdb1 494M 402M 67M 86% /geekpeek

    1. Unmount the partition

    1 month ago | 5 Comments

    Kickstart File onCentOS 6

    2 months ago | No Comments

    Working with YUMon CentOS 6

    2 months ago | No Comments

    CentOS Linux 6Things You ShouldKnow About

    3 months ago | 2 Comments

    Sponsored by

    Recent Comments

    aliosha says: Hello Mtch:Thanks so much for thetutorial. I have a question;keeps complaining "Badmagic num...

    Mitch says: Hi c1c3ru, you

  • [root@foo1 ~]# umount /geekpeek/

    [root@foo1 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_foo-LogVol01

    13G 4.6G 7.7G 38% /

    tmpfs 376M 0 376M 0% /dev/shm

    /dev/sda1 485M 105M 355M 23% /boot

    2. Delete the partition

    [root@foo1 ~]# fdisk /dev/sdb

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

    switch off the mode (command 'c') and change display units to

    sectors (command 'u').

    Command (m for help): d

    Selected partition 1

    Command (m for help): p

    Disk /dev/sdb: 1073 MB, 1073741824 bytes

    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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: 0x2dbb9f13

    Device Boot Start End Blocks Id System

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Syncing disks.

    should install daemonpackage: apt-get installdaemon. Regards, Mitch...

    Sahil says: Hi Mitch , Thankyou very much for overviewand installtion for space walk,I want to learn more ab...

    Bob says: Hi Alex, s tftp-server package installed? canyou run the following tocheck: # rpm -qi tftp-serv...

    c1c3ru says: hi! thanks forsharing your knowledge,butnow in test is show:/usr/local/nagios/nagios-4.0.2# serv...

  • 3. Create a new (larger) partition

    [root@foo1 ~]# fdisk /dev/sdb

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

    switch off the mode (command 'c') and change display units to

    sectors (command 'u').

    Command (m for help): n

    Command action

    e extended

    p primary partition (1-4)

    p

    Partition number (1-4): 1

    First sector (2048-2097151, default 2048):

    Using default value 2048

    Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):

    Using default value 2097151

    Command (m for help): p

    Disk /dev/sdb: 1073 MB, 1073741824 bytes

    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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: 0x2dbb9f13

    Device Boot Start End Blocks Id System

    /dev/sdb1 2048 2097151 1047552 83 Linux

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

  • We are able to mount the partition at this point, but the filesystem onthis partition is only 500MB large. We need to resize the filesystemusing resize2fs command in the following steps.

    4. Run fsck on your filesystem

    [root@foo1 ~]# e2fsck -f /dev/sdb1

    e2fsck 1.41.12 (17-May-2010)

    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

    /dev/sdb1: 16/130560 files (0.0% non-contiguous), 426988/522080 blocks

    5. Resize your filesystem with resize2fs

    [root@foo1 ~]# resize2fs /dev/sdb1

    resize2fs 1.41.12 (17-May-2010)

    Resizing the filesystem on /dev/sdb1 to 1044192 (1k) blocks.

    The filesystem on /dev/sdb1 is now 1044192 blocks long.

    6. Re-mount extended partition

    [root@foo1 ~]# mount /dev/sdb1 /geekpeek/

    [root@foo1 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_foo-LogVol01

    13G 4.6G 7.7G 38% /

    tmpfs 376M 0 376M 0% /dev/shm

    /dev/sda1 485M 105M 355M 23% /boot

    /dev/sdb1 988M 402M 536M 43% /geekpeek

    Voila! The partition was successfully extended, as we can see all of thedata survived! Always remember to resize the filesystem with

  • resize2fs.

    Reduce a Partition and Filesystem

    Reviewing the current disk configuration: Geekpeek mount point is thepartition we want to reduce. We can see that the partition has 988MBof available space and 324MB is used by dummy data. We want toreduce the partition to 400MB without loosing data:

    [root@foo1 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_foo-LogVol01

    13G 4.6G 7.7G 38% /

    tmpfs 376M 0 376M 0% /dev/shm

    /dev/sda1 485M 105M 355M 23% /boot

    /dev/sdb1 988M 324M 614M 35% /geekpeek

    1. Unmount the partition

    [root@foo1 ~]# umount /geekpeek/

    [root@foo1 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_foo-LogVol01

    13G 4.6G 7.7G 38% /

    tmpfs 376M 0 376M 0% /dev/shm

    /dev/sda1 485M 105M 355M 23% /boot

    2. Run fsck on your filesystem

    [root@foo1 ~]# e2fsck -f /dev/sdb1

    e2fsck 1.41.12 (17-May-2010)

    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

    /dev/sdb1: 15/261120 files (0.0% non-contiguous), 363953/1044192 blocks

  • 3. Resize the filesystem with resize2fs

    [root@foo1 ~]# resize2fs /dev/sdb1 400M

    resize2fs 1.41.12 (17-May-2010)

    Resizing the filesystem on /dev/sdb1 to 409600 (1k) blocks.

    The filesystem on /dev/sdb1 is now 409600 blocks long.

    4. Delete the partition

    [root@foo1 ~]# fdisk /dev/sdb

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

    switch off the mode (command 'c') and change display units to

    sectors (command 'u').

    Command (m for help): d

    Selected partition 1

    Command (m for help): p

    Disk /dev/sdb: 1073 MB, 1073741824 bytes

    255 heads, 63 sectors/track, 130 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x2dbb9f13

    Device Boot Start End Blocks Id System

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Syncing disks.

    4. Create a new (smaller) partition

  • [root@foo1 ~]# fdisk /dev/sdb

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

    switch off the mode (command 'c') and change display units to

    sectors (command 'u').

    Command (m for help): n

    Command action

    e extended

    p primary partition (1-4)

    p

    Partition number (1-4): 1

    First cylinder (1-130, default 1):

    Using default value 1

    Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +400M

    Command (m for help): p

    Disk /dev/sdb: 1073 MB, 1073741824 bytes

    255 heads, 63 sectors/track, 130 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x2dbb9f13

    Device Boot Start End Blocks Id System

    /dev/sdb1 1 52 417658+ 83 Linux

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Syncing disks.

    5. Mount the new partition and filesystem

  • TweetTweet 1 0

    [root@foo1 ~]# mount /dev/sdb1 /geekpeek/

    [root@foo1 ~]# df -h

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_foo-LogVol01

    13G 4.6G 7.7G 38% /

    tmpfs 376M 0 376M 0% /dev/shm

    /dev/sda1 485M 105M 355M 23% /boot

    /dev/sdb1 388M 323M 45M 88% /geekpeek

    Voila! The partition was successfully reduced to 400MB, as we can seeall of the data survived! Always remember to resize the filesystemwith resize2fs.

    4LikeLike

    Manage Users and Groups on Linux

    2 weeks ago

    Build Apache 2.4.9 RPM on CentOS 6 RPM

    Download

    1 month ago

    Kickstart File on CentOS 6

  • 2 months ago

    % All Posts, CentOS, FileSystem Resize Partition and Filesystemwith fdisk &... & centos, filesystem

    About the Author: Mitch

    I am an Open Source enthusiast and Red Hat Certified LinuxProfessional. I have been working professionally with Linux and OpenSource Software for over 7 years. I started GeekPeek.Net to share mylinux knowledge with you.

    3 Responses

    1. dan says:April 26, 2014 at 1:28 am

    Hi Mitch,Nice comprehensive, precise guide for onine-resizing!This is exactly what i was searching for.Have your site bookmarked now.

    I am deeply open-source interested as well, but its more ahobby of mine.Do you have a tipp for a good start into linux serveradministration perhaps? (and a recommendation for a suitabledistro as well)

    Thanks in advance, dan

  • Reply

    Mitch says:May 3, 2014 at 8:19 am

    Hi Dan! Nice to hear from another open sourceenthusiast Where to start? It all depends what youwant from it. To work with linux professionally red hatclassess and certifications are the best. You learneverything from fundamentals up and it is really intense!As far as distributions go, i prefer red hat and centosover ubuntu. It is in the end your choice to make.Regards, Mitch

    Reply

    2. aliosha says:June 10, 2014 at 5:29 pm

    Hello Mtch:Thanks so much for the tutorial.I have a question; keeps complaining Bad magic number insuper-block while trying to open /dev/sdb1. The superblockcould not be read or does not describe a correct ext2 filesystem... after creates the new partition. We tried with thealternative superblock provided by mke2fs -n /dev/sdb1 withthe same luck.Do you have any idea of what may be wrong?-aliosha

    Reply

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Name *

  • Email *

    Website

    Comment

    You may use these HTML tags and attributes:

    Post Comment

    Linux Cluster Part 3 Manage Cluster Nodes and Resources ResetFile Permissions on CentOS 6

    All rights reserved 2014 GeekPeek.Net

    Powered by Wordpress . Designed by Themnific