Install Packages required to mount window partition in Ubuntu 24
sudo apt install ntfs-3g fuse3
Make Directory to mount Window Partition C
sudo mkdir -p /mnt/windows_c
Find partition to mount:
sudo fdisk -l
Output:
Disk /dev/loop0: 4 KiB, 4096 bytes, 8 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 /dev/loop1: 55.36 MiB, 58052608 bytes, 113384 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 /dev/loop2: 63.7 MiB, 66789376 bytes, 130448 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 /dev/loop3: 74.27 MiB, 77881344 bytes, 152112 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 /dev/loop4: 269.77 MiB, 282873856 bytes, 552488 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 /dev/loop5: 73.88 MiB, 77463552 bytes, 151296 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 /dev/loop6: 10.72 MiB, 11239424 bytes, 21952 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 /dev/loop7: 91.69 MiB, 96141312 bytes, 187776 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 /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: PM9B1 NVMe Samsung 512GB
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: gpt
Disk identifier: D312188E-7631-40DA-9BB4-EB29F963E1A6
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 411647 409600 200M EFI System
/dev/nvme0n1p2 411648 673791 262144 128M Microsoft reserved
/dev/nvme0n1p3 673792 504090623 503416832 240G Microsoft basic data
/dev/nvme0n1p4 504090624 954650623 450560000 214.8G Linux filesystem
/dev/nvme0n1p5 954650624 956852223 2201600 1G Windows recovery environment
/dev/nvme0n1p6 956852224 997101567 40249344 19.2G Windows recovery environment
/dev/nvme0n1p7 997103616 1000187903 3084288 1.5G Windows recovery environment
Disk /dev/loop8: 505.09 MiB, 529625088 bytes, 1034424 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 /dev/loop9: 11.11 MiB, 11649024 bytes, 22752 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 /dev/loop10: 301.45 MiB, 316096512 bytes, 617376 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 /dev/loop11: 38.83 MiB, 40714240 bytes, 79520 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 /dev/loop12: 10.54 MiB, 11051008 bytes, 21584 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 /dev/loop13: 500 KiB, 512000 bytes, 1000 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 /dev/loop14: 149.63 MiB, 156901376 bytes, 306448 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 /dev/loop16: 568 KiB, 581632 bytes, 1136 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 /dev/loop15: 1.77 MiB, 1855488 bytes, 3624 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 /dev/loop17: 150.29 MiB, 157593600 bytes, 307800 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
We have identified C: as /dev/nvme0n1p3
sudo mount -t ntfs-3g /dev/nvme0n1p3 /mnt/windows_c
As this failed with following error
NTFS signature is missing.
Failed to mount '/dev/nvme0n1p3': Invalid argument
The device '/dev/nvme0n1p3' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
Lets use other method:
sudo blkid
Output:
/dev/nvme0n1p4: UUID="2be2c7c1-62de-4734-8373-48e0fc083321" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="d2d1f772-7ad2-44b8-b4a6-c3651ff97179"
/dev/loop1: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/nvme0n1p7: LABEL="DELLSUPPORT" BLOCK_SIZE="512" UUID="AA46EDC646ED92FD" TYPE="ntfs" PARTUUID="56b859e8-8a4f-43f1-8673-39f46dc6ac4b"
/dev/nvme0n1p5: LABEL="WINRETOOLS" BLOCK_SIZE="512" UUID="AED6479BD64762A7" TYPE="ntfs" PARTUUID="d0944af5-6b66-4830-a766-71376d7b791b"
/dev/nvme0n1p3: TYPE="BitLocker" PARTLABEL="Basic data partition" PARTUUID="9838e955-a1ed-4bb2-b548-ff0bbfee5dea"
/dev/nvme0n1p1: LABEL_FATBOOT="ESP" LABEL="ESP" UUID="9280-D831" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="5c9392f9-e8a7-4bda-a20a-9cbbc370888e"
/dev/nvme0n1p6: LABEL="Image" BLOCK_SIZE="512" UUID="CEF647B2F647999B" TYPE="ntfs" PARTUUID="401fff82-a681-4e84-b2a7-617f3215afd4"
/dev/loop17: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop8: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop15: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop6: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop13: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop4: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop11: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop2: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop0: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop9: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop16: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop7: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop14: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop5: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop12: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop3: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/loop10: BLOCK_SIZE="131072" TYPE="squashfs"
/dev/nvme0n1p2: PARTLABEL="Microsoft reserved partition" PARTUUID="b10249a2-2134-4fc3-ab2b-46a1239d75b8"
Install
sudo apt install dislocker
sudo mkdir /mnt/bitlocker
sudo dislocker -r -V /dev/nvme0n1p3 -- /mnt/bitlocker
The unlocked data will be accessible in the dislocker-file within /mnt/bitlocker:
sudo mount -o loop /mnt/bitlocker/dislocker-file /mnt/windows_c
Automounting Partitions at Boot:
we need to find the UUID of window partition.
Hence
sudo blkid /dev/nvme0n1p3
Output:
/dev/nvme0n1p3: TYPE="BitLocker" PARTLABEL="Basic data partition" PARTUUID="9838e955-a1ed-4bb2-b548-ff0bbfee5dea"
Edit fstab file:
sudo nano /etc/fstab
Add following at end of file:
# Mount the BitLocker partition using dislocker
UUID=9838e955-a1ed-4bb2-b548-ff0bbfee5dea /mnt/bitlocker dislocker defaults 0 0
# Mount the unlocked data
/mnt/bitlocker/dislocker-file /mnt/windows_c ntfs-3g defaults,windows_names,locale=en_US.utf8 0 0
If we prefer that partition is not mounted automatically then we need to update above to following
# Mount the BitLocker partition using dislocker, do not auto-mount
UUID=9838e955-a1ed-4bb2-b548-ff0bbfee5dea /mnt/bitlocker dislocker noauto 0 0
# Mount the unlocked data, do not auto-mount
/mnt/bitlocker/dislocker-file /mnt/windows_c ntfs-3g noauto,defaults,windows_names,locale=en_US.utf8 0 0
But then you have to manually mount & unmount it.
Manually Mounting whenever needed:
sudo dislocker -r -V /dev/nvme0n1p3 -- /mnt/bitlocker
sudo mount -o loop /mnt/bitlocker/dislocker-file /mnt/windows_c
Manually Unmounting at shutdown:
sudo umount /mnt/windows_c
sudo umount /mnt/bitlocker
I will prefer automated mounting approach.
Now I need to gracefully unmount it before shutdown automatically.
So lets have Script to Unmount Partitions
sudo nano /usr/local/bin/unmount_bitlocker.sh
Add following code into it
#!/bin/bash
# Unmount the unlocked data
umount /mnt/windows_c 2>/dev/null
# Unmount the dislocker mount
umount /mnt/bitlocker 2>/dev/null
save & exit.
Make script executable
sudo chmod +x /usr/local/bin/unmount_bitlocker.sh
Create a service to call this script
sudo nano /etc/systemd/system/unmount-bitlocker.service
Add following content to it
[Unit]
Description=Unmount BitLocker Partitions
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/unmount_bitlocker.sh
RemainAfterExit=yes
[Install]
WantedBy=halt.target reboot.target shutdown.target
Lets enable the service so it runs at shutdown.
sudo systemctl enable unmount-bitlocker.service
Now suppose you modified this service then to make it
work do following
sudo systemctl daemon-reload
sudo systemctl enable unmount-bitlocker.service
Test the Configuration: After making changes, you can test it by running:
sudo mount -a
Now, every time the system is shutting down, your script will
run and unmount the BitLocker partitions automatically & boot
time it will mount the system.
We need to test this setup by shutting down your system and
ensuring the partitions are unmounted as expected.
Automated mounting approach fails so /etc/fstab is modified as
# Mount the BitLocker partition using dislocker, do not auto-mount
UUID=9838e955-a1ed-4bb2-b548-ff0bbfee5dea /mnt/bitlocker dislocker noauto 0 0
# Mount the unlocked data, do not auto-mount
/mnt/bitlocker/dislocker-file /mnt/windows_c ntfs-3g noauto,defaults,windows_names,locale=en_US.utf8 0 0
I am creating script to run after boot:
sudo nano /usr/local/bin/mount_bitlocker.sh
Add following content to it
#!/bin/bash
# Mounting BitLocker-encrypted drive
sudo dislocker -r -V /dev/nvme0n1p3 -- /mnt/bitlocker
# Mount the dislocker file
sudo mount -o loop /mnt/bitlocker/dislocker-file /mnt/windows_c
save & exit.
Make script executable
sudo chmod +x /usr/local/bin/mount_bitlocker.sh
create a service
sudo nano /etc/systemd/system/mount_bitlocker.service
Add Following content to service
[Unit]
Description=Mount BitLocker Encrypted Drive
After=local-fs.target
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/mount_bitlocker.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Save & Exit.
Enable service:
sudo systemctl enable mount_bitlocker.service
Test Script Manually
sudo /usr/local/bin/mount_bitlocker.sh
I checked this approach now its working.
No comments:
Post a Comment