Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: Force mkfs.xfs to overwrite #718

Merged
merged 1 commit into from
Jul 23, 2024
Merged

Conversation

sacsant
Copy link
Contributor

@sacsant sacsant commented Jul 23, 2024

Reusing a disk (after manually deleting partitions on it) with xfs
as file system, install to-disk command fails complaning about
existing file system on root partition.

Creating root filesystem (xfs) on device /dev/sdb2 (size=107.4 GB)

mkfs.xfs -m uuid=4826aa5b-0dd0-4382-a0c1-7c0b77cfd47d -L root /dev/sdb2
mkfs.xfs: /dev/sdb2 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.

Use the -f option with mkfs.xfs to force overwrite.

Signed-off-by: Sachin Sant sachinp@linux.ibm.com

@cgwalters
Copy link
Collaborator

Hm, you got this even when specifying --wipe? Or did you run wipefs manually?

@cgwalters
Copy link
Collaborator

(after manually deleting partitions on it)

Ah yes you did say that. Well...we have to-disk --wipe for this reason which note explicitly clears each child device too. (I don't know why wipefs doesn't have --recursive or so...probably wouldn't be hard to add)

How about: Only if --wipe is passed then we also pass -f to the mkfs invocations?

@sacsant
Copy link
Contributor Author

sacsant commented Jul 23, 2024

Hm, you got this even when specifying --wipe? Or did you run wipefs manually?

Yes, the sequence I tried was as follows. I used bootc install to-disk command to write images to /dev/sdb which was successful. The partition table was as follows:

$ fdisk -l /dev/sdb
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 26214400 sectors
..........
Disklabel type: gpt
Disk identifier: 647711E3-99C1-4591-95C6-EEDDD647BF2D

Device     Start      End  Sectors  Size Type
/dev/sdb1    256     1279     1024    4M PowerPC PReP boot
/dev/sdb2   1280 26214394 26213115  100G Linux filesystem
$

I then deleted the 2 partitions on /dev/sdb manually using disk command.

$ fdisk /dev/sdb

Welcome to fdisk (util-linux 2.40.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2, default 2): 

Partition 2 has been deleted.

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

Command (m for help): p
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 26214400 sectors
Disk model: VDASD           
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 647711E3-99C1-4591-95C6-EEDDD647BF2D

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

After this when I ran the bootc install command it failed with the mentioned error. Even though --wipe was specified it only wiped the data on /dev/sdb.

Writing manifest to image destination
Installing image: docker://quay.io/sacsant/bootc:latest
Digest: sha256:9a52a5ed463a951331338f7dca7b9bcacf22fc14af64c62dfc0e63aeb21151d1
Wiping /dev/sdb
Wiping device /dev/sdb
/dev/sdb: 8 bytes were erased at offset 0x00001000 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 8 bytes were erased at offset 0x18fffff000 (gpt): 45 46 49 20 50 41 52 54
/dev/sdb: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sdb: calling ioctl to re-read partition table: Success
Block setup: direct
       Size: 107374182400
     Serial: <unknown>
      Model: VDASD           
Initializing partitions
Reread partition table
Creating root filesystem (xfs) on device /dev/sdb2 (size=107.4 GB)
> mkfs.xfs -m uuid=23e201f4-8d49-4587-a0e9-cdd466aa3a0d -L root /dev/sdb2
mkfs.xfs: /dev/sdb2 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
ERROR Installing to disk: Creating rootfs: Task Creating root filesystem (xfs) on device /dev/sdb2 (size=107.4 GB) failed: ExitStatus(unix_wait_status(256))

@cgwalters
Copy link
Collaborator

There's a flip side to this in that this "existing partitions" check is the only thing right now that stops one from actively destroying e.g. the booted disk if --wipe is used: we definitely need to strengthen the to-disk path to bail hard if the device is mounted for example, even if --wipe is specified.

(xref https://lwn.net/Articles/941764/ )

Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

Reusing a disk (after manually deleting partitions on it) with
xfs as file system, install to-disk command fails complaning about
existing file system on root partition.

Creating root filesystem (xfs) on device /dev/sdb2 (size=107.4 GB)
> mkfs.xfs -m uuid=4826aa5b-0dd0-4382-a0c1-7c0b77cfd47d -L root /dev/sdb2
mkfs.xfs: /dev/sdb2 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.

Use the -f option with mkfs.xfs to force overwrite when --wipe is used.

Signed-off-by: Sachin Sant <sachinp@linux.ibm.com>
Signed-off-by: Colin Walters <walters@verbum.org>
@cgwalters
Copy link
Collaborator

(This was missing a cargo fmt; in this repo remember to run make validate before pushing)

@cgwalters cgwalters enabled auto-merge July 23, 2024 19:35
@cgwalters cgwalters merged commit 356943a into containers:main Jul 23, 2024
8 of 28 checks passed
@sacsant
Copy link
Contributor Author

sacsant commented Jul 24, 2024

(This was missing a cargo fmt; in this repo remember to run make validate before pushing)

Thanks. Will take care of this requirement for future PRs.

@sacsant sacsant deleted the xfs-fix branch August 11, 2024 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants