Ubuntu 20.04 Essentials
上QQ阅读APP看书,第一时间看更新

5.4 Accessing the Windows Partition from the Command-line

When running Ubuntu in a dual boot configuration it is still possible to access files located on the Windows partition. This can be achieved by manually mounting the partition from the command-line or from the desktop using the Disks (gnome-disks) graphical utility.

When working from the command-line, the first step in this process is to create a directory to use as the mount point for our Windows partition. In this example we will create a directory named /mnt/windows:

# mkdir /mnt/windows

In order to identify the device name that has been assigned to the Windows partition, use the fdisk command as follows:

# fdisk -l

.

.

Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 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: 0x7ef44412

 

Device Boot Start End Sectors Size Id Type

/dev/sda1 * 2048 1187839 1185792 579M 7 HPFS/NTFS/exFAT

/dev/sda2 1187840 59770533 58582694 28G 7 HPFS/NTFS/exFAT

/dev/sda3 59770878 104855551 45084674 21.5G 5 Extended

/dev/sda5 59770880 104855551 45084672 21.5G 83 Linux

.

.

In the above output, the main Windows partitions can be identified from the NTFS entry in the type column. In the above example output the system contains one physical disk drive referenced by device name /dev/sda. The first is the Windows system partition while the second, much larger, NTFS partition is the Windows boot partition containing the Windows operating system and user data. This partition contains the files we need access to and is represented by /dev/sda2.

With this knowledge, we need to run the mount command (assuming the Windows partition is /dev/sda2) as follows:

# mount /dev/sda2 /mnt/windows

Check that the mount was successful by listing the contents of the top level directory of the mount point:

# ls /mnt/windows

‘$Recycle.Bin’ ProgramData swapfile.sys

‘Documents and Settings’ ‘Program Files’ ‘System Volume Information’

 pagefile.sys ‘Program Files (x86)’ Users

 PerfLogs Recovery Windows

To automate the mount each time the system is booted, simply add the appropriate mount line to the /etc/fstab file:

/dev/sda2 /mnt/windows ntfs defaults 0 0

To unmount the Windows file system at any time:

# umount /mnt/windows