Was scared just now — extend the partition

NeilZhang
NeilZhang
管理员
140
文章
106.8千
浏览
Linux评论378字数 1208阅读4分1秒阅读模式

Have to say, these days I should be more careful when I dealt with any problem.

I have extended many partitions in the past, including the real environment or in my VMs. And I also know this is a very dangerous action, so for every step, need to know what I am doing and the possible result.

I know this, but this is not enough!

Today I wanted to enlarge a partition in an AWS EC2 instance. I could create a new partition but in that way I have to do more extra actions when I manage the data files in the future, so I prefer to extend the existing partition.

OK, did a check first:

  1. [root@oradump ~]# fdisk -l
  2. WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
  3.  
  4. Disk /dev/xvda: 10.7 GB, 10737418240 bytes, 20971520 sectors
  5. Units = sectors of 1 * 512 = 512 bytes
  6. Sector size (logical/physical): 512 bytes / 512 bytes
  7. I/O size (minimum/optimal): 512 bytes / 512 bytes
  8. Disk label type: gpt
  9.  
  10.  
  11. # Start End Size Type Name
  12. 1 2048 4095 1M BIOS boot parti
  13. 2 4096 20971486 10G Microsoft basic
  14.  
  15. Disk /dev/xvdf: 1073.7 GB, 1073741824000 bytes, 2097152000 sectors
  16. Units = sectors of 1 * 512 = 512 bytes
  17. Sector size (logical/physical): 512 bytes / 512 bytes
  18. I/O size (minimum/optimal): 512 bytes / 512 bytes
  19. Disk label type: dos
  20. Disk identifier: 0x00000000
  21.  
  22. Device Boot Start End Blocks Id System
  23. /dev/xvdf1 1 1048575999 524287999+ ee GPT

I recalled parted could resize partition directly so I searched and found there should be 'resize' or 'resizepart' subcommands, but I could not find them in the system (RHEL7.3), so just one way left to me: deleting the current partition, and creating a new partition with the same start point. I read some webpages and knew I should use 'unit s' to get the actual sector for every partition, and did it as below:

  1. (parted) select /dev/xvdf
  2. Using /dev/xvdf
  3. (parted) print
  4. Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the
  5. backup to the end (and removing the old backup)?
  6. Fix/Ignore/Cancel? Fix
  7. Warning: Not all of the space available to /dev/xvdf appears to be used, you can fix the GPT to use all of the space (an extra 1048576000 blocks) or continue with the current
  8. setting?
  9. Fix/Ignore? Fix
  10. Model: Xen Virtual Block Device (xvd)
  11. Disk /dev/xvdf: 1074GB
  12. Sector size (logical/physical): 512B/512B
  13. Partition Table: gpt
  14. Disk Flags:
  15.  
  16. Number Start End Size File system Name Flags
  17. 1 1049kB 2097kB 1049kB bios_grub
  18. 2 2097kB 537GB 537GB xfs
  19. (parted) unit s
  20. (parted) p
  21. Model: Xen Virtual Block Device (xvd)
  22. Disk /dev/xvdf: 2097152000s
  23. Sector size (logical/physical): 512B/512B
  24. Partition Table: gpt
  25. Disk Flags:
  26.  
  27. Number Start End Size File system Name Flags
  28. 1 2048s 4095s 2048s bios_grub
  29. 2 4096s 1048575966s 1048571871s xfs
  30. (parted) rm 2
  31. (parted) mkpart primary xfs 4096s 2097152000s
  32. Error: The location 2097152000s is outside of the device /dev/xvdf.
  33. (parted) mkpart primary xfs 4096s 2097151999s
  34. Warning: You requested a partition from 4096s to 2097151999s (sectors 4096..2097151999).
  35. The closest location we can manage is 4096s to 2097151966s (sectors 4096..2097151966).
  36. Is this still acceptable to you?
  37. Yes/No? Yes
  38. (parted) p
  39. Model: Xen Virtual Block Device (xvd)
  40. Disk /dev/xvdf: 2097152000s
  41. Sector size (logical/physical): 512B/512B
  42. Partition Table: gpt
  43. Disk Flags:
  44.  
  45. Number Start End Size File system Name Flags
  46. 1 2048s 4095s 2048s bios_grub
  47. 2 4096s 2097151966s 2097147871s xfs primary
  48. (parted) quit
  49. Information: You may need to update /etc/fstab.

Tried to mount it:

  1. [root@oradump ~]# mount /dev/xvdf2 /oracle
  2. mount: wrong fs type, bad option, bad superblock on /dev/xvdf2,
  3. missing codepage or helper program, or other error
  4.  
  5. In some cases useful info is found in syslog - try
  6. dmesg | tail or so.
  7. [root@oradump ~]# mount -t xfs /dev/xvdf2 /oracle
  8. mount: wrong fs type, bad option, bad superblock on /dev/xvdf2,
  9. missing codepage or helper program, or other error
  10.  
  11. In some cases useful info is found in syslog - try
  12. dmesg | tail or so.

I guessed maybe something wrong. The partition name was /dev/xvdf1, but at that time it became /dev/xvdf2!

I run 'fdisk -l', and it did become /dev/xvdf2.

And I tried the following things in a short time:

  1. changed the partition type to 'Linux Filesystem'
  2. removed both partitions and created a new one large partition
  3. tried to adjust the start sector to 34

All of them failed to mount the filesystem, so I did lose my mind. I just did one thing right -- in such situation, never write any data on it.

I know I can change the partition many times as the partition information will not destroy the filesystem, which is stored at the beginning of the hard disk, and some in the end of the partition.

Why not checked the message file? Usually when I lose my mind, I will not do any change on the system, and just check the log files.

This time, the message file save me again!

  1. Apr 24 07:01:01 oradump systemd: Stopping user-0.slice.
  2. Apr 24 07:01:27 oradump kernel: xvdf: xvdf1 xvdf2
  3. Apr 24 07:02:15 oradump kernel: XFS (xvdf2): Filesystem has duplicate UUID 3ed41454-00c8-4803-bf61-2ee88aa54dbf - can't mount
  4. Apr 24 07:03:02 oradump kernel: XFS (xvdf2): Filesystem has duplicate UUID 3ed41454-00c8-4803-bf61-2ee88aa54dbf - can't mount
  5. Apr 24 07:04:43 oradump kernel: xvdf: xvdf1 xvdf2
  6. Apr 24 07:04:49 oradump kernel: xvdf: xvdf1 xvdf2
  7. Apr 24 07:04:54 oradump kernel: XFS (xvdf2): Filesystem has duplicate UUID 3ed41454-00c8-4803-bf61-2ee88aa54dbf - can't mount
  8. Apr 24 07:08:30 oradump kernel: xvdf: xvdf1 xvdf2

So it seems I could not mount it just because the UUID was duplicated, right? Google helped me many many times!

XFS Filesystem has duplicate UUID problem

My Putty kept long history so I restored the partitions to the initial layout, and tried the nouuid option:

  1. [root@oradump log]# mount -o nouuid -t xfs /dev/xvdf2 /oracle
  2. [root@oradump log]# df -h
  3. Filesystem Size Used Avail Use% Mounted on
  4. /dev/xvda2 10G 2.7G 7.4G 27% /
  5. devtmpfs 1.9G 0 1.9G 0% /dev
  6. tmpfs 1.8G 5.4M 1.8G 1% /dev/shm
  7. tmpfs 1.8G 73M 1.7G 5% /run
  8. tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
  9. tmpfs 354M 0 354M 0% /run/user/1002
  10. /dev/xvdf2 500G 500G 140M 100% /oracle
  11. [root@oradump log]# ls /oracle
  12. 11gr2 base dmp_files install new_7z oraInventory source swapfile

So I got my files back finally!

  1. [root@oradump log]# umount /oracle
  2. [root@oradump log]# xfs_admin -U generate /dev/xvdf2
  3. Clearing log and setting UUID
  4. writing all SBs
  5. new UUID = 1a0a2a4c-7791-41f9-b3d9-3cb357ff05a9
  6. [root@oradump log]# mount -t xfs /dev/xvdf2 /oracle
  7. [root@oradump log]# xfs_growfs /oracle
  8. meta-data=/dev/xvdf2 isize=512 agcount=334, agsize=393216 blks
  9. = sectsz=512 attr=2, projid32bit=1
  10. = crc=1 finobt=0 spinodes=0
  11. data = bsize=4096 blocks=131071483, imaxpct=25
  12. = sunit=0 swidth=0 blks
  13. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
  14. log =internal bsize=4096 blocks=2560, version=2
  15. = sectsz=512 sunit=0 blks, lazy-count=1
  16. realtime =none extsz=4096 blocks=0, rtextents=0
  17. data blocks changed from 131071483 to 262143483
  18. [root@oradump log]# df -h
  19. Filesystem Size Used Avail Use% Mounted on
  20. /dev/xvda2 10G 2.7G 7.4G 27% /
  21. devtmpfs 1.9G 0 1.9G 0% /dev
  22. tmpfs 1.8G 5.4M 1.8G 1% /dev/shm
  23. tmpfs 1.8G 73M 1.7G 5% /run
  24. tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
  25. tmpfs 354M 0 354M 0% /run/user/1002
  26. /dev/xvdf2 1000G 500G 501G 50% /oracle

One issue left for me: how to quit parted without saving?

And more important, I should backup the partition table first!

 
  • 本文由 NeilZhang 发表于25/04/2017 01:37:18
  • Repost please keep this link: https://www.dbcloudsvc.com/blogs/linux/was-scared-just-now-extend-the-partition/
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定