ابزار کاربر

ابزار سایت


tutorials:file_system:how-to-resize-ext4-root-partition-live-without-umount

تغییر اندازه پارتیشن ریشه ext4 بدون umount در لینوکس

در این آموزش سعی داریم طریقه افزایش پارتیشن روت را بدون آنکه آنرا unmount کنیم را به شما آموزش دهیم

اگر اطلاعات مهم و حساسی دارید حتما بک آپ تهیه نمایید تا در صورت خطاهای احتمالی مشکلی برای اطلاعات شما ایجاد نشود

همانطور که در دستور زیر میبنید پارتیشن روت ما 7.8 گیگابایت است

df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  642M  6.8G   9% /

ولی اندازه دیسک ما 20 گیگابایت است با دستور fdisk دقت کنید

fdisk -l
 
Disk /dev/xvda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xd7f2e0e8
 
Device     Boot Start      End  Sectors Size Id Type
/dev/xvda1 *     4096 16773119 16769024   8G 83 Linux

پارتیشن فوق به عنوان ریشه تعریف شده و نمیشه unmount کرد به دستور زیر دقت کنید

umount /
umount: /: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

این مرحله مهم هست ما پارتیشن روت را پاک میکنیم و دقیقا در همان سکتور مرتبط به پارتیشن روت اقدام به ساختش میکنیم همانطور که در پارتیشن روت ما مشخص هست از سکتور ۴۰۹۶ شروع میشود پس با دستور زیر اقدام به فراخوانی پارتیشن توسط fdisk میکنیم

fdisk /dev/xvda
 
Welcome to fdisk (util-linux 2.25.2).                                                                                                                                                           
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Command (m for help): p
Disk /dev/xvda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xd7f2e0e8
 
Device     Boot Start      End  Sectors Size Id Type
/dev/xvda1 *     4096 16773119 16769024   8G 83 Linux

بازم تاکید میکنم که حتما سکتور شروع پارتیشن روت را یادداشت کنید که برای ما ۴۰۹۶ است پس با دستور زیر اقدام به حذف پارتیشن روت میکنیم

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

در این مرحله یک پارتیشن جدید میسازیم و مجددا تاکید میکنم که شروع سکتور پارتیشن روت که برای من ۴۰۹۶ بود باشد

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 4096
Last sector, +sectors or +size{K,M,G,T,P} (4096-41943039, default 41943039): 
 
Created a new partition 1 of type 'Linux' and of size 20 GiB.

پارتیشن ۱ را بوتیبیل کنید و از پارتیشن ها خروجی بگیرید

Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.
 
Command (m for help): p
Disk /dev/xvda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xd7f2e0e8
 
Device     Boot Start      End  Sectors Size Id Type
/dev/xvda1 *     4096 41943039 41938944  20G 83 Linux

تغییرات را ذخیره کنید

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
 
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

در این مرحله باید سیستم را ریستارت کنید تا روت با فضای جدید شروع به کار کند قبل از ریستارت بهتر است fsck را فعال کنید تا بعد از ریستارت پارتیشن چک شود برای این منظور یک فایل خالی با اسم forcefsck در روت / بسازید

touch /forcefsck

بعد از ریستارت مجددا اندازه پارتیشن روت را بررسی میکنیم

df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G  644M   19G   4% /

همانطور که در خروجی مشخص هست پارتیشن روت به ۲۰ گیگابایت تغییر کرده است و برای بار آخر توسط fsck پارتیشن را چک میکنیم

tune2fs -l /dev/xvda1
tutorials/file_system/how-to-resize-ext4-root-partition-live-without-umount.txt · آخرین ویرایش: 2019/01/04 10:45 توسط phoenix

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki